98 lines
3.4 KiB
Python
98 lines
3.4 KiB
Python
|
from ChatBot import ChatBot
|
||
|
from obspython import *
|
||
|
from services.CommandService import CommandService
|
||
|
from services.DiceService import DiceService
|
||
|
from services.SpotifyService import SpotifyService
|
||
|
from services.TimedMessageService import TimedMessageService
|
||
|
from threading import Thread
|
||
|
|
||
|
DESCRIPTION = "A Twitch chat bot that interacts with OBS and other services.\n\nby kholo"
|
||
|
|
||
|
chatbot = ChatBot()
|
||
|
|
||
|
services = {
|
||
|
"command": CommandService(),
|
||
|
"dice": DiceService(),
|
||
|
"spotify": SpotifyService(),
|
||
|
"tmsg": TimedMessageService()
|
||
|
}
|
||
|
|
||
|
def set_services():
|
||
|
chatbot.clear_services()
|
||
|
for name, service in services.items():
|
||
|
if service.enabled:
|
||
|
print(f"- Enabling service {name}")
|
||
|
chatbot.add_service(service)
|
||
|
|
||
|
# Callbacks -----
|
||
|
|
||
|
def start(props, prop):
|
||
|
print("[ STARTING THE BOT ]")
|
||
|
set_services()
|
||
|
thread = Thread(target=chatbot.start)
|
||
|
thread.daemon = True
|
||
|
thread.start()
|
||
|
print("Bot started")
|
||
|
|
||
|
def stop(props, prop):
|
||
|
print("[ STOPPING THE BOT ]")
|
||
|
chatbot.stop()
|
||
|
print("Bot stopped")
|
||
|
|
||
|
# Helpers -----
|
||
|
|
||
|
def create_messages_properties():
|
||
|
props = obs_properties_create()
|
||
|
obs_properties_add_text(props, "msg_help", "Help message", OBS_TEXT_DEFAULT)
|
||
|
obs_properties_add_text(props, "msg_unknown_cmd", "Unknown command message", OBS_TEXT_DEFAULT)
|
||
|
obs_properties_add_text(props, "msg_hi", "Welcome message", OBS_TEXT_DEFAULT)
|
||
|
obs_properties_add_text(props, "msg_bye", "Farewell message", OBS_TEXT_DEFAULT)
|
||
|
return props
|
||
|
|
||
|
def create_twitch_irc_properties():
|
||
|
props = obs_properties_create()
|
||
|
obs_properties_add_text(props, "irc_nickname", "Nickname", OBS_TEXT_DEFAULT)
|
||
|
obs_properties_add_text(props, "irc_password", "OAuth password", OBS_TEXT_PASSWORD)
|
||
|
obs_properties_add_text(props, "irc_channel", "Channel", OBS_TEXT_DEFAULT)
|
||
|
return props
|
||
|
|
||
|
# OBS functions -----
|
||
|
|
||
|
def script_description():
|
||
|
return DESCRIPTION
|
||
|
|
||
|
def script_load(settings):
|
||
|
for service in services.values():
|
||
|
service.load(settings)
|
||
|
|
||
|
def script_properties():
|
||
|
props = obs_properties_create()
|
||
|
obs_properties_add_button(props, "start", "Start bot", start)
|
||
|
obs_properties_add_button(props, "stop", "Stop bot", stop)
|
||
|
obs_properties_add_group(props, "messages", "Default messages", OBS_GROUP_NORMAL, create_messages_properties())
|
||
|
obs_properties_add_group(props, "irc", "Twitch IRC", OBS_GROUP_NORMAL, create_twitch_irc_properties())
|
||
|
for name, service in services.items():
|
||
|
obs_properties_add_group(props, name, service.title, OBS_GROUP_CHECKABLE, service.create_properties())
|
||
|
return props
|
||
|
|
||
|
def script_update(settings):
|
||
|
chatbot.set_help_message(obs_data_get_string(settings, "msg_help"))
|
||
|
chatbot.set_unknown_command_message(obs_data_get_string(settings, "msg_unknown_cmd"))
|
||
|
chatbot.set_welcome_message(obs_data_get_string(settings, "msg_hi"))
|
||
|
chatbot.set_farewell_message(obs_data_get_string(settings, "msg_bye"))
|
||
|
chatbot.set_twitch_irc_settings(
|
||
|
obs_data_get_string(settings, "irc_nickname"),
|
||
|
obs_data_get_string(settings, "irc_password"),
|
||
|
obs_data_get_string(settings, "irc_channel")
|
||
|
)
|
||
|
for name, service in services.items():
|
||
|
if obs_data_get_bool(settings, name):
|
||
|
service.enabled = True
|
||
|
service.update(settings)
|
||
|
else:
|
||
|
service.enabled = False
|
||
|
|
||
|
def script_save(settings):
|
||
|
for service in services.values():
|
||
|
service.save(settings)
|