Merge pull request 'added roll command & test pull request' (#29) from v2.0 into v2-cleaned-up
Reviewed-on: #29
This commit is contained in:
commit
c7c4318867
@ -53,5 +53,5 @@ class AbstractCommand(metaclass=ABCMeta):
|
|||||||
return self.isCommandEnabled
|
return self.isCommandEnabled
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def do_command(self, bot, user, command, rest):
|
def do_command(self, bot, user, command, rest, bonusData):
|
||||||
pass
|
pass
|
||||||
114
commands/implemented/Command_roll_v2.py
Normal file
114
commands/implemented/Command_roll_v2.py
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
from abc import ABCMeta
|
||||||
|
|
||||||
|
from commands.command_base import AbstractCommand
|
||||||
|
|
||||||
|
import random
|
||||||
|
import utilities_script as utility
|
||||||
|
|
||||||
|
class Command_test_v2(AbstractCommand, metaclass=ABCMeta):
|
||||||
|
"""
|
||||||
|
this is the test command.
|
||||||
|
"""
|
||||||
|
command = "!roll"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(Command_test_v2.command, n_args=1, command_type=AbstractCommand.CommandType.Ver2)
|
||||||
|
self.help = ["This will roll dice, based on your inputs.",
|
||||||
|
"\nExample:","roll \"d20\"", "roll \"1D20+5\"", "roll \"10df\"", "roll \"10Df+3\""]
|
||||||
|
self.isCommandEnabled = True
|
||||||
|
|
||||||
|
def do_command(self, source = AbstractCommand.CommandSource.default, user = "User", command = "", rest = "", bonusData = None):
|
||||||
|
returnString = user + " sent: [ " + command + " ] with: " + rest
|
||||||
|
|
||||||
|
if ("f") in rest.lower():
|
||||||
|
returnString = self.roll(2, user, command + " " +rest)
|
||||||
|
else:
|
||||||
|
returnString = self.roll(1, user, command + " " +rest)
|
||||||
|
|
||||||
|
return returnString
|
||||||
|
|
||||||
|
def roll(self, roll_type, user, user_message):
|
||||||
|
diceRoll = ""
|
||||||
|
switch = {
|
||||||
|
1: "Standard",
|
||||||
|
2: "Fate Dice"
|
||||||
|
}
|
||||||
|
temp_preParsedMessage = user_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
|
||||||
|
|
||||||
|
def get_help(self):
|
||||||
|
return self.help
|
||||||
@ -16,7 +16,7 @@ class Command_test_v2(AbstractCommand, metaclass=ABCMeta):
|
|||||||
"\nExample:","testerino"]
|
"\nExample:","testerino"]
|
||||||
self.isCommandEnabled = True
|
self.isCommandEnabled = True
|
||||||
|
|
||||||
def do_command(self, source = AbstractCommand.CommandSource.default, user = "User", command = "", rest = ""):
|
def do_command(self, source = AbstractCommand.CommandSource.default, user = "User", command = "", rest = "", bonusData = None):
|
||||||
returnString = user + " sent: [ " + command + " ] with: " + rest
|
returnString = user + " sent: [ " + command + " ] with: " + rest
|
||||||
#print(returnString)
|
#print(returnString)
|
||||||
return returnString
|
return returnString
|
||||||
|
|||||||
@ -40,7 +40,7 @@ def handle_command(source, username, command, rest, bonusData):
|
|||||||
|
|
||||||
cmd:AbstractCommand = loadedCommands[command]
|
cmd:AbstractCommand = loadedCommands[command]
|
||||||
if cmd is not None:
|
if cmd is not None:
|
||||||
cmd_response = cmd.do_command(source, username, command, rest)
|
cmd_response = cmd.do_command(source, username, command, rest, bonusData)
|
||||||
return flask.make_response("{\"message\":\"%s\"}" % cmd_response, 200, {"Content-Type": "application/json"})
|
return flask.make_response("{\"message\":\"%s\"}" % cmd_response, 200, {"Content-Type": "application/json"})
|
||||||
|
|
||||||
#print("Doing a command")
|
#print("Doing a command")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user