Command Restrictions
This commit is contained in:
parent
25fee4cb5c
commit
d5f8d8e38d
@ -27,7 +27,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
|
||||
#print("sending:",user, 16, "!lights hydration")
|
||||
try:
|
||||
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
|
||||
self.threads.append(thread_)
|
||||
thread_.start()
|
||||
@ -42,7 +42,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
|
||||
|
||||
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
|
||||
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
|
||||
#standalone_lights
|
||||
|
||||
@ -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):
|
||||
|
||||
#self.dothething(user, 16, "!lights rubikscube", "")
|
||||
#self.send_Lights_Command(user, 16, "!lights rubikscube", "")
|
||||
|
||||
try:
|
||||
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
|
||||
self.threads.append(thread_)
|
||||
thread_.start()
|
||||
@ -43,7 +43,7 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta):
|
||||
|
||||
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
|
||||
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
|
||||
#standalone_lights
|
||||
|
||||
@ -27,7 +27,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta):
|
||||
#print("sending:",user, 16, "!lights hydration")
|
||||
try:
|
||||
#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
|
||||
#self.threads.append(thread_)
|
||||
#thread_.start()
|
||||
@ -41,7 +41,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta):
|
||||
|
||||
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
|
||||
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
|
||||
#standalone_lights
|
||||
|
||||
@ -27,7 +27,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta):
|
||||
#print("sending:",user, 16, "!lights hydration")
|
||||
try:
|
||||
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
|
||||
self.threads.append(thread_)
|
||||
thread_.start()
|
||||
@ -42,7 +42,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta):
|
||||
|
||||
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
|
||||
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
|
||||
#standalone_lights
|
||||
|
||||
@ -31,20 +31,19 @@ class Command_lights_v2(AbstractCommand, metaclass=ABCMeta):
|
||||
praxis_logger_obj.log("\n Command>: " + command + rest)
|
||||
isTwitch = False
|
||||
|
||||
if source is not None and source == AbstractCommand.CommandSource.Twitch:
|
||||
for user_ in config.allowedCommandsList_TwitchPowerUsers:
|
||||
if user_.lower() == user.lower():
|
||||
praxis_logger_obj.log(user_)
|
||||
praxis_logger_obj.log(user)
|
||||
returnString = self.dothething(user, 16, command, rest)
|
||||
isTwitch = True
|
||||
if "Twitch" in source:
|
||||
for name in config.allowedCommandsList_TwitchPowerUsers:
|
||||
print(name)
|
||||
tempName = user.lower()
|
||||
if name == tempName:
|
||||
returnString = self.send_Lights_Command(user, 16, command, rest)
|
||||
else:
|
||||
returnString = self.send_Lights_Command(user, 16, command, rest)
|
||||
|
||||
if isTwitch == False:
|
||||
returnString = self.dothething(user, 16, command, rest)
|
||||
|
||||
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
|
||||
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
|
||||
#standalone_lights
|
||||
|
||||
75
commands/implemented/Command_tts_v2.py
Normal file
75
commands/implemented/Command_tts_v2.py
Normal 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
|
||||
@ -10,7 +10,7 @@ user_module: bool = True
|
||||
|
||||
autoJoin_TwitchChannel = "thecuriousnerd"
|
||||
autoJoin_TwitchChannels = ["thecuriousnerd"]
|
||||
allowedCommandsList_TwitchPowerUsers = ["thecuriousnerd"]
|
||||
allowedCommandsList_TwitchPowerUsers = ["thecuriousnerd", "lakotor", "blastofcynicism"]
|
||||
|
||||
#Twitch Module Configs
|
||||
block_TwitchChannelsMessaging = [""] # Blocks the ability to send messages to twitch channels
|
||||
|
||||
@ -49,9 +49,11 @@ def handle_reward(source, username, reward_name, reward_type, rewardPrompt, user
|
||||
try:
|
||||
tempType = reward_type.replace('ChannelRewardsType.', '')
|
||||
realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType]
|
||||
tempSource = source.replace('ChannelRewardsSource.', '')
|
||||
realSource = AbstractChannelRewards.ChannelRewardsSource.__dict__[tempSource]
|
||||
reward:AbstractChannelRewards = loadedRewards[realTempType][reward_name]
|
||||
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"})
|
||||
except:
|
||||
return flask.make_response("This is a magic test", 500)
|
||||
|
||||
@ -44,6 +44,8 @@ def handle_command(source, username, command, rest, bonusData):
|
||||
#print(message)
|
||||
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]
|
||||
if cmd is not None:
|
||||
cmd_response = cmd.do_command(source, username, command, rest, bonusData)
|
||||
|
||||
@ -81,7 +81,13 @@ class Twitch_Module():
|
||||
|
||||
def exec_command(self, realMessage: twitch.chat.Message, command: str, rest: str):
|
||||
# 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
|
||||
resp = requests.get(url)
|
||||
if resp.status_code == 200:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user