def run(message): global flag flag = True db = connector.DataBaseConnect() if int(message.chat.id) != int(user_id) and str( message.chat.id) not in db.get_banned_users(user_id=user_id, bot_name=_bot): bot.forward_message(user_id, message_id=message.message_id, from_chat_id=message.chat.id) db.add_user(user_id=user_id, user=message, _bot=_bot) if str(message.chat.id) not in db.get_banned_users(user_id=user_id, bot_name=_bot): if db.off_greeting(get_status=True, user_id=user_id, bot_name=bot.get_me().username) == '1': delay = db.get_delay(user_id=user_id, bot_name=bot.get_me().username) sleep(int(delay[0])) greeting = db.get_greeting(user_id=str(user_id), bot_name=bot.get_me().username)[0] if db.manage_ad(get=True, user_id=user_id, bot_name=_bot)[0][0]: greeting += '\n\nБот создан с помощью @FoqBot.' bot.send_message(message.chat.id, text=greeting)
def ban_user(message): db = connector.DataBaseConnect() if message.reply_to_message is not None: if message.reply_to_message.forward_from.id != user_id: db.ban_user(user_id=user_id, bot_name=_bot, banned_user=str( message.reply_to_message.forward_from.id)) bot.send_message(user_id, text='Пользователь успешно заблокирован.') else: bot.send_message(user_id, text='Вы неможете заблокировать себя.') else: bot.send_message(user_id, text='Пользователь невыбран.')
print('Запуск пользовательских ботов.') counter = 0 for i in DB.get_all_tokens(): if check_token(i[0]): counter += 1 print('Запуск бота под номером: {}.'.format(counter)) name = get_bot_name(i[0]) process = Process(target=func.main, args=(i[0], i[1])) if i[1] not in processes: processes[i[1]] = {name: process} else: processes[i[1]].update({name: process}) try: process.start() except RuntimeError: print('Can\'t start new process') else: print('Token {} was deleted'.format(i[0])) DB.delete_items(token=i[0], user_id=i[1]) def main(): run_bots() print('Основной бот запущен.') bot.polling(none_stop=True) if __name__ == '__main__': DB = connector.DataBaseConnect() main()
def driver(message): nonlocal client_id global flag db = connector.DataBaseConnect() if str(message.chat.id) not in db.get_banned_users(user_id=user_id, bot_name=_bot): if int(message.from_user.id) != int(user_id): bot.forward_message(user_id, message_id=message.message_id, from_chat_id=message.chat.id) if message.text in [ x[0] for x in db.get_commands(user_id=user_id, _all=True) ] and message.text != 'empty': command_message = db.get_commands(user_id=user_id, command=message.text) bot.send_message(message.from_user.id, text=command_message) bot.send_message(user_id, text=command_message) try: if flag: status = db.get_second_greeting_status( user_id=user_id, bot_name=_bot)[0][0] if status: second_greeting = db.get_greeting(second=True, user_id=user_id, bot_name=_bot) if second_greeting[0] != 'empty': bot.send_message(message.from_user.id, text=second_greeting[0]) flag = False except NameError: pass else: try: if message.reply_to_message is not None: bot.send_message( message.reply_to_message.forward_from.id, text=message.text) client_id = message.reply_to_message.forward_from.id if message.text in [ x[0] for x in db.get_commands(user_id=user_id, _all=True) ] and message.text != 'empty': command_message = db.get_commands( user_id=user_id, command=message.text) bot.send_message(client_id, text=command_message) bot.send_message(user_id, text=command_message) else: if client_id: flag = False if message.text in [ x[0] for x in db.get_commands(user_id=user_id, _all=True) ]: command_message = db.get_commands( user_id=user_id, command=message.text) bot.send_message(client_id, message.text) bot.send_message(client_id, text=command_message) bot.send_message(user_id, text=command_message) else: bot.send_message(client_id, text=message.text) else: bot.send_message(message.chat.id, 'Вы не выбрали получателя.') except Exception as Error: print(Error)