如何在电报漫游器中同时管理多个用户请求?

时间:2019-04-09 19:20:38

标签: python

我使用python编写了我人生中的第一个机器人,该机器人从用户输入中获取用户名,密码和一些其他数据,进入一个站点并单击此处。即使对于只有2个月编程经验的我来说,这似乎也没什么复杂的。)))如果该机器人自始至终被一个用户使用,则一切运行正常,但如果该机器人仍未完成工作,对于一个用户和其他一些用户已经开始使用它,我遇到了问题,全局变量感到困惑和混合。 请帮助我解决我的错误(((

import telebot
from telebot.types import Message
from telebot import types
import requests


bot = telebot.TeleBot('xxx')


start_text = """
Hello

"""

payment_text = """
Chose the payment type:
"""

help_text = """
Commands:
/pushup - starting
"""

def check_reg(login, password):
    r = requests.post('xxx', data={'login': str(login), 'password': 
str(password)})
    response = r.text
    return response


@bot.message_handler(commands=['start'])
def start_handler(message: Message):
    bot.send_message(message.from_user.id, start_text)


@bot.message_handler(commands=['help'])
def help_handler(message: Message):
    bot.send_message(message.from_user.id, help_text)



@bot.message_handler(commands=['up'])
def login_handler(message: Message):
    bot.send_message(message.from_user.id, a)
    bot.register_next_step_handler(message, get_login)


@bot.message_handler(content_types=['text'])
def text_handler(message: Message):
        bot.send_message(message.from_user.id, b)


def get_login(message: Message):
    if '@' in message.text or '+' in message.text:
        global login
        login = message.text
        bot.send_message(message.from_user.id, c)
        bot.register_next_step_handler(message, get_psw)
    else:
        bot.send_message(message.from_user.id, d)
        bot.register_next_step_handler(message, get_login)


def get_psw(message):
    global password
    password = message.text
    if check_reg(login, password) == '1':
        bot.send_message(message.from_user.id, e)
        bot.register_next_step_handler(message, get_up)
    else:
        bot.send_message(message.from_user.id, f)

def get_up(message):
    global up
    up = message.text
    if up.isdigit():
        if int(up) <= 0:
            bot.send_message(message.from_user.id, g)
            bot.register_next_step_handler(message, get_up)
        else:
            get_url(message)
    else:
        bot.send_message(message.from_user.id, h)
        bot.register_next_step_handler(message, get_up)


def get_url(message):
    keyboard = types.InlineKeyboardMarkup()
    key_xx = types.InlineKeyboardButton("xx", callback_data='xx')
    keyboard.add(key_xx)
    key_yy = types.InlineKeyboardButton("yy", callback_data='yy')
    keyboard.add(key_yy)
    bot.send_message(message.from_user.id, text=i, reply_markup=keyboard)


@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
    global url
    if call.data == "xx":
        url = "xx"
        test(call)
    elif call.data == "yy":
        url = "yy"
        test(call)


def test(message):
    test= test()
    if test.login(url, login, password):
        bot.send_message(message.from_user.id, j)
        if test.auto_click(up):
            bot.send_message(message.from_user.id, k)
            bot.send_message(message.from_user.id, n)
            test.kill_task()
        else:
            bot.send_message(message.from_user.id, l)
            test.kill_task()
    else:
        bot.send_message(message.from_user.id, m)
        bot.register_next_step_handler(message, get_login)
        test.kill_task()

bot.polling(timeout=90)

1 个答案:

答案 0 :(得分:0)

我自己做的

user = {}

class user_cred():
   login = ''
    password = ''
    up = ''

def __init__(self, login, password, up):
    self.login = login
    self.password = password
    self.up = up

def set_login(self, login):
    self.login = login

def set_password(self, password):
    self.password = password

def set_up(self, up):
    self.up = up