Skip to content

Commit

Permalink
Merge pull request #95 from Krutyi-4el/develop
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
solaluset authored Jan 27, 2024
2 parents 763df84 + a9cb3f4 commit b1d29e3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
9 changes: 9 additions & 0 deletions config/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
with open("config/config_comments.json", "w") as f:
json.dump(config.get_comments(), f)

yt_dlp_plugins = glob.glob(
os.path.join("musicbot", "yt_dlp_plugins/**/*.py"), recursive=True
)

sys.argv.extend(
[
"--onefile",
Expand All @@ -19,6 +23,7 @@
"--hidden-import="
+ os.path.splitext(file)[0].replace(os.path.sep, ".")
for file in glob.glob("musicbot/**/*.py", recursive=True)
if file not in yt_dlp_plugins
],
"--hidden-import=" + config.DATABASE_LIBRARY,
*[
Expand All @@ -29,6 +34,10 @@
"--add-data=" + file + os.pathsep + "assets"
for file in glob.glob("assets/*.mp3")
],
*[
"--add-data=" + file + os.pathsep + os.path.dirname(file)
for file in yt_dlp_plugins
],
"-p=config",
"-n=DandelionMusic",
"-i=assets/note.ico",
Expand Down
1 change: 1 addition & 0 deletions config/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"STARTUP_MESSAGE": "Starting Bot...",
"SHUTDOWN_MESSAGE": "\nShutting down...",
"STARTUP_COMPLETE_MESSAGE": "Startup Complete",
"STATUS_TEXT": "Music, type {prefix}help",

Expand Down
3 changes: 2 additions & 1 deletion musicbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ async def start(self, *args, **kwargs):
return await super().start(*args, **kwargs)

async def close(self):
print("Shutting down...", flush=True)
if "--run" not in sys.argv:
print(config.SHUTDOWN_MESSAGE, flush=True)

await asyncio.gather(
*(
Expand Down
17 changes: 11 additions & 6 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"""


def shutdown(config, p):
print(config.SHUTDOWN_MESSAGE)
p.stdin.write("shutdown\n")
p.stdin.flush()


def main():
import sys

Expand All @@ -18,6 +24,8 @@ def main():
import signal
import subprocess

from config import config

print("You can close this window and the bot will run in the background")
print("To stop the bot, press Ctrl+C")

Expand All @@ -36,8 +44,8 @@ def main():
def handler(event):
if event != signal.CTRL_C_EVENT:
return
p.stdin.write("shutdown\n")
p.stdin.flush()
shutdown(config, p)
SetHandler(handler, False)

kwargs = {
"creationflags": subprocess.CREATE_NO_WINDOW
Expand Down Expand Up @@ -80,12 +88,9 @@ def new_handler(sig, frame):
while line := p.stdout.readline():
print(line, end="")
except KeyboardInterrupt:
print()
if not on_windows:
p.stdin.write("shutdown\n")
p.stdin.flush()
shutdown(config, p)
# display shutdown message
print(p.stdout.readline(), end="")
print(p.stdout.read(), end="")

exit_code = p.wait()
Expand Down

0 comments on commit b1d29e3

Please sign in to comment.