예제 #1
0
 async def on_raw_message_delete(self, message_id, channel_id):
     if message_id in self.approved:
         BugLog.info("Caught a submision before it fell into the void!")
         return
     self.bot.DBC.query(
         f"DELETE FROM submissions WHERE message = {message_id} AND points = 0"
     )
     await self.updateScoreboard('Post Pick-Up Hug / Fight Strings!')
예제 #2
0
def loadConfigFile(id):
    global SERVER_CONFIGS
    try:
        with open(f'config/{id}.json', 'r') as jsonfile:
            config = json.load(jsonfile)
            for key in CONFIG_TEMPLATE:
                if key not in config:
                    config[key] = CONFIG_TEMPLATE[key]
            SERVER_CONFIGS[id] = config
    except FileNotFoundError:
        BugLog.info(f"No config available for ({guild.id}), creating blank one.")
        SERVER_CONFIGS[id] = copy.deepcopy(CONFIG_TEMPLATE)
        saveConfig(id)
예제 #3
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."
     )
예제 #4
0
async def on_guild_join(guild: discord.Guild):
    BugLog.info(f"A new guild came up: {guild.name} ({guild.id}).")
    Configuration.loadConfig(guild)
예제 #5
0
async def onReady(bot: commands.Bot):
    BugLog.info(f"Loading configurations for {len(bot.guilds)} guilds")
    for guild in bot.guilds:
        BugLog.info(f"Loading info for {guild.name} ({guild.id})")
        loadConfig(guild)
예제 #6
0
async def unmuteTask(modcog: ModerationCog):
    while not modcog.bot.startup_done:
        await asyncio.sleep(1)
        BugLog.info("Started unmute background task")
    skips = []
    updated = False
    while modcog.running:
        userid = 0
        guildid = 0
        try:
            guildstoremove = []
            for guildid, list in modcog.mutes.items():
                guild: discord.Guild = modcog.bot.get_guild(int(guildid))
                toremove = []
                if Configuration.getConfigVar(int(guildid), "MUTE_ROLE") is 0:
                    guildstoremove.append(guildid)
                for userid, until in list.items():
                    if time.time() > until and userid not in skips:
                        member = guild.get_member(int(userid))
                        role = discord.utils.get(guild.roles,
                                                 id=Configuration.getConfigVar(
                                                     int(guildid),
                                                     "MUTE_ROLE"))
                        if guild.me.guild_permissions.manage_roles:
                            await member.remove_roles(role,
                                                      reason="Mute expired")
                            await BugLog.logToModLog(
                                guild,
                                f":innocent: {member.name}#{member.discriminator} (`{member.id}`) has automatically been unmuted"
                            )
                        else:
                            await BugLog.logToModLog(
                                guild,
                                f":no_entry: ERROR: {member.name}#{member.discriminator} (`{member.id}`) was muted earlier but i no longer have the permissions needed to unmute this person, please remove the role manually!"
                            )
                        updated = True
                        toremove.append(userid)
                for todo in toremove:
                    del list[todo]
                await asyncio.sleep(0)
            if updated:
                Util.saveToDisk("mutes", modcog.mutes)
                updated = False
            for id in guildstoremove:
                del modcog.mutes[id]
            await asyncio.sleep(10)
        except CancelledError:
            pass  #bot shutdown
        except Exception as ex:
            BugLog.error("Something went wrong in the unmute task")
            BugLog.error(traceback.format_exc())
            skips.append(userid)
            embed = discord.Embed(colour=discord.Colour(0xff0000),
                                  timestamp=datetime.datetime.utcfromtimestamp(
                                      time.time()))

            embed.set_author(name="Something went wrong in the unmute task:")
            embed.add_field(name="Current guildid", value=guildid)
            embed.add_field(name="Current userid", value=userid)
            embed.add_field(name="Exception", value=ex)
            v = ""
            for line in traceback.format_exc().splitlines():
                if len(v) + len(line) > 1024:
                    embed.add_field(name="Stacktrace", value=v)
                    v = ""
                v = f"{v}\n{line}"
            if len(v) > 0:
                embed.add_field(name="Stacktrace", value=v)
            await BugLog.logToBotlog(embed=embed)
            await asyncio.sleep(10)
    BugLog.info("Unmute background task terminated")