Exemplo n.º 1
0
 async def on_message(self, message: discord.Message):
     while not self.bot.startup_done:
         await asyncio.sleep(1)
     if not hasattr(message.channel,
                    "guild") or message.channel.guild is None:
         return
     if Configuration.getConfigVar(message.guild.id,
                                   "MINOR_LOGS") is 0 or message.author.bot:
         return
     for a in message.attachments:
         LoggedAttachment.create(id=a.id,
                                 url=self.bot.aes.encrypt(a.url),
                                 isImage=(a.width is not None
                                          or a.width is 0),
                                 messageid=message.id)
     LoggedMessage.create(messageid=message.id,
                          author=message.author.id,
                          content=self.bot.aes.encrypt(message.content),
                          timestamp=message.created_at.timestamp(),
                          channel=message.channel.id)
Exemplo n.º 2
0
 async def buildCache(self, guild: discord.Guild):
     start = time.perf_counter()
     BugLog.info(
         f"Populating modlog with missed messages during downtime for {guild.name} ({guild.id})."
     )
     newCount = 0
     editCount = 0
     count = 0
     for channel in guild.text_channels:
         if channel.permissions_for(guild.get_member(
                 self.bot.user.id)).read_messages:
             async for message in channel.history(limit=250, reverse=False):
                 if message.author == self.bot.user:
                     continue
                 logged = LoggedMessage.get_or_none(messageid=message.id)
                 if logged is None:
                     LoggedMessage.create(
                         messageid=message.id,
                         author=message.author.id,
                         content=self.bot.aes.encrypt(message.content),
                         timestamp=message.created_at.timestamp(),
                         channel=channel.id)
                     for a in message.attachments:
                         LoggedAttachment.create(
                             id=a.id,
                             url=self.bot.aes.encrypt(a.url),
                             isImage=(a.width is not None or a.width is 0),
                             messageid=message.id)
                     newCount = newCount + 1
                 elif self.bot.aes.decrypt(
                         logged.content) != message.content:
                     logged.content = self.bot.aes.encrypt(message.content)
                     logged.save()
                     editCount = editCount + 1
                 count = count + 1
     BugLog.info(
         f"Discovered {newCount} new messages and {editCount} edited in {guild.name} (checked {count}) in {time.perf_counter() - start }s."
     )
Exemplo n.º 3
0
 async def quote(self, ctx: commands.Context, messageid: int):
     """Quotes the requested message."""
     async with ctx.typing():
         message = LoggedMessage.get_or_none(messageid=messageid)
         if message is None:
             for guild in self.bot.guilds:
                 for channel in guild.text_channels:
                     try:
                         dmessage: discord.Message = await channel.get_message(
                             messageid)
                         for a in dmessage.attachments:
                             LoggedAttachment.get_or_create(
                                 id=a.id,
                                 url=a.url,
                                 isImage=(a.width is not None
                                          or a.width is 0),
                                 messageid=message.id)
                         message = LoggedMessage.create(
                             messageid=messageid,
                             content=self.bot.aes.encrypt(dmessage.content),
                             author=dmessage.author.id,
                             timestamp=dmessage.created_at.timestamp(),
                             channel=channel.id)
                     except Exception as ex:
                         # wrong channel
                         pass
                     if message is not None:
                         break
         if message is None:
             await ctx.send(
                 "I was unable to find that message anywhere, is it somewhere i can't see?"
             )
         else:
             attachment = None
             attachments = LoggedAttachment.select().where(
                 LoggedAttachment.messageid == messageid)
             if len(attachments) == 1:
                 attachment = attachments[0]
             embed = discord.Embed(colour=discord.Color(0xd5fff),
                                   timestamp=datetime.utcfromtimestamp(
                                       message.timestamp))
             if message.content is None or message.content == "":
                 if attachment is not None:
                     if attachment.isImage:
                         embed.set_image(
                             url=self.bot.aes.decrypt(attachment.url))
                     else:
                         embed.add_field(name="Attachment link",
                                         value=self.bot.aes.decrypt(
                                             attachment.url))
             else:
                 embed = discord.Embed(
                     colour=discord.Color(0xd5fff),
                     description=self.bot.aes.decrypt(message.content),
                     timestamp=datetime.utcfromtimestamp(message.timestamp))
                 if attachment is not None:
                     if attachment.isImage:
                         embed.set_image(
                             url=self.bot.aes.decrypt(attachment.url))
                     else:
                         embed.add_field(name="Attachment link",
                                         value=self.bot.aes.decrypt(
                                             attachment.url))
             try:
                 user = await commands.MemberConverter().convert(
                     ctx, message.author)
             except:
                 user = await ctx.bot.get_user_info(message.author)
             embed.set_author(name=user.name, icon_url=user.avatar_url)
             embed.set_footer(
                 text=
                 f"Send in #{self.bot.get_channel(message.channel).name} | Quote requested by {ctx.author.display_name} | {messageid}"
             )
             await ctx.send(embed=embed)
             await ctx.message.delete()
Exemplo n.º 4
0
 async def quote(self, ctx: commands.Context, messageid: int):
     """Quotes the requested message."""
     async with ctx.typing():
         try:
             message = LoggedMessage.get(messageid=messageid)
             embed = discord.Embed(colour=discord.Color(0xd5fff),
                                   timestamp=datetime.utcfromtimestamp(
                                       message.timestamp))
             user = await ctx.bot.get_user_info(message.author)
             embed.set_author(name=user.name, icon_url=user.avatar_url)
             embed.set_footer(
                 text=
                 f"Sent in #{self.bot.get_channel(message.channel).name} | Quote requested by {ctx.author.display_name} | {messageid}"
             )
             attachmentsraw = LoggedAttachment.select().where(
                 LoggedAttachment.messageid == messageid)
             attachments = []
             for attachmentraw in attachmentsraw:
                 attachments.append(attachmentraw)
             if attachments != [] and attachments != None:
                 if len(attachments) == 1 and attachments[0].isImage:
                     embed.set_image(
                         url=self.bot.aes.decrypt(attachments[0].url))
                 else:
                     for attachment in attachments:
                         embed.add_field(name="Attachment link",
                                         value=self.bot.aes.decrypt(
                                             attachment.url))
             if message.content is not None and message.content is not "":
                 embed.description = self.bot.aes.decrypt(message.content)
             await ctx.send(embed=embed)
             await ctx.message.delete()
         except LoggedMessage.DoesNotExist:
             dmessage = None
             for server in ctx.bot.guilds:
                 for txtchannel in server.text_channels:
                     try:
                         dmessage = await txtchannel.get_message(messageid)
                         embed = discord.Embed(
                             colour=discord.Color(0xd5fff),
                             timestamp=datetime.utcfromtimestamp(
                                 dmessage.created_at.timestamp()))
                         embed.set_author(
                             name=dmessage.author.name,
                             icon_url=dmessage.author.avatar_url)
                         embed.set_footer(
                             text=
                             f"Sent in #{dmessage.channel.name} | Quote Requested by {ctx.author.display_name} | {dmessage.id}"
                         )
                         if dmessage.attachments != []:
                             if len(dmessage.attachments) == 1:
                                 embed.set_image(
                                     url=dmessage.attachments[0].url)
                             else:
                                 for attachment in dmessage.attachments:
                                     embed.add_field(name="Attachment link",
                                                     value=attachment.url)
                         if dmessage.content is not None:
                             embed.description = dmessage.content
                         await ctx.send(embed=embed)
                         await ctx.message.delete()
                         for a in dmessage.attachments:
                             LoggedAttachment.get_or_create(
                                 id=a.id,
                                 url=self.bot.aes.encrypt(a.url),
                                 isImage=(a.width is not None
                                          or a.width is 0),
                                 messageid=dmessage.id)
                         LoggedMessage.create(
                             messageid=messageid,
                             content=self.bot.aes.encrypt(dmessage.content),
                             author=dmessage.author.id,
                             timestamp=dmessage.created_at.timestamp(),
                             channel=dmessage.channel.id)
                     except discord.Forbidden:
                         pass
                     except discord.NotFound:
                         pass
             if dmessage is None:
                 await ctx.send(
                     "Sorry, I couldn't find that message anywhere")