@@ -110,9 +110,9 @@ public function close(bool $closeLoop = true): void
110110 }
111111 }
112112
113- public function sendMessage (string $ data ): void
113+ public function sendMessage (string $ data, string $ channel = null ): void
114114 {
115- $ this ->connection ->write ("PRIVMSG # " . $ this ->channel . " : " . $ data . "\n" );
115+ $ this ->connection ->write ("PRIVMSG # " . ( $ channel ?? $ this ->channel ) . " : " . $ data . "\n" );
116116 $ this ->emit ("[REPLY] $ data " );
117117 }
118118
@@ -203,7 +203,7 @@ protected function parseMessage(string $data): ?string
203203 /* Output to Discord */
204204 $ this ->lastmessage = $ messageContents ;
205205 $ this ->reallastuser = $ this ->parseUser ($ data );
206- $ this ->reallastchannel = null ;
206+ $ this ->reallastchannel = $ this -> parseChannel ( $ data ) ;
207207 $ this ->discordRelay ('[MSG] ' . $ this ->reallastuser . ': ' . $ messageContents );
208208
209209 $ commandsymbol = '' ;
@@ -218,6 +218,7 @@ protected function parseMessage(string $data): ?string
218218 $ command = strtolower (trim (substr ($ dataArr [0 ], strlen ($ commandsymbol ))));
219219 if ($ this ->verbose ) $ this ->emit ("[COMMAND] ` $ command` " );
220220 $ this ->lastuser = $ this ->reallastuser ;
221+ $ this ->lastchannel = $ this ->reallastchannel ;
221222 $ this ->lastchannel = null ;
222223
223224 //Public commands
@@ -256,8 +257,17 @@ protected function parseUser(string $data): ?string
256257 if (substr ($ data , 0 , 1 ) == ": " ) {
257258 $ tmp = explode ('! ' , $ data );
258259 $ user = substr ($ tmp [0 ], 1 );
259- return $ user ;
260260 }
261+ return $ user ;
262+ }
263+
264+ protected function parseChannel (string $ data ): ?string
265+ {
266+ $ arr = explode (' ' , substr ($ data , strpos ($ data , '# ' )));
267+ if (substr ($ arr [0 ], 0 , 1 ) == "# " ) {
268+ $ channel = substr ($ arr [0 ], 1 );
269+ }
270+ return $ channel ;
261271 }
262272
263273 public function emit (string $ string ): void
0 commit comments