def main(): """""" _ = lambda text: text """-----------------User-----------------""" Permission.create('start_menu_access', _('Access to "Start" menu')) """-----------------Admin-----------------""" # menus Permission.create('admin_menu_access', _('Access to "Admin" menu')) Permission.create('distribution_menu_access', _('Access to "Distribution" admin menu')) Permission.create('settings_menu_access', _('Access to "Settings" admin menu')) # permissions menu Permission.create(Permission.view_permission, _('Access to "Permissions" menu')) Permission.create(Permission.add_permission, _('Allow add permission')) Permission.create(Permission.delete_permission, _('Allow remove permission')) Permission.create('superuser', _('Superuser')) DBSession.commit() users = DBSession.query(User).filter( User.chat_id.in_(SUPERUSER_ACCOUNTS)).all() permission = DBSession.query(Permission).get('superuser') for user in users: if not user.has_permission(permission.code): user.permissions.append(permission) DBSession.add(user) DBSession.commit()
def main(): users = DBSession.query(User).filter(User.is_active == True).all() for user in users: user.init_permissions() DBSession.add(user) DBSession.commit()
def stop(bot, update, user_data): _ = user_data['_'] if '_' in user_data else gettext user = DBSession.query(User).filter( User.chat_id == user_data['user'].chat_id).first() user.active = False DBSession.add(user) DBSession.commit() bot.send_message(chat_id=user.chat_id, text='Вы удалены из бота.')
def stop(update, context): # if user never have a conversation with bot and sending /stop he has empty user_data if context.user_data: _ = context.user_data['user'].translator user = DBSession.query(User).filter( User.chat_id == context.user_data['user'].chat_id).first() user.active = False user.chat_room_id = None DBSession.add(user) DBSession.commit() context.bot.send_message(chat_id=user.chat_id, text=_("You are deleted from this bot."))
def users_from_chat(bot=None, job=None): data = get_settings_file(SETTINGS_FILE) day, month, year = data['transition'].split('.') transition = date(int(year), int(month), int(day)) with client: entity = client.get_entity(data['chat_link']) users_in_chat = client.get_participants(entity) for user_chat in users_in_chat: user = DBSession.query(User).filter(User.chat_id == user_chat.id).first() if user is None: user = User() user.chat_id = user_chat.id user.name = user_chat.first_name user.username = user_chat.username user.active = True user.join_date = date.today() user.expiration_date = transition DBSession.add(user) DBSession.commit() logger.info(f"Added {user.username}") else: pass