From fdbc05c3677b3477a21f4e971e1a56bd119f066d Mon Sep 17 00:00:00 2001 From: Polish Hammer Date: Thu, 30 Oct 2025 16:59:07 +0100 Subject: [PATCH] Tag: 1.13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Intermediate commits (oldest → newest): - UPdate for music tracker - Buffx - Fix - Fix - tst fx - Fx frmt - fx frmt - Fx frmt - Now playing - bgfx - fx - Fix tracker - bgfx - fx - Fx --- bot.py | 26 +++++++++++++++++--- communication_subroutine.py | 16 ++++++------ conjurer_musician/conjurer_musician.py | 34 ++++++++++++++++++++++---- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/bot.py b/bot.py index 6706ded..0e3e1bf 100644 --- a/bot.py +++ b/bot.py @@ -47,6 +47,7 @@ from communication_subroutine import ( OUT_COMM_Q, QueryControl, comm_subroutine, + PREPPED_TRACKS, ) from spotify_dl import spotify from spotify_dl import youtube as youtube_download @@ -2520,10 +2521,29 @@ async def krecimy_pornola(ctx): sciezka, files = await get_file(ctx, "Pornol", item_yt) if files: logger.info("Pornol udany") - ctx.send(f"Jest w tajnym archiwum pod adresem{sciezka})") + await ctx.send(f"Jest w tajnym archiwum pod adresem{sciezka})") else: - ctx.reply("Jak ładnie szefa poprosisz.") + await ctx.reply("Jak ładnie szefa poprosisz.") +@client.hybrid_command( + name="co_na_plejliscie_wariacie", + description="Wyswietl kawalki ktore sa na pocztku list radia", + guild=discord.Object(id=664789470779932693), +) +async def co_na_plejliscie_wariacie(ctx): + """ + Download a music number from youtube. + + :param ctx: ctx stands for "context" and is a parameter commonly used in Discord.py commands. It + represents the context in which the command was invoked, including information such as the message, + the channel, the server, and the user who invoked the command. It allows the command to interact + with the Discord API and + """ + await ctx.send("Dej mnie chwilkę") + async with ctx.typing(): + logger.info("plejlista") + logger.info(PREPPED_TRACKS) + await ctx.send(f"Didżej Hammer i jego sztuczna inteligencja (||he he||) prezentują: \n- obecnie grany jest {(PREPPED_TRACKS['now_playing']).rstrip()} \n- na liście priorytetowej {(PREPPED_TRACKS['priority']).rstrip()} \n- na liście hitów obecnie czeka kawałek {(PREPPED_TRACKS['hit']).rstrip()} \n- na liście wszystkich kawałków {(PREPPED_TRACKS['all']).rstrip()} \n- najświeższym zamówieniem od słuchaczy jest {(PREPPED_TRACKS['requests']).rstrip()} \nZ kolei jingiel to: {(PREPPED_TRACKS['jingles']).rstrip()}") # *================================== Run if __name__ == "__main__": @@ -2531,7 +2551,7 @@ if __name__ == "__main__": threads = [] logger.info("Starting discord bot: Creating threads") threads.append(threading.Thread(target=client.run, args=(TOKEN,))) - threads.append(threading.Thread(target=comm_subroutine, args=(logger,))) + threads.append(threading.Thread(target=comm_subroutine)) logger.info("Starting discord bot: Starting threads") WRK_CNT = 0 for worker in threads: diff --git a/communication_subroutine.py b/communication_subroutine.py index ef4302b..77122f3 100644 --- a/communication_subroutine.py +++ b/communication_subroutine.py @@ -13,13 +13,15 @@ IN_COMM_Q = Queue() awaiting_q = [] incoming_q = Queue() app = Flask(__name__) -prepped_tracks = { +PREPPED_TRACKS = { "requests" : "", - "hits" : "", + "hit" : "", "all": "", - "prio":"", - "jingles":"" + "priority":"", + "jingles":"", + "now_playing":"" } +logger = logging.getLogger("discord") class QueryControl: """ @@ -45,6 +47,7 @@ def log_radio_tracks(): logger.info(request) record = json.loads(request.data) logger.info(record) + PREPPED_TRACKS[record[0]] = record[1] logger.info("DATA RECEIVED") return jsonify("SUCCESS") @@ -145,7 +148,7 @@ def scan_incoming(): time.sleep(1) -def comm_subroutine(logger): +def comm_subroutine(): """ The `comm_subroutine` function starts multiple threads to run different tasks concurrently. @@ -169,5 +172,4 @@ def comm_subroutine(logger): worker.join() if __name__ == "__main__": - logging_client = logging.getLogger(__name__) - comm_subroutine(logging_client) + comm_subroutine() diff --git a/conjurer_musician/conjurer_musician.py b/conjurer_musician/conjurer_musician.py index 8965df1..f626452 100644 --- a/conjurer_musician/conjurer_musician.py +++ b/conjurer_musician/conjurer_musician.py @@ -32,6 +32,7 @@ if platform in ("linux", "linux2"): LOGSTORE = "/home/mtuszowski/conjurer/logs/" ENCODING = "utf-8" RADIOLOG_PATH = '/home/pi/Conjurer/radio_log.log' + PERSISTENCE_PATH = '/home/pi/Conjurer/persistence.log' else: LOGFILE = "/home/pi/Conjurer/discord_mus_service.log" @@ -41,6 +42,7 @@ if platform in ("linux", "linux2"): MUSIC_FOLDER = "/home/pi/RetroPie/mp3/" PRIORITY_FOLDER = "/home/pi/RetroPie/mp3/Magiczne i chuj/" RADIOLOG_PATH = '/home/pi/Conjurer/radio_log.log' + PERSISTENCE_PATH = '/home/pi/Conjurer/persistence.log' music_file_list = [] @@ -102,13 +104,35 @@ def scan_tracks(): logger = logging.getLogger("conjurer_musician") file = open(RADIOLOG_PATH,'r') - #Find the size of the file and move to the end st_results = os.stat(RADIOLOG_PATH) st_size = st_results[6] file.seek(st_size) + st_results1 = os.stat(PERSISTENCE_PATH) + prev_st_size1 = st_results[6] while 1: + + st_results1 = os.stat(PERSISTENCE_PATH) + st_size1 = st_results1[6] + if prev_st_size1 != st_size1: + while prev_st_size1 != st_size1: + prev_st_size1 = st_size1 + st_results1 = os.stat(PERSISTENCE_PATH) + st_size1 = st_results1[6] + time.sleep(0.1) + file1 = open(PERSISTENCE_PATH, 'r') + lines = file1.readlines() + result = ["now_playing", lines[2]] + file1.close() + returned = requests.post( + f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}", + json=result, + timeout=360) + logger.info("SENT") + logger.info(returned.status_code) + logger.info("SEND CONFIRMED") + where = file.tell() line = file.readline() if not line: @@ -126,7 +150,7 @@ def scan_tracks(): logger.info(line) # already has newline result = ["priority", line] elif re.match(".*hit.*", line): - logger.info("priority") + logger.info("hit") logger.info(line) # already has newline result = ["hit", line] elif re.match(".*all_playlist.*", line): @@ -142,9 +166,9 @@ def scan_tracks(): f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}", json=result, timeout=360) - logger.info("SENT") - logger.info(returned.status_code) - logger.info("SEND CONFIRMED") + logger.info("SENT") + logger.info(returned.status_code) + logger.info("SEND CONFIRMED") time.sleep(0.1)