radio: minor/misc_util: add coffee 'Kopi luwak'
This commit is contained in:
		| @@ -62,7 +62,7 @@ class Util: | |||||||
|                         'a chocolate frappuccino', 'a butter pecan coffee', 'a maple pecan latte', |                         '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 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 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 = [] |         self.LAST_5_COFFEES: list = [] | ||||||
|          |          | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ import logging | |||||||
| import traceback | import traceback | ||||||
| from typing import Optional | from typing import Optional | ||||||
| from discord.ext import bridge, commands, tasks | 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 | import discord | ||||||
| from disc_havoc import Havoc | from disc_havoc import Havoc | ||||||
|  |  | ||||||
| @@ -115,6 +115,21 @@ class Radio(commands.Cog): | |||||||
|             #         await vc.channel.set_status(f"Now playing: {np_track}") |             #         await vc.channel.set_status(f"Now playing: {np_track}") | ||||||
|         except: |         except: | ||||||
|             traceback.print_exc() |             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: |     def cog_unload(self) -> None: | ||||||
|         """Run on Cog Unload"""           |         """Run on Cog Unload"""           | ||||||
|   | |||||||
| @@ -7,7 +7,8 @@ from aiohttp import ClientSession, ClientTimeout | |||||||
| async def get_now_playing() -> Optional[str]: | async def get_now_playing() -> Optional[str]: | ||||||
|     """ |     """ | ||||||
|     Get radio now playing |     Get radio now playing | ||||||
|      |     Args: | ||||||
|  |         None | ||||||
|     Returns: |     Returns: | ||||||
|         str |         str | ||||||
|     """ |     """ | ||||||
| @@ -24,4 +25,26 @@ async def get_now_playing() -> Optional[str]: | |||||||
|     except Exception as e: |     except Exception as e: | ||||||
|         logging.critical("Now playing retrieval failed: %s", |         logging.critical("Now playing retrieval failed: %s", | ||||||
|                       str(e)) |                       str(e)) | ||||||
|         return None    |         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    | ||||||
|  |      | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user