Example #1
0
 async def add_to_censor_list(self, ctx, *, text: str):
     if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}",
                    "automod") is False:
         return await ctx.send(
             Translator.translate(ctx.guild,
                                  "black_list_disabled",
                                  _emote="NO",
                                  prefix=ctx.prefix))
     _censor_list = [
         x for x in DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}",
                                "censored_words") if x != "--------------"
     ]
     if text.lower() in [
             x.strip().lower() for x in DBUtils.get(
                 db.configs, "guildId", f"{ctx.guild.id}", "censored_words")
             if x != "--------------"
     ]:
         return await ctx.send(
             Translator.translate(ctx.guild,
                                  "already_on_black_list",
                                  _emote="NO",
                                  word=text))
     _censor_list.append(str(text))
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "censored_words", _censor_list)
     await ctx.send(
         Translator.translate(ctx.guild,
                              "added_to_black_list",
                              _emote="YES",
                              word=text))
Example #2
0
    async def add(self, ctx, lvl: RangedInt(2, 200), role: discord.Role):
        "add_help"
        if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem") is False:
            return await ctx.send(Translator.translate(ctx.guild, "lvlsystem_disabled", _emote="NO"))
        
        automod = await Utils.get_member(self.bot, ctx.guild, self.bot.user.id)
        if role.position >= automod.top_role.position:
            return await ctx.send(Translator.translate(ctx.guild, "role_too_high"))
        
        level_roles = DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "level_roles")
        roles = [x.split("-")[1] for x in level_roles]
        levels = [x.split("-")[0] for x in level_roles]

        if str(lvl) in levels:
            return await ctx.send(Translator.translate(ctx.guild, "already_role_for_lvl", _emote="NO", lvl=lvl))
        
        if str(role.id) is roles:
            return await ctx.send(Translator.translate(ctx.guild, "already_lvl_role", _emote="NO", role=role))

        if len(level_roles) > 10:
            return await ctx.send(Translator.translate(ctx.guild, "max_lvl_roles", _emote="NO"))

        level_roles.append(f"{lvl}-{role.id}")
        DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "level_roles", level_roles)
        await ctx.send(Translator.translate(ctx.guild, "added_lvl_role", _emote="YES", role=role, lvl=lvl))
Example #3
0
 async def welcome_off(self, ctx):
     """welcome_off_help"""
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "welcomeChannel", "")
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "welcomeMessage", "")
     await ctx.send(
         Translator.translate(ctx.guild, "off_success", _emote="YES"))
Example #4
0
 async def _lvlsystem(self, ctx):
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem",
                    False)
     await ctx.send(
         Translator.translate(ctx.guild,
                              "disabled_module",
                              _emote="YES",
                              module="rank_system"))
Example #5
0
 async def _automod(self, ctx):
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "automod",
                    False)
     await ctx.send(
         Translator.translate(ctx.guild,
                              "disabled_module",
                              _emote="YES",
                              module="automod"))
Example #6
0
 async def _member_logging(self, ctx):
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "memberLogging", False)
     await ctx.send(
         Translator.translate(ctx.guild,
                              "disabled_module",
                              _emote="YES",
                              module="join_leave_logging"))
Example #7
0
 async def lvlsystem(self, ctx):
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem",
                    True)
     await ctx.send(
         Translator.translate(ctx.guild,
                              "enabled_module_no_channel",
                              _emote="YES",
                              module="rank_system"))
Example #8
0
 async def welcome_channel(self, ctx, channel: discord.TextChannel):
     """welcome_channel_help"""
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "welcomeChannel", channel.id)
     await ctx.send(
         Translator.translate(ctx.guild,
                              "channel_success",
                              _emote="YES",
                              channel=channel.mention))
Example #9
0
 async def welcome_msg(self, ctx, *, msg: str):
     """welcome_msg_help"""
     if len(msg) > 1500:
         return await ctx.send(
             Translator.translate(ctx.guild, "msg_too_long"))
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "welcomeMessage", f"{msg}")
     await ctx.send(
         Translator.translate(ctx.guild, "msg_success", _emote="YES"))
Example #10
0
 async def action_log(self, ctx, channel: discord.TextChannel):
     """action_log_help"""
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "memberLogChannel", int(channel.id))
     await ctx.send(
         Translator.translate(ctx.guild,
                              "log_mod_actions",
                              _emote="YES",
                              channel=channel.mention))
Example #11
0
 async def member_logging(self, ctx, channel: discord.TextChannel):
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "joinLogChannel", int(channel.id))
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "memberLogging", True)
     await ctx.send(
         Translator.translate(ctx.guild,
                              "enabled_module_channel",
                              _emote="YES",
                              module="join_leave_logging",
                              channel=channel.mention))
Example #12
0
 async def _remove(self, ctx, user: discord.User):
     ignored_users = DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}",
                                 "ignored_users")
     if not user.id in ignored_users:
         return await ctx.send(
             Translator.translate(ctx.guild,
                                  "not_existing_ignored_user",
                                  _emote="NO",
                                  user=user.name))
     ignored_users.remove(int(user.id))
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "ignored_users", ignored_users)
     await ctx.send(
         Translator.translate(ctx.guild,
                              "ignored_user_removed",
                              _emote="YES",
                              user=user.name))
Example #13
0
 async def _add(self, ctx, member: discord.Member):
     ignored_users = DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}",
                                 "ignored_users")
     if member.id in ignored_users:
         return await ctx.send(
             Translator.translate(ctx.guild,
                                  "already_ignored_user",
                                  _emote="YES",
                                  user=member.name))
     ignored_users.append(int(member.id))
     DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                    "ignored_users", ignored_users)
     await ctx.send(
         Translator.translate(ctx.guild,
                              "ignored_user_added",
                              _emote="YES",
                              user=member.name))
Example #14
0
    async def remove(self, ctx, role: discord.Role):
        "remove_help"
        if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem") is False:
            return await ctx.send(Translator.translate(ctx.guild, "lvlsystem_disabled", _emote="NO"))

        level_roles = DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "level_roles")
        roles = [x.split("-")[1] for x in level_roles]
        levels = [x.split("-")[0] for x in level_roles]

        if len(level_roles) < 1:
            return await ctx.send(Translator.translate(ctx.guild, "no_lvl_roles", _emote="NO"))

        if not str(role.id) in roles:
            return await ctx.send(Translator.translate(ctx.guild, "invalid_lvl_role", _emote="NO", role=role))

        lvl = levels[roles.index(str(role.id))]
        level_roles.remove(f"{lvl}-{role.id}")

        DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "level_roles", level_roles)
        await ctx.send(Translator.translate(ctx.guild, "removed_lvl_role", _emote="YES", role=role))
Example #15
0
 async def prefix(self, ctx, new_prefix: str = None):
     """prefix_help"""
     if new_prefix is None:
         await ctx.send(
             Translator.translate(ctx.guild,
                                  "current_prefix",
                                  prefix=DBUtils.get(
                                      db.configs, "guildId",
                                      f"{ctx.guild.id}", "prefix")))
     elif len(new_prefix) > 15:
         await ctx.send(
             Translator.translate(ctx.guild, "prefix_too_long",
                                  _emote="NO"))
     else:
         DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "prefix",
                        f"{new_prefix}")
         await ctx.send(
             Translator.translate(ctx.guild,
                                  "prefix_updated",
                                  _emote="YES",
                                  prefix=new_prefix))
Example #16
0
def translate(guild, key, _emote=None, **kwargs):
    if not guild.id in LANG_CACHE:
        try:
            lang = DBUtils.get(db.configs, "guildId", guild.id, "lang")
        except KeyError:
            DBUtils.update(db.configs, "guildId", guild.id, "lang", "en_US")
            lang = "en_US"
        LANG_CACHE[
            guild.
            id] = lang  # cache the language for the guild, so we don't have to fetch it from the DB every time
    else:
        lang = LANG_CACHE[guild.id]
    global string
    try:
        string = LANGS[lang][key]
    except KeyError:
        string = LANGS["en_US"][key]
    finally:
        if "{emote}" in string:
            return str(string).format(emote=str(Emotes.get(_emote)), **kwargs)
        else:
            return str(string).format(**kwargs)
Example #17
0
    async def remove_from_censor_list(self, ctx, *, text: str):
        if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}",
                       "automod") is False:
            return await ctx.send(
                Translator.translate(ctx.guild,
                                     "black_list_disabled",
                                     _emote="NO",
                                     prefix=ctx.prefix))

        lower = [
            x.lower() for x in DBUtils.get(db.configs, "guildId",
                                           f"{ctx.guild.id}", "censored_words")
            if x != "--------------"
        ]
        if len(lower) < 1:
            return await ctx.send(
                Translator.translate(ctx.guild,
                                     "black_list_empty",
                                     _emote="NO",
                                     prefix=ctx.prefix))

        _censor_list = [
            x.strip().lower() for x in DBUtils.get(
                db.configs, "guildId", f"{ctx.guild.id}", "censored_words")
        ]
        if not text.lower() in _censor_list:
            return await ctx.send(
                Translator.translate(ctx.guild,
                                     "not_on_black_list",
                                     _emote="NO",
                                     word=text))
        _censor_list.remove(str(text.lower()))
        DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}",
                       "censored_words", _censor_list)
        await ctx.send(
            Translator.translate(ctx.guild,
                                 "removed_from_black_list",
                                 _emote="YES",
                                 word=text))
Example #18
0
    async def _level_up(message, lvl_id, user):
        xp = DBUtils.get(db.levels, "levelId", lvl_id, "xp")
        lvl = DBUtils.get(db.levels, "levelId", lvl_id, "lvl")

        # calculations
        #TODO: It's way to easy to level up, migth have to change that
        starting_xp = 10
        counter = 0
        while counter < lvl:
            counter += 1
            if counter > 1:
                starting_xp += 40
            if counter >= lvl:
                break
        if lvl > 1:
            starting_xp += 40

        if starting_xp < xp:
            after = lvl + 1
            DBUtils.update(db.levels, "levelId", lvl_id, "lvl", after)
            try:
                await message.channel.send(Translator.translate(ctx.guild, "lvl_up", _emote="PARTY", user=user, lvl=after))
            except Exception:
                pass

            lvl_roles = DBUtils.get(db.configs, "guildId", f"{message.guild.id}", "level_roles")
            if len(lvl_roles) < 1:
                return
            for l in lvl_roles:
                if str(l.split("-")[0]) == str(after):
                    try:
                        role = discord.utils.get(message.guild.roles, id=int(l.split("-")[1]))
                        await user.add_roles(role)
                        try:
                            await user.send(Translator.translate(ctx.guild, "role_added", user=user.name, role=role.name, guild_name=message.guild.name, lvl=after))
                        except Exception:
                            pass
                    except Exception:
                        pass
Example #19
0
 async def mute_role(self, ctx, role: discord.Role):
     """mute_role_help"""
     if role == ctx.guild.default_role:
         return await ctx.send(
             Translator.translate(ctx.guild,
                                  "default_role_forbidden",
                                  _emote="NO"))
     guild: discord.Guild = ctx.guild
     perms = guild.me.guild_permissions
     if not perms.manage_roles:
         return await ctx.send(
             Translator.translate(ctx.guild,
                                  "mute_missing_perm",
                                  _emote="NO"))
     if not guild.me.top_role > role:
         return await ctx.send(
             Translator.translate(ctx.guild, "role_too_high"))
     DBUtils.update(db.configs, "guildId", f"{guild.id}", "muteRole",
                    int(role.id))
     await ctx.send(
         Translator.translate(ctx.guild,
                              "updated_mute_role",
                              _emote="YES",
                              role=role.mention))
Example #20
0
async def on_guild_update(before, after):
    if before.name != after.name:
        DBUtils.update(db.configs, "guildId", f"{before.id}", "guildName",
                       f"{after.name}")
Example #21
0
 async def _add_xp(lvl_id, xp):
     cur = DBUtils.get(db.levels, "levelId", lvl_id, "xp")
     new_xp = int(cur) + xp
     DBUtils.update(db.levels, "levelId", lvl_id, "xp", new_xp)