bot new commands and funcs + api updates

This commit is contained in:
Linus E
2022-04-17 12:20:53 +02:00
parent 543c51397e
commit b06b024326
3 changed files with 55 additions and 1 deletions

View File

@@ -437,7 +437,56 @@ def set_new_transaction_step(message):
bot.send_message(chat_id=user_id, text=f'Failed adding transaction. (statuscode {status})')
@bot.message_handler(commands=['interval'])
def send_interval(message):
""" send interval for user
:type message: message object bot
:param message: message that was reacted to, in this case always '/interval'
:raises: none
:rtype: none
"""
user_id = int(message.from_user.id)
interval = api_handler.get_user(user_id)['cron']
if interval == None:
bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too connect your telegram id (/id) on https://gruppe1.testsites.info and set an interval with /setinterval')
return
else:
interval = str(interval)
formatted_interval = str(interval).replace(' ', '_')
bot.send_message(chat_id=user_id, text=f'Your update interval: {interval} (https://crontab.guru/#{formatted_interval})', parse_mode="MARKDOWN")
@bot.message_handler(commands=['setinterval'])
def set_new_interval(message):
""" Set new interval for user
:type message: message object bot
:param message: message that was reacted to, in this case always '/setinterval'
:raises: none
:rtype: none
"""
user_id = int(message.from_user.id)
bot.send_message(chat_id=user_id, text='Type interval in cron format (https://crontab.guru/):')
bot.register_next_step_handler(message, set_new_interval_step)
def set_new_interval_step(message):
user_id = int(message.from_user.id)
interval = str(message.text)
status = api_handler.set_cron_interval(user_id, interval)
if status == 200:
bot.send_message(chat_id=user_id, text='Interval succesfully set.')
return
if status == -1:
bot.send_message(chat_id=user_id, text='Invalid interval. Try again with /setinterval.')
return
else:
bot.send_message(chat_id=user_id, text=f'Failed setting interval. (statuscode {status})')
@bot.message_handler(func=lambda message: True) # Returning that command is unknown for any other statement