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()
def del_user(user_id): with LOCK: session = get_session() session.query(User).filter(User.id == user_id).delete() session.commit() session.close() return
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()
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()
def set_nanny(chat_id): with LOCK: session = get_session() nanny = SettingsNurse(id=chat_id) session.add(nanny) session.commit() session.close()
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()
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()
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()
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()
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()
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()
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()
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
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()
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()
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()
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()
def set_admin(chat_id): with LOCK: session = get_session() admin = AdminGroups(id=chat_id) session.add(admin) session.commit() session.close() return
def set_user(user_id): with LOCK: session = get_session() user = User(id=user_id) session.add(user) session.commit() session.close() return
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()
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()
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()
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
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
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()
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()
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()
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()
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()
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()