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
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.n_args = n_args
self.ChannelRewardType = ChannelReward_type
self.ChannelRewardType = ChannelRewardType
self.help = helpText
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"):
ChannelReward_inst = obj()
if channelRewardsType == ChannelReward_inst.get_ChannelRewardType():
print(" ---Successfully loaded %s: %s" % (channelRewardsType, ChannelReward_inst.get_ChannelRewardType()))
return ChannelReward_inst.get_ChannelRewardType(), ChannelReward_inst
print(" ---Successfully loaded %s: %s" % (channelRewardsType, ChannelReward_inst.get_ChannelRewardName()))
return ChannelReward_inst.get_ChannelRewardName(), ChannelReward_inst
elif channelRewardsType != ChannelReward_inst.get_ChannelRewardType():
print(" -%s ChannelRewardsType did not match: %s for: %s" % (ChannelReward_inst.get_ChannelRewardType(), channelRewardsType, ChannelReward_inst.get_ChannelRewardName()))
return "", None
@ -51,12 +51,12 @@ def get_base_dir() -> str:
cwd = os.getcwd()
split = os.path.split(cwd)
current = split[len(split) - 1]
if current == 'channel_points':
if current == 'channel_rewards':
return check_dir(cwd)
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:
print("could not find working directory for Praxis_Bot/channel_points")
print("could not find working directory for Praxis_Bot/channel_rewards")
raise Exception

View File

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

View File

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