Praxis_Bot/channel_rewards/implemented/ChannelReward_RubiksCube.py
2021-04-28 15:01:24 -04:00

44 lines
1.7 KiB
Python

from abc import ABCMeta
from channel_rewards.channelRewards_base import AbstractChannelRewards
from json import loads
from urllib.parse import urlencode
import requests
class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta):
"""
this is the hydration reward.
"""
ChannelRewardName = "Solve a Rubiks Cube"
def __init__(self):
super().__init__(ChannelReward_RubiksCube.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints)
self.help = ["This is a rubiks cube reward."]
self.isChannelRewardEnabled = True
def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None):
#print("sending:",user, 16, "!lights hydration")
self.dothething(user, 16, "!lights rubikscube", "")
return None
def dothething(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
pass
def get_help(self):
return self.help