def command_healthcheck(self, event): if event.msg.channel.guild_id != self.config.indexGuildID: return if not is_mod(self, event.msg.author.id): return self.client.api.channels_typing(event.msg.channel.id) start_servers_healthcheck(self) event.msg.reply('Completed healthcheck')
def command_refresh_index(self, event): if event.msg.channel.guild_id != self.config.indexGuildID: return if not is_mod(self, event.msg.author.id): return self.client.api.channels_typing(event.msg.channel.id) update_discord_index(self) event.msg.reply('Refreshed index')
def on_message_create(self, event): if event.message.channel.guild_id != self.config.indexGuildID: return if event.message.channel.id != self.config.approvalQueueChannelID: return if not is_mod(self, event.message.author.id): return self.denyReasonQueryResponseManager.handle_possible_response( self, event.message) self.queueEditQueryResponseManager.handle_possible_response( self, event.message)
def on_queue_edit_reaction(self, event): if event.channel.guild_id != self.config.indexGuildID: return if event.channel_id != self.config.approvalQueueChannelID: return if not is_mod(self, event.user_id): return bot_queue_message = get_queue_bot_message(self) if not bot_queue_message: return entry = get_entry_from_embed(self, bot_queue_message.embeds[0]) if not entry: return user = self.client.state.users[event.user_id] if not user: return edit_query_text = '<@{user.id}>\n' \ 'Please tell me what change you would like to make for `{entry.name}`.\n' \ 'Say `name <New Name>` to change the name.\n' \ 'Example `name Kpop Server Index`.\n' \ 'Say `description <New Description>` to change the description.\n' \ 'Example `description The server for all Kpop groups.`.\n' \ 'Say `category <#new-category>` to change the category.\n' \ 'Example `category #general`.\n' \ 'Say `cancel` to cancel editing the server.\n'.format( user=user, entry=entry) self.queueEditQueryResponseManager.start_query( self, user.id, event.channel_id, edit_query_text, more_args={'entry': entry}) try: self.client.api.channels_messages_reactions_delete( event.channel_id, event.message_id, event.emoji.name, event.user_id) except APIException: pass
def command_remove(self, event, invite): if event.msg.channel.guild_id != self.config.indexGuildID: return if event.msg.channel.id not in self.config.addChannelIDs: return sudo = False if event.name == 'sudo-remove': if not is_mod(self, event.msg.author.id): return sudo = True self.client.api.channels_typing(event.msg.channel.id) invite_code = extract_invite_code(invite) if len(invite_code) <= 0: event.msg.reply('no invite code found') return discord_server_found = self.db.DiscordServer.get( invite_code=invite_code) if not discord_server_found: event.msg.reply('invite not found in queue or index') return if discord_server_found.invitee_id != event.msg.author.id and sudo == False: event.msg.reply( 'you can only remove entries your submitted yourself') return discord_server_found_data = discord_server_found.to_dict() remove_discord_server(self, discord_server_found, event.msg.author.id) self.log.info( '{author.username} #{author.id} removed ' 'server: #{entry[server_id]} discord.gg/{entry[invite_code]} ' 'name: {entry[name]} description: {entry[description]} ' 'category: {entry[category_channel_name]} genre: {entry[genre_category_name]} ' 'invitee: #{entry[invitee_id]} ' 'submitted at: {entry[submitted_at]} last checked: {entry[submitted_at]} ' 'index message id: {entry[index_message_id]} ' 'sudo: {sudo}'.format(author=event.msg.author, entry=discord_server_found_data, sudo=sudo)) event.msg.reply('Removed!')
def on_queue_reject_reaction(self, event): if event.channel.guild_id != self.config.indexGuildID: return if event.channel_id != self.config.approvalQueueChannelID: return if not is_mod(self, event.user_id): return bot_queue_message = get_queue_bot_message(self) if not bot_queue_message: return entry = get_entry_from_embed(self, bot_queue_message.embeds[0]) if not entry: return user = self.client.state.users[event.user_id] if not user: return deny_query_text = '<@{user.id}>\n' \ 'Please tell me the reason for rejecting `{entry.name}`.\n' \ 'Say `cancel` to cancel rejecting the server.'.format( user=user, entry=entry) self.denyReasonQueryResponseManager.start_query( self, user.id, event.channel_id, deny_query_text, more_args={'entry': entry}) try: self.client.api.channels_messages_reactions_delete( event.channel_id, event.message_id, event.emoji.name, event.user_id) except APIException: pass
def on_queue_approval_reaction(self, event): if event.channel.guild_id != self.config.indexGuildID: return if event.channel_id != self.config.approvalQueueChannelID: return if not is_mod(self, event.user_id): return bot_queue_message = get_queue_bot_message(self) if not bot_queue_message: return entry = get_entry_from_embed(self, bot_queue_message.embeds[0]) if not entry: return user = self.client.state.users[event.user_id] if not user: return approve_queue_entry(self, entry, event.user_id) self.log.info( '#{author_id} approved ' 'server: #{entry[server_id]} discord.gg/{entry[invite_code]} ' 'name: {entry[name]} description: {entry[description]} ' 'category: {entry[category_channel_name]} genre: {entry[genre_category_name]} ' 'invitee: #{entry[invitee_id]} ' 'submitted at: {entry[submitted_at]} last checked: {entry[submitted_at]}' .format(author_id=event.user_id, entry=entry.to_dict())) try: self.client.api.channels_messages_reactions_delete( event.channel_id, event.message_id, event.emoji.name, event.user_id) except APIException: pass
def command_update(self, event, invite, category_channel=None, name_and_description=""): if event.msg.channel.guild_id != self.config.indexGuildID: return if event.msg.channel.id not in self.config.addChannelIDs: return sudo = False if event.name == 'sudo-update': if not is_mod(self, event.msg.author.id): return sudo = True self.client.api.channels_typing(event.msg.channel.id) name = name_and_description.strip() description = "" if "|" in name: parts = name.split('|', 2) name = parts[0].strip() description = parts[1].strip() if len(name) > 32: event.msg.reply('name too long') return if len(description) > 100: event.msg.reply('description too long') return invite_code = extract_invite_code(invite) if len(invite_code) <= 0: event.msg.reply('no invite code found') return try: invite = self.client.api.invites_get(invite_code) except APIException: event.msg.reply('expired invite code') return if not is_valid_invite( self.client, invite, event.msg.author.id, sudo=sudo): event.msg.reply( 'you can only submit invites you generated yourself') return discord_server_found = self.db.DiscordServer.get( server_id=invite.guild.id) if not discord_server_found: event.msg.reply('server not found in queue or index') return if category_channel is not None and not isinstance( category_channel, DiscoChannel): category_channel = self.state.channels.get(category_channel) if category_channel is not None and category_channel.guild_id != event.msg.channel.guild_id: event.msg.reply('invalid category channel') return genre_category_name = "" if category_channel is not None and category_channel.parent is not None: genre_category_name = category_channel.parent.name if not get_channel_for_name_and_category(self, category_channel.name, genre_category_name): event.msg.reply('invalid category channel') return if discord_server_found.invitee_id != event.msg.author.id and sudo == False: event.msg.reply( 'you can only edit entries your submitted yourself') return attr = {'invite_code': invite.code} response_text = 'Updated!' if len(name) > 0: attr['name'] = name attr['description'] = description if category_channel is not None and len(category_channel.name) > 0: if category_channel.name != discord_server_found.category_channel_name or genre_category_name != discord_server_found.genre_category_name: attr['category_channel_name'] = category_channel.name attr['genre_category_name'] = genre_category_name if not sudo: attr['state'] = 4 response_text = 'Category changes have to be approved, we will inform you when it\'s done!' before_data = discord_server_found.to_dict() update_discord_server(self, discord_server_found, attr) self.log.info( '{author.username} #{author.id} updated ' 'server: #{entry[server_id]} discord.gg/{entry[invite_code]} ' 'name: {entry[name]} description: {entry[description]} ' 'category: {entry[category_channel_name]} genre: {entry[genre_category_name]} ' 'invitee: #{entry[invitee_id]} ' 'submitted at: {entry[submitted_at]} last checked: {entry[submitted_at]} ' 'index message id: {entry[index_message_id]} ' 'sudo: {sudo} ' 'new data: {attr}'.format(author=event.msg.author, entry=before_data, sudo=sudo, attr=attr)) event.msg.reply(response_text)
def command_add(self, event, invite, category_channel, name_and_description): if event.msg.channel.guild_id != self.config.indexGuildID: return if event.msg.channel.id not in self.config.addChannelIDs: return sudo = False if event.name == 'sudo-add': if not is_mod(self, event.msg.author.id): return sudo = True self.client.api.channels_typing(event.msg.channel.id) name = name_and_description.strip() description = "" if "|" in name: parts = name.split('|', 2) name = parts[0].strip() description = parts[1].strip() if len(name) > 32: event.msg.reply('name too long') return if len(description) > 100: event.msg.reply('description too long') return invite_code = extract_invite_code(invite) if len(invite_code) <= 0: event.msg.reply('no invite code found') return try: invite = self.client.api.invites_get(invite_code) except APIException: event.msg.reply('expired invite code') return if self.db.DiscordServer.get(server_id=invite.guild.id): event.msg.reply('server already in the index or queue') return if not is_valid_invite( self.client, invite, event.msg.author.id, sudo=sudo): event.msg.reply( 'you can only submit invites you generated yourself') return if not isinstance(category_channel, DiscoChannel): category_channel = self.state.channels.get(category_channel) if category_channel is None or category_channel.guild_id != event.msg.channel.guild_id: event.msg.reply('invalid category channel') return genre_category_name = "" if category_channel.parent is not None: genre_category_name = category_channel.parent.name if not get_channel_for_name_and_category(self, category_channel.name, genre_category_name): event.msg.reply('invalid category channel') return add_discord_server(self, invite_code, invite.guild.id, name, description, invite.inviter.id, category_channel.name, genre_category_name, event.msg.author.id, sudo=sudo) if sudo: self.log.info( '{author.username} #{author.id} added ' 'server: {invite.guild.name} #{invite.guild.id} discord.gg/{invite_code} ' 'name: {name} description: {description} ' 'category: {category_channel_name} genre: {genre_category_name} ' 'invitee: {invite.inviter.username} #{invite.inviter.id} ' 'sudo: {sudo}'.format( author=event.msg.author, invite=invite, invite_code=invite_code, category_channel_name=category_channel.name, genre_category_name=genre_category_name, name=name, description=description, sudo=sudo)) event.msg.reply('Added server!') else: self.log.info( '{author.username} #{author.id} added ' 'server to queue: {invite.guild.name} #{invite.guild.id} discord.gg/{invite_code} ' 'name: {name} description: {description} ' 'category: {category_channel_name} genre: {genre_category_name} ' 'invitee: {invite.inviter.username} #{invite.inviter.id} ' 'sudo: {sudo}'.format( author=event.msg.author, invite=invite, invite_code=invite_code, category_channel_name=category_channel.name, genre_category_name=genre_category_name, name=name, description=description, sudo=sudo)) event.msg.reply('Added to queue!')