-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
106 lines (84 loc) · 3.78 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
# Import StreamController modules
from src.backend.PluginManager.PluginBase import PluginBase
from src.backend.PluginManager.ActionHolder import ActionHolder
# Import actions
from .actions.MuteAction import MuteAction
from .actions.DeafenAction import DeafenAction
from .actions.ChangeVoiceChannelAction import ChangeVoiceChannelAction
from .actions.ChangeTextChannel import ChangeTextChannel
from .actions.TogglePushToTalkAction import TogglePushToTalkAction
from loguru import logger as log
class PluginTemplate(PluginBase):
def __init__(self):
super().__init__()
self.callbacks = {}
self.auth_callback_fn: callable = None
self.lm = self.locale_manager
self.lm.set_to_os_default()
self.message_mute_action_holder = ActionHolder(
plugin_base=self,
action_base=MuteAction,
action_id="com_imdevinc_StreamControllerDiscordPlugin::Mute",
action_name="Mute"
)
self.add_action_holder(self.message_mute_action_holder)
self.message_deafen_action_holder = ActionHolder(
plugin_base=self,
action_base=DeafenAction,
action_id="com_imdevinc_StreamControllerDiscordPlugin::Deafen",
action_name="Deafen"
)
self.add_action_holder(self.message_deafen_action_holder)
self.change_voice_channel_action = ActionHolder(
plugin_base=self,
action_base=ChangeVoiceChannelAction,
action_id="com_imdevinc_StreamControllerDiscordPlugin::ChangeVoiceChannel",
action_name="Change Voice Channel"
)
self.add_action_holder(self.change_voice_channel_action)
self.change_text_channel_action = ActionHolder(
plugin_base=self,
action_base=ChangeTextChannel,
action_id="com_imdevinc_StreamControllerDiscordPlugin::ChangeTextChannel",
action_name="Change Text Channel"
)
self.add_action_holder(self.change_text_channel_action)
self.message_ptt_action_holder = ActionHolder(
plugin_base=self,
action_base=TogglePushToTalkAction,
action_id="com_imdevinc_StreamControllerDiscordPlugin::Push_To_Talk",
action_name="Toggle push to talk"
)
self.add_action_holder(self.message_ptt_action_holder)
self.register(
plugin_name="Discord",
github_repo="https://github.com/imdevinc/StreamControllerDiscordPlugin",
plugin_version="1.0.0",
app_version="1.5.0"
)
settings = self.get_settings()
client_id = settings.get('client_id', '')
client_secret = settings.get('client_secret', '')
access_token = settings.get('access_token', '')
backend_path = os.path.join(self.PATH, 'backend.py')
self.launch_backend(backend_path=backend_path,
open_in_terminal=False, venv_path=os.path.join(self.PATH, '.venv'))
self.wait_for_backend(10)
self.backend.update_client_credentials(
client_id, client_secret, access_token)
self.add_css_stylesheet(os.path.join(self.PATH, "style.css"))
def save_access_token(self, access_token: str):
settings = self.get_settings()
settings['access_token'] = access_token
self.set_settings(settings)
def add_callback(self, key: str, callback: callable):
callbacks = self.callbacks.get(key, [])
callbacks.append(callback)
self.callbacks[key] = callbacks
def handle_callback(self, key: str, data: any):
for callback in self.callbacks.get(key):
callback(data)
def on_auth_callback(self, success: bool, message: str = None):
if self.auth_callback_fn:
self.auth_callback_fn(success, message)