Command Restrictions

This commit is contained in:
Alex Orid 2021-04-29 16:39:22 -04:00
parent 25fee4cb5c
commit d5f8d8e38d
10 changed files with 106 additions and 22 deletions

View File

@ -27,7 +27,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
#print("sending:",user, 16, "!lights hydration") #print("sending:",user, 16, "!lights hydration")
try: try:
if self.is_ChannelReward_enabled: if self.is_ChannelReward_enabled:
thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights hydration", "")) thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights hydration", ""))
thread_.daemon = True thread_.daemon = True
self.threads.append(thread_) self.threads.append(thread_)
thread_.start() thread_.start()
@ -42,7 +42,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
return None return None
def dothething(self, username, light_group, command, rest): def send_Lights_Command(self, username, light_group, command, rest):
# todo need to url-escape command and rest # todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest}) params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights #standalone_lights

View File

@ -24,11 +24,11 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta):
def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None): def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None):
#self.dothething(user, 16, "!lights rubikscube", "") #self.send_Lights_Command(user, 16, "!lights rubikscube", "")
try: try:
if self.is_ChannelReward_enabled: if self.is_ChannelReward_enabled:
thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights rubikscube", "")) thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights rubikscube", ""))
thread_.daemon = True thread_.daemon = True
self.threads.append(thread_) self.threads.append(thread_)
thread_.start() thread_.start()
@ -43,7 +43,7 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta):
return None return None
def dothething(self, username, light_group, command, rest): def send_Lights_Command(self, username, light_group, command, rest):
# todo need to url-escape command and rest # todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest}) params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights #standalone_lights

View File

@ -27,7 +27,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta):
#print("sending:",user, 16, "!lights hydration") #print("sending:",user, 16, "!lights hydration")
try: try:
#if self.is_ChannelReward_enabled: #if self.is_ChannelReward_enabled:
#thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights hydration", "")) #thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights hydration", ""))
#thread_.daemon = True #thread_.daemon = True
#self.threads.append(thread_) #self.threads.append(thread_)
#thread_.start() #thread_.start()
@ -41,7 +41,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta):
return None return None
def dothething(self, username, light_group, command, rest): def send_Lights_Command(self, username, light_group, command, rest):
# todo need to url-escape command and rest # todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest}) params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights #standalone_lights

View File

@ -27,7 +27,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta):
#print("sending:",user, 16, "!lights hydration") #print("sending:",user, 16, "!lights hydration")
try: try:
if self.is_ChannelReward_enabled: if self.is_ChannelReward_enabled:
thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights ravemode", "")) thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights ravemode", ""))
thread_.daemon = True thread_.daemon = True
self.threads.append(thread_) self.threads.append(thread_)
thread_.start() thread_.start()
@ -42,7 +42,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta):
return None return None
def dothething(self, username, light_group, command, rest): def send_Lights_Command(self, username, light_group, command, rest):
# todo need to url-escape command and rest # todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest}) params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights #standalone_lights

View File

@ -31,20 +31,19 @@ class Command_lights_v2(AbstractCommand, metaclass=ABCMeta):
praxis_logger_obj.log("\n Command>: " + command + rest) praxis_logger_obj.log("\n Command>: " + command + rest)
isTwitch = False isTwitch = False
if source is not None and source == AbstractCommand.CommandSource.Twitch: if "Twitch" in source:
for user_ in config.allowedCommandsList_TwitchPowerUsers: for name in config.allowedCommandsList_TwitchPowerUsers:
if user_.lower() == user.lower(): print(name)
praxis_logger_obj.log(user_) tempName = user.lower()
praxis_logger_obj.log(user) if name == tempName:
returnString = self.dothething(user, 16, command, rest) returnString = self.send_Lights_Command(user, 16, command, rest)
isTwitch = True else:
returnString = self.send_Lights_Command(user, 16, command, rest)
if isTwitch == False:
returnString = self.dothething(user, 16, command, rest)
return returnString return returnString
def dothething(self, username, light_group, command, rest): def send_Lights_Command(self, username, light_group, command, rest):
# todo need to url-escape command and rest # todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest}) params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights #standalone_lights

View File

@ -0,0 +1,75 @@
from abc import ABCMeta
from commands.command_base import AbstractCommand
from json import loads
from urllib.parse import urlencode
import requests
import config
import os
import praxis_logging
praxis_logger_obj = praxis_logging.praxis_logger()
praxis_logger_obj.init(os.path.basename(__file__))
praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__))
class Command_tts_v2(AbstractCommand, metaclass=ABCMeta):
"""
this is the test command.
"""
command = "!tts"
def __init__(self):
super().__init__(Command_tts_v2.command, n_args=1, command_type=AbstractCommand.CommandType.Ver2)
self.help = ["This command allows you to do tts.",
"\nExample:","tts \"TEXT\""]
self.isCommandEnabled = True
def do_command(self, source = AbstractCommand.CommandSource.default, user:str = "User", command = "", rest = "", bonusData = None):
returnString = ""
praxis_logger_obj.log("\n Command>: " + command + rest)
for name in config.allowedCommandsList_TwitchPowerUsers:
print(name)
tempName = user.lower()
if name == tempName:
self.send_TTS(user, rest)
return returnString
def send_Lights_Command(self, username, light_group, command, rest):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
data = loads(resp.text)
msg = data['message']
if msg is not None:
return msg
# todo send to logger and other relevent services
else:
# todo handle failed requests
return None
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
data = loads(resp.text)
msg = data['message']
if msg is not None:
return msg
# todo send to logger and other relevent services
else:
# todo handle failed requests
pass
def get_help(self):
return self.help

View File

@ -10,7 +10,7 @@ user_module: bool = True
autoJoin_TwitchChannel = "thecuriousnerd" autoJoin_TwitchChannel = "thecuriousnerd"
autoJoin_TwitchChannels = ["thecuriousnerd"] autoJoin_TwitchChannels = ["thecuriousnerd"]
allowedCommandsList_TwitchPowerUsers = ["thecuriousnerd"] allowedCommandsList_TwitchPowerUsers = ["thecuriousnerd", "lakotor", "blastofcynicism"]
#Twitch Module Configs #Twitch Module Configs
block_TwitchChannelsMessaging = [""] # Blocks the ability to send messages to twitch channels block_TwitchChannelsMessaging = [""] # Blocks the ability to send messages to twitch channels

View File

@ -49,9 +49,11 @@ def handle_reward(source, username, reward_name, reward_type, rewardPrompt, user
try: try:
tempType = reward_type.replace('ChannelRewardsType.', '') tempType = reward_type.replace('ChannelRewardsType.', '')
realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType] realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType]
tempSource = source.replace('ChannelRewardsSource.', '')
realSource = AbstractChannelRewards.ChannelRewardsSource.__dict__[tempSource]
reward:AbstractChannelRewards = loadedRewards[realTempType][reward_name] reward:AbstractChannelRewards = loadedRewards[realTempType][reward_name]
if reward is not None: if reward is not None:
reward_response = reward.do_ChannelReward(source, username, reward_name, rewardPrompt, userInput, bonusData) reward_response = reward.do_ChannelReward(realSource, username, reward_name, rewardPrompt, userInput, bonusData)
return flask.make_response("{\"message\":\"%s\"}" % reward_response, 200, {"Content-Type": "application/json"}) return flask.make_response("{\"message\":\"%s\"}" % reward_response, 200, {"Content-Type": "application/json"})
except: except:
return flask.make_response("This is a magic test", 500) return flask.make_response("This is a magic test", 500)

View File

@ -44,6 +44,8 @@ def handle_command(source, username, command, rest, bonusData):
#print(message) #print(message)
return flask.make_response("{\"message\":\"%s\"}" % message, 200, {"Content-Type": "application/json"}) return flask.make_response("{\"message\":\"%s\"}" % message, 200, {"Content-Type": "application/json"})
tempSource = source.replace('CommandSource.', '')
realSource = AbstractCommand.CommandSource.__dict__[tempSource]
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, bonusData) cmd_response = cmd.do_command(source, username, command, rest, bonusData)

View File

@ -81,7 +81,13 @@ class Twitch_Module():
def exec_command(self, realMessage: twitch.chat.Message, command: str, rest: str): def exec_command(self, realMessage: twitch.chat.Message, command: str, rest: str):
# todo need to url-escape command and rest # todo need to url-escape command and rest
params = urlencode({'command_source': commands.command_base.AbstractCommand.CommandSource.Twitch,'user_name': realMessage.sender, 'command_name': command, 'rest': rest, 'bonus_data': realMessage}) params = urlencode(
{'command_source': commands.command_base.AbstractCommand.CommandSource.Twitch,
'user_name': realMessage.sender,
'command_name': command,
'rest': rest,
'bonus_data': realMessage})
url = "http://standalone_command:6009/api/v1/exec_command?%s" % params url = "http://standalone_command:6009/api/v1/exec_command?%s" % params
resp = requests.get(url) resp = requests.get(url)
if resp.status_code == 200: if resp.status_code == 200: