I have a Telegram bot which responds with different messages depending on the value funcnex.state
has.
Function is operating with this class:
class FuncCreator:
def __init__(self, start_state):
self.state = start_state
def __call__(self):
print(self.state)
self.state += 1
funcnex = FuncCreator(0)
The answer message is defined like this:
elif ' Next' in text:
if funcnex.state == 0:
b2 = u'\U0001F532'+' Next'
line1 = linecache.getline('stattxt/sc1-1.txt', 6)
line2 = linecache.getline('stattxt/sc1-1.txt', 7)
json_keyboard = json.dumps({keym: [[b2]], 'resize_keyboard': True, 'one_time_keyboard': False})
reply(u'\U000025FC'+line1+'\n'+line2)
funcnex()
elif funcnex.state == 1:
b2 = u'\U000027A1'+' Next'
line1 = linecache.getline('stattxt/sc1-1.txt', 12)
line2 = linecache.getline('stattxt/sc1-1.txt', 13)
json_keyboard = json.dumps({keym: [[b2]], 'resize_keyboard': True, 'one_time_keyboard': False})
reply(u'\U0001F532'+line1+'\n'+line2)
funcnex()
The problem is that if several users interact with the bot, the funcnex.state
for the new user could already be 1
or higher, if some user previously interacted with the bot.
The question is - how can I reset it for every new user?
Meaning that, for example,
If one user sends the word Next
to the bot for the first time, they would receive answer 1. When he sends the word Next
for second time, he would receive answer 2, and so on.
To count amount of times user send word Next
, I am using the function that is in the example. If there would be only one user everything works fine, but for second user when counter
should have value 0
for the start, now he gets the value of counter that previous user gained.