async def callback(self, response: discord.SlashCommandResponse) -> None: server_id = response.options.id or response.guild_id if not str(server_id).isdigit(): return await response.send_message('Not a valid serverid', ephemeral=True) guild = self.parent.cog.bot.get_guild(int(server_id)) if guild is not None: database = await self.parent.cog.database_class_server() await database.set(server_id, response.options.reason) self.parent.cog.bot.blacklist.append(int(server_id)) channel = await self.parent.cog.bot.get_welcome_channel(guild) embed = ErrorEmbed(title=f'Left {guild.name}') embed.description = f'I have to leave the `{guild.name}` because it was marked as a `blacklist guild` by my developer. For further queries please contact my developer.' embed.add_field( name='Developer', value= f'[{self.parent.cog.bot.get_user(self.parent.cog.bot.owner_id)}](https://discord.com/users/{self.parent.cog.bot.owner_id})' ) embed.add_field( name="Support Server", value=f"https://discord.gg/{LinksAndVars.invite_code.value}", ) await channel.send(embed=embed) await guild.leave() log.info(f'Left guild {guild.id} [Marked as spam]') await response.send_message('Server added to the blacklist', ephemeral=True) return else: return await response.send_message('Server not found', ephemeral=True)
async def on_guild_join(self, guild: discord.Guild): if guild.id in self.blacklist: channel = await self.get_welcome_channel(guild) embed = ErrorEmbed(title=f'Left {guild.name}') embed.description = f'I have to leave the `{guild.name}` because it was marked as a `blacklist guild` by my developer. For further queries please contact my developer.' embed.add_field(name = 'Developer', value=f'[{self.get_user(self.owner_id)}](https://discord.com/users/{self.owner_id})') embed.add_field( name="Support Server", value=f"https://discord.gg/{LinksAndVars.invite_code.value}", ) await channel.send(embed=embed) await guild.leave() log.info(f'Left guild {guild.id} [Marked as spam]')
async def callback(self, response: discord.SlashCommandResponse): detected_urls = await detect_bad_domains(response.options.content) if len(detected_urls) != 0: embed = ErrorEmbed(title='SCAM/PHISHING/ADULT LINK(S) DETECTED') detected_string = '\n'.join( [f'- ||{i}||' for i in set(detected_urls)]) embed.description = f'The following scam url(s) were detected:\n{detected_string}' embed.set_author( name=response.interaction.user.display_name, icon_url=response.interaction.user.display_avatar.url) await response.send_message(embed=embed, ephemeral=True) return await response.send_message( embed=SuccessEmbed(title="The url or the text message is safe!"), ephemeral=True)
async def process_commands(self, message): ctx = await self.get_context(message, cls=Context) if ctx.command is None: return if ctx.author.id in self.blacklist: embed = ErrorEmbed(title='Blacklisted User!') embed.description = 'You have been `blacklisted` from using my commands. For further queries please contact my developer.' embed.add_field(name = 'Developer', value=f'[{self.get_user(self.owner_id)}](https://discord.com/users/{self.owner_id})') embed.add_field( name="Support Server", value=f"https://discord.gg/{LinksAndVars.invite_code.value}", ) await ctx.send(embed=embed, delete_after=5) return if ctx.guild is not None and ctx.guild.id in self.blacklist: return bucket = self.spam_control.get_bucket(message) current = message.created_at.timestamp() retry_after = bucket.update_rate_limit(current) author_id = message.author.id if retry_after and author_id != self.owner_id: self._auto_spam_count[author_id] += 1 if self._auto_spam_count[author_id] >= 5: await self.add_to_blacklist(author_id) del self._auto_spam_count[author_id] await self.log_spammer(ctx, message, retry_after, autoblock=True) else: self.log_spammer(ctx, message, retry_after) return else: self._auto_spam_count.pop(author_id, None) try: await self.invoke(ctx) except: pass
async def update_blacklist(self): database = await self.db.new(Database.database_category_name.value, Database.user_blacklist_channel_name.value) async for message in database._Database__channel.history(limit=None): cnt = message.content try: data = loads(str(cnt)) data.pop("type") data_keys = list(map(str, list(data.keys()))) self.blacklist.append(int(data_keys[0])) except Exception as e: log.error(e) continue database = await self.db.new(Database.database_category_name.value, Database.server_blacklist_channel_name.value) async for message in database._Database__channel.history(limit=None): cnt = message.content try: data = loads(str(cnt)) data.pop("type") data_keys = list(map(str, list(data.keys()))) self.blacklist.append(int(data_keys[0])) guild = self.get_guild(int(data_keys[0])) if guild is not None: channel = await self.get_welcome_channel(guild) embed = ErrorEmbed(title=f'Left {guild.name}') embed.description = f'I have to leave the `{guild.name}` because it was marked as a `blacklist guild` by my developer. For further queries please contact my developer.' embed.add_field(name = 'Developer', value=f'[{self.get_user(self.owner_id)}](https://discord.com/users/{self.owner_id})') embed.add_field( name="Support Server", value=f"https://discord.gg/{LinksAndVars.invite_code.value}", ) await channel.send(embed=embed) await guild.leave() log.info(f'Left guild {guild.id} [Marked as spam]') except Exception as e: log.error(e) continue self.blacklist = list(set(self.blacklist)) log.info('Blacklist Data updated')