mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-11-07 17:36:00 +00:00
Fixed some issues
Patched `_ba.chatmessage` instead of polling for previous chat message as suggested by https://github.com/bombsquad-community/plugin-manager/pull/47/files/195f70d728ea224815f138c5fa0404fba556141e#r985130539 Moved settings from txt file to `ba.app.config` https://github.com/bombsquad-community/plugin-manager/pull/47/files/195f70d728ea224815f138c5fa0404fba556141e#r985130531
This commit is contained in:
parent
2afe98515d
commit
16138295d8
1 changed files with 24 additions and 32 deletions
|
|
@ -2,8 +2,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import TYPE_CHECKING, cast
|
from typing import TYPE_CHECKING, cast
|
||||||
|
|
||||||
import ba
|
import ba,_ba
|
||||||
import _ba
|
|
||||||
import random
|
import random
|
||||||
from ba._map import Map
|
from ba._map import Map
|
||||||
from bastd import mainmenu
|
from bastd import mainmenu
|
||||||
|
|
@ -21,16 +20,11 @@ def Print(arg1, arg2="", arg3=""):
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("moodlightSettings.txt", "r") as mltxt:
|
Ldefault, Udefault=ba.app.config.get("moodlightingSettings")
|
||||||
global Ldefault, Udefault
|
|
||||||
data = mltxt.read()
|
|
||||||
Ldefault, Udefault = data.split("\n")
|
|
||||||
Ldefault = int(Ldefault)
|
|
||||||
Udefault = int(Udefault)
|
|
||||||
except:
|
except:
|
||||||
with open("moodlightSettings.txt", "w") as mltxt:
|
ba.app.config["moodlightingSettings"]=(15,20)
|
||||||
mltxt.write("15 \n 20")
|
Ldefault, Udefault=ba.app.config.get("moodlightingSettings")
|
||||||
Ldefault, Udefault = 15, 20
|
Print("settings up moodlight")
|
||||||
|
|
||||||
|
|
||||||
class SettingWindow(ba.Window):
|
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"))
|
ba.textwidget(edit=self.lower_text, on_activate_call=ba.Call(self.on_text_click, "lower"))
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
with open("moodlightSettings.txt", "w") as mltxt:
|
ba.app.config["moodlightingSettings"]=(Ldefault,Udefault)
|
||||||
data = "\n".join([str(Ldefault), str(Udefault)])
|
|
||||||
mltxt.write(data)
|
|
||||||
Print("settings saved")
|
Print("settings saved")
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
ba.containerwidget(edit=self._root_widget, transition="out_right",)
|
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
|
# ba_meta export plugin
|
||||||
|
|
||||||
|
|
||||||
class moodlight(ba.Plugin):
|
class moodlight(ba.Plugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
Map._old_init = Map.__init__
|
|
||||||
|
|
||||||
def on_app_running(self):
|
def on_app_running(self):
|
||||||
try:
|
try:
|
||||||
_ba.timer(0.5, self.on_chat_message, True)
|
pass
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
Print(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):
|
def on_plugin_manager_prompt(self):
|
||||||
SettingWindow()
|
SettingWindow()
|
||||||
|
|
||||||
|
|
@ -251,3 +242,4 @@ class moodlight(ba.Plugin):
|
||||||
})
|
})
|
||||||
_ba.timer(0.3, changetint, repeat=True)
|
_ba.timer(0.3, changetint, repeat=True)
|
||||||
Map.__init__ = _new_init
|
Map.__init__ = _new_init
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue