I wrote the first bot in my life using python, which get a username, password and some other data from user input, enter into a site and do some clicking there. It seems to be nothing complicated even for me whose experience in programming is only 2 months))) If the bot is used by one user from beginning to end, everything works well as it should, But if while the bot still has not finished working for one user and some other users are already beginning to use it, I have problems, global variables are confused and mixed. Please help me to handle my bug (((
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)