diff --git a/cast.py b/cast.py index 2fa44190..6028dfab 100644 --- a/cast.py +++ b/cast.py @@ -1,5 +1,6 @@ import random import math +import dice def cast(spell_name: str, target_name: str, platform: str) -> str: diff --git a/db.py b/db.py index b33d5ef8..73cf7a1e 100644 --- a/db.py +++ b/db.py @@ -805,7 +805,7 @@ class Reddit(Base): royal_id = Column(Integer, ForeignKey("royals.id")) royal = relationship("Royal", backref="reddit", lazy="joined") - username = Column(String) + username = Column(String, primary_key=True) karma = Column(BigInteger) @@ -815,7 +815,7 @@ class GameLog(Base): royal_id = Column(Integer, ForeignKey("royals.id")) royal = relationship("Royal", backref="gamelog", lazy="joined") - username = Column(String) + username = Column(String, primary_key=True) owned_games = Column(Integer) unfinished_games = Column(Integer) beaten_games = Column(Integer) diff --git a/telegrambot.py b/telegrambot.py index 978314fb..258eb093 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -7,7 +7,7 @@ import stagismo from telegram import Bot, Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram.ext import Updater, CommandHandler, CallbackQueryHandler import telegram.error -from discord import Status as DiscordStatus +import dice import subprocess import os import time @@ -503,11 +503,23 @@ def cmd_markov(bot: Bot, update: Update): bot.send_message(update.message.chat.id, sentence) +def cmd_roll(bot: Bot, update: Update): + dice_string = update.message.text.split(" ", 1)[1] + try: + result = dice.utilities.verbose_print(dice_string) + except dice.DiceBaseException: + bot.send_message(update.message.chat.id, "⚠ Il tiro dei dadi è fallito. Controlla la sintassi!") + return + bot.send_message(update.message.chat.id, f"🎲 Tiro {int(dice_string)}: **{result}**", parse_mode="Markdown") + + def process(arg_discord_connection): if arg_discord_connection is not None: global discord_connection discord_connection = arg_discord_connection + logger.info("Creating updater...") u = Updater(config["Telegram"]["bot_token"]) + logger.info("Registering handlers...") u.dispatcher.add_handler(CommandHandler("register", cmd_register)) u.dispatcher.add_handler(CommandHandler("discord", cmd_discord)) u.dispatcher.add_handler(CommandHandler("cv", cmd_discord)) @@ -527,6 +539,8 @@ def process(arg_discord_connection): u.dispatcher.add_handler(CommandHandler("newevent", cmd_newevent)) u.dispatcher.add_handler(CommandHandler("calendar", cmd_calendar)) u.dispatcher.add_handler(CommandHandler("markov", cmd_markov)) + u.dispatcher.add_handler(CommandHandler("roll", cmd_roll)) + u.dispatcher.add_handler(CommandHandler("r", cmd_roll)) u.dispatcher.add_handler(CallbackQueryHandler(on_callback_query)) logger.info("Handlers registered.") u.bot.send_message(config["Telegram"]["main_group"],