-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventHandler.py
224 lines (165 loc) · 7.07 KB
/
EventHandler.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import asyncio
import logging
from Module import Module
from ConfigHandler import ConfigHandler
from twitchAPI.object.eventsub import ChannelFollowEvent, ChannelBanEvent
from twitchAPI.chat import Chat, EventData, ChatMessage, ChatCommand
from Databaseconn import Databaseconn
from TadaLogger import tadaLogger
class EventHandler:
def __init__(self):
super().__init__()
self.TwitchAPI = None
self.DBConn: Databaseconn = None
self.config: ConfigHandler = None
self.tadalogger: tadaLogger = None
self.commands = {}
self.Modules: list[Module] = []
self.is_recording = False
self.streamID = 1
#assign twitch api
def assign_to_twitch(self, TwitchAPI):
self.TwitchAPI = TwitchAPI
def assign_to_DBConn(self, DBConn):
self.DBConn = DBConn
def assign_to_config(self, config):
self.config = config
def assign_to_logger(self, logger):
self.tadalogger = logger
def go_live(self,streamID):
self.is_recording = True
self.streamID = streamID
def go_offline(self):
self.is_recording = False
self.streamID = 1
#add module
def AddModule(self, Module: Module):
self.Modules.append(Module)
#------- webfrontend events -------
async def on_webfrontend_message(self, command:str):
for Module in self.Modules:
await Module.on_webfrontend_message(command)
#------- chat bot events -------
# on_message
async def on_message(self, data: ChatMessage):
# print(f'{msg.user.name}: {msg.text}')
for Module in self.Modules:
await Module.on_message(data)
# send message
async def send_message(self, message):
await self.TwitchAPI.send_message(message)
# send whisper
async def send_whisper(self, user, message):
await self.TwitchAPI.send_whisper(user, message)
def Get_commands(self):
return self.commands
def Add_command(self, command, function):
self.commands[command] = function
async def get_pfp(self, user):
result = await self.TwitchAPI.get_user_pfp(user)
return result
#------- API events -------
async def ban_user(self, user, reason):
await self.TwitchAPI.ban_user(user, reason)
async def unban_user(self, user):
await self.TwitchAPI.unban_user(user)
async def get_chat_users(self):
return await self.TwitchAPI.get_chat_users()
#------- event sub events -------
async def on_channel_update(self, data):
for Module in self.Modules:
await Module.on_channel_update(data)
# on_follow
async def on_follow(self, data: ChannelFollowEvent):
#print(f'{data.event.user_name} followed, called from EventHandler')
for Module in self.Modules:
await Module.on_follow(data)
async def on_subscribe(self, data):
for Module in self.Modules:
await Module.on_subscribe(data)
async def on_subscription_gift(self, data):
for Module in self.Modules:
await Module.on_subscription_gift(data)
async def on_subscription_message(self, data):
for Module in self.Modules:
await Module.on_subscription_message(data)
async def on_cheer(self, data):
for Module in self.Modules:
await Module.on_cheer(data)
async def on_raid(self, data):
for Module in self.Modules:
await Module.on_raid(data)
# on_ban
async def on_ban(self, data: ChannelBanEvent):
for Module in self.Modules:
await Module.on_ban(data)
async def on_unban(self, data):
for Module in self.Modules:
await Module.on_unban(data)
async def on_moderator_add(self, data):
for Module in self.Modules:
await Module.on_moderator_add(data)
async def on_moderator_remove(self, data):
for Module in self.Modules:
await Module.on_moderator_remove(data)
async def on_channel_points_custom_reward_add(self, data):
for Module in self.Modules:
await Module.on_channel_points_redeem_reward_add(data)
async def on_channel_points_custom_reward_update(self, data):
for Module in self.Modules:
await Module.on_channel_points_redeem_reward_update(data)
async def on_channel_points_custom_reward_remove(self, data):
for Module in self.Modules:
await Module.on_channel_points_redeem_reward_remove(data)
async def on_channel_points_reward_redeem(self, data):
for Module in self.Modules:
await Module.on_channel_points_redeem(data)
async def on_channel_points_reward_redeem_update(self, data):
for Module in self.Modules:
await Module.on_channel_points_redeem_update(data)
async def on_poll_begin(self, data):
for Module in self.Modules:
await Module.on_channel_poll_begin(data)
async def on_poll_progress(self, data):
for Module in self.Modules:
await Module.on_channel_poll_progress(data)
async def on_poll_end(self, data):
for Module in self.Modules:
await Module.on_channel_poll_end(data)
async def on_stream_online(self, data):
for Module in self.Modules:
await Module.on_stream_online(data)
async def on_stream_offline(self, data):
for Module in self.Modules:
await Module.on_stream_offline(data)
async def on_shoutout_create(self, data):
for Module in self.Modules:
await Module.on_shoutout_create(data)
async def on_shoutout_recieve(self, data):
for Module in self.Modules:
await Module.on_shoutout_received(data)
async def on_chat_clear(self, data):
for Module in self.Modules:
await Module.on_channel_chat_clear(data)
async def on_chat_clear_user_messages(self, data):
for Module in self.Modules:
await Module.on_channel_chat_clear_user_messages(data)
async def on_chat_delete_messages(self, data):
for Module in self.Modules:
await Module.on_channel_chat_message_delete(data)
async def do_worker(self):
for Module in self.Modules:
await Module.do_worker()
#------- log events -------
def logwarning(self,caller:str, message:str):
self.tadalogger.logwarning(caller, message)
def loginfo(self,caller:str, message:str):
self.tadalogger.loginfo(caller, message)
def logerror(self,caller:str, message:str):
self.tadalogger.logerror(caller, message)
def logdebug(self,caller:str, message:str):
self.tadalogger.logdebug(caller, message)
def eventtofrontend(self,caller:str, message:str):
self.tadalogger.eventtofrontend(caller, message)
def ensurelog(self):
self.tadalogger.ensurelog()