@@ -258,7 +258,7 @@ async def _periodic_ping(self) -> None:
258
258
await self .msg ("PING" , self .server .servername )
259
259
self .ping_sent = True
260
260
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 :
262
262
"""Prepare and sends a response to the client.
263
263
264
264
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:
273
273
source = None
274
274
elif isinstance (command , (RPL , ERR )) or command == "PONG" :
275
275
source = self .server .servername
276
+ elif from_bot :
277
+ source = self .server .botid
276
278
else :
277
279
source = self .client_ident
278
280
@@ -809,12 +811,10 @@ async def broadcast(self, target: str, msg: str) -> None:
809
811
810
812
The source of the message is the bot's name.
811
813
"""
812
- message = str (IRCMessage ("PRIVMSG" , [target , msg ], source = self .botid ))
813
-
814
814
clients = self ._channels .setdefault (target , set ())
815
815
for client in clients :
816
816
try :
817
- await client .send ( message )
817
+ await client .msg ( "PRIVMSG" , [ target , msg ], from_bot = True )
818
818
except Exception : # pylint: disable=broad-except
819
819
self .metrics ["errors" ].labels ("broadcast" ).inc ()
820
820
self .log .debug ("Unable to broadcast" , exc_info = True )
0 commit comments