Merge pull request 'Command-Management-Module & Command File Simplification/Reduction' (#27) from Command-Management-Module into master
Reviewed-on: #27
This commit is contained in:
commit
4f0d3892a3
46
Command_Management_Module.py
Normal file
46
Command_Management_Module.py
Normal file
@ -0,0 +1,46 @@
|
||||
from main import user_module_init
|
||||
import config as config
|
||||
import db
|
||||
|
||||
import user_module
|
||||
|
||||
import commands.loader as command_loader
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import credentials
|
||||
|
||||
class Command_Management_Module():
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.dbCredential: credentials.DB_Credential
|
||||
|
||||
def main_test(self):
|
||||
print("[TEST Module]> test")
|
||||
|
||||
tempModule = user_module.User_Module()
|
||||
#tempModule.commands = command_loader.load_commands_new(AbstractCommand.CommandType.Praxis)
|
||||
print(self.getCommandsList(tempModule.commands))
|
||||
|
||||
def getCommandsList(self, targetModuleCommands):
|
||||
print(type(targetModuleCommands))
|
||||
commandsList = "\n"
|
||||
for cmd in targetModuleCommands:
|
||||
targetCommand = targetModuleCommands[cmd]
|
||||
print(targetCommand.command)
|
||||
print(targetCommand.isCommandEnabled)
|
||||
|
||||
|
||||
return commandsList
|
||||
|
||||
|
||||
def getUserPermission():
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
testModule = Command_Management_Module()
|
||||
|
||||
credentials_manager = credentials.Credentials_Module()
|
||||
credentials_manager.load_credentials()
|
||||
testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname)
|
||||
testModule.main_test()
|
||||
@ -18,11 +18,12 @@ class AbstractCommand(metaclass=ABCMeta):
|
||||
TWITCH = auto()
|
||||
DISCORD = auto()
|
||||
|
||||
def __init__(self, command: str, n_args: int = 0, command_type=CommandType.NONE, helpText:list=["No Help"]):
|
||||
def __init__(self, command: str, n_args: int = 0, command_type=CommandType.NONE, helpText:list=["No Help"], CommandEnabled = True):
|
||||
self.command = command
|
||||
self.n_args = n_args
|
||||
self.command_type = command_type
|
||||
self.help = helpText
|
||||
self.isCommandEnabled = CommandEnabled
|
||||
|
||||
# no touch!
|
||||
def get_args(self, text: str) -> list:
|
||||
@ -32,10 +33,18 @@ class AbstractCommand(metaclass=ABCMeta):
|
||||
def get_command(self) -> str:
|
||||
return self.command
|
||||
|
||||
# no touch!
|
||||
def get_commandType(self):
|
||||
return self.command_type
|
||||
|
||||
# no touch!
|
||||
def get_help(self):
|
||||
return self.help
|
||||
|
||||
# no touch!
|
||||
def is_command_enabled(self):
|
||||
return self.isCommandEnabled
|
||||
|
||||
@abstractmethod
|
||||
def do_command(self, bot, twitch_message):
|
||||
pass
|
||||
|
||||
@ -17,6 +17,7 @@ class CommandChyron(AbstractCommand, metaclass=ABCMeta):
|
||||
super().__init__(CommandChyron.command, n_args=5, command_type=AbstractCommand.CommandType.Praxis)
|
||||
self.help = ["The chyron string can be generated and updated with this command.",
|
||||
"\nExample:","chyron update \"RIGHTNOW\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
def do_command(self, bot, user_message):
|
||||
tempBool = True
|
||||
|
||||
@ -17,6 +17,7 @@ class CommandChyron(AbstractCommand, metaclass=ABCMeta):
|
||||
super().__init__(CommandChyron.command, n_args=5, command_type=AbstractCommand.CommandType.Praxis)
|
||||
self.help = ["This is a command to learn more about other commands.",
|
||||
"\nExample:","help \"COMMAND\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
self.blockDecor = "\n================================================================\n"
|
||||
|
||||
@ -30,10 +31,10 @@ class CommandChyron(AbstractCommand, metaclass=ABCMeta):
|
||||
targetCommand = bot.commands[tempParsedMessage[1]]
|
||||
helper = help_module.Help_Module_.help_command_response(targetCommand, help_module.help_command_responseType.fancy)
|
||||
|
||||
returnMessage = helper.response
|
||||
returnMessage = "\n" + helper.response
|
||||
bot.return_message(returnMessage)
|
||||
elif i == 1:
|
||||
commandsList = self.blockDecor + "Commands List:" + self.blockDecor + self.GetCommandsList(bot) + self.blockDecor
|
||||
commandsList = "\n" + self.blockDecor + "Commands List:" + self.blockDecor + self.GetCommandsList(bot) + self.blockDecor
|
||||
print(commandsList)
|
||||
|
||||
def GetCommandsList(self, bot):
|
||||
|
||||
@ -7,16 +7,17 @@ import random
|
||||
|
||||
import utilities_script as utilities
|
||||
|
||||
class CommandLights(AbstractCommand, metaclass=ABCMeta):
|
||||
class CommandLights_Praxis(AbstractCommand, metaclass=ABCMeta):
|
||||
"""
|
||||
this is the lights command.
|
||||
"""
|
||||
command = "lights"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandLights.command, n_args=3, command_type=AbstractCommand.CommandType.Praxis)
|
||||
super().__init__(CommandLights_Praxis.command, n_args=3, command_type=AbstractCommand.CommandType.Praxis)
|
||||
self.help = ["This command allows you to modify the lights via the Lights_Module.",
|
||||
"\nExample:","lights \"SCENE\"","lights \"COLOR\"","lights \"R\" \"G\" \"B\"","lights \"1\" \"0.5\" \"0\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
def do_command(self, bot, user_message):
|
||||
tempBool = True
|
||||
@ -70,3 +71,69 @@ class CommandLights(AbstractCommand, metaclass=ABCMeta):
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
|
||||
|
||||
class CommandLights_Twitch(AbstractCommand, metaclass=ABCMeta):
|
||||
"""
|
||||
this is the roll command.
|
||||
"""
|
||||
command = "!lights"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandLights_Twitch.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["This command allows you to modify the lights via the Lights_Module.",
|
||||
"\nExample:","!lights \"SCENE\"","!lights \"COLOR\"","!lights \"R\" \"G\" \"B\"","!lights \"1\" \"0.5\" \"0\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
|
||||
if bot.allow_rgbLightControl == True:
|
||||
LightModule = lights_module.Lights_Module()
|
||||
LightModule.main()
|
||||
#print("\nRGB Command Detected!")
|
||||
|
||||
tempParsedMessage = twitch_message.text.split(" ")
|
||||
sceneCommand = False
|
||||
if (len(tempParsedMessage)) > 2:
|
||||
print("RGB Command!")
|
||||
rgb_r = float(tempParsedMessage[1])
|
||||
rgb_g = float(tempParsedMessage[2])
|
||||
rgb_b = float(tempParsedMessage[3])
|
||||
xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b)
|
||||
#print("got XY")
|
||||
LightModule.bridge_.set_group(16, "xy", xy_result)
|
||||
print("sent color to [Lights_Module]")
|
||||
else:
|
||||
if "stream" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.run_scene("Downstairs", "Stream")
|
||||
elif "normal" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.run_scene("Downstairs", "Bright")
|
||||
elif "haxor" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.run_scene("Downstairs", "hacker vibes")
|
||||
elif "off" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.set_group("Downstairs", "on", False)
|
||||
elif "on" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.set_group("Downstairs", "on", True)
|
||||
elif "ravemode" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.raveMode()
|
||||
else:
|
||||
print("Color Command!")
|
||||
xy_result = LightModule.color_string_parser(tempParsedMessage)
|
||||
#print("got XY")
|
||||
LightModule.bridge_.set_group(16, "xy", xy_result)
|
||||
print("sent color to [Lights_Module]")
|
||||
|
||||
if sceneCommand == True:
|
||||
print("Scene Command!")
|
||||
|
||||
returnMessage = "@" + twitch_message.sender + " changed the light's color!"
|
||||
bot.send_message(returnMessage)
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
@ -1,72 +0,0 @@
|
||||
from abc import ABCMeta
|
||||
import lights_module
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import random
|
||||
|
||||
import utilities_script as utilities
|
||||
|
||||
class CommandLights(AbstractCommand, metaclass=ABCMeta):
|
||||
"""
|
||||
this is the roll command.
|
||||
"""
|
||||
command = "!lights"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandLights.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["This command allows you to modify the lights via the Lights_Module.",
|
||||
"\nExample:","!lights \"SCENE\"","!lights \"COLOR\"","!lights \"R\" \"G\" \"B\"","!lights \"1\" \"0.5\" \"0\""]
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
|
||||
if bot.allow_rgbLightControl == True:
|
||||
LightModule = lights_module.Lights_Module()
|
||||
LightModule.main()
|
||||
#print("\nRGB Command Detected!")
|
||||
|
||||
tempParsedMessage = twitch_message.text.split(" ")
|
||||
sceneCommand = False
|
||||
if (len(tempParsedMessage)) > 2:
|
||||
print("RGB Command!")
|
||||
rgb_r = float(tempParsedMessage[1])
|
||||
rgb_g = float(tempParsedMessage[2])
|
||||
rgb_b = float(tempParsedMessage[3])
|
||||
xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b)
|
||||
#print("got XY")
|
||||
LightModule.bridge_.set_group(16, "xy", xy_result)
|
||||
print("sent color to [Lights_Module]")
|
||||
else:
|
||||
if "stream" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.run_scene("Downstairs", "Stream")
|
||||
elif "normal" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.run_scene("Downstairs", "Bright")
|
||||
elif "haxor" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.run_scene("Downstairs", "hacker vibes")
|
||||
elif "off" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.set_group("Downstairs", "on", False)
|
||||
elif "on" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.bridge_.set_group("Downstairs", "on", True)
|
||||
elif "ravemode" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
LightModule.raveMode()
|
||||
else:
|
||||
print("Color Command!")
|
||||
xy_result = LightModule.color_string_parser(tempParsedMessage)
|
||||
#print("got XY")
|
||||
LightModule.bridge_.set_group(16, "xy", xy_result)
|
||||
print("sent color to [Lights_Module]")
|
||||
|
||||
if sceneCommand == True:
|
||||
print("Scene Command!")
|
||||
|
||||
returnMessage = "@" + twitch_message.sender + " changed the light's color!"
|
||||
bot.send_message(returnMessage)
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
47
commands/implemented/command_restartBot.py
Normal file
47
commands/implemented/command_restartBot.py
Normal file
@ -0,0 +1,47 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import discord
|
||||
import discord.message
|
||||
|
||||
import utilities_script as utilities
|
||||
|
||||
class CommandTTS_Twitch(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "!restart"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandTTS_Twitch.command, n_args=0, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
args = self.get_args(twitch_message.text)
|
||||
if twitch_message.sender.lower() == twitch_message.channel:
|
||||
bot.send_message("Bot restarting...")
|
||||
utilities.restart_self()
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
|
||||
class CommandTTS_Discord(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "//restart"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandTTS_Discord.command, n_args=0, command_type=AbstractCommand.CommandType.DISCORD)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
async def do_command(self, bot, discord_message: discord.message):
|
||||
|
||||
if str(discord_message.author.top_role) == "Admin":
|
||||
print("Admin Check")
|
||||
#response = str("Bot restarting... on %s" % discord_message.guild.name)
|
||||
response = str("Bot restarting...")
|
||||
await bot.send_message(discord_message, response)
|
||||
utilities.restart_self()
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
@ -1,28 +0,0 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import discord
|
||||
import discord.message
|
||||
|
||||
import utilities_script as utilities
|
||||
|
||||
class CommandTTS(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "//restart"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.DISCORD)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
|
||||
async def do_command(self, bot, discord_message: discord.message):
|
||||
|
||||
if str(discord_message.author.top_role) == "Admin":
|
||||
print("Admin Check")
|
||||
#response = str("Bot restarting... on %s" % discord_message.guild.name)
|
||||
response = str("Bot restarting...")
|
||||
await bot.send_message(discord_message, response)
|
||||
utilities.restart_self()
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
@ -1,22 +0,0 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import utilities_script as utilities
|
||||
|
||||
class CommandTTS(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "!restart"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
args = self.get_args(twitch_message.text)
|
||||
if twitch_message.sender.lower() == twitch_message.channel:
|
||||
bot.send_message("Bot restarting...")
|
||||
utilities.restart_self()
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
@ -1,25 +1,143 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
from discord import message
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import random
|
||||
|
||||
from discord import message
|
||||
import discord
|
||||
import discord.message
|
||||
import discord.channel
|
||||
|
||||
class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
||||
class CommandRoll_Twitch(AbstractCommand, metaclass=ABCMeta):
|
||||
"""
|
||||
this is the roll command.
|
||||
"""
|
||||
command = "!roll"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandRoll.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD)
|
||||
super().__init__(CommandRoll_Twitch.command, n_args=1, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
print("!roll Detected")
|
||||
#twitch_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)
|
||||
else:
|
||||
diceRoll = self.roll(1, twitch_message)
|
||||
|
||||
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(" ")
|
||||
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:
|
||||
# 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 = "@" + 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
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
|
||||
|
||||
class CommandRoll_Discord(AbstractCommand, metaclass=ABCMeta):
|
||||
"""
|
||||
this is the roll command.
|
||||
"""
|
||||
command = "!roll"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandRoll_Discord.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
async def do_command(self, bot, discord_message: discord.Message):
|
||||
print("!roll Detected")
|
||||
@ -35,59 +153,6 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
||||
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)
|
||||
|
||||
@ -1,173 +0,0 @@
|
||||
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)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
print("!roll Detected")
|
||||
#twitch_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)
|
||||
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(" ")
|
||||
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:
|
||||
# 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 = "@" + 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
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
47
commands/implemented/command_shutdownBot.py
Normal file
47
commands/implemented/command_shutdownBot.py
Normal file
@ -0,0 +1,47 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import discord
|
||||
import discord.message
|
||||
|
||||
import utilities_script as utilities
|
||||
|
||||
class ShutdownCommand_Twitch(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "!shutdown"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(ShutdownCommand_Twitch.command, n_args=0, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
args = self.get_args(twitch_message.text)
|
||||
if twitch_message.sender.lower() == twitch_message.channel:
|
||||
bot.send_message("Bot shutting down...")
|
||||
utilities.hard_shutdown()
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
|
||||
class ShutdownCommand_Discord(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "//shutdown"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(ShutdownCommand_Discord.command, n_args=0, command_type=AbstractCommand.CommandType.DISCORD)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
async def do_command(self, bot, discord_message: discord.message):
|
||||
|
||||
if str(discord_message.author.top_role) == "Admin":
|
||||
print("Admin Check")
|
||||
#response = str("Bot restarting... on %s" % discord_message.guild.name)
|
||||
response = str("Bot shutting down...")
|
||||
await bot.send_message(discord_message, response)
|
||||
utilities.hard_shutdown()
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
@ -1,28 +0,0 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import discord
|
||||
import discord.message
|
||||
|
||||
import utilities_script as utilities
|
||||
|
||||
class CommandTTS(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "//shutdown"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.DISCORD)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
|
||||
async def do_command(self, bot, discord_message: discord.message):
|
||||
|
||||
if str(discord_message.author.top_role) == "Admin":
|
||||
print("Admin Check")
|
||||
#response = str("Bot restarting... on %s" % discord_message.guild.name)
|
||||
response = str("Bot shutting down...")
|
||||
await bot.send_message(discord_message, response)
|
||||
utilities.hard_shutdown()
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
@ -1,22 +0,0 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import utilities_script as utilities
|
||||
|
||||
class CommandTTS(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "!shutdown"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
args = self.get_args(twitch_message.text)
|
||||
if twitch_message.sender.lower() == twitch_message.channel:
|
||||
bot.send_message("Bot shutting down...")
|
||||
utilities.hard_shutdown()
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
@ -13,6 +13,7 @@ class CommandTest(AbstractCommand, metaclass=ABCMeta):
|
||||
super().__init__(CommandTest.command, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
print("!test Detected")
|
||||
|
||||
@ -5,13 +5,37 @@ from commands.command_base import AbstractCommand
|
||||
import discord
|
||||
import discord.message
|
||||
|
||||
class CommandTTS(AbstractCommand, metaclass=ABCMeta):
|
||||
class CommandTTS_Twitch(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "!tts"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandTTS_Twitch.command, n_args=1, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
args = self.get_args(twitch_message.text)
|
||||
if args[1] == "start":
|
||||
if twitch_message.sender.lower() == twitch_message.channel:
|
||||
bot.send_message("tts activated on #%s" % twitch_message.channel)
|
||||
bot.tts_enabled = True
|
||||
elif args[1] == "stop":
|
||||
if twitch_message.sender.lower() == twitch_message.channel:
|
||||
bot.send_message("tts deactivated on #%s" % twitch_message.channel)
|
||||
bot.tts_enabled = False
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
|
||||
class CommandTTS_Discord(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "//tts"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandTTS.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD)
|
||||
super().__init__(CommandTTS_Discord.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
self.isCommandEnabled = True
|
||||
|
||||
async def do_command(self, bot, discord_message: discord.message):
|
||||
args = self.get_args(discord_message.content)
|
||||
@ -1,27 +0,0 @@
|
||||
from abc import ABCMeta
|
||||
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
|
||||
|
||||
class CommandTTS(AbstractCommand, metaclass=ABCMeta):
|
||||
command = "!tts"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(CommandTTS.command, n_args=1, command_type=AbstractCommand.CommandType.TWITCH)
|
||||
self.help = ["MISSING HELP ENTRY",
|
||||
"\nExample:","command \"PARAM\""]
|
||||
|
||||
def do_command(self, bot, twitch_message):
|
||||
args = self.get_args(twitch_message.text)
|
||||
if args[1] == "start":
|
||||
if twitch_message.sender.lower() == twitch_message.channel:
|
||||
bot.send_message("tts activated on #%s" % twitch_message.channel)
|
||||
bot.tts_enabled = True
|
||||
elif args[1] == "stop":
|
||||
if twitch_message.sender.lower() == twitch_message.channel:
|
||||
bot.send_message("tts deactivated on #%s" % twitch_message.channel)
|
||||
bot.tts_enabled = False
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
@ -12,7 +12,9 @@ def load_commands() -> Dict[str, AbstractCommand]:
|
||||
commands = compile_and_load()
|
||||
return commands
|
||||
|
||||
#New
|
||||
def load_commands_new(commandType: AbstractCommand.CommandType) -> Dict[str, AbstractCommand]:
|
||||
print(" -Loading ", commandType ," Commands...\n")
|
||||
commands = compile_and_load_new(commandType)
|
||||
return commands
|
||||
|
||||
@ -30,6 +32,23 @@ def compile_and_load_file(path: str) -> (str, AbstractCommand):
|
||||
return command_inst.get_command(), command_inst
|
||||
return "", None
|
||||
|
||||
#New
|
||||
def compile_and_load_file_new(path: str, commandType: AbstractCommand.CommandType) -> (str, AbstractCommand):
|
||||
module_name = os.path.split(path)[1].replace(".py", "")
|
||||
spec = importlib.util.spec_from_file_location(module_name, path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[module_name] = module
|
||||
spec.loader.load_module(module_name)
|
||||
|
||||
for name, obj in inspect.getmembers(module):
|
||||
if inspect.isclass(obj) and name.startswith("Command"):
|
||||
command_inst = obj()
|
||||
if commandType == command_inst.get_commandType():
|
||||
print(" ---Successfully loaded %s: %s" % (commandType, command_inst.get_command()))
|
||||
return command_inst.get_command(), command_inst
|
||||
elif commandType != command_inst.get_commandType():
|
||||
print(" -%s CommandType did not match: %s for: %s" % (command_inst.get_commandType(), commandType, command_inst.get_command()))
|
||||
return "", None
|
||||
|
||||
def compile_and_load() -> Dict[str, AbstractCommand]:
|
||||
dic = {}
|
||||
@ -37,21 +56,22 @@ def compile_and_load() -> Dict[str, AbstractCommand]:
|
||||
for dirName, subdirList, fileList in os.walk(implementations):
|
||||
for file in fileList:
|
||||
name = os.path.join(dirName, file)
|
||||
print("compiling %s" % name)
|
||||
print("compiling: %s" % name)
|
||||
name, command = compile_and_load_file(name)
|
||||
if command is not None:
|
||||
dic[name] = command
|
||||
break
|
||||
return dic
|
||||
|
||||
#New
|
||||
def compile_and_load_new(commandType: AbstractCommand.CommandType) -> Dict[str, AbstractCommand]:
|
||||
dic = {}
|
||||
implementations = get_implementations_dir()
|
||||
for dirName, subdirList, fileList in os.walk(implementations):
|
||||
for file in fileList:
|
||||
name = os.path.join(dirName, file)
|
||||
print("compiling %s" % name)
|
||||
name, command = compile_and_load_file(name)
|
||||
print("compiling: %s" % name)
|
||||
name, command = compile_and_load_file_new(name, commandType)
|
||||
if command is not None and command.command_type is commandType:
|
||||
dic[name] = command
|
||||
break
|
||||
|
||||
@ -25,6 +25,9 @@ blockAll_TTS_URL_Twitch = True
|
||||
|
||||
autoEnabled_Twitch_rgbLightControl = False
|
||||
|
||||
twitch_defaultCommandEnabledState = True
|
||||
#twitch_defaultCommandEnabledState_liveStreamOnly = True # If true this will make commands only available during live streams.
|
||||
|
||||
#Discord Module Configs
|
||||
block_DiscordChannelsMessaging = [""] # Blocks the ability to send messages to Discord channels
|
||||
blockAll_DiscordChannelsMessaging = False # Blocks the ability to send messages to Discord channels
|
||||
@ -41,6 +44,9 @@ blockAll_TTS_URL_Discord = True
|
||||
|
||||
autoEnabled_Discord_rgbLightControl = False
|
||||
|
||||
#discord_defaultCommandEnabledState = True
|
||||
#discord_defaultCommandEnabledState_liveStreamOnly = True # If true this will make commands only available during live streams.
|
||||
|
||||
#User Module Configs
|
||||
blockAll_TTS_URL_UserModule = True
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ class Help_Module():
|
||||
|
||||
def main(self):
|
||||
print("[Help Module]> help test")
|
||||
self.isCommandEnabled = True
|
||||
|
||||
def help_command_response(self, command:AbstractCommand, responseType):
|
||||
response = help_command_response()
|
||||
|
||||
@ -6,7 +6,7 @@ import credentials
|
||||
class Test_Module():
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
#self.dbCredential: credentials.DB_Credential
|
||||
self.dbCredential: credentials.DB_Credential
|
||||
|
||||
def main(self):
|
||||
print("[TEST Module]> test")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user