Merge branch 'Fate-Dice-Rolls' into master

This commit is contained in:
alex_orid 2021-04-09 17:22:55 +00:00
commit 8512e9a59b
2 changed files with 253 additions and 53 deletions

View File

@ -21,6 +21,72 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
bot.send_message("Rolling Dice...") bot.send_message("Rolling Dice...")
print("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("+") temp_preParsedMessage = twitch_message.text.split("+")
tempParsedMessage = temp_preParsedMessage[0].split(" ") tempParsedMessage = temp_preParsedMessage[0].split(" ")
@ -34,11 +100,12 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
if int(parsedMessage[0]) == 1: if int(parsedMessage[0]) == 1:
loopBool = False loopBool = False
if roll_type == 1:
# If roll is in xdx+x format # If roll is in xdx+x format
if loopBool == True: if loopBool == True:
rolls: list = [] rolls: list = []
for x in range(int(parsedMessage[0])): for x in range(int(parsedMessage[0])):
rolls.append(random.randint(1, int(parsedMessage[1]))) rolls.append(random.randint(1, int(parsedMessage[1]))) # This is the roller
rollTotal = 0 rollTotal = 0
for roll in rolls: for roll in rolls:
@ -53,7 +120,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
diceRoll = diceRoll + " = " + str(rollTotal) diceRoll = diceRoll + " = " + str(rollTotal)
# If roll is in dx+x format # If roll is in dx+x format
if loopBool == False: if loopBool == False:
roll: int = random.randint(1, int(parsedMessage[1])) roll: int = random.randint(1, int(parsedMessage[1])) # This is the roller
if len(temp_preParsedMessage) == 2: if len(temp_preParsedMessage) == 2:
diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str( diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str(
@ -63,4 +130,39 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
diceRoll = "@" + twitch_message.sender + " rolled: " + diceRoll diceRoll = "@" + twitch_message.sender + " rolled: " + diceRoll
print(diceRoll) print(diceRoll)
bot.send_message(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

View File

@ -28,6 +28,72 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
#await discord_message.channel.send("Rolling Dice...") #await discord_message.channel.send("Rolling Dice...")
print("Rolling Dice...") print("Rolling Dice...")
if ("f") in discord_message.content.lower():
diceRoll = await self.roll(2, discord_message)
else:
diceRoll = await 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: "Fate Dice"
}
temp_preParsedMessage = discord_message.content.split("+") temp_preParsedMessage = discord_message.content.split("+")
tempParsedMessage = temp_preParsedMessage[0].split(" ") tempParsedMessage = temp_preParsedMessage[0].split(" ")
@ -41,11 +107,12 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
if int(parsedMessage[0]) == 1: if int(parsedMessage[0]) == 1:
loopBool = False loopBool = False
if roll_type == 1:
# If roll is in xdx+x format # If roll is in xdx+x format
if loopBool == True: if loopBool == True:
rolls: list = [] rolls: list = []
for x in range(int(parsedMessage[0])): for x in range(int(parsedMessage[0])):
rolls.append(random.randint(1, int(parsedMessage[1]))) rolls.append(random.randint(1, int(parsedMessage[1]))) # This is the roller
rollTotal = 0 rollTotal = 0
for roll in rolls: for roll in rolls:
@ -60,7 +127,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
diceRoll = diceRoll + " = " + str(rollTotal) diceRoll = diceRoll + " = " + str(rollTotal)
# If roll is in dx+x format # If roll is in dx+x format
if loopBool == False: if loopBool == False:
roll: int = random.randint(1, int(parsedMessage[1])) roll: int = random.randint(1, int(parsedMessage[1])) # This is the roller
if len(temp_preParsedMessage) == 2: if len(temp_preParsedMessage) == 2:
diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str( diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str(
@ -70,5 +137,36 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
diceRoll = discord_message.author.mention + " rolled: " + diceRoll diceRoll = discord_message.author.mention + " rolled: " + diceRoll
print(diceRoll) print(diceRoll)
await bot.send_message(discord_message, diceRoll)
#await discord_message.channel.send(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 + " fate rolled: " + diceRoll
print(diceRoll)
return diceRoll