import weakref from discord import Guild, Member from discord.ext import commands from config import CONFIG from rocketbot.cogs.basecog import BaseCog, BotMessage, BotMessageReaction, CogSetting class AutoKickCog(BaseCog, name='Auto Kick'): """ Cog for automatically kicking ALL new joins. For temporary use during join raids. """ SETTING_ENABLED = CogSetting('enabled', bool, brief='autokick', description='Whether this cog is enabled for a guild.') def __init__(self, bot): super().__init__(bot) self.add_setting(AutoKickCog.SETTING_ENABLED) @commands.group( brief='Automatically kicks all new users as soon as they join', ) @commands.has_permissions(ban_members=True) @commands.guild_only() async def autokick(self, context: commands.Context): 'Auto-kick' if context.invoked_subcommand is None: await context.send_help() @commands.Cog.listener() async def on_member_join(self, member: Member) -> None: 'Event handler' guild: Guild = member.guild if not self.get_guild_setting(guild, self.SETTING_ENABLED): return await member.kick(reason=f'Rocketbot: Autokick enabled.') msg = BotMessage(guild, text=f'Autokicked {member.mention} ({member.id}). To disable this feature: `{CONFIG["command_prefix"]}autokick disable`.', type=BotMessage.TYPE_INFO, context=None) await self.post_message(msg) self.log(guild, f'Autokicked {member.nick}')