bot: remember joined channels
This commit is contained in:
parent
721d99dba3
commit
ff88bfbb05
|
@ -12,6 +12,8 @@ from edmond.log import Logger
|
|||
|
||||
class Bot(irc.client.SimpleIRCClient, Logger):
|
||||
|
||||
CHANNELS_RUNTIME_KEY = "_channels"
|
||||
|
||||
def __init__(self, config, logger):
|
||||
super().__init__()
|
||||
self.config = config
|
||||
|
@ -30,6 +32,13 @@ class Bot(irc.client.SimpleIRCClient, Logger):
|
|||
def names(self):
|
||||
return (self.nick, *self.config["alternative_nicks"])
|
||||
|
||||
@property
|
||||
def channels(self):
|
||||
"""List of joined channels."""
|
||||
if self.CHANNELS_RUNTIME_KEY not in self.values:
|
||||
self.values[self.CHANNELS_RUNTIME_KEY] = []
|
||||
return self.values[self.CHANNELS_RUNTIME_KEY]
|
||||
|
||||
def _get_storage(self):
|
||||
"""Load data from storage."""
|
||||
try:
|
||||
|
@ -61,11 +70,13 @@ class Bot(irc.client.SimpleIRCClient, Logger):
|
|||
def on_join(self, connection, event):
|
||||
if event.source.nick == self.nick:
|
||||
self.log_i(f"Joined {event.target}.")
|
||||
self.channels.append(event.target)
|
||||
self.run_plugin_callbacks(event)
|
||||
|
||||
def on_part(self, connection, event):
|
||||
if event.source.nick == self.nick:
|
||||
self.log_i(f"Left {event.target} (args: {event.arguments[0]}).")
|
||||
self.channels.remove(event.target)
|
||||
self.run_plugin_callbacks(event)
|
||||
|
||||
def on_pubmsg(self, connection, event):
|
||||
|
|
Loading…
Reference in a new issue