misc/add compliment bridge command
This commit is contained in:
parent
43ecfc6633
commit
2c2d191a08
@ -148,7 +148,7 @@ class Karma(commands.Cog):
|
|||||||
"""Karma Cog for Havoc"""
|
"""Karma Cog for Havoc"""
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
importlib.reload(constants)
|
importlib.reload(constants)
|
||||||
self.bot = bot
|
self.bot: discord.Bot = bot
|
||||||
self.util = Util(self.bot)
|
self.util = Util(self.bot)
|
||||||
# self.karma_regex = regex.compile(r'(\w+)(\+\+|\-\-)')
|
# self.karma_regex = regex.compile(r'(\w+)(\+\+|\-\-)')
|
||||||
self.karma_regex: Pattern = regex.compile(r'(\b\w+(?:\s+\w+)*)(\+\+($|\s)|\-\-($|\s))')
|
self.karma_regex: Pattern = regex.compile(r'(\b\w+(?:\s+\w+)*)(\+\+($|\s)|\-\-($|\s))')
|
||||||
|
34
cogs/misc.py
34
cogs/misc.py
@ -255,6 +255,40 @@ class Misc(commands.Cog):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return await ctx.respond(f"Insult failed :(\nError: {str(e)}")
|
return await ctx.respond(f"Insult failed :(\nError: {str(e)}")
|
||||||
|
|
||||||
|
@bridge.bridge_command()
|
||||||
|
async def compliment(self, ctx, *,
|
||||||
|
recipient: Optional[str] = None) -> None:
|
||||||
|
"""
|
||||||
|
Compliment someone (or yourself)
|
||||||
|
Args:
|
||||||
|
ctx (Any)
|
||||||
|
recipient (Optional[str])
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
|
||||||
|
else ctx.message.author.display_name
|
||||||
|
|
||||||
|
if recipient is None:
|
||||||
|
recipient: str = authorDisplay.strip()
|
||||||
|
else:
|
||||||
|
if discord.utils.raw_mentions(recipient):
|
||||||
|
# There are mentions
|
||||||
|
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
|
||||||
|
recipient: str = self.bot.get_guild(ctx.guild.id)\
|
||||||
|
.get_member(recipient_id).display_name
|
||||||
|
else:
|
||||||
|
recipient: str = discord.utils.escape_mentions(recipient.strip())
|
||||||
|
with ctx.channel.typing():
|
||||||
|
compliment: str = await self.util.get_compliment(recipient)
|
||||||
|
if compliment:
|
||||||
|
return await ctx.respond(compliment)
|
||||||
|
return await ctx.respond("Compliment failed :(")
|
||||||
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
|
return await ctx.respond(f"Compliment failed :(\nError: {str(e)}")
|
||||||
|
|
||||||
@bridge.bridge_command(aliases=['whiskey'])
|
@bridge.bridge_command(aliases=['whiskey'])
|
||||||
async def whisky(self, ctx, *,
|
async def whisky(self, ctx, *,
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
|
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
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
class Radio(commands.Cog):
|
class Radio(commands.Cog):
|
||||||
@ -14,7 +16,7 @@ class Radio(commands.Cog):
|
|||||||
'sfm': (1145182936002482196, 1221615558492029050), # Tuple: Guild Id, Chan Id
|
'sfm': (1145182936002482196, 1221615558492029050), # Tuple: Guild Id, Chan Id
|
||||||
}
|
}
|
||||||
self.STREAM_URL: str = "https://relay.sfm.codey.lol/aces.ogg"
|
self.STREAM_URL: str = "https://relay.sfm.codey.lol/aces.ogg"
|
||||||
|
self.LAST_NP_TRACK: Optional[str] = None
|
||||||
try:
|
try:
|
||||||
self.radio_state_loop.cancel()
|
self.radio_state_loop.cancel()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -75,7 +77,7 @@ class Radio(commands.Cog):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return
|
return
|
||||||
|
|
||||||
@tasks.loop(seconds=2.0)
|
@tasks.loop(seconds=5.0)
|
||||||
async def radio_state_loop(self) -> None:
|
async def radio_state_loop(self) -> None:
|
||||||
"""Radio State Loop"""
|
"""Radio State Loop"""
|
||||||
try:
|
try:
|
||||||
@ -93,7 +95,12 @@ class Radio(commands.Cog):
|
|||||||
source = discord.FFmpegOpusAudio(self.STREAM_URL,
|
source = discord.FFmpegOpusAudio(self.STREAM_URL,
|
||||||
before_options="-timeout 3000000")
|
before_options="-timeout 3000000")
|
||||||
vc.play(source, after=lambda e: logging.info("Error: %s", e)\
|
vc.play(source, after=lambda e: logging.info("Error: %s", e)\
|
||||||
if e else None)
|
if e else None)
|
||||||
|
# Get Now Playing
|
||||||
|
np_track = await get_now_playing()
|
||||||
|
if np_track and not self.LAST_NP_TRACK == np_track:
|
||||||
|
self.LAST_NP_TRACK: str = np_track
|
||||||
|
await vc.channel.set_status(f"Now playing: {np_track}")
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ cogs_list: list[str] = [
|
|||||||
'owner',
|
'owner',
|
||||||
'sing',
|
'sing',
|
||||||
'meme',
|
'meme',
|
||||||
'ai',
|
|
||||||
'karma',
|
'karma',
|
||||||
'lovehate',
|
'lovehate',
|
||||||
'quote',
|
'quote',
|
||||||
|
21
util/radio_util.py
Normal file
21
util/radio_util.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python3.12
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from aiohttp import ClientSession, ClientTimeout
|
||||||
|
|
||||||
|
"""Radio Utils"""
|
||||||
|
|
||||||
|
async def get_now_playing() -> str:
|
||||||
|
np_url: str = "https://api.codey.lol/radio/np"
|
||||||
|
try:
|
||||||
|
async with ClientSession() as session:
|
||||||
|
async with await session.post(np_url, headers={
|
||||||
|
'content-type': 'application/json; charset=utf-8',
|
||||||
|
}, timeout=ClientTimeout(connect=1.5, sock_read=1.5)) as request:
|
||||||
|
request.raise_for_status()
|
||||||
|
response_json = await request.json()
|
||||||
|
artistsong = response_json.get('artistsong')
|
||||||
|
return artistsong
|
||||||
|
except Exception as e:
|
||||||
|
logging.critical("Now playing retrieval failed: %s",
|
||||||
|
str(e))
|
Loading…
x
Reference in New Issue
Block a user