Ejemplo n.º 1
0
 def delete_keys(config_keys: List[str]):
     with BotDB(conf.bot_name(), DB_NAME) as db:
         if id_str in db:
             new_version = db[id_str]
             for name in config_keys:
                 new_version.pop(name)
             db[id_str] = new_version
Ejemplo n.º 2
0
def load_user(user):
    with BotDB(conf.bot_name(), DBNAME) as db:
        if str(user.id) in db:
            rep_info = db[str(user.id)]
        else:
            rep_info = Rep()
    return rep_info
Ejemplo n.º 3
0
 def delete_rolls(names: List[str]):
     with BotDB(conf.bot_name(), DB_NAME) as db:
         if id_str in db:
             new_version = db[id_str]
             for name in names:
                 new_version.pop(name.lower())
             db[id_str] = new_version
Ejemplo n.º 4
0
def remove_key(user_id, key):
    id_str = str(user_id)
    with BotDB(conf.bot_name(), DB_NAME) as db:
        if id_str in db:
            new_version = db[id_str]
            if key in new_version:
                new_version.pop(key)
            db[id_str] = new_version
Ejemplo n.º 5
0
def add_key(user_id, key, value):
    id_str = str(user_id)
    with BotDB(conf.bot_name(), DB_NAME) as db:
        if DB_NAME not in db:
            db[id_str] = {key: value}
        else:
            new_version = db[id_str]
            new_version[key] = value
            db[id_str] = new_version
Ejemplo n.º 6
0
async def end_sprint(channel):
    result = activeSprints.pop(channel.id)
    leaderboardString = '\n'.join(
        '{0}: {1}'.format(*a)
        for a in sorted([(key, value['endCount'] - value['startCount'])
                         for key, value in result['members'].items()],
                        key=lambda x: x[1],
                        reverse=True))
    await channel.send(leaderboardString)
    with BotDB(conf.bot_name(), dbname) as db:
        db['::'.join([str(channel.id), result['start'].isoformat()])] = result
Ejemplo n.º 7
0
def save_command(name, rolls, user):
    name = name.strip().lower()
    rolls = rolls.strip().lower()
    id_str = str(user.id)
    try:
        parser.parse(rolls)
    except LarkError:
        return f'Command "{rolls}" was not valid.'
    if any(char.isdigit() for char in name):
        return f'Name "{name}" was not valid. Please do not include any numbers or special characters.'
    with BotDB(conf.bot_name(), DB_NAME) as db:
        if id_str not in db:
            db[id_str] = {name: rolls}
        else:
            new_version = db[id_str]
            new_version[name] = rolls
            db[id_str] = new_version
    return f'You have saved {rolls} as {name}'
Ejemplo n.º 8
0
def roll_command(user, command):
    if not command:
        command = 'd20'
    name = ''
    if ':' in command:
        command, name = command.split(':')
        name = name.strip()
    else:
        with BotDB(conf.bot_name(), DB_NAME) as db:
            if user in db:
                macros = db[user]
                for key in sorted(macros.keys(), key=len):
                    # For prefix matching, you want to match to the shortest possible match so all matches can be hit
                    if key.startswith(command.lower()):
                        if not name:
                            name = key
                        command = macros[key]
        # TODO this should be way more specific
    return name, RollsetTransformer().transform(parser.parse(command))
Ejemplo n.º 9
0
def leader_list(members) -> list[(str, int)]:
    with BotDB(conf.bot_name(), DBNAME) as db:
        sorted_list = [(member.name, db[str(member.id)].received) for member in members if
                       str(member.id) in db and db[str(member.id)].received > 0]
        sorted_list.sort(key=lambda user: user[1], reverse=True)
        return sorted_list
Ejemplo n.º 10
0
def save_notices(curr_notices, server_id):
    with BotDB(conf.bot_name(), dbname) as db:
        db[str(server_id)] = curr_notices
Ejemplo n.º 11
0
def load_notices(server_id):
    with BotDB(conf.bot_name(), dbname) as db:
        if str(server_id) not in db:
            db[str(server_id)] = {}
        curr_notices = db[str(server_id)]
    return curr_notices
Ejemplo n.º 12
0
def save_pet(my_pet, name):
    with BotDB(conf.bot_name(), dbname) as db:
        db[name] = my_pet
Ejemplo n.º 13
0
def get_commands(user):
    try:
        with BotDB(conf.bot_name(), DB_NAME) as db:
            return db[user]
    except KeyError:
        return {}
Ejemplo n.º 14
0
def get_user_config(user_id):
    with BotDB(conf.bot_name(), DB_NAME) as db:
        if str(user_id) in db:
            return db[str(user_id)]
        else:
            return {}
Ejemplo n.º 15
0
def save_reminders(schedule):
    with BotDB(conf.bot_name(), DB_NAME) as db:
        db[DB_KEY] = schedule
Ejemplo n.º 16
0
def load_reminders():
    with BotDB(conf.bot_name(), DB_NAME) as db:
        if DB_KEY in db:
            return db[DB_KEY]
        else:
            return {}
Ejemplo n.º 17
0
def save_user(rep_info, user):
    with BotDB(conf.bot_name(), DBNAME) as db:
        db[str(user.id)] = rep_info
Ejemplo n.º 18
0
def load_pet(name):
    with BotDB(conf.bot_name(), dbname) as db:
        my_pet = db[name]
    my_pet.update()
    return my_pet