diff --git a/plugins/utilities/mood_light.py b/plugins/utilities/mood_light.py index 65c5d01..9599374 100644 --- a/plugins/utilities/mood_light.py +++ b/plugins/utilities/mood_light.py @@ -2,8 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, cast -import ba -import _ba +import ba,_ba import random from ba._map import Map from bastd import mainmenu @@ -21,16 +20,11 @@ def Print(arg1, arg2="", arg3=""): try: - with open("moodlightSettings.txt", "r") as mltxt: - global Ldefault, Udefault - data = mltxt.read() - Ldefault, Udefault = data.split("\n") - Ldefault = int(Ldefault) - Udefault = int(Udefault) + Ldefault, Udefault=ba.app.config.get("moodlightingSettings") except: - with open("moodlightSettings.txt", "w") as mltxt: - mltxt.write("15 \n 20") - Ldefault, Udefault = 15, 20 + ba.app.config["moodlightingSettings"]=(15,20) + Ldefault, Udefault=ba.app.config.get("moodlightingSettings") + Print("settings up moodlight") class SettingWindow(ba.Window): @@ -193,44 +187,41 @@ class SettingWindow(ba.Window): ba.textwidget(edit=self.lower_text, on_activate_call=ba.Call(self.on_text_click, "lower")) def save_settings(self): - with open("moodlightSettings.txt", "w") as mltxt: - data = "\n".join([str(Ldefault), str(Udefault)]) - mltxt.write(data) + ba.app.config["moodlightingSettings"]=(Ldefault,Udefault) Print("settings saved") self.close() def close(self): ba.containerwidget(edit=self._root_widget, transition="out_right",) +Map._old_init = Map.__init__ + +def new_chat_message(msg: Union[str, ba.Lstr], clients:Sequence[int] = None, sender_override: str = None): + old_fcm(msg, clients, sender_override) + if msg == 'ml': + try: + Ldefault, Udefault=ba.app.config.get("moodlightingSettings") + SettingWindow() + _ba.chatmessage("Mood light settings opened") + except Exception as err: + Print(err) + +old_fcm = _ba.chatmessage +_ba.chatmessage = new_chat_message + # ba_meta export plugin class moodlight(ba.Plugin): def __init__(self): pass - Map._old_init = Map.__init__ - + def on_app_running(self): try: - _ba.timer(0.5, self.on_chat_message, True) + pass except Exception as err: Print(err) - def on_chat_message(self): - messages = _ba.get_chat_messages() - if len(messages) > 0: - lastmessage = messages[-1].split(":")[-1].strip().lower() - if lastmessage in ("/mood light", "/mood lighting", "/mood_light", "/mood_lighting", "/moodlight", "ml"): - - with open("moodlightSettings.txt", "r") as mltxt: - global Ldefault, Udefault - data = mltxt.read() - Ldefault, Udefault = data.split("\n") - Ldefault = int(Ldefault) - Udefault = int(Udefault) - SettingWindow() - _ba.chatmessage("Mood light settings opened") - def on_plugin_manager_prompt(self): SettingWindow() @@ -251,3 +242,4 @@ class moodlight(ba.Plugin): }) _ba.timer(0.3, changetint, repeat=True) Map.__init__ = _new_init +