|
@@ -7,28 +7,30 @@ license: AGPL-3.0-only, see COPYING
|
|
|
|
|
|
|
|
|
|
import logging
|
|
import logging
|
|
-from telegram.ext import Updater, CommandHandler
|
|
|
|
-import helpers
|
|
|
|
-from bottoken import TOKEN
|
|
|
|
|
|
+from telegram import Update
|
|
|
|
+from telegram.ext import Updater, CommandHandler, CallbackContext
|
|
|
|
+from . import config, helpers
|
|
|
|
|
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
-def start(update, context):
|
|
|
|
|
|
+def start(update: Update, context: CallbackContext) -> None:
|
|
|
|
+ """Send explanation what this bot does on /start"""
|
|
reply = "Do '/roll <number> to roll up 100 dice.\nFor source code, do /license."
|
|
reply = "Do '/roll <number> to roll up 100 dice.\nFor source code, do /license."
|
|
context.bot.send_message(chat_id=update.effective_chat.id, text=reply)
|
|
context.bot.send_message(chat_id=update.effective_chat.id, text=reply)
|
|
|
|
|
|
-def license(update, context):
|
|
|
|
|
|
+def license(update: Update, context: CallbackContext) -> None:
|
|
|
|
+ """Send message with license and link to source code"""
|
|
reply = "This bot is free software under the AGPLv3. \nSource: https://notabug.org/samtinel/telegram-bot-shadowrun"
|
|
reply = "This bot is free software under the AGPLv3. \nSource: https://notabug.org/samtinel/telegram-bot-shadowrun"
|
|
context.bot.send_message(chat_id=update.effective_chat.id, text=reply)
|
|
context.bot.send_message(chat_id=update.effective_chat.id, text=reply)
|
|
|
|
|
|
-def roll(update, context):
|
|
|
|
|
|
+def roll(update: Update, context: CallbackContext) -> None:
|
|
"""Rolls dice for /roll x
|
|
"""Rolls dice for /roll x
|
|
x dice, if x not given, roll DEFAULT_AMOUNT
|
|
x dice, if x not given, roll DEFAULT_AMOUNT
|
|
returns pseudo-random numbers provided by python's random, meaning seed is system time
|
|
returns pseudo-random numbers provided by python's random, meaning seed is system time
|
|
NOTE: if cheating is something to worry about, a better source of randomness should be used"""
|
|
NOTE: if cheating is something to worry about, a better source of randomness should be used"""
|
|
- DEFAULT_AMOUNT = 1 # default amount for /roll without arg
|
|
|
|
- LIMIT_DICE = 99 # how much dice can be rolled at the same time?
|
|
|
|
|
|
+ DEFAULT_AMOUNT = config.DEFAULT_AMOUNT
|
|
|
|
+ LIMIT_DICE = config.LIMIT_DICE
|
|
|
|
|
|
# set amount
|
|
# set amount
|
|
if not context.args:
|
|
if not context.args:
|
|
@@ -54,17 +56,18 @@ def roll(update, context):
|
|
reply = f"Enter a valid integer between 0 and 100"
|
|
reply = f"Enter a valid integer between 0 and 100"
|
|
context.bot.send_message(chat_id=update.effective_chat.id, text=reply)
|
|
context.bot.send_message(chat_id=update.effective_chat.id, text=reply)
|
|
|
|
|
|
-# set up bot
|
|
|
|
-updater = Updater(token=TOKEN, use_context=True)
|
|
|
|
|
|
+def main():
|
|
|
|
+ # set up bot
|
|
|
|
+ updater = Updater(token=config.TOKEN, use_context=True)
|
|
|
|
|
|
-# set up handlers
|
|
|
|
-handlers = []
|
|
|
|
-handlers.append(CommandHandler('start', start))
|
|
|
|
-handlers.append(CommandHandler('roll', roll))
|
|
|
|
-handlers.append(CommandHandler('license', license))
|
|
|
|
|
|
+ # set up handlers
|
|
|
|
+ handlers = []
|
|
|
|
+ handlers.append(CommandHandler('start', start))
|
|
|
|
+ handlers.append(CommandHandler('roll', roll))
|
|
|
|
+ handlers.append(CommandHandler('license', license))
|
|
|
|
|
|
-for handler in handlers:
|
|
|
|
- updater.dispatcher.add_handler(handler)
|
|
|
|
|
|
+ for handler in handlers:
|
|
|
|
+ updater.dispatcher.add_handler(handler)
|
|
|
|
|
|
-# start polling
|
|
|
|
-updater.start_polling()
|
|
|
|
|
|
+ # start polling
|
|
|
|
+ updater.start_polling()
|