typing + smaller bugfixes

This commit is contained in:
relikd
2022-04-09 03:45:48 +02:00
parent a25b62d934
commit d0c5072d27
15 changed files with 415 additions and 199 deletions

View File

@@ -1,20 +1,20 @@
#!/usr/bin/env python3
from botlib.tgclient import TGClient
from botlib.tgclient import TGClient, Message
bot = TGClient(__API_KEY__, polling=True, allowedUsers=['my-username'])
@bot.message_handler(commands=['hi'])
def bot_reply(message):
def bot_reply(message: Message) -> None:
if bot.allowed(message): # only reply to a single user (my-username)
bot.reply_to(message, 'Good evening my dear.')
@bot.message_handler(commands=['set'])
def update_config(message):
def update_config(message: Message) -> None:
if bot.allowed(message):
try:
config = data_store.get(message.chat.id)
config = DATA_STORE.get(message.chat.id)
except KeyError:
bot.reply_to(message, 'Not found.')
return
@@ -28,32 +28,32 @@ def update_config(message):
@bot.message_handler(commands=['start'])
def new_chat_info(message):
def new_chat_info(message: Message) -> None:
bot.log_chat_info(message.chat)
if bot.allowed(message):
if data_store.get(message.chat.id):
if DATA_STORE.get(message.chat.id):
bot.reply_to(message, 'Already exists')
else:
CreateNew(message)
class CreateNew:
def __init__(self, message):
def __init__(self, message: Message) -> None:
self.ask_name(message)
def ask_name(self, message):
def ask_name(self, message: Message) -> None:
msg = bot.send_force_reply(message.chat.id, 'Enter Name:')
bot.register_next_step_handler(msg, self.ask_interval)
def ask_interval(self, message):
def ask_interval(self, message: Message) -> None:
self.name = message.text
msg = bot.send_buttons(message.chat.id, 'Update interval (minutes):',
options=[3, 5, 10, 15, 30, 60])
bot.register_next_step_handler(msg, self.finish)
def finish(self, message):
def finish(self, message: Message) -> None:
try:
interval = int(message.text)
interval = int(message.text or 'error')
except ValueError:
bot.send_abort_keyboard(message, 'Not a number. Aborting.')
return