Add on_connect callback and joined_channels property
* on_connect is called on all plugins on the first message received from the IRC server * joined_channels property gets all of the channels that this bot has currently joined in IRC Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -33,6 +33,13 @@ class Bot:
|
|||||||
def plugins(self) -> Sequence[plugin.Plugin]:
|
def plugins(self) -> Sequence[plugin.Plugin]:
|
||||||
return self.__plugins
|
return self.__plugins
|
||||||
|
|
||||||
|
@property
|
||||||
|
def joined_channels(self) -> Set[str]:
|
||||||
|
"""
|
||||||
|
Returns a list of all channels that this bot has joined.
|
||||||
|
"""
|
||||||
|
return self.__channels
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
self.__quitting.set()
|
self.__quitting.set()
|
||||||
|
|
||||||
@@ -67,6 +74,8 @@ class Bot:
|
|||||||
for ch in self.server_config.all_channels:
|
for ch in self.server_config.all_channels:
|
||||||
msg = Message(None, None, "JOIN", ch)
|
msg = Message(None, None, "JOIN", ch)
|
||||||
conn.send(str(msg))
|
conn.send(str(msg))
|
||||||
|
# on_connect event on all plugins
|
||||||
|
await asyncio.gather(*[plugin.on_connect(conn) for plugin in self.plugins])
|
||||||
|
|
||||||
async def on_join(self, conn: IrcProtocol, message: Message):
|
async def on_join(self, conn: IrcProtocol, message: Message):
|
||||||
log.debug("%s", message)
|
log.debug("%s", message)
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ class Plugin:
|
|||||||
async def on_load(self):
|
async def on_load(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def on_connect(self, conn: IrcProtocol):
|
||||||
|
pass
|
||||||
|
|
||||||
async def on_unload(self, conn: IrcProtocol):
|
async def on_unload(self, conn: IrcProtocol):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user