async def on_message(self, message): if message.author.bot: return ctx = await self.bot.get_context(message) if not ctx.command: return self.bot.prom.commands.inc({"name": ctx.command.name}) if message.guild: if await tools.is_guild_banned(self.bot, message.guild): await message.guild.leave() return permissions = await message.channel.permissions_for(await ctx.guild.me()) if permissions.send_messages is False: return if permissions.embed_links is False: await message.channel.send( "The Embed Links permission is needed for basic commands to work." ) return if await tools.is_user_banned(self.bot, message.author): await ctx.send(embed=ErrorEmbed( description="You are banned from the bot.")) return if (ctx.command.cog_name in ["Owner", "Admin"] and ctx.author.id in self.bot.config.admins + self.bot.config.owners): embed = Embed( title=ctx.command.name.title(), description=ctx.message.content, timestamp=datetime.datetime.utcnow(), ) embed.set_author(name=f"{ctx.author} ({ctx.author.id})", icon_url=ctx.author.avatar_url) if self.bot.config.admin_channel: channel = await self.bot.get_channel( self.bot.config.admin_channel) if channel: await channel.send(embed=embed) if ctx.prefix in [f"<@{self.bot.id}> ", f"<@!{self.bot.id}> "]: ctx.prefix = await tools.get_guild_prefix(self.bot, message.guild) await self.bot.invoke(ctx)
async def help(self, ctx, *, command: str = None): if command: command = self.bot.get_command(command.lower()) if not command: await ctx.send( embed=Embed( description=f"That command does not exist. Use `{ctx.prefix}help` to see all the commands.", ) ) return embed = Embed(title=command.name, description=command.description) usage = "\n".join([ctx.prefix + x.strip() for x in command.usage.split("\n")]) embed.add_field(name="Usage", value=f"```{usage}```", inline=False) if len(command.aliases) > 1: embed.add_field(name="Aliases", value=f"`{'`, `'.join(command.aliases)}`") elif len(command.aliases) > 0: embed.add_field(name="Alias", value=f"`{command.aliases[0]}`") await ctx.send(embed=embed) return bot_user = await self.bot.real_user() all_pages = [] page = Embed( title=f"{bot_user.name} Help Menu", description="Thank you for using ModMail! Please direct message me if you wish to contact staff. You can " "also invite me to your server with the link below, or join our support server if you need further help.\n" f"\nDon't forget to check out our partners with the `{ctx.prefix}partners` command!", ) page.set_thumbnail(url=bot_user.avatar_url) page.set_footer(text="Use the reactions to flip pages.") page.add_field(name="Invite", value="https://modmail.xyz/invite", inline=False) page.add_field(name="Support Server", value="https://discord.gg/wjWJwJB", inline=False) all_pages.append(page) page = Embed(title=f"{bot_user.name} Help Menu") page.set_thumbnail(url=bot_user.avatar_url) page.set_footer(text="Use the reactions to flip pages.") page.add_field( name="About ModMail", value="ModMail is a feature-rich Discord bot designed to enable your server members to contact staff " "easily. A new channel is created whenever a user messages the bot, and the channel will serve as a shared " "inbox for seamless communication between staff and the user.", inline=False, ) page.add_field( name="Getting Started", value="Follow these steps to get the bot all ready to serve your server!\n1. Invite the bot with " f"[this link](https://modmail.xyz/invite)\n2. Run `{ctx.prefix}setup`, there will be an interactive guide." f"\n3. All done! For a full list of commands, see `{ctx.prefix}help`.", inline=False, ) all_pages.append(page) for cog_name in self.bot.cogs: if cog_name in ["Owner", "Admin"]: continue cog = self.bot.get_cog(cog_name) cog_commands = cog.get_commands() if len(cog_commands) == 0: continue page = Embed( title=cog_name, description=f"My prefix is `{ctx.prefix}`. Use `{ctx.prefix}help <command>` for more information on a " "command.", ) page.set_author(name=f"{bot_user.name} Help Menu", icon_url=bot_user.avatar_url) page.set_thumbnail(url=bot_user.avatar_url) page.set_footer(text="Use the reactions to flip pages.") for cmd in cog_commands: page.add_field(name=cmd.name, value=cmd.description, inline=False) all_pages.append(page) for page in range(len(all_pages)): all_pages[page].set_footer(text=f"Use the reactions to flip pages. (Page {page + 1}/{len(all_pages)})") await tools.create_paginator(self.bot, ctx, all_pages)
async def send_mail_mod(self, message, prefix, anon=False, snippet=False): self.bot.prom.tickets_message.inc({}) data = await tools.get_data(self.bot, message.guild.id) user = tools.get_modmail_user(message.channel) if user.id in data[9]: await message.channel.send( ErrorEmbed( "That user is blacklisted from sending a message here. You need to whitelist " "them before you can send them a message.")) return try: member = await message.guild.fetch_member(user.id) except discord.NotFound: await message.channel.send( ErrorEmbed( f"The user was not found. Use `{prefix}close [reason]` to close this channel." )) return if snippet is True: message.content = tools.tag_format(message.content, member) embed = Embed("Message Received", message.content, colour=0xFF4500, timestamp=True) embed.set_author( str(message.author) if anon is False else "Anonymous#0000", message.author.avatar_url if anon is False else "https://cdn.discordapp.com/embed/avatars/0.png", ) embed.set_footer(f"{message.guild.name} | {message.guild.id}", message.guild.icon_url) files = [] for file in message.attachments: saved_file = io.BytesIO() await file.save(saved_file) files.append(discord.File(saved_file, file.filename)) dm_channel = tools.get_modmail_channel(self.bot, message.channel) try: dm_message = await dm_channel.send(embed, files=files) except discord.Forbidden: await message.channel.send( ErrorEmbed( "The message could not be sent. The user might have disabled Direct Messages." )) return embed.title = "Message Sent" embed.set_author( str(message.author) if anon is False else f"{message.author} (Anonymous)", message.author.avatar_url, ) embed.set_footer(f"{member} | {member.id}", member.avatar_url) for count, attachment in enumerate( [attachment.url for attachment in dm_message.attachments], start=1): embed.add_field(f"Attachment {count}", attachment, False) for file in files: file.reset() await message.channel.send(embed, files=files) try: await message.delete() except (discord.Forbidden, discord.NotFound): pass
async def help(self, ctx, *, command: str = None): if command: command = self.bot.get_command(command.lower()) if not command: await ctx.send( Embed( f"That command does not exist. Use `{ctx.prefix}help` to see all the " "commands.", ) ) return embed = Embed(command.name, command.description) usage = "\n".join([ctx.prefix + x.strip() for x in command.usage.split("\n")]) embed.add_field("Usage", f"```{usage}```", False) if len(command.aliases) > 1: embed.add_field("Aliases", f"`{'`, `'.join(command.aliases)}`") elif len(command.aliases) > 0: embed.add_field("Alias", f"`{command.aliases[0]}`") await ctx.send(embed) return bot_user = await self.bot.real_user() all_pages = [] page = Embed( "ModMail Help Menu", "ModMail is a feature-rich Discord bot designed to enable your server members to " "contact staff easily.\n\nPlease direct message me if you wish to contact staff. You " "can also invite me to your server with the link below, or join our support server if " f"you need further help.\n\nTo setup the bot, run `{ctx.prefix}setup`.", ) page.set_thumbnail(bot_user.avatar_url) page.set_footer("Use the reactions to flip pages.") page.add_field("Invite", f"{self.bot.config.BASE_URI}/invite", False) page.add_field("Support Server", "https://discord.gg/wjWJwJB", False) all_pages.append(page) for cog_name in self.bot.cogs: if cog_name in ["Owner", "Admin"]: continue cog = self.bot.get_cog(cog_name) cog_commands = cog.get_commands() if len(cog_commands) == 0: continue page = Embed( cog_name, f"My prefix is `{ctx.prefix}`. Use `{ctx.prefix}help <command>` for more " "information on a command.", ) page.set_author("ModMail Help Menu", bot_user.avatar_url) page.set_thumbnail(bot_user.avatar_url) page.set_footer("Use the reactions to flip pages.") for cmd in cog_commands: page.add_field(cmd.name, cmd.description, False) all_pages.append(page) for page in range(len(all_pages)): all_pages[page].set_footer( f"Use the reactions to flip pages. (Page {page + 1}/{len(all_pages)})" ) await tools.create_paginator(self.bot, ctx, all_pages)