mirror of
https://github.com/UiO-Gaming/ShiteMusicBot.git
synced 2026-11-05 13:56:51 +01:00
custom threshold, command channels and music channels.
This commit is contained in:
1 parent
2d7bf0c36b
commit
0768c4a12d
5 files changed
+62
-20
No files matched your search
+8
-8
@@ -84,19 +84,19 @@ class BotSettings:
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.guild_only()
|
||||
@_set.command(name='voicechannels')
|
||||
@_set.command(name='musicchannels')
|
||||
async def set_music_voice(self, ctx, *channels: discord.VoiceChannel):
|
||||
if channels:
|
||||
channel_ids = [channel.id for channel in channels]
|
||||
self.bot.settings.set(ctx.guild, 'channels.voice', channel_ids)
|
||||
self.bot.settings.set(ctx.guild, 'channels.music', channel_ids)
|
||||
else:
|
||||
self.bot.settings.set(ctx.guild, 'channels.voice', None)
|
||||
self.bot.settings.set(ctx.guild, 'channels.music', None)
|
||||
|
||||
voicechannels = self.bot.settings.get(ctx.guild, 'channels.voice')
|
||||
musicchannels = self.bot.settings.get(ctx.guild, 'channels.music')
|
||||
|
||||
if voicechannels:
|
||||
if musicchannels:
|
||||
embed = discord.Embed(title='Music channels set', color=ctx.me.color)
|
||||
channels = [ctx.guild.get_channel(channel) for channel in voicechannels]
|
||||
channels = [ctx.guild.get_channel(channel) for channel in musicchannels]
|
||||
mentioned = [channel.name for channel in channels if channel is not None]
|
||||
embed.description = ', '.join(mentioned)
|
||||
await ctx.send(embed=embed)
|
||||
@@ -168,11 +168,11 @@ class BotSettings:
|
||||
mentioned = [channel.mention for channel in channels if channel is not None]
|
||||
embed.add_field(name='Text channels', value='\n'.join(mentioned))
|
||||
|
||||
voicechannels = self.bot.settings.get(ctx.guild, 'channels.voice')
|
||||
voicechannels = self.bot.settings.get(ctx.guild, 'channels.music')
|
||||
if voicechannels:
|
||||
channels = [ctx.guild.get_channel(channel) for channel in voicechannels]
|
||||
mentioned = [channel.name for channel in channels if channel is not None]
|
||||
embed.add_field(name='Voice channels', value='\n'.join(mentioned))
|
||||
embed.add_field(name='Music channels', value='\n'.join(mentioned))
|
||||
|
||||
listenchannels = self.bot.settings.get(ctx.guild, 'channels.listen_only')
|
||||
if listenchannels:
|
||||
|
||||
+42
-12
@@ -39,6 +39,18 @@ class Music:
|
||||
lang = self.bot.settings.get(guild, 'locale', 'default_locale')
|
||||
return LocalizerWrapper(self.bot.localizer, lang, "music.response")
|
||||
|
||||
async def __local_check(self, ctx):
|
||||
""" Ensures the commands are used in the correct channels """
|
||||
textchannels = self.bot.settings.get(ctx.guild, 'channels.text', [])
|
||||
if textchannels:
|
||||
if ctx.channel.id not in textchannels:
|
||||
localizer = self.getLocalizer(ctx.guild)
|
||||
response = localizer.format_str('{settings_check.textchannel}')
|
||||
for channel_id in textchannels:
|
||||
response += f'<#{channel_id}>, '
|
||||
await ctx.send(response[:-2])
|
||||
return False
|
||||
return True
|
||||
|
||||
async def __before_invoke(self, ctx):
|
||||
# TODO: rewrite this thing. Probably remove ensure_voice.
|
||||
@@ -134,12 +146,15 @@ class Music:
|
||||
player.add_skipper(ctx.author)
|
||||
total = len(player.listeners)
|
||||
skips = len(player.skip_voters)
|
||||
if skips >= math.ceil(total/2) or player.current.requester == ctx.author.id:
|
||||
threshold = self.bot.settings.get(ctx.guild, 'vote_threshold', 'default_threshold')
|
||||
|
||||
if skips/total >= threshold/100 or player.current.requester == ctx.author.id:
|
||||
await player.skip()
|
||||
await ctx.send(localizer.format_str("{skip.skipped}"))
|
||||
else:
|
||||
if skips != 0:
|
||||
msg = localizer.format_str("{skip.require_vote}", _skips=skips, _total=math.ceil(total/2))
|
||||
needed = math.ceil(total*threshold/100)
|
||||
msg = localizer.format_str("{skip.require_vote}", _skips=skips, _total=needed)
|
||||
await ctx.send(msg)
|
||||
|
||||
@commands.command(name='skipto', aliases=['forceskip','hopptil','tvinghopp'])
|
||||
@@ -662,11 +677,26 @@ class Music:
|
||||
if not should_connect:
|
||||
raise commands.CommandInvokeError('Not connected.')
|
||||
|
||||
permissions = ctx.author.voice.channel.permissions_for(ctx.me)
|
||||
voice_channel = ctx.author.voice.channel
|
||||
|
||||
permissions = voice_channel.permissions_for(ctx.me)
|
||||
|
||||
if not permissions.connect or not permissions.speak: # Check user limit too?
|
||||
raise commands.CommandInvokeError('I need the `CONNECT` and `SPEAK` permissions.')
|
||||
|
||||
voice_channels = self.bot.settings.get(ctx.guild, 'channels.music', [])
|
||||
|
||||
if voice_channels:
|
||||
if voice_channel.id not in voice_channels:
|
||||
localizer = self.getLocalizer(ctx.guild)
|
||||
response = localizer.format_str('{settings_check.voicechannel}')
|
||||
for channel_id in voice_channels:
|
||||
channel = ctx.guild.get_channel(channel_id)
|
||||
if channel is not None:
|
||||
response += f'{channel.name}, '
|
||||
await ctx.send(response[:-2])
|
||||
raise commands.CommandInvokeError('You need to be in the right voice channel')
|
||||
|
||||
player.store('channel', ctx.channel.id)
|
||||
await self.connect_to(ctx.guild.id, str(ctx.author.voice.channel.id))
|
||||
|
||||
@@ -674,15 +704,6 @@ class Music:
|
||||
if int(player.channel_id) != ctx.author.voice.channel.id:
|
||||
raise commands.CommandInvokeError('You need to be in my voicechannel.')
|
||||
|
||||
def max_track_length(self, guild):
|
||||
player = self.bot.lavalink.players.get(guild.id)
|
||||
if len(player.listeners):
|
||||
listeners = len(player.listeners)
|
||||
else:
|
||||
listeners = 1
|
||||
maxlen = max(60*60/listeners, 60*10)
|
||||
return maxlen
|
||||
|
||||
async def enqueue(self, ctx, track, embed):
|
||||
|
||||
player = self.bot.lavalink.players.get(ctx.guild.id)
|
||||
@@ -712,6 +733,15 @@ class Music:
|
||||
duration = lavalink.utils.format_time(int(track.duration))
|
||||
embed.description = f'[{track.title}]({track.uri})\n**{duration}**'
|
||||
|
||||
def max_track_length(self, guild):
|
||||
player = self.bot.lavalink.players.get(guild.id)
|
||||
if len(player.listeners):
|
||||
listeners = len(player.listeners)
|
||||
else:
|
||||
listeners = 1
|
||||
maxlen = max(60*60/listeners, 60*10)
|
||||
return maxlen
|
||||
|
||||
async def on_command_error(self, ctx, err):
|
||||
if isinstance(err, commands.CommandInvokeError):
|
||||
pass
|
||||
|
||||
@@ -80,6 +80,10 @@
|
||||
"track": "`{_index}.` **[{_title}]({_uri})** _by <@{_id}>_",
|
||||
"previous": "**{_len} Previous songs:**",
|
||||
"empty": "There are no tracks in the history"
|
||||
},
|
||||
"settings_check": {
|
||||
"textchannel": "You can't use music commands in this channel.\nTry in: ",
|
||||
"voicechannel": "I can only play music in: "
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,10 @@
|
||||
"track": "`{_index}.` **[{_title}]({_uri})** _av <@{_id}>_",
|
||||
"previous": "**Tidligere sanger ({_len}):**",
|
||||
"empty": "Ingen tidligere spilte sanger"
|
||||
},
|
||||
"settings_check": {
|
||||
"textchannel": "Du kan ikke bruke musikkommandoer i denne kanalen.\nPrøv i: ",
|
||||
"voicechannel": "Jeg kan bare spille musikk i: "
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,10 @@
|
||||
"track": "`{_index}.` **[{_title}]({_uri})** _av <@{_id}>_",
|
||||
"previous": "**Tidlegare songar ({_len}):**",
|
||||
"empty": "Ingen tidlegare spelte songar"
|
||||
},
|
||||
"settings_check": {
|
||||
"textchannel": "Du kan ikkje bruke musikkommandoar i denne kanalen.\nPrøv i: ",
|
||||
"voicechannel": "Eg kan berre spele musikk i: "
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user