if recipient is None

This commit is contained in:
2025-02-15 13:57:47 -05:00
parent 9d23438b13
commit 6463ace40c
9 changed files with 617 additions and 716 deletions

View File

@ -29,7 +29,7 @@ class Radio(commands.Cog):
"""Run on Bot Ready"""
await self.radio_init()
def is_radio_chan(): # pylint: disable=no-method-argument
def is_radio_chan(): # type: ignore
"""Check if channel is radio chan"""
def predicate(ctx):
try:
@ -59,8 +59,12 @@ class Radio(commands.Cog):
"""
try:
(radio_guild, radio_chan) = self.channels['sfm']
channel: discord.TextChannel = self.bot.get_guild(radio_guild)\
.get_channel(radio_chan)
guild: Optional[discord.Guild] = self.bot.get_guild(radio_guild)
if not guild:
return
channel = guild.get_channel(radio_chan)
if not isinstance(channel, discord.VoiceChannel):
return
if not self.bot.voice_clients:
await channel.connect()
try:
@ -84,24 +88,35 @@ class Radio(commands.Cog):
try:
(radio_guild, radio_chan) = self.channels['sfm']
try:
vc: discord.VoiceClient = self.bot.voice_clients[-1]
vc: discord.VoiceProtocol = self.bot.voice_clients[-1]
except:
logging.debug("No voice client, establishing new VC connection...")
channel = self.bot.get_guild(radio_guild)\
.get_channel(radio_chan)
guild: Optional[discord.Guild] = self.bot.get_guild(radio_guild)
if not guild:
return
channel = guild.get_channel(radio_chan)
if not isinstance(channel, discord.VoiceChannel):
return
await channel.connect()
vc = self.bot.voice_clients[-1]
if not(vc.is_playing()) or vc.is_paused():
if not vc.is_playing() or vc.is_paused(): # type: ignore
"""
Mypy does not seem aware of the is_playing, play, and is_paused methods,
but they exist.
"""
logging.info("Detected VC not playing... playing!")
source = discord.FFmpegOpusAudio(self.STREAM_URL,
before_options="-timeout 3000000")
vc.play(source, after=lambda e: logging.info("Error: %s", e)\
if e else None)
vc.play(source, after=lambda e: logging.info("Error: %s", e) if e else None) # type: ignore
# 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}")
self.LAST_NP_TRACK = np_track
if isinstance(vc.channel, discord.VoiceChannel):
await vc.channel.set_status(f"Now playing: {np_track}")
except:
traceback.print_exc()