Skip to content

Commit

Permalink
fix #30 aggiunta azione "sta scrivendo..." e sleep anche quando viene
Browse files Browse the repository at this point in the history
data la risposta giusta
  • Loading branch information
tapionx committed Jun 27, 2018
1 parent faa4c17 commit 88e8442
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion chatta_tesoro_adminbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def do_csv_import(csvfile, chat_id):
bot.message_loop(handle)

while 1:
sleep(10)
sleep(1)
finally:
os.unlink(PIDFILE)

Expand Down
14 changes: 12 additions & 2 deletions chatta_tesoro_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __setitem__(self, key, value):
# Global variables
USER_STATE = UserState()
TEMPS = {}
SLEEP_TIME = 2


def handle(msg):
Expand Down Expand Up @@ -183,7 +184,8 @@ def handle(msg):
messages = [x.strip() for x in msg_success.split('---')]
for message in messages:
bot.sendMessage(chat_id, message, reply_markup=ReplyKeyboardRemove(remove_keyboard=True))
sleep(4)
bot.sendChatAction(chat_id, 'typing')
sleep(SLEEP_TIME)

if help_img != '':
with open('img/' + help_img, 'rb') as f:
Expand All @@ -203,6 +205,8 @@ def handle(msg):
error_message = riddle[10]
if not error_message:
error_message = 'Sbagliato!'
bot.sendChatAction(chat_id, 'typing')
sleep(SLEEP_TIME)
bot.sendMessage(chat_id, error_message)
bot.sendMessage(chat_id, "Riprova tra 60 secondi")
else:
Expand Down Expand Up @@ -257,6 +261,8 @@ def handle(msg):
add_solved(chat_id, state.riddle_id)

# Invia il messaggio di successo
bot.sendChatAction(chat_id, 'typing')
sleep(SLEEP_TIME)
bot.sendMessage(chat_id, state.msg_success)

# Invia il successivo riddle
Expand Down Expand Up @@ -295,14 +301,18 @@ def handle(msg):
if riddle[1] == 'open':
markup = None

bot.sendChatAction(chat_id, 'typing')
sleep(SLEEP_TIME)

# Multimessagges support: issue #11
# Each Messagge has the "---" separator if it is a multimessage
question = riddle[0]
messages = [x.strip() for x in question.split('---')]
last_message_with_markup = messages.pop()
for message in messages:
bot.sendMessage(chat_id, message)
sleep(4)
bot.sendChatAction(chat_id, 'typing')
sleep(SLEEP_TIME)
bot.sendMessage(chat_id, last_message_with_markup, reply_markup=markup)
else:
bot.sendMessage(chat_id, 'QR non valido! Riprova')
Expand Down

0 comments on commit 88e8442

Please sign in to comment.