Added Docker url fix to docker_utility.py
This commit is contained in:
parent
a5429e5ce5
commit
6d1c07f39b
@ -6,6 +6,8 @@ from json import loads
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import docker_utility
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import random
|
import random
|
||||||
@ -46,7 +48,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
# 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
|
||||||
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
|
url = "http://%s:42069/api/v1/exec_lights?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_lights"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
@ -62,7 +64,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
def send_TTS(self, username, message):
|
def send_TTS(self, username, message):
|
||||||
params = urlencode({'tts_sender': username, 'tts_text': message})
|
params = urlencode({'tts_sender': username, 'tts_text': message})
|
||||||
#standalone_tts_core
|
#standalone_tts_core
|
||||||
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
|
url = "http://%s:60809/api/v1/tts/send_text?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_tts_core"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
|
|||||||
@ -6,6 +6,8 @@ from json import loads
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import docker_utility
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import random
|
import random
|
||||||
@ -47,7 +49,7 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
# 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
|
||||||
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
|
url = "http://%s:42069/api/v1/exec_lights?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_lights"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
@ -63,7 +65,7 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
def send_TTS(self, username, message):
|
def send_TTS(self, username, message):
|
||||||
params = urlencode({'tts_sender': username, 'tts_text': message})
|
params = urlencode({'tts_sender': username, 'tts_text': message})
|
||||||
#standalone_tts_core
|
#standalone_tts_core
|
||||||
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
|
url = "http://%s:60809/api/v1/tts/send_text?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_tts_core"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
|
|||||||
@ -6,6 +6,8 @@ from json import loads
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import docker_utility
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import random
|
import random
|
||||||
@ -45,7 +47,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
# 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
|
||||||
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
|
url = "http://%s:42069/api/v1/exec_lights?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_lights"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
@ -61,7 +63,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
def send_TTS(self, username, message):
|
def send_TTS(self, username, message):
|
||||||
params = urlencode({'tts_sender': username, 'tts_text': message})
|
params = urlencode({'tts_sender': username, 'tts_text': message})
|
||||||
#standalone_tts_core
|
#standalone_tts_core
|
||||||
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
|
url = "http://%s:60809/api/v1/tts/send_text?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_tts_core"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
|
|||||||
@ -6,6 +6,8 @@ from json import loads
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import docker_utility
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import random
|
import random
|
||||||
@ -46,7 +48,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
# 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
|
||||||
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
|
url = "http://%s:42069/api/v1/exec_lights?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_lights"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
@ -62,7 +64,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
def send_TTS(self, username, message):
|
def send_TTS(self, username, message):
|
||||||
params = urlencode({'tts_sender': username, 'tts_text': message})
|
params = urlencode({'tts_sender': username, 'tts_text': message})
|
||||||
#standalone_tts_core
|
#standalone_tts_core
|
||||||
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
|
url = "http://%s:60809/api/v1/tts/send_text?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_tts_core"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
|
|||||||
@ -6,6 +6,8 @@ from json import loads
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import docker_utility
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -47,7 +49,7 @@ class Command_lights_v2(AbstractCommand, metaclass=ABCMeta):
|
|||||||
# 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
|
||||||
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
|
url = "http://%s:42069/api/v1/exec_lights?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_lights"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
|
|||||||
@ -6,6 +6,8 @@ from json import loads
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import docker_utility
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -42,7 +44,7 @@ class Command_tts_v2(AbstractCommand, metaclass=ABCMeta):
|
|||||||
# 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
|
||||||
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
|
url = "http://%s:42069/api/v1/exec_lights?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_lights"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
@ -58,7 +60,7 @@ class Command_tts_v2(AbstractCommand, metaclass=ABCMeta):
|
|||||||
def send_TTS(self, username, message):
|
def send_TTS(self, username, message):
|
||||||
params = urlencode({'tts_sender': username, 'tts_text': message})
|
params = urlencode({'tts_sender': username, 'tts_text': message})
|
||||||
#standalone_tts_core
|
#standalone_tts_core
|
||||||
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
|
url = "http://%s:60809/api/v1/tts/send_text?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_tts_core"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
|
|||||||
14
docker_utility.py
Normal file
14
docker_utility.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
def isRunningInDocker():
|
||||||
|
isD = os.getenv('ISDOCKER')
|
||||||
|
if isD is None:
|
||||||
|
return False
|
||||||
|
return isD == "cat"
|
||||||
|
|
||||||
|
def ifNotDockerUseLocalhost(address):
|
||||||
|
amIDocker = isRunningInDocker()
|
||||||
|
if amIDocker:
|
||||||
|
return address
|
||||||
|
else:
|
||||||
|
return "localhost"
|
||||||
@ -25,6 +25,8 @@ import discord.abc
|
|||||||
|
|
||||||
from cooldowns import Cooldown_Module
|
from cooldowns import Cooldown_Module
|
||||||
|
|
||||||
|
import docker_utility
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import praxis_logging
|
import praxis_logging
|
||||||
praxis_logger_obj = praxis_logging.praxis_logger()
|
praxis_logger_obj = praxis_logging.praxis_logger()
|
||||||
@ -105,14 +107,14 @@ class Discord_Module(discord.Client):
|
|||||||
async def is_command(self, word: str) -> bool:
|
async def is_command(self, word: str) -> bool:
|
||||||
# todo need to url-escape word
|
# todo need to url-escape word
|
||||||
clean_param = urlencode({'name': word})
|
clean_param = urlencode({'name': word})
|
||||||
url = "http://standalone_command:6009/api/v1/command?%s" % clean_param
|
url = "http://%s:6009/api/v1/command?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_command"), clean_param
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
return resp.status_code == 200
|
return resp.status_code == 200
|
||||||
|
|
||||||
async def exec_command(self, realMessage: discord.Message, command: str, rest: str):
|
async def exec_command(self, realMessage: discord.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.Discord, 'user_name': realMessage.author.mention, 'command_name': command, 'rest': rest, 'bonus_data': realMessage})
|
clean_param = urlencode({'command_source': commands.command_base.AbstractCommand.CommandSource.Discord, 'user_name': realMessage.author.mention, 'command_name': command, 'rest': rest, 'bonus_data': realMessage})
|
||||||
url = "http://standalone_command:6009/api/v1/exec_command?%s" % params
|
url = "http://%s:6009/api/v1/exec_command?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_command"), clean_param
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
@ -174,7 +176,7 @@ class Discord_Module(discord.Client):
|
|||||||
async def exec_tts_sender(self, username, message):
|
async def exec_tts_sender(self, username, message):
|
||||||
params = urlencode({'tts_sender': username, 'tts_text': message})
|
params = urlencode({'tts_sender': username, 'tts_text': message})
|
||||||
#standalone_tts_core
|
#standalone_tts_core
|
||||||
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
|
url = "http://%s:60809/api/v1/tts/send_text?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_tts_core"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
|
|||||||
@ -20,6 +20,8 @@ from uuid import UUID
|
|||||||
|
|
||||||
from cooldowns import Cooldown_Module
|
from cooldowns import Cooldown_Module
|
||||||
|
|
||||||
|
import docker_utility
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import praxis_logging
|
import praxis_logging
|
||||||
praxis_logger_obj = praxis_logging.praxis_logger()
|
praxis_logger_obj = praxis_logging.praxis_logger()
|
||||||
@ -171,7 +173,7 @@ class Twitch_Pubsub():
|
|||||||
clean_param = urlencode({'reward_name': rewardName, 'reward_type':rewardType})
|
clean_param = urlencode({'reward_name': rewardName, 'reward_type':rewardType})
|
||||||
print(rewardName, rewardType)
|
print(rewardName, rewardType)
|
||||||
#standalone_channelrewards
|
#standalone_channelrewards
|
||||||
url = "http://standalone_channelrewards:6969/api/v1/reward?%s" % clean_param
|
url = "http://%s:6969/api/v1/reward?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_channelrewards"), clean_param
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
return resp.status_code == 200
|
return resp.status_code == 200
|
||||||
|
|
||||||
@ -186,7 +188,7 @@ class Twitch_Pubsub():
|
|||||||
'bonus_data': realMessage})
|
'bonus_data': realMessage})
|
||||||
|
|
||||||
#standalone_channelrewards
|
#standalone_channelrewards
|
||||||
url = "http://standalone_channelrewards:6969/api/v1/exec_reward?%s" % params
|
url = "http://%s:6969/api/v1/exec_reward?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_channelrewards"), params
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
|
|||||||
@ -12,6 +12,8 @@ from cooldowns import Cooldown_Module
|
|||||||
import commands.command_base
|
import commands.command_base
|
||||||
import utilities_script as utility
|
import utilities_script as utility
|
||||||
|
|
||||||
|
import docker_utility
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import praxis_logging
|
import praxis_logging
|
||||||
praxis_logger_obj = praxis_logging.praxis_logger()
|
praxis_logger_obj = praxis_logging.praxis_logger()
|
||||||
@ -75,20 +77,20 @@ class Twitch_Module():
|
|||||||
def is_command(self, word: str) -> bool:
|
def is_command(self, word: str) -> bool:
|
||||||
# todo need to url-escape word
|
# todo need to url-escape word
|
||||||
clean_param = urlencode({'name': word})
|
clean_param = urlencode({'name': word})
|
||||||
url = "http://standalone_command:6009/api/v1/command?%s" % clean_param
|
url = "http://%s:6009/api/v1/command?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_command"), clean_param
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
return resp.status_code == 200
|
return resp.status_code == 200
|
||||||
|
|
||||||
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(
|
clean_param = urlencode(
|
||||||
{'command_source': commands.command_base.AbstractCommand.CommandSource.Twitch,
|
{'command_source': commands.command_base.AbstractCommand.CommandSource.Twitch,
|
||||||
'user_name': realMessage.sender,
|
'user_name': realMessage.sender,
|
||||||
'command_name': command,
|
'command_name': command,
|
||||||
'rest': rest,
|
'rest': rest,
|
||||||
'bonus_data': realMessage})
|
'bonus_data': realMessage})
|
||||||
|
|
||||||
url = "http://standalone_command:6009/api/v1/exec_command?%s" % params
|
url = "http://%s:6009/api/v1/exec_command?%s" % docker_utility.ifNotDockerUseLocalhost("standalone_command"), clean_param
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("Got the following message: %s" % resp.text)
|
print("Got the following message: %s" % resp.text)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user