Beispiel #1
0
 async def faction_desc_set(self, ctx, *, description):
     description = re.sub("[^\S ]+", "", description)
     if not (len(description) <= 240):
         raise BadArgumentErrorWithMessage(
             ctx.s("faction.err.description_length"))
     sql.guild_faction_set(ctx.guild.id, desc=description)
     await ctx.send(ctx.s("faction.set_description"))
Beispiel #2
0
 async def faction_alias_set(self, ctx, new_alias):
     new_alias = re.sub("[^A-Za-z]+", "", new_alias).lower()
     if not (1 <= len(new_alias) <= 5):
         raise BadArgumentErrorWithMessage(ctx.s("faction.err.alias_length"))
     if sql.guild_get_by_faction_alias(new_alias):
         await ctx.send(ctx.s("faction.alias_already_exists"))
         return
     sql.guild_faction_set(ctx.guild.id, alias=new_alias)
     await ctx.send(ctx.s("faction.set_alias").format(new_alias))
Beispiel #3
0
 async def faction_name_set(self, ctx, new_name):
     new_name = re.sub("[^\S ]+", "", new_name)
     if not (6 <= len(new_name) <= 32):
         raise BadArgumentErrorWithMessage(ctx.s("faction.err.name_length"))
     if sql.guild_get_by_faction_name(new_name):
         await ctx.send(ctx.s("faction.name_already_exists"))
         return
     sql.guild_faction_set(ctx.guild.id, name=new_name)
     await ctx.send(ctx.s("faction.set_name").format(new_name))
Beispiel #4
0
    async def assemble(self, ctx, name, alias=""):
        if sql.guild_is_faction(ctx.guild.id):
            await ctx.send(ctx.s("faction.already_faction"))
            return
        name = re.sub("[^\S ]+", "", name)
        if not (6 <= len(name) <= 32):
            raise BadArgumentErrorWithMessage(ctx.s("faction.err.name_length"))
        if sql.guild_get_by_faction_name(name):
            await ctx.send(ctx.s("faction.name_already_exists"))
            return
        alias = re.sub("[^A-Za-z]+", "", alias).lower()
        if alias and not (1 <= len(alias) <= 5):
            raise BadArgumentErrorWithMessage(ctx.s("faction.err.alias_length"))
        if sql.guild_get_by_faction_alias(alias):
            await ctx.send(ctx.s("faction.alias_already_exists"))
            return

        sql.guild_faction_set(ctx.guild.id, name=name, alias=alias)
        await ctx.send(ctx.s("faction.assembled").format(name))
Beispiel #5
0
 async def faction_desc_set(self, ctx, *, description):
     description = re.sub(r"[^\S ]+", "", description)
     if not (len(description) <= 240):
         raise BadArgumentErrorWithMessage(
             ctx.s("faction.err.description_length"))
     guild = ctx.session.query(Guild).get(ctx.guild.id)
     if not guild.is_faction:
         return await ctx.send(ctx.s("faction.must_be_a_faction"))
     guild.faction_desc = description
     await ctx.send(ctx.s("faction.set_description"))
Beispiel #6
0
 async def faction_alias_set(self, ctx, new_alias):
     guild = ctx.session.query(Guild).get(ctx.guild.id)
     if not guild.is_faction:
         return await ctx.send(ctx.s("faction.must_be_a_faction"))
     new_alias = re.sub("[^A-Za-z]+", "", new_alias).lower()
     if not (1 <= len(new_alias) <= 5):
         raise BadArgumentErrorWithMessage(
             ctx.s("faction.err.alias_length"))
     if ctx.session.query(Guild).filter_by(faction_alias=new_alias).first():
         return await ctx.send(ctx.s("faction.alias_already_exists"))
     guild.faction_alias = new_alias
     await ctx.send(ctx.s("faction.set_alias").format(new_alias))
Beispiel #7
0
 async def faction_name_set(self, ctx, new_name):
     new_name = re.sub(r"[^\S ]+", "", new_name)
     if not (6 <= len(new_name) <= 32):
         raise BadArgumentErrorWithMessage(ctx.s("faction.err.name_length"))
     elif ctx.session.query(Guild).filter_by(faction_name=new_name).first():
         await ctx.send(ctx.s("faction.name_already_exists"))
     else:
         guild = ctx.session.query(Guild).get(ctx.guild.id)
         if not guild.is_faction:
             return await ctx.send(ctx.s("faction.must_be_a_faction"))
         guild.faction_name = new_name
         await ctx.send(ctx.s("faction.set_name").format(new_name))
Beispiel #8
0
def parse_duration(ctx, duration: str) -> int:
    matches = re.findall(r"(\d+[wdhms])", duration.lower())

    if not matches:
        raise BadArgumentErrorWithMessage(ctx.s("error.invalid_duration_1"))

    matches = {match[-1]: int(match[:-1]) for match in matches}

    suffixes = list(matches.keys())
    if len(suffixes) != len(set(suffixes)):
        raise BadArgumentErrorWithMessage(ctx.s("error.invalid_duration_2"))

    seconds = {
        "w": 7 * 24 * 60 * 60,
        "d": 24 * 60 * 60,
        "h": 60 * 60,
        "m": 60,
        "s": 1
    }

    return sum(num * seconds.get(suffix) for suffix, num in matches.items())
Beispiel #9
0
    async def assemble(self, ctx, name, alias=""):
        guild = ctx.session.query(Guild).get(ctx.guild.id)

        if guild.is_faction:
            await ctx.send(ctx.s("faction.already_faction"))
            return
        name = re.sub(r"[^\S ]+", "", name)
        if not (6 <= len(name) <= 32):
            raise BadArgumentErrorWithMessage(ctx.s("faction.err.name_length"))
        if ctx.session.query(Guild).filter_by(faction_name=name).first():
            await ctx.send(ctx.s("faction.name_already_exists"))
            return
        alias = re.sub(r"[^A-Za-z]+", "", alias).lower()
        if alias and not (1 <= len(alias) <= 5):
            raise BadArgumentErrorWithMessage(
                ctx.s("faction.err.alias_length"))
        if ctx.session.query(Guild).filter_by(faction_alias=alias).first():
            await ctx.send(ctx.s("faction.alias_already_exists"))
            return

        guild.faction_name = name
        guild.faction_alias = alias
        await ctx.send(ctx.s("faction.assembled").format(name))