示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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}'
示例#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))
示例#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
示例#10
0
def save_notices(curr_notices, server_id):
    with BotDB(conf.bot_name(), dbname) as db:
        db[str(server_id)] = curr_notices
示例#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
示例#12
0
def save_pet(my_pet, name):
    with BotDB(conf.bot_name(), dbname) as db:
        db[name] = my_pet
示例#13
0
def get_commands(user):
    try:
        with BotDB(conf.bot_name(), DB_NAME) as db:
            return db[user]
    except KeyError:
        return {}
示例#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 {}
示例#15
0
def save_reminders(schedule):
    with BotDB(conf.bot_name(), DB_NAME) as db:
        db[DB_KEY] = schedule
示例#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 {}
示例#17
0
def save_user(rep_info, user):
    with BotDB(conf.bot_name(), DBNAME) as db:
        db[str(user.id)] = rep_info
示例#18
0
def load_pet(name):
    with BotDB(conf.bot_name(), dbname) as db:
        my_pet = db[name]
    my_pet.update()
    return my_pet