add command name to settings
This commit is contained in:
+36
-5
@@ -5,7 +5,7 @@ from urllib.parse import quote_plus
|
|||||||
from urllib.request import urlretrieve, urlopen, Request, HTTPError
|
from urllib.request import urlretrieve, urlopen, Request, HTTPError
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from os import makedirs,path
|
from os import makedirs,path
|
||||||
import json,sys,webbrowser,importlib
|
import json,sys,webbrowser,importlib,tomllib
|
||||||
|
|
||||||
def dependency_setup():
|
def dependency_setup():
|
||||||
print('checking dependencies')
|
print('checking dependencies')
|
||||||
@@ -22,6 +22,16 @@ def dependency_setup():
|
|||||||
|
|
||||||
# Astrology functions
|
# Astrology functions
|
||||||
|
|
||||||
|
def load_settings():
|
||||||
|
try:
|
||||||
|
with open(script_path()+'config.toml','r') as file:
|
||||||
|
return tomllib.loads(file.read())
|
||||||
|
except FileNotFoundError:
|
||||||
|
return {
|
||||||
|
'positions':'!positions',
|
||||||
|
'transits':'!transits',
|
||||||
|
}
|
||||||
|
|
||||||
zodiac_signs = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
|
zodiac_signs = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
|
||||||
"Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"]
|
"Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"]
|
||||||
|
|
||||||
@@ -231,11 +241,12 @@ def main():
|
|||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_chat_message(data: eventsub.chat.MessageEvent):
|
async def on_chat_message(data: eventsub.chat.MessageEvent):
|
||||||
if data['message']['text']=='!astrology':
|
config=load_settings()
|
||||||
|
if data['message']['text']==config['positions']:
|
||||||
for line in get_planet_info_formatted().splitlines(False):
|
for line in get_planet_info_formatted().splitlines(False):
|
||||||
await client.channel.chat.send_message(line,data['message_id'])
|
await client.channel.chat.send_message(line,data['message_id'])
|
||||||
return
|
return
|
||||||
if data['message']['text']=='!transits':
|
if data['message']['text']==config['transits']:
|
||||||
for line in get_transits_formatted().splitlines(False):
|
for line in get_transits_formatted().splitlines(False):
|
||||||
await client.channel.chat.send_message(line,data['message_id'])
|
await client.channel.chat.send_message(line,data['message_id'])
|
||||||
|
|
||||||
@@ -249,6 +260,12 @@ def script_main():
|
|||||||
dependency_setup()
|
dependency_setup()
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
def obs_load_settings():
|
||||||
|
import obspython
|
||||||
|
global obs_settings
|
||||||
|
settings=json.loads(obspython.obs_data_get_json_with_defaults(obs_settings))
|
||||||
|
return settings
|
||||||
|
|
||||||
def obs_load_tokens():
|
def obs_load_tokens():
|
||||||
import obspython
|
import obspython
|
||||||
access_token=obspython.obs_data_get_string(obs_settings,'access_token')
|
access_token=obspython.obs_data_get_string(obs_settings,'access_token')
|
||||||
@@ -271,19 +288,29 @@ def obs_save_tokens(access_token,refresh_token):
|
|||||||
# https://docs.obsproject.com/scripting#script-function-exports
|
# https://docs.obsproject.com/scripting#script-function-exports
|
||||||
|
|
||||||
def script_description():
|
def script_description():
|
||||||
return 'adds the !astrology and !transits commands to your twitch channel, providing the current and upcoming star signs and retrograde status of the planets'
|
return 'adds astrology commands to your twitch channel, providing the current and upcoming star signs and retrograde status of the planets'
|
||||||
|
|
||||||
def script_properties():
|
def script_properties():
|
||||||
import obspython
|
import obspython
|
||||||
properties=obspython.obs_properties_create()
|
properties=obspython.obs_properties_create()
|
||||||
obspython.obs_properties_add_button(properties,'login','Login to Twitch',login)
|
obspython.obs_properties_add_button(properties,'login','Login to Twitch',login)
|
||||||
|
obspython.obs_properties_add_text(properties,'commands','commands',obspython.OBS_TEXT_INFO)
|
||||||
|
obspython.obs_properties_add_text(properties,'positions','positions',obspython.OBS_TEXT_DEFAULT)
|
||||||
|
obspython.obs_properties_add_text(properties,'transits','transits',obspython.OBS_TEXT_DEFAULT)
|
||||||
return properties
|
return properties
|
||||||
|
|
||||||
|
def script_defaults(settings):
|
||||||
|
import obspython
|
||||||
|
obspython.obs_data_set_default_string(settings,'commands','you can change the commands below, they save automatically')
|
||||||
|
obspython.obs_data_set_default_string(settings,'positions','!positions')
|
||||||
|
obspython.obs_data_set_default_string(settings,'transits','!transits')
|
||||||
|
|
||||||
def script_load(settings):
|
def script_load(settings):
|
||||||
global obs_settings, save_tokens, load_tokens
|
global obs_settings, save_tokens, load_tokens, load_settings
|
||||||
obs_settings=settings
|
obs_settings=settings
|
||||||
save_tokens=obs_save_tokens
|
save_tokens=obs_save_tokens
|
||||||
load_tokens=obs_load_tokens
|
load_tokens=obs_load_tokens
|
||||||
|
load_settings=obs_load_settings
|
||||||
def isatty():
|
def isatty():
|
||||||
return False
|
return False
|
||||||
sys.stdout.isatty=isatty
|
sys.stdout.isatty=isatty
|
||||||
@@ -297,6 +324,10 @@ def script_unload():
|
|||||||
except NameError or ImportError:
|
except NameError or ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def script_update(settings):
|
||||||
|
global obs_settings
|
||||||
|
obs_settings=settings
|
||||||
|
|
||||||
# test functions
|
# test functions
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user