@@ -258,7 +258,7 @@ async def _periodic_ping(self) -> None:
258258 await self .msg ("PING" , self .server .servername )
259259 self .ping_sent = True
260260
261- async def msg (self , command : str | IRCNumeric , params : list [str ] | str ) -> None :
261+ async def msg (self , command : str | IRCNumeric , params : list [str ] | str , from_bot : bool = False ) -> None :
262262 """Prepare and sends a response to the client.
263263
264264 This generally does the right thing, and reduces boilerplate by
@@ -273,6 +273,8 @@ async def msg(self, command: str | IRCNumeric, params: list[str] | str) -> None:
273273 source = None
274274 elif isinstance (command , (RPL , ERR )) or command == "PONG" :
275275 source = self .server .servername
276+ elif from_bot :
277+ source = self .server .botid
276278 else :
277279 source = self .client_ident
278280
@@ -809,12 +811,10 @@ async def broadcast(self, target: str, msg: str) -> None:
809811
810812 The source of the message is the bot's name.
811813 """
812- message = str (IRCMessage ("PRIVMSG" , [target , msg ], source = self .botid ))
813-
814814 clients = self ._channels .setdefault (target , set ())
815815 for client in clients :
816816 try :
817- await client .send ( message )
817+ await client .msg ( "PRIVMSG" , [ target , msg ], from_bot = True )
818818 except Exception : # pylint: disable=broad-except
819819 self .metrics ["errors" ].labels ("broadcast" ).inc ()
820820 self .log .debug ("Unable to broadcast" , exc_info = True )
0 commit comments