async def time_configure(self, author, channel, raid_id): bot = self.bot def check(msg): return author == msg.author msg = await channel.send(_("Please specify the new raid time.")) try: response = await bot.wait_for('message', check=check, timeout=30) except asyncio.TimeoutError: return else: try: await response.delete() except discord.NotFound: pass except discord.Forbidden: await channel.send( _("Missing permissions to clean up your response. Please grant me the 'Manage messages' permission in this channel." )) finally: try: await msg.delete() except discord.NotFound: pass try: timestamp = Time().converter(bot, channel.guild.id, author.id, response.content) except commands.BadArgument: error_msg = _("Failed to parse time argument: ") + response.content await channel.send(error_msg, delete_after=20) else: upsert(self.conn, 'Raids', ['time'], [timestamp], ['raid_id'], [raid_id]) return
async def fastraid(self, ctx, tier: typing.Optional[Tier], *, time: Time()): """Shortcut to schedule a raid""" res = count_rows(self.conn, "Raids", ctx.guild.id) if self.host_id and res >= self.event_limit: # host_id will not be set for private bots msg = _( "Due to limited resources you may only post up to {0} concurrent raids." ).format(self.event_limit) await ctx.send(msg) return name = ctx.invoked_with if name == "fastraid": name = _("unknown raid") if tier is None: tier = await Tier.channel_converter(ctx.channel) if '1' in tier or '2' in tier: roster = False else: roster = True raid_id = await self.raid_command(ctx, name, tier, "", time, roster=roster) self.raids.append(raid_id) await self.bot.get_cog('CalendarCog').update_calendar(ctx.guild.id)
async def fastraid(self, ctx, *, time: Time()): """Shortcut to schedule a raid""" res = count_rows(self.conn, "Raids", ctx.guild.id) if self.host_id and res > 4: # host_id will not be set for private bots await ctx.send( _("Due to limited resources you may only post up to 5 concurrent raids." )) return name = ctx.invoked_with if name == "fastraid": name = _("unknown raid") try: tier = Tier().converter(ctx.channel.name) except commands.BadArgument: msg = _("Channel name does not specify tier.") + "\n" + _( "Defaulting to tier 1.") await ctx.send(msg, delete_after=10) tier = 'T1' if '1' in tier or '2' in tier: roster = False else: roster = True raid_id = await self.raid_command(ctx, name, tier, _("All"), time, roster=roster) self.raids.append(raid_id)
async def raid(self, ctx, name, tier: typing.Optional[Tier], *, time: Time()): """Schedules a raid""" if not await self.check_event_limit(ctx.channel): return if tier is None: tier = await Tier.channel_converter(ctx.channel) await self.raid_command(ctx, name, tier, "", time)
async def raid(self, ctx, name, tier: Tier, *, time: Time()): """Schedules a raid""" res = count_rows(self.conn, "Raids", ctx.guild.id) if self.host_id and res > 4: # host_id will not be set for private bots await ctx.send( _("Due to limited resources you may only post up to 5 concurrent raids." )) return raid_id = await self.raid_command(ctx, name, tier, _("All"), time) self.raids.append(raid_id)
async def meetup(self, ctx, name, *, time: Time()): """Schedules a meetup""" res = count_rows(self.conn, "Raids", ctx.guild.id) if self.host_id and res >= self.event_limit: # host_id will not be set for private bots msg = _( "Due to limited resources you may only post up to {0} concurrent raids." ).format(self.event_limit) await ctx.send(msg) return raid_id = await self.raid_command(ctx, name, "", "", time) self.raids.append(raid_id) await self.bot.get_cog('CalendarCog').update_calendar(ctx.guild.id)
async def aliasraid(self, ctx, tier: typing.Optional[Tier], *, time: Time()): """Shortcut to schedule a raid""" if not await self.check_event_limit(ctx.channel): return name = ctx.invoked_with if name == "aliasraid": name = _("unknown raid") if tier is None: tier = await Tier.channel_converter(ctx.channel) if '1' in tier or '2' in tier: roster = False else: roster = True await self.raid_command(ctx, name, tier, "", time, roster=roster)
async def raid(self, ctx, name, tier: typing.Optional[Tier], *, time: Time()): """Schedules a raid""" res = count_rows(self.conn, "Raids", ctx.guild.id) if self.host_id and res >= self.event_limit: # host_id will not be set for private bots msg = _( "Due to limited resources you may only post up to {0} concurrent raids." ).format(self.event_limit) await ctx.send(msg) return if tier is None: tier = await Tier.channel_converter(ctx.channel) raid_id = await self.raid_command(ctx, name, tier, "", time) self.raids.append(raid_id) await self.bot.get_cog('CalendarCog').update_calendar(ctx.guild.id)
async def meetup(self, ctx, name, *, time: Time()): """Schedules a meetup""" if not await self.check_event_limit(ctx.channel): return await self.raid_command(ctx, name, "", "", time)
async def on_interaction(self, interaction): if interaction.type == discord.InteractionType.application_command_autocomplete: self.handle_autocomplete(interaction) return if interaction.type != discord.InteractionType.application_command: return guild_id = interaction.guild_id if not guild_id: self.interaction_response(interaction, _("Use this command in a server.")) return user = interaction.user d = interaction.data name = d['name'] try: if d['options'][0]['type'] == 1: name = "_".join([name, d['options'][0]['name']]) options = { option['name']: option['value'] for option in d['options'][0]['options'] } else: options = { option['name']: option['value'] for option in d['options'] } except KeyError: options = None ephemeral = True embed = None post_new_raid = False post_new_calendar = False update_roles = False post_events = False guild = self.bot.get_guild(guild_id) channel_required_commands = self.raid_cog.nicknames[:] channel_required_commands.extend( ['custom', 'calendar_channel', 'calendar_both', 'twitter_on']) if name in channel_required_commands: channel = interaction.channel perms = channel.permissions_for(guild.me) if not (perms.send_messages and perms.embed_links): channel = None if name in self.raid_cog.nicknames or name == 'custom': if not channel: content = _("Missing permissions to access this channel.") else: time_arg = options['time'] try: timestamp = Time().converter(self.bot, guild_id, user.id, time_arg) except commands.BadArgument as e: content = str(e) else: content = _("Posting a new raid!") post_new_raid = True elif name.startswith('calendar'): if self.is_raid_leader(user, guild_id): if name in ['calendar_channel', 'calendar_both']: if not channel: content = _( "Missing permissions to access this channel.") else: content = _("Events will be posted to this channel.") post_new_calendar = True else: upsert(self.conn, 'Settings', ['calendar'], [None], ['guild_id'], [guild_id]) if name == 'calendar_discord': content = _( "Events will be posted as discord guild events.") if name == 'calendar_both': content = _( "Events will be posted to this channel and as discord guild events." ) if name == 'calendar_off': content = _("Events will not be posted to a calendar.") guild_events = name in ['calendar_discord', 'calendar_both'] upsert(self.conn, 'Settings', ['guild_events'], [guild_events], ['guild_id'], [guild_id]) else: content = _("You must be a raid leader to set the calendar.") elif name.startswith('twitter'): if user.guild_permissions.administrator: channel_id = None if name == 'twitter_on': try: channel_id = channel.id except AttributeError: content = _( "Missing permissions to access this channel.") else: content = _( "@lotro tweets will be posted to this channel.") elif name == 'twitter_off': content = _( "Tweets will no longer be posted to this channel.") else: return upsert(self.conn, 'Settings', ['twitter'], [channel_id], ['guild_id'], [guild_id]) else: content = _("You must be an admin to set up tweets.") elif name == 'events': ephemeral = False content = _("Waiting for lotro.com to respond...") post_events = True elif name == 'leader': ephemeral = False content = self.parse_leader_slash_command(guild_id, user, options) elif name == 'remove_roles': content = _("Removing your class roles...") update_roles = True elif name == 'time_zones_personal': content = self.process_time_zones_personal(user.id, options) elif name == 'time_zones_server': ephemeral = False content = self.process_time_zones_server(user, guild_id, options) elif name == 'about': ephemeral = False embed = await self.config_cog.about_embed() embed = embed.to_dict() content = '' elif name == 'privacy': ephemeral = False content = _( "**PII:**\n" "When you sign up for a raid the bot stores the time, your discord id, discord nickname and the class(" "es) you sign up with. This information is automatically deleted 2 hours after the scheduled " "raid time or immediately when you cancel your sign up.\n " "If you set a default time zone for yourself, the bot will additionally store your time zone " "along with your discord id such that it can parse times provided in your commands in your " "preferred time zone.") elif name == 'welcome': ephemeral = False content = _( "Greetings {0}! I am confined to Orthanc and here to spend my days doing your raid admin.\n\n" "You can quickly schedule a raid with the `/rem` and `/ad` commands. Examples:\n" "`/rem t2 Friday 8pm`\n" "`/ad t3 26 July 1pm`\n" "Use `/custom` to schedule a custom raid or meetup.\n\n" "With `/calendar` you can get an (automatically updated) overview of all scheduled raids. " "It is recommended you use a separate discord channel to display the calendar in.\n" "Use `/time_zones` to change the default time settings and " "you can designate a raid leader role with `/leader`, which allows non-admins to edit raids." ).format(guild.name) elif name == 'server_time': content = self.process_server_time(guild_id) elif name == 'list_players': ephemeral = False player_msg, success = self.process_list_players( user, guild_id, options) if success: embed = player_msg.to_dict() content = '' else: content = player_msg # string elif name == 'kin': content = self.parse_priority_slash_command( guild_id, user, options) else: content = _("Slash command not yet supported.") self.interaction_response(interaction, content, ephemeral=ephemeral, embed=embed) if post_new_raid: await self.raid_command(name, guild_id, channel, user.id, timestamp, options) elif post_new_calendar: await self.post_calendar(guild_id, channel) elif update_roles: await self.process_roles_command(guild, user, interaction.token) elif post_events: self.process_events_command(guild_id, interaction.token) timestamp = int(datetime.datetime.now().timestamp()) upsert(self.conn, 'Settings', ['last_command'], [timestamp], ['guild_id'], [guild_id]) increment(self.conn, 'Settings', 'slash_count', ['guild_id'], [guild_id]) self.conn.commit()