Updated Roll Command
This commit is contained in:
parent
9ab31b6320
commit
d00f01edc3
66
commands/implemented/command_roll.py
Normal file
66
commands/implemented/command_roll.py
Normal file
@ -0,0 +1,66 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import random
|
||||
|
||||
class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
||||
"""
|
||||
this is the roll command.
|
||||
"""
|
||||
command = "!roll"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandRoll.command, n_args=1, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
print("!roll Detected")
|
||||
#twitch_message.chat.send("test acknowledged")
|
||||
|
||||
diceRoll: str = ""
|
||||
twitch_message.chat.send("Rolling Dice...")
|
||||
print("Rolling Dice...")
|
||||
|
||||
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)
|
||||
twitch_message.chat.send(diceRoll)
|
||||
@ -24,13 +24,10 @@ class Twitch_Credential():
|
||||
|
||||
class Discord_Credential():
|
||||
# Discord Credentials explanations here.
|
||||
def __init__(self, username, helix, oauth, v5_client):
|
||||
def __init__(self, nickname, token):
|
||||
# super().__init__()
|
||||
# all of this is completely made up, i just wanted to make sure your file name switch worked right
|
||||
self.username = username
|
||||
self.helix = helix
|
||||
self.oauth = oauth
|
||||
self.v5_client = v5_client
|
||||
self.nickname = nickname
|
||||
self.token = token
|
||||
|
||||
class DB_Credential():
|
||||
# engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"
|
||||
@ -133,7 +130,7 @@ class Credentials_Module():
|
||||
def find_Twitch_Credential(self, searchParam: str):
|
||||
print("Searching for Twitch Credential named: " + searchParam)
|
||||
foundSomething = False
|
||||
tempCert: Twitch_Credential
|
||||
tempCert: Twitch_Credential = None
|
||||
for cert in self.Twitch_Credentials_List:
|
||||
if cert.username == searchParam:
|
||||
print("Twitch Credential Found: {" + cert.username + "}")
|
||||
@ -147,7 +144,7 @@ class Credentials_Module():
|
||||
def find_Discord_Credential(self, searchParam: str):
|
||||
print("Searching for Discord Credential named: " + searchParam)
|
||||
foundSomething = False
|
||||
tempCert: Discord_Credential
|
||||
tempCert: Discord_Credential = None
|
||||
for cert in self.Discord_Credentials_List:
|
||||
if cert.username == searchParam:
|
||||
print("Discord Credential Found: {" + cert.username + "}")
|
||||
@ -161,7 +158,7 @@ class Credentials_Module():
|
||||
def find_DB_Credential(self, searchParam: str):
|
||||
print("Searching for DB Credential named: " + searchParam)
|
||||
foundSomething = False
|
||||
tempCert: DB_Credential
|
||||
tempCert: DB_Credential = None
|
||||
for cert in self.DB_Credentials_List:
|
||||
if cert.nickname == searchParam:
|
||||
print("DB Credential Found: {" + cert.nickname + "}")
|
||||
|
||||
@ -98,12 +98,13 @@ class Twitch_Module():
|
||||
# message.chat.send("test acknowledged")
|
||||
# # message.chat.send(f'@{message.user().display_name}, you have {message.user().view_count} views.')
|
||||
|
||||
if message.text.startswith('!roll'):
|
||||
try:
|
||||
self.dice_roll(message)
|
||||
except Exception:
|
||||
self.send_message("{something went wrong}")
|
||||
print("{something went wrong}")
|
||||
# if message.text.startswith('!roll'):
|
||||
# try:
|
||||
# pass
|
||||
# #self.dice_roll(message)
|
||||
# except Exception:
|
||||
# self.send_message("{something went wrong}")
|
||||
# print("{something went wrong}")
|
||||
|
||||
def tts_message(self, message: twitch.chat.Message):
|
||||
if not self.contains_slur(message):
|
||||
@ -149,55 +150,6 @@ class Twitch_Module():
|
||||
print("<{ slur detected! }> " + " [#" + message.channel + "](" + message.sender + ") used a slur in chat")
|
||||
return containsSlur
|
||||
|
||||
# Rolls Dice.
|
||||
def dice_roll(self, message: twitch.chat.Message):
|
||||
diceRoll: str = ""
|
||||
self.send_message("Rolling Dice...")
|
||||
print("Rolling Dice...")
|
||||
|
||||
temp_preParsedMessage = 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 = "@" + message.sender + " rolled: " + diceRoll
|
||||
print(diceRoll)
|
||||
self.send_message(diceRoll)
|
||||
|
||||
|
||||
# This is a old function used prior to the creation of the Twitch_Module class above.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user