@@ -36,6 +36,9 @@ def __post_init__(self):
3636 else :
3737 raise NotImplementedError ("This needs to be created" )
3838
39+ # ----------------------------------------------------------------------------------------------------------------------
40+ # - Protocol neseccary -
41+ # ----------------------------------------------------------------------------------------------------------------------
3942 def connection_made (self , transport : asyncio .transports .Transport ) -> None :
4043 self .transport = transport
4144 # first write the password then the nickname else the connection will fail
@@ -44,26 +47,40 @@ def connection_made(self, transport: asyncio.transports.Transport) -> None:
4447 self .transport .write (messages .join (channel = self .bot .channel ))
4548 self .transport .write (messages .request_tags )
4649
50+ # add frequent_ouput methods to the coroutine loop
51+ loop = asyncio .get_running_loop ()
52+ for callback , delay in self .bot .frequent_outputs :
53+ coro = loop .create_task (self .frequent_output_call (callback ,delay ))
54+ asyncio .ensure_future (coro , loop = loop )
55+
56+ async def frequent_output_call (self , callback ,delay :int ):
57+ context = TwitchMessageContext (
58+ message = TwitchMessage (channel = f"#{ self .bot .channel } " ),
59+ transport = self .transport
60+ )
61+ while True :
62+ await asyncio .sleep (delay )
63+ callback (
64+ self = self .bot ,
65+ context = context )
66+
4767 def data_received (self , data : bytearray ) -> None :
4868 for message in data .split (b"\r \n " ):
4969 match (twitch_message := self .message_constructor (message , bot_name = self .bot .nickname )):
5070 # Keepalive messages : https://dev.twitch.tv/docs/irc#keepalive-messages
5171 case TwitchMessagePing ():
5272 print (ForeNest .ForestGreen ("PINGED BY TWITCH" ))
53- self .transport .write (pong_message := messages .pong (message = twitch_message .text ))
54- print (pong_message )
73+ self .transport .write (messages .pong (message = twitch_message .text ))
5574
5675 # catch a message which starts with a command:
57- case TwitchMessage (text = user_message ) if user_message .startswith (f"{ self .bot .prefix } " ):
58- user_message :str
76+ case TwitchMessage (text = str (user_message )) if user_message .startswith (f"{ self .bot .prefix } " ):
5977 print (ForeNest .ForestGreen ("COMMAND CAUGHT" ))
6078 try :
6179 user_cmd = user_message .replace (f"{ self .bot .prefix } " , "" )
6280 # tuple unpacking because we have a callback
6381 # and the object instance where the command is placed in
64- callback , orign_obj = self .bot .commands [user_cmd ]
65- callback (
66- self = orign_obj ,
82+ self .bot .commands [user_cmd ](
83+ self = self .bot ,
6784 # Assign a context so the user doesn't need to write the transport messages themselves
6885 # A user opnly has to write the text
6986 context = TwitchMessageContext (
0 commit comments