From 59558ba1af18b8faccf7d09d89334d5cf73e4f42 Mon Sep 17 00:00:00 2001 From: Migatu Date: Tue, 23 Apr 2024 10:42:19 +0200 Subject: [PATCH] Radio hardkor --- bot.py | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index 61b7373..098d376 100644 --- a/bot.py +++ b/bot.py @@ -139,6 +139,7 @@ GET_MP3 = "/mp3" SEND_MP3 = "/update_mp3" GET_PLAYLIST = "/get_music" ADD_TO_PRIO_PLAYLIST = "/add_to_priority" +REQUEST_MUSIC = "/request_radio_file" CLEAR_PRIO = "/clear_pr_pls" LIBRARIAN_SERVICE_ADDRESS = "http://192.168.1.192:5001" SEND_QUERY = "/query" @@ -1579,20 +1580,19 @@ async def graj_muzyko(ctx): ) async def radio_hardkor(ctx): """ - Async function named "graj_muzyko" starts music playback on channel "Nocna Zmiana". + Plays the radio hardkor stream in the voice channel. - :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. This parameter is required in all - Discord.py commands + Args: + ctx: The context object representing the invocation context. + + Returns: + None """ - logger.info("Press play on radio hardkor") async with ctx.typing(): global MUZYKA # pylint: disable=global-variable-not-assigned MUZYKA["ctx"] = ctx await connect(ctx=ctx) - await play(ctx=ctx) logger.info("Press play on radio completed") voice_client = client.voice_clients[0] if not client.voice_clients: @@ -1781,7 +1781,36 @@ async def dodaj_do_ulubionych(ctx): timeout=360, ) _ = await coroutine +@client.hybrid_command( + name="ja_chiol", + description="Dodaje do listy ulubionych w radiu", + guild=discord.Object(id=664789470779932693), +) +async def request_radio(ctx): + """ + Generate a playlist in queue. First word in this command shall be int defining length of the playlist. + Rest of the line are search terms. + :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. This parameter is required in all + Discord.py commands + """ + async with ctx.typing(): + logger.info("Zaczynam szukać timestamp %s", datetime.now()) + + word_list = ctx.message.content.split() + jrequest = { + "lista_slow": word_list, + "UUID": str(uuid.uuid4()), + } + coroutine = asyncio.to_thread( + requests.post, + f"{FILE_SERVICE_ADDRESS}{REQUEST_MUSIC}", + json=jrequest, + timeout=360, + ) + _ = await coroutine @client.hybrid_command( name="wyczysc_ulubione", description="Czysci liste ulubionych w radiu",