예제 #1
0
 async def on_message(self, message):
     if message.author.bot or not message.guild or not message.channel.category_id:
         return
     if not is_modmail_channel2(self.bot, message.channel):
         return
     if (message.channel.permissions_for(message.guild.me).send_messages is
             False or message.channel.permissions_for(
                 message.guild.me).embed_links is False):
         return
     prefix = tools.get_guild_prefix(self.bot, message)
     if message.content.startswith(prefix):
         return
     if message.author.id in self.bot.banned_users:
         return await message.channel.send(embed=discord.Embed(
             description="You are banned from this bot.",
             colour=self.bot.error_colour))
     await self.send_mail_mod(message, prefix)
예제 #2
0
파일: events.py 프로젝트: LyricWulf/modmail
 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.total_commands += 1
     if message.guild:
         if message.guild.id in self.bot.banned_guilds:
             return await message.guild.leave()
         permissions = message.channel.permissions_for(message.guild.me)
         if permissions.send_messages is False:
             return
         elif permissions.embed_links is False:
             return await message.channel.send(
                 "The Embed Links permission is needed for basic commands to work."
             )
     if message.author.id in self.bot.banned_users:
         return await ctx.send(embed=discord.Embed(
             description="You are banned from this bot.",
             colour=self.bot.error_colour))
     if ctx.command.cog_name in [
             "Owner", "Admin"
     ] and (ctx.author.id in ctx.bot.config.admins
            or ctx.author.id in ctx.bot.config.owners):
         admin_channel = self.bot.get_channel(self.bot.config.admin_channel)
         embed = discord.Embed(
             title=ctx.command.name.title(),
             description=ctx.message.content,
             colour=self.bot.primary_colour,
             timestamp=datetime.datetime.utcnow(),
         )
         embed.set_author(
             name=
             f"{ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id})",
             icon_url=ctx.author.avatar_url)
         await admin_channel.send(embed=embed)
     if ctx.prefix == f"<@{self.bot.user.id}> " or ctx.prefix == f"<@!{self.bot.user.id}> ":
         ctx.prefix = get_guild_prefix(self.bot, message)
     await self.bot.invoke(ctx)
예제 #3
0
파일: main.py 프로젝트: YeahNahCunt/modmail
def _get_guild_prefix(bot2, message):
    prefix = get_guild_prefix(bot2, message)
    return commands.when_mentioned_or(prefix)(bot2, message)
예제 #4
0
 async def send_mail(self, message, guild, to_send):
     self.bot.total_messages += 1
     guild = self.bot.get_guild(guild)
     if guild is None:
         return await message.channel.send(
             embed=discord.Embed(description="The server was not found.",
                                 colour=self.bot.error_colour))
     if guild.get_member(message.author.id) is False:
         return await message.channel.send(embed=discord.Embed(
             description=
             "You are not in that server, and the message is not sent.",
             colour=self.bot.error_colour,
         ))
     data = self.bot.get_data(guild.id)
     category = guild.get_channel(data[2])
     if category is None:
         return await message.channel.send(embed=discord.Embed(
             description=
             "A ModMail category is not found. The bot is not set up properly in the server.",
             colour=self.bot.error_colour,
         ))
     if data[9] and str(message.author.id) in data[9].split(","):
         return await message.channel.send(embed=discord.Embed(
             description=
             "That server has blacklisted you from sending a message there.",
             colour=self.bot.error_colour,
         ))
     channels = [
         channel for channel in guild.text_channels
         if is_modmail_channel2(self.bot, channel, message.author.id)
     ]
     channel = None
     new_ticket = False
     if len(channels) > 0:
         channel = channels[0]
     if not channel:
         self.bot.total_tickets += 1
         try:
             name = "".join(
                 l for l in message.author.name.lower()
                 if l not in string.punctuation and l.isprintable())
             if name:
                 name = name + f"-{message.author.discriminator}"
             else:
                 name = message.author.id
             channel = await category.create_text_channel(
                 name,
                 topic=
                 f"ModMail Channel {message.author.id} (Please do not change this)"
             )
             new_ticket = True
             log_channel = guild.get_channel(data[4])
             if log_channel:
                 try:
                     embed = discord.Embed(
                         title="New Ticket",
                         colour=self.bot.user_colour,
                         timestamp=datetime.datetime.utcnow(),
                     )
                     embed.set_footer(
                         text=
                         f"{message.author.name}#{message.author.discriminator} | {message.author.id}",
                         icon_url=message.author.avatar_url,
                     )
                     await log_channel.send(embed=embed)
                 except discord.Forbidden:
                     pass
         except discord.Forbidden:
             return await message.channel.send(embed=discord.Embed(
                 description=
                 "The bot is missing permissions to create a channel. Please contact an admin on "
                 "the server.",
                 colour=self.bot.error_colour,
             ))
         except discord.HTTPException:
             return await message.channel.send(embed=discord.Embed(
                 description=
                 "A HTTPException error occurred. This is most likely because the server has "
                 "reached the maximum number of channels (500). Please join the support server "
                 "if you cannot figure out what went wrong.",
                 colour=self.bot.error_colour,
             ))
     try:
         if new_ticket is True:
             self.guild = guild
             prefix = tools.get_guild_prefix(self.bot, self)
             embed = discord.Embed(
                 title="New Ticket",
                 description=
                 "Type a message in this channel to reply. Messages starting with the server prefix "
                 f"`{prefix}` are ignored, and can be used for staff discussion. Use the command "
                 f"`{prefix}close [reason]` to close this ticket.",
                 colour=self.bot.primary_colour,
                 timestamp=datetime.datetime.utcnow(),
             )
             embed.set_footer(
                 text=
                 f"{message.author.name}#{message.author.discriminator} | {message.author.id}",
                 icon_url=message.author.avatar_url,
             )
             await channel.send(
                 content=f"<@&{data[8]}>" if data[8]
                 and data[8] not in ["@here", "@everyone"] else data[8],
                 embed=embed,
             )
             if data[5]:
                 embed = discord.Embed(
                     title="Custom Greeting Message",
                     description=data[5],
                     colour=self.bot.mod_colour,
                     timestamp=datetime.datetime.utcnow(),
                 )
                 embed.set_footer(text=f"{guild.name} | {guild.id}",
                                  icon_url=guild.icon_url)
                 await message.channel.send(embed=embed)
         embed = discord.Embed(
             title="Message Received",
             description=to_send,
             colour=self.bot.user_colour,
             timestamp=datetime.datetime.utcnow(),
         )
         embed.set_footer(
             text=
             f"{message.author.name}#{message.author.discriminator} | {message.author.id}",
             icon_url=message.author.avatar_url,
         )
         files = []
         for file in message.attachments:
             saved_file = io.BytesIO()
             await file.save(saved_file)
             files.append(discord.File(saved_file, file.filename))
         await channel.send(embed=embed, files=files)
         embed.title = "Message Sent"
         embed.set_footer(text=f"{guild.name} | {guild.id}",
                          icon_url=guild.icon_url)
         for file in files:
             file.reset()
         await message.channel.send(embed=embed, files=files)
     except discord.Forbidden:
         return await message.channel.send(embed=discord.Embed(
             description=
             "No permission to send message in the channel. Please contact an admin on the server.",
             colour=self.bot.error_colour,
         ))