Skip to content

Commit

Permalink
Merge pull request #83 from r-Norge/feature/library_updates
Browse files Browse the repository at this point in the history
Update dependencies, force disconnect on empty voice, more typing
  • Loading branch information
Ev-1 authored Jun 22, 2023
2 parents 61d0bfb + ef37fe2 commit 7884b15
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
10 changes: 5 additions & 5 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def __init__(self, datadir, debug: bool = False):
self.settings = Settings(datadir, **conf['default server settings'])
self.APIkeys = conf.get('APIkeys', {})

self.localizer = Localizer(conf.get('locale path', "./localization"), conf.get('locale', 'en_en'))
self.aliaser = Aliaser(conf.get('locale path', "./localization"), conf.get('locale', 'en_en'))
self.localizer: Localizer = Localizer(conf.get('locale path', "./localization"), conf.get('locale', 'en_en'))
self.aliaser: Aliaser = Aliaser(conf.get('locale path', "./localization"), conf.get('locale', 'en_en'))

self.datadir = datadir
self.debug = debug
self.main_logger = logger
self.debug: bool = debug
self.main_logger: BotLogger = logger
self.logger = self.main_logger.bot_logger.getChild("Bot")
self.logger.debug("Debug: %s" % debug)
self.lavalink: Optional[lavalink.Client] = None
Expand All @@ -66,7 +66,7 @@ async def process_commands(self, message):
ctx = await self.get_context(message, cls=LocalizedContext)

# Replace aliases with commands
ctx = self.aliaser.get_command(ctx)
ctx: LocalizedContext = self.aliaser.get_command(ctx)

# Add the localizer
if ctx.command and ctx.command.cog_name:
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default:
# Make a new virtual environment
[private]
make_venv:
python3.10 -m venv {{env_name}}
python3 -m venv {{env_name}}
{{python}} -m pip install --upgrade pip
{{python}} -m pip install -r requirements.txt

Expand Down
20 changes: 7 additions & 13 deletions musicbot/cogs/music/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from .music_errors import MusicError, PlayerNotAvailableError, WrongTextChannelError
from .voice_client import BasicVoiceClient

time_rx = re.compile('[0-9]+')
url_rx = re.compile('https?:\\/\\/(?:www\\.)?.+')


Expand Down Expand Up @@ -199,19 +198,13 @@ async def _forceplay(self, ctx, *, query: str):
@checks.dj_or(alone=True, track_requester=True)
@require_voice_connection()
@require_playing(require_user_listening=True)
async def _seek(self, ctx, *, time: str):
async def _seek(self, ctx, *, seconds: int):
"""Seeks to a given position in a track."""
player = self.get_player(ctx.guild)
if seconds := time_rx.search(time):
# Convert to milliseconds, include sign
milliseconds = int(seconds.group())*1000 * (-1 if time.startswith('-1') else 1)

track_time = player.position + milliseconds
await player.seek(int(track_time))
msg = ctx.localizer.format_str("{seek.track_moved}", _position=timeformatter.format_ms(track_time))
await ctx.send(msg)
else:
await ctx.send(ctx.localizer.format_str("{seek.missing_amount}"))
track_time = player.position + seconds * 1000 # milliseconds
await player.seek(int(track_time))
msg = ctx.localizer.format_str("{seek.track_moved}", _position=timeformatter.format_ms(track_time))
return await ctx.send(msg)

@commands.command(name='skip')
@require_voice_connection()
Expand Down Expand Up @@ -868,8 +861,9 @@ async def check_leave_voice(self, guild: discord.Guild):
if len(player.listeners) == 0 and player.is_connected:
if player.queue.empty and player.current is None:
await player.stop()
voice_client: BasicVoiceClient
if voice_client := guild.voice_client:
await voice_client.disconnect(force=False)
await voice_client.disconnect(force=True)

async def leave_check(self):
for player_id in self.lavalink.player_manager.players:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
discord.py == 2.0.*
discord.py == 2.3.*
lavalink == 4.0.*
asyncio
pyyaml
BeautifulSoup4
pytest
ruff==0.0.263
ruff==0.0.274
pre-commit

0 comments on commit 7884b15

Please sign in to comment.