Merge pull request 'v2-cleaned-up' (#33) from v2-cleaned-up into v2.0

Reviewed-on: #33
This commit is contained in:
alex_orid 2021-04-22 17:50:22 +00:00
commit 7ec8dd5e0e
16 changed files with 71 additions and 1348 deletions

View File

@ -1,48 +0,0 @@
from abc import ABCMeta
import chyron_module
from commands.command_base import AbstractCommand
import random
import utilities_script as utilities
class CommandChyron(AbstractCommand, metaclass=ABCMeta):
"""
this is the chyron command.
"""
command = "chyron"
def __init__(self):
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
if tempBool == True:
tempParsedMessage = user_message.message.split(" ")
i = len(tempParsedMessage)
if i > 2:
if "update" in tempParsedMessage[1]:
chyron = chyron_module.Chyron_Module()
if i > 2:
rightNow = ""
counter = 0
for word in tempParsedMessage:
if counter > 1:
rightNow = rightNow + word + " "
counter = counter + 1
rightNow = rightNow[:-1]
chyron.main(rightNow)
else:
chyron.main()
chyron.updateChyronFile()
returnMessage = "@" + user_message.user + " updated the chyron!\n"
bot.return_message(returnMessage)
def get_help(self):
return self.help

View File

@ -1,23 +0,0 @@
from abc import ABCMeta
from commands.command_base import AbstractCommand
import utilities_script as utility
class Command_Clear(AbstractCommand, metaclass=ABCMeta):
"""
this is the clear command.
"""
command = "clear"
def __init__(self):
super().__init__(Command_Clear.command, n_args=1, command_type=AbstractCommand.CommandType.Praxis)
self.help = ["This is a command to clear the screen.",
"\nExample:","clear"]
self.isCommandEnabled = True
def do_command(self, bot, user_message):
utility.clearScreen()
def get_help(self):
return self.help

View File

@ -1,25 +0,0 @@
from abc import ABCMeta
import time
from commands.command_base import AbstractCommand
class Command_Exit(AbstractCommand, metaclass=ABCMeta):
"""
this is the exit command.
"""
command = "exit"
def __init__(self):
super().__init__(Command_Exit.command, n_args=1, command_type=AbstractCommand.CommandType.Praxis)
self.help = ["This is a command to exit [User Module].",
"\nExample:","exit"]
self.isCommandEnabled = True
def do_command(self, bot, user_message):
bot.return_message("\nQuitting [User Module] Interface...")
time.sleep(0.2)
bot.inputLoop = False
def get_help(self):
return self.help

View File

@ -1,49 +0,0 @@
from abc import ABCMeta
import help_module
from commands.command_base import AbstractCommand
import random
import utilities_script as utilities
class Command_Help(AbstractCommand, metaclass=ABCMeta):
"""
this is the help command.
"""
command = "help"
def __init__(self):
super().__init__(Command_Help.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"
def do_command(self, bot, user_message):
tempBool = True
if tempBool == True:
tempParsedMessage = user_message.message.split(" ")
i = len(tempParsedMessage)
if i > 1:
targetCommand = bot.commands[tempParsedMessage[1]]
helper = help_module.Help_Module_.help_command_response(targetCommand, help_module.help_command_responseType.fancy)
returnMessage = "\n" + helper.response
bot.return_message(returnMessage)
elif i == 1:
commandsList = "\n" + self.blockDecor + "Commands List:" + self.blockDecor + self.GetCommandsList(bot) + self.blockDecor
bot.return_message(commandsList)
def GetCommandsList(self, bot):
commandsList = ""
i = 0
for cmd in bot.commands:
commandsList = commandsList + cmd + "\n"
return commandsList
def get_help(self):
return self.help

View File

@ -1,139 +0,0 @@
from abc import ABCMeta
import lights_module
from commands.command_base import AbstractCommand
import random
import utilities_script as utilities
class CommandLights_Praxis(AbstractCommand, metaclass=ABCMeta):
"""
this is the lights command.
"""
command = "lights"
def __init__(self):
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
if tempBool == True:
LightModule = lights_module.Lights_Module()
LightModule.main()
#bot.return_message("\nRGB Command Detected!")
tempParsedMessage = user_message.message.split(" ")
sceneCommand = False
if (len(tempParsedMessage)) > 2:
bot.return_message("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)
#bot.return_message("got XY")
LightModule.bridge_.set_group(16, "xy", xy_result)
bot.return_message("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:
bot.return_message("Color Command!")
xy_result = LightModule.color_string_parser(tempParsedMessage)
#bot.return_message("got XY")
LightModule.bridge_.set_group(16, "xy", xy_result)
bot.return_message("sent color to [Lights_Module]")
if sceneCommand == True:
bot.return_message("Scene Command!")
returnMessage = "@" + user_message.user.name + " changed the light's color!\n"
bot.return_message(returnMessage)
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!\n"
bot.send_message(returnMessage)
def get_help(self):
return self.help

View File

@ -1,47 +0,0 @@
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

View File

@ -1,359 +0,0 @@
from abc import ABCMeta
from commands.command_base import AbstractCommand
import random
from discord import message
import discord
import discord.message
import discord.channel
class CommandRoll_Praxis(AbstractCommand, metaclass=ABCMeta):
"""
this is the roll command.
"""
command = "roll"
def __init__(self):
super().__init__(CommandRoll_Praxis.command, n_args=1, command_type=AbstractCommand.CommandType.Praxis)
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, bot, user_message):
#print("roll Detected")
#message.chat.send("test acknowledged")
diceRoll: str = ""
bot.return_message("\nRolling Dice...")
#print("Rolling Dice...")
if ("f") in user_message.message.lower():
diceRoll = self.roll(2, user_message)
else:
diceRoll = self.roll(1, user_message)
bot.return_message(diceRoll)
def roll(self, roll_type, user_message):
user = str(user_message.user.name)
diceRoll = ""
switch = {
1: "Standard",
2: "Fate Dice"
}
temp_preParsedMessage = user_message.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 + "\n"
def get_help(self):
return self.help
class CommandRoll_Twitch(AbstractCommand, metaclass=ABCMeta):
"""
this is the roll command.
"""
command = "!roll"
def __init__(self):
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, message):
print("!roll Detected")
#message.chat.send("test acknowledged")
diceRoll: str = ""
bot.send_message("Rolling Dice...")
print("Rolling Dice...")
if ("f") in message.text.lower():
diceRoll = self.roll(2, message)
else:
diceRoll = self.roll(1, message)
bot.send_message(diceRoll)
def roll(self, roll_type, message):
diceRoll = ""
switch = {
1: "Standard",
2: "Fate 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_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 = "@" + 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 = "@" + 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, message: discord.Message):
print("!roll Detected")
#message.chat.send("test acknowledged")
diceRoll: str = ""
await bot.send_message(message, "Rolling Dice...")
#await message.channel.send("Rolling Dice...")
print("Rolling Dice...")
if ("f") in message.content.lower():
diceRoll = await self.roll(2, message)
else:
diceRoll = await self.roll(1, message)
await bot.send_message(message, diceRoll)
#await message.channel.send(diceRoll)
async def roll(self, roll_type, message: discord.Message):
diceRoll = ""
switch = {
1: "Standard",
2: "Fate Dice"
}
temp_preParsedMessage = 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_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 = message.author.mention + " 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 = message.author.mention + " fate rolled: " + diceRoll
print(diceRoll)
return diceRoll
def get_help(self):
return self.help

View File

@ -1,47 +0,0 @@
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

View File

@ -1,52 +0,0 @@
from abc import ABCMeta
import tempText_Module
from commands.command_base import AbstractCommand
import random
import utilities_script as utilities
class CommandChyron(AbstractCommand, metaclass=ABCMeta):
"""
this is the temptext command.
"""
command = "temptext"
def __init__(self):
super().__init__(CommandChyron.command, n_args=5, command_type=AbstractCommand.CommandType.Praxis)
self.help = ["The temptext string can be generated and updated with this command.",
"\nExample:","temptext update \"Name\" \"Title\" \"Content\""]
self.isCommandEnabled = True
def do_command(self, bot, user_message):
tempBool = True
if tempBool == True:
tempParsedMessage = user_message.message.split(" ")
i = len(tempParsedMessage)
if i > 2:
if "update" in tempParsedMessage[1]:
tempTextModule = tempText_Module.tempText_Module()
tempText = tempText_Module.tempTextItem()
if i > 2:
newText = ""
counter = 0
for word in tempParsedMessage:
if counter > 2:
newText = newText + word + " "
counter = counter + 1
newText = newText[:-1] # Gets rid of last space
#print(tempParsedMessage[2], newText)
tempText.itemName = tempParsedMessage[2]
tempText.itemContent = newText
tempTextModule.makeItem(tempText)
else:
tempText.main()
#tempTextModule.update_tempTextFiles()
returnMessage = "@" + user_message.user.name + " updated the temptextFiles!\n"
bot.return_message(returnMessage)
def get_help(self):
return self.help

View File

@ -1,23 +0,0 @@
from abc import ABCMeta
from commands.command_base import AbstractCommand
class CommandTest(AbstractCommand, metaclass=ABCMeta):
"""
this is a test command. and a poor excuse for a git commit.
"""
command = "!test"
def __init__(self):
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")
bot.send_message("testing acknowledged")
def get_help(self):
return self.help

View File

@ -1,59 +0,0 @@
from abc import ABCMeta
from commands.command_base import AbstractCommand
import discord
import discord.message
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_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)
if args[1] == "start":
print(discord_message.author.top_role)
print("start detected")
if str(discord_message.author.top_role) == "Admin":
print("Admin Check")
response = str("tts activated on %s" % discord_message.guild.name)
await bot.send_message(discord_message, response)
bot.tts_enabled = True
elif args[1] == "stop":
print("stop detected")
if str(discord_message.author.top_role) == "Admin":
print("Admin Check")
response = str("tts deactivated on %s" % discord_message.guild.name)
await bot.send_message(discord_message, response)
bot.tts_enabled = False
def get_help(self):
return self.help

View File

@ -8,32 +8,14 @@ from typing import Dict
from commands.command_base import AbstractCommand
def load_commands() -> Dict[str, AbstractCommand]:
commands = compile_and_load()
return commands
#New
def load_commands_new(commandType: AbstractCommand.CommandType) -> Dict[str, AbstractCommand]:
def load_commands(commandType: AbstractCommand.CommandType) -> Dict[str, AbstractCommand]:
print(" -Loading ", commandType ," Commands...\n")
commands = compile_and_load_new(commandType)
commands = compile_and_load(commandType)
return commands
def compile_and_load_file(path: str):
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()
print("Successfully loaded %s: %s" % (name, command_inst.get_command()))
return command_inst.get_command(), command_inst
return "", None
#New
def compile_and_load_file_new(path: str, commandType: AbstractCommand.CommandType):
def compile_and_load_file(path: str, commandType: AbstractCommand.CommandType):
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)
@ -50,28 +32,16 @@ def compile_and_load_file_new(path: str, commandType: AbstractCommand.CommandTyp
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 = {}
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)
if command is not None:
dic[name] = command
break
return dic
#New
def compile_and_load_new(commandType: AbstractCommand.CommandType) -> Dict[str, AbstractCommand]:
def compile_and_load(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_new(name, commandType)
name, command = compile_and_load_file(name, commandType)
if command is not None and command.command_type is commandType:
dic[name] = command
break

View File

@ -1,240 +0,0 @@
import random
import re
import utilities_script as utilities
from discord import message
from discord.client import Client
import asyncio
import config as config
import db
import tts
import commands.loader as command_loader
from commands.command_base import AbstractCommand
import credentials
import discord
import discord.message
import discord.channel
import discord.abc
from cooldowns import Cooldown_Module
class Discord_Module(discord.Client):
def __init__(self):
super().__init__()
self.loop = asyncio.get_event_loop()
self.dbCredential: credentials.DB_Credential
self.discordCredential: credentials.Discord_Credential
self.cooldownModule:Cooldown_Module = Cooldown_Module()
self.cooldownModule.setupCooldown("discordRateLimit", 10, 1)
self.commands = command_loader.load_commands_new(AbstractCommand.CommandType.DISCORD)
self.tts_enabled: bool = False
self.selected_ttsChannels:list = []
self.block_tts_url: bool = False
# don't freak out, this is *merely* a regex for matching urls that will hit just about everything
self._urlMatcher = re.compile(
"(https?:(/{1,3}|[a-z0-9%])|[a-z0-9.-]+[.](com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))")
async def startup(self):
await self.start(self.discordCredential.token)
def main(self):
print("starting loop")
self.loop.create_task(self.startup())
self.loop.run_forever()
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message: discord.Message):
print("{" + message.guild.name + "}[ " + str(message.channel) + " ](" + message.author.display_name + ")> ")
#print(message.author.mention)
print(message.content)
#print(message.channel.id)
#Message ID
#print(str(message.id))
#print(str(message.channel.id))
if message.content == "//test":
#pass
await message.channel.send('test response')
#test = self.get_channel(431129571308339210)
#await test.send("testerino")
temp = message.channel.last_message
delayTime:float = 3
await message.delete(delay=delayTime)
await temp.delete(delay=delayTime)
if not await self.isSenderBot(message):
# This will check for the praxis_bot-tts channel and will TTS stuff from there.
await self.eval_triggeredEvents(message)
if self.cooldownModule.isCooldownActive("discordRateLimit") == False:
await self.eval_commands(message)
#await self.tts_message(message)
async def eval_triggeredEvents(self, message: discord.Message):
# This will check for the selected channels and will TTS stuff from there.
await self.tts_message(message)
foundChannel = False
for channel in self.selected_ttsChannels:
if channel == message.channel.id:
# await self.tts_message(message)
pass
async def eval_automaticEvents(self, message: discord.Message):
pass
async def eval_commands(self, message: discord.Message):
# containsURL: bool = self.contains_url(message)
try:
#first_space_idx = message.text.index(' ')
# This fixes a error where if you send a command without arguments it fails because
# it cant find the substring.
if message.content.find(" ") != -1:
first_space_idx = message.content.index(' ')
else:
first_space_idx = -1
command_text = ' '
if first_space_idx > -1:
command_text = message.content[0:first_space_idx]
else:
command_text = message.content
command = self.commands[command_text]
if command is not None and command.command_type is AbstractCommand.CommandType.DISCORD:
await command.do_command(self, message)
except Exception as e:
# Undo the following for debug stuff
#print(e)
pass # we don't care
async def send_message(self, message: discord.Message, response):
isBlocked = await self.isChannel_inConfigList(str(message.channel.id), config.block_DiscordChannelsMessaging)
if self.cooldownModule.isCooldownActive("discordRateLimit") == False and not isBlocked and not config.blockAll_DiscordChannelsMessaging:
await message.channel.send(response)
self.cooldownModule.actionTrigger("discordRateLimit")
async def tts_message(self, message: discord.Message):
isBlocked = await self.isChannel_inConfigList(str(message.channel.id), config.block_DiscordChannelsTTS)
isForced = (await self.isChannel_inConfigList(str(message.channel.id), config.force_DiscordChannelsTTS) and not config.blockAll_DiscordChannelsTTS)
#print("isBlocked: " + str(isBlocked))
#print("isForced: " + str(isForced))
if (not await self.contains_slur(message)) and (await self.isTTS_URL_Enabled(message)):
print(message.channel.id, message.channel.id, message.channel.id)
isMessageChannelInList = False
for TTS_C_id in config.selected_DiscordTTSChannels:
print(TTS_C_id)
if int(TTS_C_id) == int(message.channel.id):
isMessageChannelInList = True
if self.tts_enabled and (isMessageChannelInList) and not isBlocked and not config.blockAll_DiscordChannelsTTS or isForced or config.forceAll_DiscordChatChannelsTTS:
if not message.content.startswith('!'):
text_to_say: str = "%s says, %s" % (message.author.display_name, message.content)
channel_text = "%s user msg" % message.channel
tts.tts(text_to_say)
if not await self.contains_slur(message):
if self.tts_enabled:
if not message.content.startswith('!'):
pass
#text_to_say: str = "%s says, %s" % (message.author.display_name, message.content)
#channel_text = "%s user msg" % message.channel
#tts.tts(text_to_say)
# Checks for basic slurs.
async def contains_slur(self, message: discord.Message):
containsSlur: bool = False
if await self.slur_check(message.content) or await self.slur_check(message.author.display_name):
containsSlur = True
return containsSlur
async def slur_check(self, text):
containsSlur: bool = False
parsedMessage = text.split(" ")
for word in parsedMessage:
for slur in config.slurList:
if word.lower() == slur:
containsSlur = True
break # we want to immediately escape if we found a slur
if containsSlur:
break
if containsSlur:
print("<{ slur detected! }>")
#print("<{ slur detected! }> " + " [#" + message.channel + "](" + message.author.display_name + ") used a slur in chat")
return containsSlur
async def contains_url(self, message: discord.Message):
containsURL = re.search(self._urlMatcher, message.content.lower()) is not None
if containsURL:
print("<{ link detected! }> " + " [#" + str(message.channel) + "](" + message.author.display_name + ") sent a link in chat")
return containsURL
async def isTTS_URL_Enabled(self, message: discord.Message):
is_ttsEnabled = False
if not config.blockAll_TTS_URL_Discord or not self.block_tts_url:
if not await self.contains_url(message):
is_ttsEnabled = True
return is_ttsEnabled
# Checks if Sender is bot.
async def isSenderBot(self, message: discord.Message):
isBot = False
for bot in config.botList:
if message.author.display_name.lower() == bot.lower():
isBot = True
print("<{ bot detected! }> ")
return isBot
async def isChannel_inConfigList(self, selectedChannel, selectedList):
#print(channel)
#print(selectedList)
is_Self = False
for discordChannel in selectedList:
#print("isSelf: " + str(discordChannel) + " vs " + str(selectedChannel))
if discordChannel == selectedChannel:
is_Self = True
#if is_Self:
# print("Is Self")
#if not is_Self:
# print("Is Not Self")
return is_Self
if __name__ == "__main__":
testModule = Discord_Module()
credentials_manager = credentials.Credentials_Module()
credentials_manager.load_credentials()
testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname)
testModule.discordCredential = credentials_manager.find_Discord_Credential(config.credentialsNickname)
for ttsChannel in config.selected_discordTTSChannels:
testModule.selected_ttsChannels.append(int(ttsChannel))
testModule.main()

View File

@ -17,7 +17,7 @@ def init():
def load_commands():
global loadedCommands
loadedCommands = command_loader.load_commands_new(AbstractCommand.CommandType.Ver2)
loadedCommands = command_loader.load_commands(AbstractCommand.CommandType.Ver2)
def is_command(command: str) -> bool:

View File

@ -1,201 +0,0 @@
from typing import Sequence
import random
import re
import utilities_script as utilities
import twitch
import twitch.chat
import config as config
import db
import tts
import commands.loader as command_loader
import credentials
from commands.command_base import AbstractCommand
from cooldowns import Cooldown_Module
class Twitch_Module():
def __init__(self):
super().__init__()
self.twitchCredential: credentials.Twitch_Credential
self.dbCredential: credentials.DB_Credential
self.db_manager: db.db_module = db.db_module()
self.chat: twitch.Chat
self.commands = command_loader.load_commands_new(AbstractCommand.CommandType.TWITCH)
self.tts_enabled: bool = False
self.block_tts_url: bool = False
self.tts_whitelist_enabled: bool = False
self.block_chat_url: bool = True
self.whitelisted_users: list = ["thecuriousnerd"]
# don't freak out, this is *merely* a regex for matching urls that will hit just about everything
self._urlMatcher = re.compile(
"(https?:(/{1,3}|[a-z0-9%])|[a-z0-9.-]+[.](com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))")
# Default Twitch Chat limit is 20 per 30 seconds
# If Mod or Op, Twitch Chat limit is 100 per 30 seconds
self.cooldownModule:Cooldown_Module = Cooldown_Module()
self.cooldownModule.setupCooldown("twitchChat", 20, 32)
self.allow_rgbLightControl = config.autoEnabled_Twitch_rgbLightControl
def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str):
channel_name = "#" + channel_name
print("Connecting to Channel: " + channel_name + "...")
if credential is None:
credential = self.twitchCredential
self.chat = twitch.Chat(
channel = channel_name,
nickname = credential.username,
oauth = credential.oauth,
# LIBRARY UPDATE BROKE THE FOLLOWING LINE [FIX THIS]
#helix = twitch.Helix(credential.helix, use_cache=True)
)
self.chat.subscribe(self.twitch_chat)
print("Connected to Channel: ", channel_name)
def leave_channel(self):
print("Leaving Channel", self.chat.channel)
self.chat.irc.leave_channel(self.chat.channel)
self.chat.irc.socket.close()
def send_message(self, message):
isBlocked = self.isChannel_inConfigList(self.chat.channel, config.block_TwitchChannelsMessaging)
#print("isBlocked: " + str(isBlocked) + " for: " + self.chat.channel)
if self.cooldownModule.isCooldownActive("twitchChat") == False and not isBlocked and not config.blockAll_TwitchChatChannelsMessaging:
self.chat.send(message)
#print("Sent ChatMSG")
self.cooldownModule.actionTrigger("twitchChat")
def send_whisper(self, user, message):
pass
# This reacts to messages
def twitch_chat(self, message: twitch.chat.Message) -> None:
print("[#" + message.channel + "](" + message.sender + ")> " + message.text)
if not self.isSenderBot(message):
if self.cooldownModule.isCooldownActive("twitchChat") == False:
print("Pre Eval")
self.eval_commands(message)
self.tts_message(message)
def eval_commands(self, message: twitch.chat.Message):
print("evaling command")
# containsURL: bool = self.contains_url(message)
try:
#first_space_idx = message.text.index(' ')
# This fixes a error where if you send a command without arguments it fails because
# it cant find the substring.
if message.text.find(" ") != -1:
first_space_idx = message.text.index(' ')
else:
first_space_idx = -1
command_text = ' '
if first_space_idx > -1:
command_text = message.text[0:first_space_idx]
else:
command_text = message.text
command = self.commands[command_text]
if command is not None and command.command_type is AbstractCommand.CommandType.TWITCH:
print("running command")
command.do_command(self, message)
except Exception as e:
# Undo the following for debug stuff
#print(e)
print("failed command")
pass # we don't care
def tts_message(self, message: twitch.chat.Message):
isBlocked = self.isChannel_inConfigList(self.chat.channel, config.block_TwitchChannelsTTS)
isForced = (self.isChannel_inConfigList(self.chat.channel, config.force_TwitchChannelsTTS) and not config.blockAll_TwitchChatChannelsTTS)
if (not self.contains_slur(message)) and (self.isTTS_URL_Enabled(message)):
if self.tts_enabled and not isBlocked and not config.blockAll_TwitchChatChannelsTTS or isForced or config.forceAll_TwitchChatChannelsTTS:
if not message.text.startswith('!'):
text_to_say: str = "%s says, %s" % (message.sender, message.text)
channel_text = "%s user msg" % message.channel
tts.tts(text_to_say)
def contains_url(self, message: twitch.chat.Message):
containsURL = re.search(self._urlMatcher, message.text.lower()) is not None
if containsURL:
print("<{ link detected! }> " + " [#" + message.channel + "](" + message.sender + ") sent a link in chat")
return containsURL
# Checks if Sender is bot.
def isSenderBot(self, message: twitch.chat.Message):
isBot = False
for bot in config.botList:
if message.sender.lower() == bot.lower():
isBot = True
print("<{ bot detected! }> " + " [#" + message.channel + "](" + message.sender + ") is a bot")
return isBot
# Checks for basic slurs.
def contains_slur(self, message: twitch.chat.Message):
containsSlur: bool = False
parsedMessage = message.text.split(" ")
for word in parsedMessage:
for slur in config.slurList:
if word.lower() == slur:
containsSlur = True
break # we want to immediately escape if we found a slur
if containsSlur:
break
if containsSlur:
print("<{ slur detected! }> " + " [#" + message.channel + "](" + message.sender + ") used a slur in chat")
return containsSlur
def isTTS_URL_Enabled(self, message: twitch.chat.Message):
is_ttsEnabled = False
if not config.blockAll_TTS_URL_Twitch or not self.block_tts_url:
if not self.contains_url(message):
is_ttsEnabled = True
return is_ttsEnabled
def isChannel_inConfigList(self, selectedChannel, selectedList):
#print(channel)
#print(selectedList)
is_Self = False
for twitchChannel in selectedList:
if twitchChannel == selectedChannel:
is_Self = True
#if is_Self:
# print("Is Self")
#if not is_Self:
# print("Is Not Self")
return is_Self
# This is a old function used prior to the creation of the Twitch_Module class above.
# I need to make a new one for the class.
def main_chat_commands_check(channel, sender, text):
response = db.basic_command_trigger(channel, sender, text)
if response == "$$None$$":
pass
else:
print("Curious Nerd Response Function:")
print(response)
if __name__ == "__main__":
testModule = Twitch_Module()
credentials_manager = credentials.Credentials_Module()
credentials_manager.load_credentials()
testModule.twitchCredential = credentials_manager.find_Twitch_Credential(config.credentialsNickname)
testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname)
for twitchChannel in config.autojoinTwitchChannels:
testModule.join_channel(None, twitchChannel)

View File

@ -0,0 +1,65 @@
from enum import Enum
from os import F_OK
import tempText_Module
import time
import config as config
import db
import tts
import threading
from flask import Flask
import credentials
import commands.loader as command_loader
from commands.command_base import AbstractCommand
from cooldowns import Cooldown_Module
import utilities_script as utility
import chyron_module
class webSource_Module():
webSources:Flask = Flask('webSources')
def __init__(self):
super().__init__()
self.dbCredential: credentials.DB_Credential
def main(self, port_=5000):
print("starting up on port: ", port_)
self.webSources.run(host="0.0.0.0", port= port_)
@webSources.route('/')
def hello_world():
return 'I can see your Ghost!'
@webSources.route('/chyron')
def textSource_chyron():
tempModule = chyron_module.Chyron_Module()
return tempModule.getChyronFile()
@webSources.route('/temptext/<filename>/')
def textSource_tempText(filename):
print("trying file: ", filename)
tempModule = tempText_Module.tempText_Module()
return tempModule.getTempTextFile(filename)
if __name__ == "__main__":
testModule = webSource_Module()
testModule_2 = webSource_Module()
threads = []
#credentials_manager = credentials.Credentials_Module()
#credentials_manager.load_credentials()
#testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname)
thread_ = threading.Thread(target=testModule.main(port_=5000))
threads.append(thread_)
thread_.start()
for t in threads:
t.join()