diff --git a/cogs/serveradmin.py b/cogs/serveradmin.py index 9fee40ce..12206792 100644 --- a/cogs/serveradmin.py +++ b/cogs/serveradmin.py @@ -41,7 +41,7 @@ async def remove(self, ctx): await ctx.defer(ephemeral=True) lang = await locale_2_lang(ctx) await ctx.bot.remove_channel(ctx.channel.id) - await ctx.interaction.edit_original_message(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) + await ctx.interaction.edit_original_response(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) @staticmethod async def post_selection(ctx, registration=False): @@ -86,7 +86,7 @@ async def post_selection(ctx, registration=False): notifiers.append(ch[0]) if not list(set(notifiers).intersection(channels)): - await ctx.interaction.edit_original_message( + await ctx.interaction.edit_original_response( content=ctx.bot.translations[lang]['msg']['no_regular_reg'], view=None) await data_cursor.close() return 0 @@ -97,12 +97,12 @@ async def post_selection(ctx, registration=False): args = view.value if args is None: - await ctx.interaction.edit_original_message( + await ctx.interaction.edit_original_response( content=ctx.bot.translations[lang]['msg']['timed_out'], view=None) await data_cursor.close() return 1 if args == 'cancel': - await ctx.interaction.edit_original_message( + await ctx.interaction.edit_original_response( content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) await data_cursor.close() return -1 @@ -138,7 +138,7 @@ async def settings(self, ctx): status = await self.post_selection(ctx) if status is None: - await ctx.interaction.edit_original_message(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) + await ctx.interaction.edit_original_response(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) @register.command( description='Make the bot start posting rotation updates in this channel', @@ -154,7 +154,7 @@ async def rotations(self, ctx): await self.post_selection(ctx, True) - await ctx.interaction.edit_original_message(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) + await ctx.interaction.edit_original_response(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) await ctx.bot.force_update(['daily', 'weekly'], get=False, channels=[ctx.channel.id], forceget=False) return @@ -169,7 +169,7 @@ async def changelogs(self, ctx): if not await message_permissions(ctx, lang): return await ctx.bot.register_channel(ctx, 'updates') - await ctx.interaction.edit_original_message(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) + await ctx.interaction.edit_original_response(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) return @slash_command(name='lfgcleanup', @@ -217,7 +217,7 @@ async def sl_rmnotifier(self, ctx): if not await message_permissions(ctx, lang): return await ctx.bot.remove_channel(ctx.channel.id) - await ctx.interaction.edit_original_message(content=ctx.bot.translations[lang]['msg']['command_is_done'], + await ctx.interaction.edit_original_response(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) @set.command( @@ -234,16 +234,16 @@ async def sl_setlang(self, ctx): await view.wait() args = view.value + if args is not None: + data_cursor = await ctx.bot.guild_db.cursor() + await data_cursor.execute('''UPDATE language SET lang=? WHERE server_id=?''', + (args[0].lower(), ctx.guild.id)) + await ctx.bot.guild_db.commit() + await data_cursor.close() + if ctx.guild.me.guild_permissions.change_nickname: + await ctx.guild.me.edit(nick=ctx.bot.translations[args[0].lower()]['nick'], reason='language change') msg = ctx.bot.translations[lang]['msg']['command_is_done'] - - data_cursor = await ctx.bot.guild_db.cursor() - await data_cursor.execute('''UPDATE language SET lang=? WHERE server_id=?''', - (args[0].lower(), ctx.guild.id)) - await ctx.bot.guild_db.commit() - await data_cursor.close() - if ctx.guild.me.guild_permissions.change_nickname: - await ctx.guild.me.edit(nick=ctx.bot.translations[args[0].lower()]['nick'], reason='language change') - await ctx.interaction.edit_original_message(content=msg, view=None) + await ctx.interaction.edit_original_response(content=msg, view=None) @set.command(name='clan', description='Set a Destiny 2 clan for the server', @@ -399,7 +399,7 @@ async def sl_update(self, ctx): args = view.value if args is None: - await ctx.interaction.edit_original_message( + await ctx.interaction.edit_original_response( content=ctx.bot.translations[lang]['msg']['timed_out'], view=None) return @@ -414,14 +414,14 @@ async def sl_update(self, ctx): regular_types = ctx.bot.all_types.copy() if not list(set(notifiers).intersection(channels)): if list(set(regular_types).intersection(args)): - await ctx.interaction.edit_original_message(content=ctx.bot.translations[lang]['msg']['no_regular_reg'], view=None) + await ctx.interaction.edit_original_response(content=ctx.bot.translations[lang]['msg']['no_regular_reg'], view=None) await data_cursor.close() return else: if list(set(regular_types).intersection(args)): correct_ch = True await ctx.bot.force_update(args, get=get, channels=channels, forceget=get) - await ctx.interaction.edit_original_message(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) + await ctx.interaction.edit_original_response(content=ctx.bot.translations[lang]['msg']['command_is_done'], view=None) await data_cursor.close() return @@ -449,7 +449,7 @@ async def lfgreminder(self, ctx, enable: Option(bool, "Enable or disable LFG ale pass await guild_cursor.close() - await ctx.interaction.edit_original_message(content=ctx.bot.translations[lang]['msg']['command_is_done']) + await ctx.interaction.edit_original_response(content=ctx.bot.translations[lang]['msg']['command_is_done']) @set.command( name='timezone', diff --git a/cogs/utils/views.py b/cogs/utils/views.py index e0c9fd9d..b8ad4c22 100644 --- a/cogs/utils/views.py +++ b/cogs/utils/views.py @@ -17,11 +17,11 @@ async def callback(self, interaction: discord.Interaction): # if interaction.user != self.view.owner: # return if self.button_type == 'confirm': - await interaction.edit_original_message(content='OK', embed=None, view=None) + await interaction.edit_original_response(content='OK', embed=None, view=None) self.view.value = True self.view.stop() elif self.button_type == 'cancel': - await interaction.edit_original_message(content=self.view.cancel_line, embed=None, view=None) + await interaction.edit_original_response(content=self.view.cancel_line, embed=None, view=None) self.view.value = False self.view.stop() elif self.button_type == 'raid': @@ -50,7 +50,7 @@ async def callback(self, interaction: discord.Interaction): self.view.stop() elif self.button_type == 'custom': self.view.value = 'custom' - await interaction.edit_original_message(content=self.response_line) + await interaction.edit_original_response(content=self.response_line) self.view.stop() elif self.button_type == 'all_upd_types': self.view.value = 'all' @@ -77,6 +77,18 @@ async def callback(self, interaction: discord.Interaction): self.view.stop() +class MentionableSelect(discord.ui.Select): + def __init__(self, max_values, row=1): + super().__init__(select_type=discord.enums.ComponentType.mentionable_select, max_values=max_values, row=row) + + async def callback(self, interaction: discord.Interaction): + await interaction.response.defer() + self.view.value = [] + for selected in self.values: + self.view.value.append(selected) + self.view.stop() + + class ConfirmView(discord.ui.View): def __init__(self, cancel_line, owner, confirm='Confirm', cancel='Cancel'): super().__init__() @@ -131,11 +143,11 @@ def __init__(self, bot_id, support_label='Support', invite_label='Invite me'): class RoleLFG(discord.ui.View): - def __init__(self, max_val, options, owner, is_edit=False, manual='Enter manually', auto='Automatic', + def __init__(self, max_val, owner, is_edit=False, manual='Enter manually', auto='Automatic', no_change='nochange', response_line='Enter names of the roles', has_custom=True): super().__init__() self.owner = owner - self.select = MySelect(min_values=1, max_values=max_val, options=options, row=1) + self.select = MentionableSelect(max_values=max_val, row=1) if has_custom: self.custom_button = MyButton(type='custom', label=manual, style=discord.ButtonStyle.gray, row=2, response_line=response_line) @@ -438,7 +450,7 @@ async def on_error(self, error: Exception, interaction: discord.Interaction) -> bot_info = await self.bot_loc.bot.application_info() locale = await locale_2_lang(self.bot_loc) if isinstance(error, OverflowError): - await interaction.edit_original_message(content=self.bot_loc.bot.translations[locale]['overflow_error'], view=None) + await interaction.edit_original_response(content=self.bot_loc.bot.translations[locale]['overflow_error'], view=None) return owner = bot_info.owner if owner.dm_channel is None: @@ -452,7 +464,7 @@ async def on_error(self, error: Exception, interaction: discord.Interaction) -> self.bot_loc.bot.logger.exception(traceback_str) command_line = '/lfg is_edit:{}'.format(self.is_edit) await owner.dm_channel.send('{}:\n{}'.format(interaction.user, command_line)) - await interaction.edit_original_message(content=self.bot_loc.bot.translations[locale]['error'], view=None) + await interaction.edit_original_response(content=self.bot_loc.bot.translations[locale]['error'], view=None) values = self.children self.bot_loc.bot.logger.info('Role LFG: \nname={}\ndescription={}\ntime={}\nsize={}\nlength={}\na_type={}\n' 'mode={}\nroles={}'. @@ -527,38 +539,38 @@ async def callback(self, interaction: discord.Interaction): await interaction.response.send_message(content=translations['type'], view=view, ephemeral=True) await view.wait() if view.value is None: - await interaction.edit_original_message(content='Timed out') + await interaction.edit_original_response(content='Timed out') return self.a_type = view.value view = ModeLFG(interaction.user, self.is_edit, basic=translations['basic_mode'], manual=translations['manual_mode'], no_change=translations['button_no_change']) - await interaction.edit_original_message( + await interaction.edit_original_response( content=translations['mode'].format(translations['manual_mode'], translations['basic_mode']), view=view) await view.wait() if view.value is None: - await interaction.edit_original_message(content='Timed out') + await interaction.edit_original_response(content='Timed out') return self.mode = view.value - role_list = [] - for role in interaction.guild.roles: - if role.mentionable and not role.managed: - role_list.append(discord.SelectOption(label=role.name, value=str(role.id))) - if len(role_list) > 25: - role_list = role_list[:25] - if len(role_list) == 0: - view.value = '-' - else: - view = RoleLFG(len(role_list), role_list, interaction.user, self.is_edit, - manual=translations['manual_roles'], - auto=translations['auto_roles'], has_custom=False, - no_change=translations['button_no_change']) - await interaction.edit_original_message(content=translations['role'], view=view) - await view.wait() + # role_list = [] + # for role in interaction.guild.roles: + # if role.mentionable and not role.managed: + # role_list.append(discord.SelectOption(label=role.name, value=str(role.id))) + # if len(role_list) > 25: + # role_list = role_list[:25] + # if len(role_list) == 0: + # view.value = '-' + # else: + view = RoleLFG(25, interaction.user, self.is_edit, + manual=translations['manual_roles'], + auto=translations['auto_roles'], has_custom=False, + no_change=translations['button_no_change']) + await interaction.edit_original_response(content=translations['role'], view=view) + await view.wait() if view.value is None: - await interaction.edit_original_message(content='Timed out') + await interaction.edit_original_response(content='Timed out', view=None) return False elif view.value in ['-']: role = '-' @@ -576,11 +588,9 @@ async def callback(self, interaction: discord.Interaction): pass else: role = '' - self.roles = [] - for role_id in view.value: + self.roles = view.value + for role_obj in view.value: try: - role_obj = interaction.guild.get_role(int(role_id)) - self.roles.append(role_obj) role = '{} {};'.format(role, role_obj.name) except ValueError: pass @@ -590,7 +600,7 @@ async def callback(self, interaction: discord.Interaction): role = role[:-1] values = self.children - await interaction.edit_original_message(content=translations['processing'], view=None) + await interaction.edit_original_response(content=translations['processing'], view=None) if self.is_edit: button_inputs = await self.validate_edits(self.a_type, self.mode, self.roles, role) else: @@ -629,11 +639,11 @@ async def callback(self, interaction: discord.Interaction): value=time_str ) - await interaction.edit_original_message(content=check_msg, embed=check_embed, view=view) + await interaction.edit_original_response(content=check_msg, embed=check_embed, view=view) await view.wait() if view.value is None: - await interaction.edit_original_message(content='Timed out') + await interaction.edit_original_response(content='Timed out', view=None, embed=None) return elif not view.value: return diff --git a/requirements.txt b/requirements.txt index 2225f490..1b9ab74b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,7 @@ typed-ast<2.0 urllib3>=1.24.2 Werkzeug>=0.15.3 wrapt==1.10.11 -py-cord[speed]==2.0.1 +py-cord[speed]==2.3.0 pydest>=0.6 bs4 apscheduler