@@ -53,19 +53,17 @@ async def scheduled_task_coro(self, tsk:ScheduledTask, channel:TwitchChannel):
5353 tags = None ,
5454 user_name_str = self .bot .nickname ,
5555 channel_str = channel ,
56- text = tuple ()
56+ text = tuple (),
57+ raw_irc = ["" ]
5758 )
5859 if tsk .wait_before : # the wait_before attribute handles if we sleep wait_before or after the task has been called
5960 await asyncio .sleep (tsk .delay )
6061 tsk .callback (self = self .bot ,context = context )
6162 else :
6263 tsk .callback (self = self .bot ,context = context )
6364 await asyncio .sleep (tsk .delay )
64- self .output_handler (
65- callback = output_scheduled_task ,
66- # below this point is all **kwargs
67- context = context
68- )
65+
66+ self .parse_context_output (context )
6967
7068 def output_handler (self ,callback :OUTPUT_CALLBACKS , ** kwargs ):
7169 # TODO test code below with asyncio.gather
@@ -79,7 +77,7 @@ def output_handler(self,callback:OUTPUT_CALLBACKS, **kwargs):
7977 ,
8078 loop = self .loop )
8179
82- def create_context (self , tags :str | None , user_name_str :str , channel_str :str | TwitchChannel , text :tuple [str ]) -> TwitchContext :
80+ def create_context (self , raw_irc , tags :str | None , user_name_str :str , channel_str :str | TwitchChannel , text :tuple [str ]) -> TwitchContext :
8381 return TwitchContext (
8482 message_tags = TwitchMessageTags .new_from_tags_str (tags )
8583 if self .bot .twitch_capability_tags and tags is not None else
@@ -88,7 +86,8 @@ def create_context(self, tags:str|None, user_name_str:str, channel_str:str|Twitc
8886 channel = channel_str
8987 if isinstance (channel_str , TwitchChannel ) else
9088 TwitchChannel (channel_str ) ,
91- raw_text = text
89+ raw_text = text ,
90+ raw_irc = raw_irc
9291 )
9392
9493 # ------------------------------------------------------------------------------------------------------------------
@@ -104,8 +103,11 @@ def connection_made(self, transport: asyncio.transports.Transport) -> None:
104103 )
105104
106105 # add frequent_output methods to the coroutine loop
106+
107+ print (self .bot .scheduled_tasks )
108+
107109 for tsk in self .bot .scheduled_tasks :
108- if tsk .channels : # the list is populated with channels
110+ if tsk .channels is not None and tsk . channels : # the list is populated with channels
109111 for channel in tsk .channels :
110112 coro = self .loop .create_task (self .scheduled_task_coro (tsk , channel = channel ))
111113 asyncio .ensure_future (coro , loop = self .loop )
@@ -168,14 +170,8 @@ def parse_data(self, data: bytearray):
168170 # PRIVMSG
169171 # #directiveathena
170172 # :that sentence was poggers
171- if self .parse_user_message (tags , user_name_str , channel_str , text ):
172- # a command was caught:
173- continue # because the output was handled by the parser above
174- # else:
175- self .output_handler (
176- callback = output_undefined ,
177- # below this point is all **kwargs
178- text = " " .join (d_split )
173+ self .parse_context_output (
174+ self .parse_user_message (d_split , tags , user_name_str , channel_str , text )
179175 )
180176
181177 case str (user_name_str ), _privmsg , str (channel_str ), * text \
@@ -186,14 +182,8 @@ def parse_data(self, data: bytearray):
186182 # PRIVMSG
187183 # #directiveathena
188184 # :that sentence was poggers
189- if self .parse_user_message (None , user_name_str , channel_str , text ):
190- # a command was caught:
191- continue # because the output was handled by the parser above
192- # else:
193- self .output_handler (
194- callback = output_undefined ,
195- # below this point is all **kwargs
196- text = " " .join (d_split )
185+ self .parse_context_output (
186+ self .parse_user_message (d_split , None , user_name_str , channel_str , text )
197187 )
198188
199189 case str (bot_name_long ), _join , str (channel ) \
@@ -203,7 +193,6 @@ def parse_data(self, data: bytearray):
203193 # :eva_athenabot!eva_athenabot@eva_athenabot.tmi.twitch.tv
204194 # JOIN
205195 # #directiveathena
206- pass # todo functionality
207196 self .output_handler (
208197 callback = output_undefined ,
209198 # below this point is all **kwargs
@@ -217,7 +206,6 @@ def parse_data(self, data: bytearray):
217206 # *
218207 # ACK
219208 # :twitch.tv/tags
220- pass # todo functionality
221209 self .output_handler (
222210 callback = output_undefined ,
223211 # below this point is all **kwargs
@@ -235,7 +223,6 @@ def parse_data(self, data: bytearray):
235223 # =
236224 # #directiveathena
237225 # :eva_athenabot
238- pass # todo functionality
239226 self .output_handler (
240227 callback = output_undefined ,
241228 # below this point is all **kwargs
@@ -251,7 +238,6 @@ def parse_data(self, data: bytearray):
251238 # =
252239 # #directiveathena
253240 # :eva_athenabot
254- pass # todo functionality
255241 self .output_handler (
256242 callback = output_undefined ,
257243 # below this point is all **kwargs
@@ -268,36 +254,42 @@ def parse_data(self, data: bytearray):
268254 # ------------------------------------------------------------------------------------------------------------------
269255 # - Message Parsing -
270256 # ------------------------------------------------------------------------------------------------------------------
271- def parse_user_message (self , tags :str | None , user_name_str :str , channel_str :str , text :tuple [str ]) -> bool :
272- context :TwitchContext = self .create_context (tags ,user_name_str ,channel_str ,text )
273-
257+ def parse_user_message (self , raw_irc , tags :str | None , user_name_str :str , channel_str :str , text :tuple [str ]) -> TwitchContext :
258+ context :TwitchContext = self .create_context (raw_irc , tags ,user_name_str ,channel_str ,text )
274259 PREFIX_FULL = f":{ self .bot .prefix } "
275260
276- if (cmd_str := context .raw_text [0 ]).startswith (PREFIX_FULL ) and context .raw_text [0 ] != PREFIX_FULL :
277- context .is_command = True
278- context .command_str = cmd_str .replace (PREFIX_FULL , "" ).lower ()
261+ if (cmd_str := context .raw_text [0 ]).startswith (PREFIX_FULL ) and cmd_str != PREFIX_FULL :
279262
280- command :Command = self .bot .commands [context .command_str .lower ()]
263+ context .command_str = cmd_str .replace (PREFIX_FULL , "" )
264+ cmd_str_lower = context .command_str .lower ()
281265
282- #checvk if the command was case-sensitive and break if it is
283- if command .case_sensitive and context .command_str != context .command_str .lower ():
284- return False
266+ try :
267+ command :Command = self .bot .commands [cmd_str_lower ]
268+ # check if the command was case-sensitive and break if it is
269+ if command .case_sensitive and context .command_str != cmd_str_lower :
270+ raise KeyError
271+ except KeyError :
272+ return context
273+
274+ context .is_command = True
275+ command .callback (self = self .bot ,context = context )
285276
286- #check if the user message is a command
287- if context .command_str .lower () in self .bot .commands :
288- command :Command
289- command .callback (self = self .bot ,context = context )
277+ return context
290278
279+ def parse_context_output (self , context :TwitchContext ):
280+ match context :
281+ case TwitchContext (is_write = True ):
291282 self .output_handler (
292- callback = output_reply if context .is_reply else output_write ,
293- # below this point is all **kwargs
283+ callback = output_write ,
294284 context = context
295285 )
296- return True
297- return False
298-
299-
300-
301-
302-
303-
286+ case TwitchContext (is_reply = True ):
287+ self .output_handler (
288+ callback = output_reply ,
289+ context = context
290+ )
291+ case _:
292+ self .output_handler (
293+ callback = output_undefined ,
294+ text = " " .join (context .raw_irc )
295+ )
0 commit comments