Skip to content

Commit

Permalink
Fixed some bugs and made some enhancements in the MusicCog (#67)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update src/esportsbot/cogs/MusicCog.py

Co-authored-by: Jasper Law <[email protected]>

* 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 <[email protected]>
Co-authored-by: Jasper Law <[email protected]>
Co-authored-by: Ryth-cs <[email protected]>
  • Loading branch information
4 people authored Jun 3, 2021
1 parent a321742 commit 2ec9b5d
Show file tree
Hide file tree
Showing 4 changed files with 467 additions and 270 deletions.
51 changes: 27 additions & 24 deletions src/esportsbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,32 @@ async def on_command_error(ctx: Context, exception: Exception):
@client.event
async def on_message(message):
if not message.author.bot:
# Ignore self messages
guild_id = message.guild.id
music_channel_in_db = db_gateway().get('music_channels', params={'guild_id': guild_id})
if len(music_channel_in_db) > 0 and message.channel.id == music_channel_in_db[0].get('channel_id'):
# The message was in a music channel and a song should be found
music_cog_instance = client.cogs.get('MusicCog')
await music_cog_instance.on_message_handle(message)

# If message was command, perform the command
await client.process_commands(message)
# Process non-dm messages
if message.guild is not None:
# Start pingable role cooldowns
if message.role_mentions:
roleUpdateTasks = client.handleRoleMentions(message)

# Handle music channel messages
guild_id = message.guild.id
music_channel_in_db = client.MUSIC_CHANNELS.get(guild_id)
if music_channel_in_db:
# The message was in a music channel and a song should be found
music_cog_instance = client.cogs.get('MusicCog')
await music_cog_instance.on_message_handle(message)
await client.process_commands(message)
await message.delete()
else:
await client.process_commands(message)

if message.role_mentions and roleUpdateTasks:
await asyncio.wait(roleUpdateTasks)
for task in roleUpdateTasks:
if e := task.exception():
lib.exceptions.print_exception_trace(e)
# Process DM messages
else:
await client.process_commands(message)


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


@client.event
async def on_message(message: discord.Message):
if message.guild is not None and message.role_mentions:
roleUpdateTasks = client.handleRoleMentions(message)
await client.process_commands(message)
if roleUpdateTasks:
await asyncio.wait(roleUpdateTasks)
for task in roleUpdateTasks:
if e := task.exception():
lib.exceptions.print_exception_trace(e)
else:
await client.process_commands(message)


@client.event
async def on_guild_role_delete(role: discord.Role):
"""Handles unregistering of pingme roles when deleted directly in discord instead of via admin command
Expand All @@ -288,6 +290,7 @@ def launch():

# Generate Database Schema
generate_schema()
client.update_music_channels()

client.load_extension('esportsbot.cogs.VoicemasterCog')
client.load_extension('esportsbot.cogs.DefaultRoleCog')
Expand Down
Loading

0 comments on commit 2ec9b5d

Please sign in to comment.