async def on_message(self, message: discord.Message): if message.author.bot or message.webhook_id is not None: return if message.author.id in Configuration.get_persistent_var( "user_blocklist", []): return if not hasattr(message.channel, "guild") or message.channel.guild is None: return me = message.guild.me if me is None: message.guild.fetch_member(self.bot.user.id) permissions = message.channel.permissions_for(me) if not (permissions.read_messages and permissions.send_messages and permissions.embed_links): return role_list = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLES") role_required = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") channel_list = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS") channels_ignored = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") mod_bypass = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "MOD_BYPASS") is_mod = message.author is not None and Permissioncheckers.is_mod( message.author) if (message.channel.id in channel_list) is channels_ignored and not ( is_mod and mod_bypass): return has_role = False if message.author is not None and hasattr(message.author, "roles"): for role in message.author.roles: if role.id in role_list: has_role = True break if has_role is not role_required and not (is_mod and mod_bypass): return prefix = Configuration.get_var(message.guild.id, "GENERAL", "PREFIX") if message.content.startswith(prefix, 0) and message.guild.id in self.commands: for trigger in self.commands[message.guild.id]: if message.content.lower() == prefix + trigger or ( message.content.lower().startswith( trigger, len(prefix)) and message.content.lower()[len(prefix + trigger)] == " "): command_content = self.commands[ message.guild.id][trigger].replace("@", "@\u200b") await message.channel.send(command_content) self.bot.custom_command_count += 1
async def on_message(self, message: discord.Message): if not hasattr(message.channel, "guild") or message.channel.guild is None: return ctx: commands.Context = await self.bot.get_context(message) guild = message.guild is_mod = Permissioncheckers.is_mod(ctx) if message.author == guild.me or is_mod or message.author.id in Configuration.getConfigVar(guild.id, "IGNORED_USERS"): return guilds = Configuration.getConfigVar(message.guild.id, "INVITE_WHITELIST") if len(guilds) is not 0: codes = INVITE_MATCHER.findall(message.content) for code in codes: try: invite:discord.Invite = await self.bot.get_invite(code) except discord.NotFound: pass except KeyError: await message.delete() clean_message = await clean_content().convert(ctx, message.content) clean_name = Utils.clean_user(message.author) await GearbotLogging.log_to_minor_log(message.guild, f":no_entry_sign: {Translator.translate('censored_invite', ctx.guild.id, user=clean_name, code=code, message=clean_message, server_name='DM group')}") else: if invite.guild is None or (not invite.guild.id in guilds and invite.guild.id != guild.id): await message.delete() clean_message = await clean_content().convert(ctx ,message.content) clean_name = Utils.clean_user(message.author) await GearbotLogging.log_to_minor_log(message.guild, f":no_entry_sign: {Translator.translate('censored_invite', ctx.guild.id, user=clean_name, code=code, message=clean_message, server_name=invite.guild.name)}")
def is_exempt(guild_id, member: Member): if not hasattr(member, "roles"): return False config = Configuration.get_var(guild_id, "ANTI_SPAM") for role in member.roles: if role.id in config["EXEMPT_ROLES"]: return True return member.id in config["EXEMPT_USERS"] or Permissioncheckers.is_mod(member)
async def on_message(self, message: discord.Message): if message.author.bot or message.webhook_id is not None: return if not hasattr(message.channel, "guild") or message.channel.guild is None: return me = message.guild.me if me is None: me = Utils.get_member(self.bot, message.guild, self.bot.user.id) permissions = message.channel.permissions_for(me) if me is None: return if not (permissions.read_messages and permissions.send_messages and permissions.embed_links): return role_list = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLES") role_required = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "ROLE_REQUIRED") channel_list = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS") channels_ignored = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "CHANNELS_IGNORED") mod_bypass = Configuration.get_var(message.guild.id, "CUSTOM_COMMANDS", "MOD_BYPASS") is_mod = message.author is not None and Permissioncheckers.is_mod(message.author) if (message.channel.id in channel_list) is channels_ignored and not (is_mod and mod_bypass): return has_role = False if message.author is not None and hasattr(message.author, "roles"): for role in message.author.roles: if role.id in role_list: has_role = True break if has_role is not role_required and not (is_mod and mod_bypass): return prefix = Configuration.get_var(message.guild.id, "GENERAL", "PREFIX") if message.content.startswith(prefix, 0) and message.guild.id in self.commands: for trigger in self.commands[message.guild.id]: if message.content.lower() == prefix + trigger or ( message.content.lower().startswith(trigger, len(prefix)) and message.content.lower()[len(prefix + trigger)] == " "): info = self.commands[message.guild.id][trigger] images = IMAGE_MATCHER.findall(info.content) image = None if len(images) == 1: image = images[0] description = info.content.replace(image, "") else: description = info.content embed = Embed(description=description) if info.created_by is not None: creator = await Utils.get_user(info.created_by) embed.set_footer(text=f"Created by {str(creator)} ({info.created_by})", icon_url=creator.avatar_url) if image is not None: embed.set_image(url=image) await message.channel.send(embed=embed) self.bot.custom_command_count += 1
async def __local_check(self, ctx): return Permissioncheckers.check_permission( ctx, Permissioncheckers.is_mod(ctx))