diff --git a/cogs/misc_util.py b/cogs/misc_util.py index 9750725..798b6c7 100644 --- a/cogs/misc_util.py +++ b/cogs/misc_util.py @@ -62,7 +62,7 @@ class Util: 'a chocolate frappuccino', 'a butter pecan coffee', 'a maple pecan latte', 'a sea salt caramel mocha', 'a nitro cold brew', 'a pumpkin cold brew', 'a honey almond flat white', 'a sweet cream cold brew', 'a matcha latte', - 'a golden latte', 'a turmeric latte', 'a beetroot latte',] + 'a golden latte', 'a turmeric latte', 'a beetroot latte', 'a Kopi luwak'] self.LAST_5_COFFEES: list = [] diff --git a/cogs/radio.py b/cogs/radio.py index 4a0ed62..8c771ef 100644 --- a/cogs/radio.py +++ b/cogs/radio.py @@ -2,7 +2,7 @@ import logging import traceback from typing import Optional from discord.ext import bridge, commands, tasks -from util.radio_util import get_now_playing +from util.radio_util import get_now_playing, skip import discord from disc_havoc import Havoc @@ -115,6 +115,21 @@ class Radio(commands.Cog): # await vc.channel.set_status(f"Now playing: {np_track}") except: traceback.print_exc() + + @bridge.bridge_command() + @commands.is_owner() + async def skip(self, ctx) -> None: + """ + Skip - Convenience Command + Args: + ctx (Any) + Returns: + None + """ + + await skip() + return await ctx.respond("OK", ephemeral=True) + def cog_unload(self) -> None: """Run on Cog Unload""" diff --git a/util/radio_util.py b/util/radio_util.py index 7e747d4..f2bbc90 100644 --- a/util/radio_util.py +++ b/util/radio_util.py @@ -7,7 +7,8 @@ from aiohttp import ClientSession, ClientTimeout async def get_now_playing() -> Optional[str]: """ Get radio now playing - + Args: + None Returns: str """ @@ -24,4 +25,26 @@ async def get_now_playing() -> Optional[str]: except Exception as e: logging.critical("Now playing retrieval failed: %s", str(e)) - return None \ No newline at end of file + return None + +async def skip() -> bool: + """ + Ask LiquidSoap server to skip to the next track + Args: + None + Returns: + bool + """ + try: + ls_uri: str = "http://127.0.0.1:29000" + async with ClientSession() as session: + async with session.get(f"{ls_uri}/next", + timeout=ClientTimeout(connect=2, sock_read=2)) as request: + request.raise_for_status() + text: Optional[str] = await request.text() + return text == "OK" + except Exception as e: + logging.debug("Skip failed: %s", str(e)) + + return False # failsafe +