mirror of
https://github.com/UiO-Gaming/ShiteMusicBot.git
synced 2026-11-05 13:56:51 +01:00
More guild settings.
This commit is contained in:
1 parent
7b2941ae2b
commit
e8225d42f0
4 files changed
+146
-18
No files matched your search
@@ -36,6 +36,7 @@ class Bot(commands.Bot):
|
|||||||
description=config["description"])
|
description=config["description"])
|
||||||
|
|
||||||
self.settings = Settings(**config)
|
self.settings = Settings(**config)
|
||||||
|
# Todo, maybe fix. Ability to set default bot lang in settings
|
||||||
self.localizer = Localizer(self.settings.default_lang_path, "en_en")
|
self.localizer = Localizer(self.settings.default_lang_path, "en_en")
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
|
||||||
@@ -63,7 +64,9 @@ class Bot(commands.Bot):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
elif isinstance(err, commands.NoPrivateMessage):
|
elif isinstance(err, commands.NoPrivateMessage):
|
||||||
await ctx.send(self.localizer.format_string("{commands.not_available_dm}", setting.get_locale(ctx.guild.id)))
|
# Todo, fix, use default bot lang.
|
||||||
|
await ctx.send('That command is not available in DMs')
|
||||||
|
#await ctx.send(self.localizer.format_str("{commands.not_available_dm}", self.settings.get(ctx.guild.id, 'locale', 'default_locale')))
|
||||||
|
|
||||||
elif isinstance(err, commands.CheckFailure):
|
elif isinstance(err, commands.CheckFailure):
|
||||||
pass
|
pass
|
||||||
|
|||||||
+138
-13
@@ -2,6 +2,7 @@ import discord
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from cogs.utils import checks
|
from cogs.utils import checks
|
||||||
|
|
||||||
@@ -10,12 +11,19 @@ class BotSettings:
|
|||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.settings = self.bot.settings
|
self.settings = self.bot.settings
|
||||||
|
|
||||||
|
def format_prefixes(self, prefixes):
|
||||||
|
if prefixes is None:
|
||||||
|
prefixes = [self.bot.settings.default_prefix]
|
||||||
|
formatted = ''
|
||||||
|
for prefix in prefixes:
|
||||||
|
formatted += f'`{prefix}`, '
|
||||||
|
return formatted[:-2]
|
||||||
|
|
||||||
@checks.is_admin()
|
@checks.is_admin()
|
||||||
@commands.group(name='set', hidden=True)
|
@commands.group(name='set', hidden=True)
|
||||||
async def _set(self, ctx):
|
async def _set(self, ctx):
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
await ctx.invoke(self.bot.get_command('help'),
|
await self.current_settings.invoke(ctx)
|
||||||
ctx.command.qualified_name)
|
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@_set.command(name='serverlocale')
|
@_set.command(name='serverlocale')
|
||||||
@@ -40,19 +48,106 @@ class BotSettings:
|
|||||||
prefixes = self.settings.get(ctx.guild.id, 'prefixes', 'default_prefix')
|
prefixes = self.settings.get(ctx.guild.id, 'prefixes', 'default_prefix')
|
||||||
await ctx.send(self.format_prefixes(prefixes))
|
await ctx.send(self.format_prefixes(prefixes))
|
||||||
|
|
||||||
def format_prefixes(self, prefixes):
|
|
||||||
if prefixes is None:
|
|
||||||
prefixes = [self.bot.settings.default_prefix]
|
|
||||||
formatted = ''
|
|
||||||
for prefix in prefixes:
|
|
||||||
formatted += f'`{prefix}`, '
|
|
||||||
return formatted[:-2]
|
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@_set.command(name='setmodrole')
|
@_set.command(name='modrole')
|
||||||
async def set_mod_role(self, ctx, modrole: discord.Role):
|
async def set_mod_role(self, ctx, modrole: discord.Role):
|
||||||
await ctx.send(f'{modrole.name} {modrole.id}')
|
await ctx.send(f'{modrole.name} {modrole.id}')
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@_set.command(name='threshold')
|
||||||
|
async def set_vote_threshold(self, ctx, threshold: int=50):
|
||||||
|
if not 0 <= threshold <= 100:
|
||||||
|
return await ctx.send('Must be between 0 and 100')
|
||||||
|
|
||||||
|
self.bot.settings.set(ctx.guild.id, 'vote_threshold', threshold)
|
||||||
|
threshold = self.bot.settings.get(ctx.guild.id, 'vote_threshold', 50)
|
||||||
|
await ctx.send(f'Vote threshold set to {threshold}%')
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@_set.command(name='textchannels')
|
||||||
|
async def set_music_text(self, ctx, *channels: discord.TextChannel):
|
||||||
|
if channels:
|
||||||
|
channel_ids = [channel.id for channel in channels]
|
||||||
|
self.bot.settings.set(ctx.guild.id, 'channels.text', channel_ids)
|
||||||
|
else:
|
||||||
|
self.bot.settings.set(ctx.guild.id, 'channels.text', None)
|
||||||
|
|
||||||
|
textchannels = self.bot.settings.get(ctx.guild.id, 'channels.text')
|
||||||
|
|
||||||
|
if textchannels:
|
||||||
|
embed = discord.Embed(title='Music command channels set', color=ctx.me.color)
|
||||||
|
channels = [ctx.guild.get_channel(channel) for channel in textchannels]
|
||||||
|
mentioned = [channel.mention for channel in channels if channel is not None]
|
||||||
|
embed.description = ', '.join(mentioned)
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
else:
|
||||||
|
embed = discord.Embed(color=ctx.me.color, description='Music command channels cleared')
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@_set.command(name='voicechannels')
|
||||||
|
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.id, 'channels.voice', channel_ids)
|
||||||
|
else:
|
||||||
|
self.bot.settings.set(ctx.guild.id, 'channels.voice', None)
|
||||||
|
|
||||||
|
voicechannels = self.bot.settings.get(ctx.guild.id, 'channels.voice')
|
||||||
|
|
||||||
|
if voicechannels:
|
||||||
|
embed = discord.Embed(title='Music channels set', color=ctx.me.color)
|
||||||
|
channels = [ctx.guild.get_channel(channel) for channel in voicechannels]
|
||||||
|
mentioned = [channel.name for channel in channels if channel is not None]
|
||||||
|
embed.description = ', '.join(mentioned)
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
else:
|
||||||
|
embed = discord.Embed(color=ctx.me.color, description='Music channels cleared')
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@_set.command(name='listenchannels')
|
||||||
|
async def set_listen_voice(self, ctx, *channels: discord.VoiceChannel):
|
||||||
|
if channels:
|
||||||
|
channel_ids = [channel.id for channel in channels]
|
||||||
|
self.bot.settings.set(ctx.guild.id, 'channels.listen_only', channel_ids)
|
||||||
|
else:
|
||||||
|
self.bot.settings.set(ctx.guild.id, 'channels.listen_only', None)
|
||||||
|
|
||||||
|
listenchannels = self.bot.settings.get(ctx.guild.id, 'channels.listen_only')
|
||||||
|
|
||||||
|
if listenchannels:
|
||||||
|
embed = discord.Embed(title='Listen only channels set', color=ctx.me.color)
|
||||||
|
channels = [ctx.guild.get_channel(channel) for channel in listenchannels]
|
||||||
|
mentioned = [channel.name for channel in channels if channel is not None]
|
||||||
|
embed.description = ', '.join(mentioned)
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
else:
|
||||||
|
embed = discord.Embed(color=ctx.me.color, description='Listen only channels cleared')
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
@commands.guild_only()
|
||||||
|
@_set.command(name='djroles')
|
||||||
|
async def set_dj_roles(self, ctx, *roles: discord.Role):
|
||||||
|
print(roles)
|
||||||
|
role_ids = [role.id for role in roles]
|
||||||
|
if roles:
|
||||||
|
self.bot.settings.set(ctx.guild.id, 'roles.dj', role_ids)
|
||||||
|
else:
|
||||||
|
self.bot.settings.set(ctx.guild.id, 'roles.dj', None)
|
||||||
|
|
||||||
|
djroles = self.bot.settings.get(ctx.guild.id, 'roles.dj')
|
||||||
|
|
||||||
|
if djroles:
|
||||||
|
embed = discord.Embed(title='DJ roles set to', color=ctx.me.color)
|
||||||
|
roles = [ctx.guild.get_role(role) for role in djroles]
|
||||||
|
mentioned = [role.name for role in roles if role is not None]
|
||||||
|
embed.description = ', '.join(mentioned)
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
else:
|
||||||
|
embed = discord.Embed(color=ctx.me.color, description='DJ roles cleared')
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@_set.command(name='current')
|
@_set.command(name='current')
|
||||||
async def current_settings(self, ctx):
|
async def current_settings(self, ctx):
|
||||||
@@ -61,10 +156,40 @@ class BotSettings:
|
|||||||
embed.set_thumbnail(url=ctx.guild.icon_url)
|
embed.set_thumbnail(url=ctx.guild.icon_url)
|
||||||
|
|
||||||
prefixes = self.bot.settings.get(ctx.guild.id, 'prefixes', 'default_prefix')
|
prefixes = self.bot.settings.get(ctx.guild.id, 'prefixes', 'default_prefix')
|
||||||
|
embed.add_field(name='Prefix', value=self.format_prefixes(prefixes))
|
||||||
|
|
||||||
locale = f"{self.bot.settings.get(ctx.guild.id, 'locale', 'default_locale')}"
|
locale = f"{self.bot.settings.get(ctx.guild.id, 'locale', 'default_locale')}"
|
||||||
embed.add_field(name='Locale', value=locale)
|
embed.add_field(name='Locale', value=locale)
|
||||||
embed.add_field(name='Prefix', value=self.format_prefixes(prefixes))
|
|
||||||
await ctx.send(embed=embed)
|
threshold = self.bot.settings.get(ctx.guild.id, 'vote_threshold', 50)
|
||||||
|
embed.add_field(name='Vote threshold', value=f'{threshold}%')
|
||||||
|
|
||||||
|
textchannels = self.bot.settings.get(ctx.guild.id, 'channels.text')
|
||||||
|
if textchannels:
|
||||||
|
channels = [ctx.guild.get_channel(channel) for channel in textchannels]
|
||||||
|
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.id, 'channels.voice')
|
||||||
|
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))
|
||||||
|
|
||||||
|
listenchannels = self.bot.settings.get(ctx.guild.id, 'channels.listen_only')
|
||||||
|
if listenchannels:
|
||||||
|
channels = [ctx.guild.get_channel(channel) for channel in listenchannels]
|
||||||
|
mentioned = [channel.name for channel in channels if channel is not None]
|
||||||
|
embed.add_field(name='Listen only channels', value='\n'.join(mentioned))
|
||||||
|
|
||||||
|
djroles = self.bot.settings.get(ctx.guild.id, 'roles.dj')
|
||||||
|
if djroles:
|
||||||
|
roles = [ctx.guild.get_role(role) for role in djroles]
|
||||||
|
mentioned = [role.name for role in roles if role is not None]
|
||||||
|
embed.add_field(name='Dj roles', value=', '.join(mentioned))
|
||||||
|
|
||||||
|
msg = await ctx.send(embed=embed)
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|||||||
+3
-3
@@ -55,10 +55,10 @@ class Cogs:
|
|||||||
"""Reloads all extensions"""
|
"""Reloads all extensions"""
|
||||||
try:
|
try:
|
||||||
for extension in self.bot.extensions:
|
for extension in self.bot.extensions:
|
||||||
if extension == 'cogs':
|
if extension == 'cogs.cogs':
|
||||||
continue
|
continue
|
||||||
self.bot.unload_extension(f'cogs.{extension}')
|
self.bot.unload_extension(f'{extension}')
|
||||||
self.bot.load_extension(f'cogs.{extension}')
|
self.bot.load_extension(f'{extension}')
|
||||||
await ctx.send('Extensions reloaded')
|
await ctx.send('Extensions reloaded')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.send(f'```py\n{traceback.format_exc()}\n```')
|
await ctx.send(f'```py\n{traceback.format_exc()}\n```')
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class Settings:
|
|||||||
class attribute the value of the attribute will get returned."""
|
class attribute the value of the attribute will get returned."""
|
||||||
guild_id = str(guild_id)
|
guild_id = str(guild_id)
|
||||||
|
|
||||||
if default and hasattr(self, default):
|
if default and isinstance(default, str) and hasattr(self, default):
|
||||||
default = getattr(self, default)
|
default = getattr(self, default)
|
||||||
elif not default:
|
elif not default:
|
||||||
default = None
|
default = None
|
||||||
|
|||||||
Reference in new issue
Block a user