From 533d69787f61a2455079f4f8bf97b26600e37068 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Mon, 5 Apr 2021 14:42:31 -0400 Subject: [PATCH 1/2] I think it works --- commands/implemented/command_roll_discord.py | 152 +++++++++++++++---- 1 file changed, 125 insertions(+), 27 deletions(-) diff --git a/commands/implemented/command_roll_discord.py b/commands/implemented/command_roll_discord.py index 4f89c74..f91a209 100644 --- a/commands/implemented/command_roll_discord.py +++ b/commands/implemented/command_roll_discord.py @@ -28,6 +28,72 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): #await discord_message.channel.send("Rolling Dice...") print("Rolling Dice...") + if "f" in discord_message.content.lower(): + await diceRoll = self.roll(2, discord_message) + else: + await diceRoll = self.roll(1, discord_message) + + #======================== + #Old Code Below + #======================== + + # temp_preParsedMessage = discord_message.content.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 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]))) + + # 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])) + + # if len(temp_preParsedMessage) == 2: + # diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str( + # roll + int(temp_preParsedMessage[1])) + # else: + # diceRoll = str(roll) + + # diceRoll = discord_message.author.mention + " rolled: " + diceRoll + # print(diceRoll) + + #======================== + #Old Code Above + #======================== + + + + await bot.send_message(discord_message, diceRoll) + #await discord_message.channel.send(diceRoll) + + async def roll(self, roll_type, discord_message: discord.Message): + switch = { + 1: "Standard", + 2: "Fudge Dice" + } temp_preParsedMessage = discord_message.content.split("+") tempParsedMessage = temp_preParsedMessage[0].split(" ") @@ -41,34 +107,66 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): if int(parsedMessage[0]) == 1: loopBool = False - # 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]))) + if roll_type == 1: + # 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 + 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])) + 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) + if len(temp_preParsedMessage) == 2: + diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str( + roll + int(temp_preParsedMessage[1])) + else: + diceRoll = str(roll) - diceRoll = discord_message.author.mention + " rolled: " + diceRoll - print(diceRoll) - await bot.send_message(discord_message, diceRoll) - #await discord_message.channel.send(diceRoll) + diceRoll = discord_message.author.mention + " rolled: " + diceRoll + print(diceRoll) + + if roll_type == 2: + # If roll is in xdx+x format + if loopBool == True: + rolls: list = [] + for x in range(int(parsedMessage[0])): + rolls.append(random.randint(1, 3)) # 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, 3) # 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 = discord_message.author.mention + " rolled: " + diceRoll + print(diceRoll) + + return diceRoll From fee939331fa02c85cc49f093713518fb024a1db7 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 13:17:56 -0400 Subject: [PATCH 2/2] Fixed Command --- commands/implemented/command_roll.py | 154 +++++++++++++++---- commands/implemented/command_roll_discord.py | 10 +- 2 files changed, 133 insertions(+), 31 deletions(-) diff --git a/commands/implemented/command_roll.py b/commands/implemented/command_roll.py index 48a87cb..7f1549d 100644 --- a/commands/implemented/command_roll.py +++ b/commands/implemented/command_roll.py @@ -21,6 +21,72 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): bot.send_message("Rolling Dice...") print("Rolling Dice...") + if ("f") in twitch_message.text.lower(): + diceRoll = self.roll(2, twitch_message) + else: + diceRoll = self.roll(1, twitch_message) + + #======================== + #Old Code Below + #======================== + + # temp_preParsedMessage = twitch_message.text.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 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]))) + + # 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])) + + # if len(temp_preParsedMessage) == 2: + # diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str( + # roll + int(temp_preParsedMessage[1])) + # else: + # diceRoll = str(roll) + + # diceRoll = "@" + twitch_message.sender + " rolled: " + diceRoll + # print(diceRoll) + + + #======================== + #Old Code Above + #======================== + + bot.send_message(diceRoll) + + + def roll(self, roll_type, twitch_message): + diceRoll = "" + switch = { + 1: "Standard", + 2: "Fate Dice" + } temp_preParsedMessage = twitch_message.text.split("+") tempParsedMessage = temp_preParsedMessage[0].split(" ") @@ -34,33 +100,69 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): if int(parsedMessage[0]) == 1: loopBool = False - # 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]))) + if roll_type == 1: + # 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 + 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])) + 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) + if len(temp_preParsedMessage) == 2: + diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str( + roll + int(temp_preParsedMessage[1])) + else: + diceRoll = str(roll) - diceRoll = "@" + twitch_message.sender + " rolled: " + diceRoll - print(diceRoll) - bot.send_message(diceRoll) \ No newline at end of file + diceRoll = "@" + twitch_message.sender + " rolled: " + diceRoll + print(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 = "@" + twitch_message.sender + " fate rolled: " + diceRoll + print(diceRoll) + + return diceRoll diff --git a/commands/implemented/command_roll_discord.py b/commands/implemented/command_roll_discord.py index f91a209..86244ea 100644 --- a/commands/implemented/command_roll_discord.py +++ b/commands/implemented/command_roll_discord.py @@ -28,10 +28,10 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): #await discord_message.channel.send("Rolling Dice...") print("Rolling Dice...") - if "f" in discord_message.content.lower(): - await diceRoll = self.roll(2, discord_message) + if ("f") in discord_message.content.lower(): + diceRoll = await self.roll(2, discord_message) else: - await diceRoll = self.roll(1, discord_message) + diceRoll = await self.roll(1, discord_message) #======================== #Old Code Below @@ -92,7 +92,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): async def roll(self, roll_type, discord_message: discord.Message): switch = { 1: "Standard", - 2: "Fudge Dice" + 2: "Fate Dice" } temp_preParsedMessage = discord_message.content.split("+") @@ -166,7 +166,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): else: diceRoll = str(roll) - diceRoll = discord_message.author.mention + " rolled: " + diceRoll + diceRoll = discord_message.author.mention + " fate rolled: " + diceRoll print(diceRoll) return diceRoll