Skip to content

Commit 2ec9b5d

Browse files
FluxticksRyth-csTrimatix
authored
Fixed some bugs and made some enhancements in the MusicCog (#67)
* Added music_channels as a new table to be part of schema * Added MusicCog - MusicCog has set channel and get channel * getmusicchannel now mentions the channel instead of listing the id * Added on_message event to capture messages * Added youtube searcher * Changed youtube search to use youtube-search-python pip module * ID validation now raises MissingRequirementArgument when the id is not valid * Added video to mp3 downloading * Changed invalid ids to use UserInputError instead of MissingRequiredArgument * Implemented basic queue and song playing * Music controls now check if user is in same channel as bot * on_message checks if there is an entry in the db first * Bot can now play songs in a queue * Added song skip * Added some comments * Added stub to create message of the current queue * Added check if no 'lyric' or 'audio' videos available to use basic search * Added queue string formatting - Fixed a bug that caused some song files to not be saved correctly - Fixed a bug that caused the bot to skip the song if paused * Added more fields to music_channels table * Now has a currently playing and queue in specified channel. - Also made some more methods async * Added interaction feedback messages for commands * Added channel reset command * Changed filepaths to use os.pathsep * Added queue clear - Title of songs in queue now use top hit title instead of the video title * Music is now streamed from youtube instead of downloading a file * Uses UoY Esports logo as idle image * Fixed a bug that caused links to not show a preview image * Player now gets the audio stream at play time instead of search time - This change means playlists load faster and that it now supports long playlists - Also added shufflequeue command * Added pip requirements to requirements.txt * Looped tasks now stop when the lists are empty and get restarted on song request * Added daily limiter * Updated README to include MusicCog commands * Added time allowance reset on 24hr task.loop * Now supports multiple requests per message when split by newline - Fixed a bug that caused links and playlists to be interpreted incorrectly * Added docstrings and some code cleanup * Removed grequests requirement * Removed BeautifulSoup4 requirement * - Added ENV VAR to enable/disable music cog. - Changed ENV VAR from GOOGLE_API_PERSONAL to GOOGLE_API. - Allowed setmusicchannel to take a mentioned channel. * Included necessary requirements to function within Docker * Added random header to youtube request to decrease chance of being blocked * Made suggested changes * Change channel purge from using math.inf to sys.maxsize * Fixed an issue where a non-async call was awaited * Fixed a bug that caused playlists to fail * Now uses YouTube API to get titles and thumbnails. * Updated docstrings and added Type hinting * Added more user feedback for commands * Fixed a bug that caused messages to not be deleted when the user was not in a valid voice channel * Removed some unnecessary type hinting for functions with no return * Fixed a bug that caused the bot to not leave when the channel was empty. * Updated README to include pausesong * Fixed an issued caused by not all videos having a "maxres" thumbnail. * Update src/esportsbot/cogs/MusicCog.py Co-authored-by: Jasper Law <1jasperlaw@gmail.com> * Update src/esportsbot/cogs/MusicCog.py Co-authored-by: Jasper Law <1jasperlaw@gmail.com> * Fixed an issue that caused the id of a video to not be obtained. * Updated README * Fixed a bug where playlists would not play * Changed how determining if a link is a playlist or a video. * Changed how determining if a link is a playlist or a video. * Fixed a bug when removing the current song from the queue will skip the next song too. * Fixed a bug where time allocated would be used when the video is too long to play * Fixed an issue where the time allowed would not visually reset, even when the value is actually reset. * Added command for administrators to reset the music allowance of a server. * Refactored message deleting in the music channel to be in on_message * Added setvolume command * Updated footer of preview message * Fixed a bug that caused the bot to not leave as the check_marked_channels task was not running * Added aliases to user-facing commands. * Minor code cleanup and a few doc strings added. * Removed time allowance restriction * No longer polls db each message to check if in music channel * Combined reaction menu and music bot on_message methods * Stopped non-youtube URLs being queried * Updated reST DocStrings to include param and return types * Base strings added for MusicCog * Added strings for commands * Added queue valid options string * Implemented user facing strings from TOML file * Removed strict typing for command args that are meant to be integers * Fixed a bug that caused a crash when a video had None as its view count * Fixed a bug that caused commands not be processed * Strict-Typed user_strings attribute to dict * Fixed on_message handle to prevent role pings Co-authored-by: Ryth-cs <rts512@york.ac.uk> Co-authored-by: Jasper Law <1jasperlaw@gmail.com> Co-authored-by: Ryth-cs <49680490+Ryth-cs@users.noreply.github.com>
1 parent a321742 commit 2ec9b5d

File tree

4 files changed

+467
-270
lines changed

4 files changed

+467
-270
lines changed

src/esportsbot/bot.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,32 @@ async def on_command_error(ctx: Context, exception: Exception):
226226
@client.event
227227
async def on_message(message):
228228
if not message.author.bot:
229-
# Ignore self messages
230-
guild_id = message.guild.id
231-
music_channel_in_db = db_gateway().get('music_channels', params={'guild_id': guild_id})
232-
if len(music_channel_in_db) > 0 and message.channel.id == music_channel_in_db[0].get('channel_id'):
233-
# The message was in a music channel and a song should be found
234-
music_cog_instance = client.cogs.get('MusicCog')
235-
await music_cog_instance.on_message_handle(message)
236-
237-
# If message was command, perform the command
238-
await client.process_commands(message)
229+
# Process non-dm messages
230+
if message.guild is not None:
231+
# Start pingable role cooldowns
232+
if message.role_mentions:
233+
roleUpdateTasks = client.handleRoleMentions(message)
234+
235+
# Handle music channel messages
236+
guild_id = message.guild.id
237+
music_channel_in_db = client.MUSIC_CHANNELS.get(guild_id)
238+
if music_channel_in_db:
239+
# The message was in a music channel and a song should be found
240+
music_cog_instance = client.cogs.get('MusicCog')
241+
await music_cog_instance.on_message_handle(message)
242+
await client.process_commands(message)
243+
await message.delete()
244+
else:
245+
await client.process_commands(message)
246+
247+
if message.role_mentions and roleUpdateTasks:
248+
await asyncio.wait(roleUpdateTasks)
249+
for task in roleUpdateTasks:
250+
if e := task.exception():
251+
lib.exceptions.print_exception_trace(e)
252+
# Process DM messages
253+
else:
254+
await client.process_commands(message)
239255

240256

241257
@client.command()
@@ -250,20 +266,6 @@ async def initialsetup(ctx):
250266
await ctx.channel.send("This server has now been initialised")
251267

252268

253-
@client.event
254-
async def on_message(message: discord.Message):
255-
if message.guild is not None and message.role_mentions:
256-
roleUpdateTasks = client.handleRoleMentions(message)
257-
await client.process_commands(message)
258-
if roleUpdateTasks:
259-
await asyncio.wait(roleUpdateTasks)
260-
for task in roleUpdateTasks:
261-
if e := task.exception():
262-
lib.exceptions.print_exception_trace(e)
263-
else:
264-
await client.process_commands(message)
265-
266-
267269
@client.event
268270
async def on_guild_role_delete(role: discord.Role):
269271
"""Handles unregistering of pingme roles when deleted directly in discord instead of via admin command
@@ -288,6 +290,7 @@ def launch():
288290

289291
# Generate Database Schema
290292
generate_schema()
293+
client.update_music_channels()
291294

292295
client.load_extension('esportsbot.cogs.VoicemasterCog')
293296
client.load_extension('esportsbot.cogs.DefaultRoleCog')

0 commit comments

Comments
 (0)