is reward real

This commit is contained in:
Alex Orid 2021-04-26 18:43:54 -04:00
parent a29f71e268
commit 7e591e3791
4 changed files with 18 additions and 17 deletions

View File

@ -24,10 +24,10 @@ class AbstractChannelRewards(metaclass=ABCMeta):
Twitch = 2 Twitch = 2
Discord = 3 Discord = 3
def __init__(self, ChannelRewardName: str, n_args: int = 0, ChannelReward_type=ChannelRewardsType.NONE, helpText:list=["No Help"], isChannelRewardEnabled = True): def __init__(self, ChannelRewardName: str, n_args: int = 0, ChannelRewardType=ChannelRewardsType.NONE, helpText:list=["No Help"], isChannelRewardEnabled = True):
self.ChannelRewardName = ChannelRewardName self.ChannelRewardName = ChannelRewardName
self.n_args = n_args self.n_args = n_args
self.ChannelRewardType = ChannelReward_type self.ChannelRewardType = ChannelRewardType
self.help = helpText self.help = helpText
self.isChannelRewardEnabled = isChannelRewardEnabled self.isChannelRewardEnabled = isChannelRewardEnabled

View File

@ -26,8 +26,8 @@ def compile_and_load_file(path: str, channelRewardsType: AbstractChannelRewards.
if inspect.isclass(obj) and name.startswith("ChannelReward"): if inspect.isclass(obj) and name.startswith("ChannelReward"):
ChannelReward_inst = obj() ChannelReward_inst = obj()
if channelRewardsType == ChannelReward_inst.get_ChannelRewardType(): if channelRewardsType == ChannelReward_inst.get_ChannelRewardType():
print(" ---Successfully loaded %s: %s" % (channelRewardsType, ChannelReward_inst.get_ChannelRewardType())) print(" ---Successfully loaded %s: %s" % (channelRewardsType, ChannelReward_inst.get_ChannelRewardName()))
return ChannelReward_inst.get_ChannelRewardType(), ChannelReward_inst return ChannelReward_inst.get_ChannelRewardName(), ChannelReward_inst
elif channelRewardsType != ChannelReward_inst.get_ChannelRewardType(): elif channelRewardsType != ChannelReward_inst.get_ChannelRewardType():
print(" -%s ChannelRewardsType did not match: %s for: %s" % (ChannelReward_inst.get_ChannelRewardType(), channelRewardsType, ChannelReward_inst.get_ChannelRewardName())) print(" -%s ChannelRewardsType did not match: %s for: %s" % (ChannelReward_inst.get_ChannelRewardType(), channelRewardsType, ChannelReward_inst.get_ChannelRewardName()))
return "", None return "", None
@ -51,12 +51,12 @@ def get_base_dir() -> str:
cwd = os.getcwd() cwd = os.getcwd()
split = os.path.split(cwd) split = os.path.split(cwd)
current = split[len(split) - 1] current = split[len(split) - 1]
if current == 'channel_points': if current == 'channel_rewards':
return check_dir(cwd) return check_dir(cwd)
elif current == 'Praxis_Bot' or current == 'Praxis': elif current == 'Praxis_Bot' or current == 'Praxis':
return check_dir(os.path.join(cwd, "channel_points")) return check_dir(os.path.join(cwd, "channel_rewards"))
else: else:
print("could not find working directory for Praxis_Bot/channel_points") print("could not find working directory for Praxis_Bot/channel_rewards")
raise Exception raise Exception

View File

@ -12,25 +12,23 @@ loadedRewards = {}
def init(): def init():
# todo load entire reward library and cache it here # todo load entire reward library and cache it here
load_rewards() print("init stuff")
def load_rewards():
global loadedRewards
loadedRewards[AbstractChannelRewards.ChannelRewardsType.channelPoints] = rewards_loader.load_rewards(AbstractChannelRewards.ChannelRewardsType.channelPoints) loadedRewards[AbstractChannelRewards.ChannelRewardsType.channelPoints] = rewards_loader.load_rewards(AbstractChannelRewards.ChannelRewardsType.channelPoints)
loadedRewards[AbstractChannelRewards.ChannelRewardsType.twitch_bits] = rewards_loader.load_rewards(AbstractChannelRewards.ChannelRewardsType.twitch_bits) loadedRewards[AbstractChannelRewards.ChannelRewardsType.twitch_bits] = rewards_loader.load_rewards(AbstractChannelRewards.ChannelRewardsType.twitch_bits)
loadedRewards[AbstractChannelRewards.ChannelRewardsType.twitch_subs] = rewards_loader.load_rewards(AbstractChannelRewards.ChannelRewardsType.twitch_subs) loadedRewards[AbstractChannelRewards.ChannelRewardsType.twitch_subs] = rewards_loader.load_rewards(AbstractChannelRewards.ChannelRewardsType.twitch_subs)
def is_reward(reward_name, reward_type) -> bool: def is_reward(reward_name, reward_type) -> bool:
#global loadedRewards
tempType = reward_type.replace('ChannelRewardsType.', '') tempType = reward_type.replace('ChannelRewardsType.', '')
realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType] realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType]
rewardList = loadedRewards[realTempType] for reward in loadedRewards[realTempType]:
print("testing mcgoo") print("found: ",reward,"type: ",type(reward))
for reward in rewardList: if reward_name == reward:
print(reward) print("Equal")
print("testing oogcm") return True
if reward_name == "!echo": if reward_name == "!echo":
return True return True
@ -51,7 +49,9 @@ def handle_reward(source, username, reward_name, reward_type, rest, bonusData):
@api.route('/api/v1/reward', methods=['GET']) @api.route('/api/v1/reward', methods=['GET'])
def reward_check(): def reward_check():
if 'reward_name' in request.args and 'reward_type' in request.args: if 'reward_name' in request.args and 'reward_type' in request.args:
print("reward_name:", request.args['reward_name'],"reward_type:", request.args['reward_type'])
if is_reward(request.args['reward_name'], request.args['reward_type']): if is_reward(request.args['reward_name'], request.args['reward_type']):
print("about to send")
return flask.make_response('', 200) return flask.make_response('', 200)
else: else:
return flask.make_response('', 404) return flask.make_response('', 404)

View File

@ -111,6 +111,7 @@ class Twitch_Pubsub():
try: try:
is_actionable = self.is_reward(rewardName, rewardType) is_actionable = self.is_reward(rewardName, rewardType)
if is_actionable: if is_actionable:
print("Trying to do the thing")
if self.cooldownModule.isCooldownActive("twitchChat") == False: if self.cooldownModule.isCooldownActive("twitchChat") == False:
self.exec_reward(sender, rewardName, rewardType, rewardPrompt, userInput, raw_data) self.exec_reward(sender, rewardName, rewardType, rewardPrompt, userInput, raw_data)
except: except: