Example #1
0
async def check_mutes(bot):
    while True:  # all guilds need to be fetched for this
        await asyncio.sleep(10)
        try:
            if len([_ for _ in db.mutes.find()]) > 0:
                for mute in db.mutes.find():
                    guild = bot.get_guild(int(mute["mute_id"].split("-")[0]))
                    target = discord.utils.get(
                        guild.members, id=int(mute["mute_id"].split("-")[1]))

                    if datetime.utcnow() > mute["ending"]:
                        try:
                            mute_role_id = DBUtils.get(db.configs, "guildId",
                                                       f"{guild.id}",
                                                       "muteRole")
                            mute_role = guild.get_role(int(mute_role_id))

                            await target.remove_roles(mute_role)
                        except Exception:
                            pass
                        else:
                            on_time = datetime.utcnow().strftime(
                                "%Y-%m-%d %H:%M:%S")
                            await Logging.log_to_guild(
                                guild.id, "memberLogChannel",
                                Translator.translate(guild,
                                                     "log_unmute",
                                                     _emote="ANGEL",
                                                     on_time=on_time,
                                                     user=target,
                                                     user_id=target.id))
                            DBUtils.delete(
                                db.mutes, "mute_id",
                                f"{mute['mute_id'].split('-')[0]}-{mute['mute_id'].split('-')[1]}"
                            )
                    else:
                        pass
        except AttributeError:
            # this happens if the guild object is a NoneType (most likely because it hasn't been cached yet)
            pass
Example #2
0
    async def delete(self, ctx, trigger: str):
        """delete_help"""
        trigger = trigger.lower()
        if len(trigger) > 20:
            await ctx.send(Translator.translate(ctx.guild, "trigger_too_long"))
        elif len([x for x in db.commands.find() if x["cmdId"].split("-")[0] == str(ctx.guild.id)]) == 0:
            await ctx.send(Translator.translate(ctx.guild, "no_custom_commands"))
        elif trigger not in [x["cmdId"].split("-")[1] for x in db.commands.find() if x["cmdId"].split("-")[0] == str(ctx.guild.id)]:
            possible = []
            for cmd in [x["cmdId"].split("-")[1].lower() for x in db.commands.find() if x["cmdId"].split("-")[0] == str(ctx.guild.id)]:
                if Utils.is_close(trigger, cmd, 75.0):
                    possible.append(cmd)
                else:
                    pass
            if len(possible) > 0:
                await ctx.send(Translator.translate(ctx.guild, "command_does_not_exist_but_possible", possible="\n".join(possible)))
            else:
                await ctx.send(Translator.translate(ctx.guild, "command_does_not_exist"))

        else:
            DBUtils.delete(db.commands, "cmdId", f"{ctx.guild.id}-{trigger}")
            self.command_cache[str(ctx.guild.id)] = [_ for _ in self.command_cache[str(ctx.guild.id)] if _["trigger"].lower() != trigger]
            await ctx.send(Translator.translate(ctx.guild, "command_removed", _emote="YES", command=trigger))
Example #3
0
async def on_guild_remove(bot, guild: Guild):
    DBUtils.delete(db.configs, "guildId", f"{guild.id}")
    await Logging.guild_log(
        bot, f"I was removed from a guild: {guild.name} ({guild.id})")