From cd5b1b0df879b099ed05bbad8edf3e6fedbe8187 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 16 Apr 2021 04:11:51 -0400 Subject: [PATCH] Expanded Roll Command --- commands/implemented/command_roll.py | 160 +++++++++++++++++++++++---- main.py | 2 +- user_module.py | 10 +- 3 files changed, 145 insertions(+), 27 deletions(-) diff --git a/commands/implemented/command_roll.py b/commands/implemented/command_roll.py index 19b34e0..68fb63f 100644 --- a/commands/implemented/command_roll.py +++ b/commands/implemented/command_roll.py @@ -9,6 +9,122 @@ import discord import discord.message import discord.channel +class CommandRoll_Praxis(AbstractCommand, metaclass=ABCMeta): + """ + this is the roll command. + """ + command = "roll" + + def __init__(self): + super().__init__(CommandRoll_Praxis.command, n_args=1, command_type=AbstractCommand.CommandType.Praxis) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] + self.isCommandEnabled = True + self.bot = None + + def do_command(self, bot, user_message): + #print("roll Detected") + #message.chat.send("test acknowledged") + + self.bot = bot + diceRoll: str = "" + self.bot.return_message("\nRolling Dice...") + #print("Rolling Dice...") + if ("f") in user_message.message.lower(): + diceRoll = self.roll(2, user_message) + else: + diceRoll = self.roll(1, user_message) + + self.bot.return_message(diceRoll) + + + def roll(self, roll_type, user_message): + user = str(user_message.user.name) + diceRoll = "" + switch = { + 1: "Standard", + 2: "Fate Dice" + } + temp_preParsedMessage = user_message.message.split("+") + + tempParsedMessage = temp_preParsedMessage[0].split(" ") + temp_dice_stmt: str = tempParsedMessage[1] + parsedMessage = temp_dice_stmt.lower().split("d") + + loopBool: bool = False + if parsedMessage[0] != "": + loopBool = True + if loopBool == True: + if int(parsedMessage[0]) == 1: + loopBool = False + + if roll_type == 1: + print("-rolling...") + # If roll is in xdx+x format + if loopBool == True: + rolls: list = [] + for x in range(int(parsedMessage[0])): + rolls.append(random.randint(1, int(parsedMessage[1]))) # This is the roller + + rollTotal = 0 + for roll in rolls: + rollTotal = rollTotal + roll + diceRoll = diceRoll + str(roll) + ", " + diceRoll = diceRoll[:-2] # This removes the last two characters in the string + + if len(temp_preParsedMessage) == 2: + diceRoll = diceRoll + " + " + temp_preParsedMessage[1] + " = " + str( + rollTotal + int(temp_preParsedMessage[1])) + else: + diceRoll = diceRoll + " = " + str(rollTotal) + # If roll is in dx+x format + if loopBool == False: + roll: int = random.randint(1, int(parsedMessage[1])) # This is the roller + + if len(temp_preParsedMessage) == 2: + diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str( + roll + int(temp_preParsedMessage[1])) + else: + diceRoll = str(roll) + diceRoll = "@" + user + " rolled: " + diceRoll + + if roll_type == 2: + + print("-fate Rolling....") + # !roll 4df + # If roll is in xdx+x format + if loopBool == True: + rolls: list = [] + for x in range(int(parsedMessage[0])): + rolls.append(random.randint(-1, 1)) # This is the roller + + rollTotal = 0 + for roll in rolls: + rollTotal = rollTotal + roll + diceRoll = diceRoll + str(roll) + ", " + diceRoll = diceRoll[:-2] # This removes the last two characters in the string + + if len(temp_preParsedMessage) == 2: + diceRoll = diceRoll + " + " + temp_preParsedMessage[1] + " = " + str( + rollTotal + int(temp_preParsedMessage[1])) + else: + diceRoll = diceRoll + " = " + str(rollTotal) + # If roll is in dx+x format + if loopBool == False: + roll: int = random.randint(-1, 1) # This is the roller + + if len(temp_preParsedMessage) == 2: + diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str( + roll + int(temp_preParsedMessage[1])) + else: + diceRoll = str(roll) + diceRoll = "@" + user + " fate rolled: " + diceRoll + + return diceRoll + "\n" + + def get_help(self): + return self.help + class CommandRoll_Twitch(AbstractCommand, metaclass=ABCMeta): """ this is the roll command. @@ -21,29 +137,29 @@ class CommandRoll_Twitch(AbstractCommand, metaclass=ABCMeta): "\nExample:","command \"PARAM\""] self.isCommandEnabled = True - def do_command(self, bot, twitch_message): + def do_command(self, bot, message): print("!roll Detected") - #twitch_message.chat.send("test acknowledged") + #message.chat.send("test acknowledged") diceRoll: str = "" bot.send_message("Rolling Dice...") print("Rolling Dice...") - if ("f") in twitch_message.text.lower(): - diceRoll = self.roll(2, twitch_message) + if ("f") in message.text.lower(): + diceRoll = self.roll(2, message) else: - diceRoll = self.roll(1, twitch_message) + diceRoll = self.roll(1, message) bot.send_message(diceRoll) - def roll(self, roll_type, twitch_message): + def roll(self, roll_type, message): diceRoll = "" switch = { 1: "Standard", 2: "Fate Dice" } - temp_preParsedMessage = twitch_message.text.split("+") + temp_preParsedMessage = message.text.split("+") tempParsedMessage = temp_preParsedMessage[0].split(" ") temp_dice_stmt: str = tempParsedMessage[1] @@ -84,7 +200,7 @@ class CommandRoll_Twitch(AbstractCommand, metaclass=ABCMeta): else: diceRoll = str(roll) - diceRoll = "@" + twitch_message.sender + " rolled: " + diceRoll + diceRoll = "@" + message.sender + " rolled: " + diceRoll print(diceRoll) if roll_type == 2: @@ -118,7 +234,7 @@ class CommandRoll_Twitch(AbstractCommand, metaclass=ABCMeta): else: diceRoll = str(roll) - diceRoll = "@" + twitch_message.sender + " fate rolled: " + diceRoll + diceRoll = "@" + message.sender + " fate rolled: " + diceRoll print(diceRoll) return diceRoll @@ -139,30 +255,30 @@ class CommandRoll_Discord(AbstractCommand, metaclass=ABCMeta): "\nExample:","command \"PARAM\""] self.isCommandEnabled = True - async def do_command(self, bot, discord_message: discord.Message): + async def do_command(self, bot, message: discord.Message): print("!roll Detected") - #twitch_message.chat.send("test acknowledged") + #message.chat.send("test acknowledged") diceRoll: str = "" - await bot.send_message(discord_message, "Rolling Dice...") - #await discord_message.channel.send("Rolling Dice...") + await bot.send_message(message, "Rolling Dice...") + #await message.channel.send("Rolling Dice...") print("Rolling Dice...") - if ("f") in discord_message.content.lower(): - diceRoll = await self.roll(2, discord_message) + if ("f") in message.content.lower(): + diceRoll = await self.roll(2, message) else: - diceRoll = await self.roll(1, discord_message) + diceRoll = await self.roll(1, message) - await bot.send_message(discord_message, diceRoll) - #await discord_message.channel.send(diceRoll) + await bot.send_message(message, diceRoll) + #await message.channel.send(diceRoll) - async def roll(self, roll_type, discord_message: discord.Message): + async def roll(self, roll_type, message: discord.Message): diceRoll = "" switch = { 1: "Standard", 2: "Fate Dice" } - temp_preParsedMessage = discord_message.content.split("+") + temp_preParsedMessage = message.content.split("+") tempParsedMessage = temp_preParsedMessage[0].split(" ") temp_dice_stmt: str = tempParsedMessage[1] @@ -203,7 +319,7 @@ class CommandRoll_Discord(AbstractCommand, metaclass=ABCMeta): else: diceRoll = str(roll) - diceRoll = discord_message.author.mention + " rolled: " + diceRoll + diceRoll = message.author.mention + " rolled: " + diceRoll print(diceRoll) if roll_type == 2: @@ -236,7 +352,7 @@ class CommandRoll_Discord(AbstractCommand, metaclass=ABCMeta): else: diceRoll = str(roll) - diceRoll = discord_message.author.mention + " fate rolled: " + diceRoll + diceRoll = message.author.mention + " fate rolled: " + diceRoll print(diceRoll) return diceRoll diff --git a/main.py b/main.py index 98c6f60..9223899 100644 --- a/main.py +++ b/main.py @@ -109,7 +109,7 @@ def thread_main(): threads.append(thread_) thread_.start() - print("---Post Thread Creation Test---") + print("---Post Thread Creation Test---\n") for t in threads: t.join() diff --git a/user_module.py b/user_module.py index 5e239a3..11e862f 100644 --- a/user_module.py +++ b/user_module.py @@ -1,4 +1,5 @@ from enum import Enum +import time import config as config import db import tts @@ -24,7 +25,8 @@ class User_Module(): self.currentUser:User = User() def main(self): - print("\nWaiting on User input...\n") + time.sleep(.01) + print("\nWaiting on User input...\n\n") inputLoop = True if utility.isRunningInDocker() == True: inputLoop = False @@ -96,7 +98,7 @@ class User_Module(): tts.tts(message) class User(): - def __init__(self, username:str = "user"): + def __init__(self, username:str = "User"): super().__init__() self.name = username self.flags = {} @@ -112,10 +114,10 @@ class User(): self.flags.pop(name, None) class UserMessage(): - def __init__(self, user = "User", message = ""): + def __init__(self, user = User(), message = ""): super().__init__() self.user = user - self.message = message + self.message:str = message def makeMessage(self, user = "User", message = ""): self.user = user