Пример #1
0
def group_message_counter(group_id, read_only=False, reset=False):
    with LOCK:
        try:
            if read_only:
                session = get_session()
                group = get_unique_from_query(
                    session.query(
                        model.Group).filter(model.Group.id == group_id))
                return group.message_num
            if reset:
                session = get_session()
                group = get_unique_from_query(
                    session.query(
                        model.Group).filter(model.Group.id == group_id))
                group.message_num = 0
                return group.message_num
            else:
                session = get_session()
                group = get_unique_from_query(
                    session.query(
                        model.Group).filter(model.Group.id == group_id))
                if group.message_num is None:
                    group.message_num = 0
                group.message_num += 1
                return group.message_num
        finally:
            session.commit()
            session.close()
Пример #2
0
def del_user(user_id):
    with LOCK:
        session = get_session()
        session.query(User).filter(User.id == user_id).delete()
        session.commit()
        session.close()
        return
Пример #3
0
def commit_user(user_id,
                alias=None,
                level=None,
                profession=None,
                house=None,
                team=None,
                validation=None,
                profession_level=None,
                fort_level=None):
    with LOCK:
        session = get_session()
        user = get_unique_from_query(
            session.query(User).filter(User.id == user_id))
        if alias:
            user.alias = alias
        if level:
            user.level = level
        if house:
            user.house = house
        if validation:
            user.validation = validation
        if profession:
            user.profession = profession
        if team:
            user.team = team
        if profession_level:
            user.profession_level = profession_level
        if fort_level:
            user.fort_level = fort_level
        session.commit()
        session.close()
Пример #4
0
def set_custom_welcome(chat_id, custom_welcome, welcome_type, buttons=None):
    if buttons is None:
        buttons = []

    with LOCK:
        session = get_session()
        welcome_settings = session.query(Welcome).get(str(chat_id))
        if not welcome_settings:
            welcome_settings = Welcome(str(chat_id), True)

        if custom_welcome:
            welcome_settings.custom_welcome = custom_welcome
            welcome_settings.welcome_type = welcome_type.value

        session.add(welcome_settings)

        with BTN_LOCK:
            prev_buttons = session.query(WelcomeButtons).filter(
                WelcomeButtons.chat_id == str(chat_id)).all()
            for btn in prev_buttons:
                session.delete(btn)

            for b_name, url, same_line in buttons:
                button = WelcomeButtons(chat_id, b_name, url, same_line)
                session.add(button)

        session.commit()
Пример #5
0
def set_nanny(chat_id):
    with LOCK:
        session = get_session()
        nanny = SettingsNurse(id=chat_id)
        session.add(nanny)
        session.commit()
        session.close()
Пример #6
0
def get_real_user(user_id):
    try:
        session = get_session()
        return get_unique_from_query(
            session.query(User).filter(User.id == user_id))
    finally:
        session.close()
Пример #7
0
def get_user_by_name(username):
    try:
        session = get_session()
        return get_unique_from_query(
            session.query(User).filter(User.alias == username))
    finally:
        session.close()
Пример #8
0
def get_particular_admin(chat_id):
    try:
        session = get_session()
        return get_unique_from_query(
            session.query(SettingsAdmin).filter(SettingsAdmin.id == chat_id))
    finally:
        session.close()
Пример #9
0
def get_admin(chat_id):
    try:
        session = get_session()
        return get_unique_from_query(
            session.query(AdminGroups).filter(AdminGroups.id == chat_id))
    finally:
        session.close()
Пример #10
0
def set_staff(user_id, staff_bool):
    with LOCK:
        session = get_session()
        user = get_unique_from_query(
            session.query(User).filter(User.id == user_id))
        user.staff = staff_bool
        session.commit()
        session.close()
Пример #11
0
def set_fc(fc, user_id):
    with LOCK:
        session = get_session()
        user = get_unique_from_query(
            session.query(User).filter(User.id == user_id))
        user.friend_id = fc
        session.commit()
        session.close()
Пример #12
0
def get_poi(poi_id):
    try:
        session = get_session()
        poi = get_unique_from_query(
            session.query(model.Portals).filter(model.Portals.id == poi_id))
        return poi
    finally:
        session.close()
Пример #13
0
def rm_link(group_id):
    with LOCK:
        session = get_session()
        session.query(LinkedGroups).filter(
            LinkedGroups.linked_id == group_id).delete()
        session.commit()
        session.close()
        return
Пример #14
0
def update_ranking(user_id):
    with LOCK:
        session = get_session()
        user = get_unique_from_query(
            session.query(User).filter(User.id == user_id))
        user.ranking = not user.ranking
        session.commit()
        session.close()
Пример #15
0
def get_welcome_settings(chat_id):
    try:
        session = get_session()
        group = get_unique_from_query(
            session.query(Welcome).filter(Welcome.chat_id == chat_id))
        return group
    finally:
        session.close()
Пример #16
0
def get_welc_buttons(chat_id):
    session = get_session()
    try:
        return session.query(WelcomeButtons).filter(
            WelcomeButtons.chat_id == str(chat_id)).order_by(
                WelcomeButtons.id).all()
    finally:
        session.close()
Пример #17
0
def set_ghost(user_id, ghost_bool):
    with LOCK:
        session = get_session()
        user = get_unique_from_query(
            session.query(User).filter(User.id == user_id))
        user.ghost = ghost_bool
        session.commit()
        session.close()
Пример #18
0
def set_admin(chat_id):
    with LOCK:
        session = get_session()
        admin = AdminGroups(id=chat_id)
        session.add(admin)
        session.commit()
        session.close()
        return
Пример #19
0
def set_user(user_id):
    with LOCK:
        session = get_session()
        user = User(id=user_id)
        session.add(user)
        session.commit()
        session.close()
        return
Пример #20
0
def get_nanny_settings(chat_id):
    try:
        session = get_session()
        nanny = get_unique_from_query(
            session.query(SettingsNurse).filter(SettingsNurse.id == chat_id))
        return nanny
    finally:
        session.close()
Пример #21
0
def update_fclist(user_id):
    with LOCK:
        session = get_session()
        user = get_unique_from_query(
            session.query(User).filter(User.id == user_id))
        user.fclists = not user.fclists
        session.commit()
        session.close()
Пример #22
0
def get_warn_limit(group_id):
    try:
        session = get_session()
        group = get_unique_from_query(
            session.query(SettingsGroup).filter(SettingsGroup.id == group_id))
        return group.warn.value
    finally:
        session.close()
Пример #23
0
def set_user_group(user_id, chat_id):
    with LOCK:
        session = get_session()
        guser = UserGroup(user_id=user_id, group_id=chat_id)
        session.add(guser)
        session.commit()
        session.close()
        return
Пример #24
0
def new_link(admin, chat):
    with LOCK:
        session = get_session()
        linked = LinkedGroups(admin_id=admin, linked_id=chat)
        session.add(linked)
        session.commit()
        session.close()
        return
Пример #25
0
def get_group_settings(group_id):
    try:
        session = get_session()
        group = get_unique_from_query(
            session.query(SettingsGroup).filter(SettingsGroup.id == group_id))
        return group
    finally:
        session.close()
Пример #26
0
def get_plant_list(group_id):
    try:
        session = get_session()
        plants = session.query(
            model.Plants).filter(model.Plants.group_id == group_id)
        return plants
    finally:
        session.close()
Пример #27
0
def get_join_settings(chat_id):
    try:
        session = get_session()
        group = get_unique_from_query(
            session.query(SettingsJoin).filter(SettingsJoin.id == chat_id))
        return group
    finally:
        session.close()
Пример #28
0
def get_real_group(group_id):
    try:
        session = get_session()
        group = get_unique_from_query(
            session.query(model.Group).filter(model.Group.id == group_id))
        return group
    finally:
        session.close()
Пример #29
0
def get_users_from_group(group_id):
    try:
        session = get_session()
        gusers = session.query(UserGroup).filter(
            UserGroup.group_id == group_id)
        return gusers
    finally:
        session.close()
Пример #30
0
def get_plant(plant_id):
    try:
        session = get_session()
        plant = get_unique_from_query(
            session.query(model.Plants).filter(model.Plants.id == plant_id))
        return plant
    finally:
        session.close()