bot: add docs
This commit is contained in:
parent
091d0ecd72
commit
f346b9cb58
|
@ -52,3 +52,4 @@ Missing features
|
||||||
- [ ] "???"
|
- [ ] "???"
|
||||||
- [ ] Simple word mappings for fun
|
- [ ] Simple word mappings for fun
|
||||||
- [ ] Lyrics
|
- [ ] Lyrics
|
||||||
|
- [ ] Phonétique
|
||||||
|
|
|
@ -24,12 +24,14 @@ class Bot(irc.client.SimpleIRCClient, Logger):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nick(self):
|
def nick(self):
|
||||||
|
"""Nickname validated by the server, or the configured nick."""
|
||||||
if self.connection.is_connected():
|
if self.connection.is_connected():
|
||||||
return self.connection.get_nickname()
|
return self.connection.get_nickname()
|
||||||
return self.config["nick"]
|
return self.config["nick"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def names(self):
|
def names(self):
|
||||||
|
"""Collection of names the bot should identify with."""
|
||||||
return (self.nick, *self.config["alternative_nicks"])
|
return (self.nick, *self.config["alternative_nicks"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -62,24 +64,28 @@ class Bot(irc.client.SimpleIRCClient, Logger):
|
||||||
self.log_e(f"Could not save storage file: {exc}")
|
self.log_e(f"Could not save storage file: {exc}")
|
||||||
|
|
||||||
def on_welcome(self, connection, event):
|
def on_welcome(self, connection, event):
|
||||||
|
"""Handle a successful connection to a server."""
|
||||||
self.log_i(f"Connected to server {event.source}.")
|
self.log_i(f"Connected to server {event.source}.")
|
||||||
self.run_plugin_callbacks(event)
|
self.run_plugin_callbacks(event)
|
||||||
for channel in self.config["channels"]:
|
for channel in self.config["channels"]:
|
||||||
connection.join(channel)
|
connection.join(channel)
|
||||||
|
|
||||||
def on_join(self, connection, event):
|
def on_join(self, connection, event):
|
||||||
|
"""Handle someone, possibly the bot, joining a channel."""
|
||||||
if event.source.nick == self.nick:
|
if event.source.nick == self.nick:
|
||||||
self.log_i(f"Joined {event.target}.")
|
self.log_i(f"Joined {event.target}.")
|
||||||
self.channels.append(event.target)
|
self.channels.append(event.target)
|
||||||
self.run_plugin_callbacks(event)
|
self.run_plugin_callbacks(event)
|
||||||
|
|
||||||
def on_part(self, connection, event):
|
def on_part(self, connection, event):
|
||||||
|
"""Handle someone, possibly the bot, leaving a channel."""
|
||||||
if event.source.nick == self.nick:
|
if event.source.nick == self.nick:
|
||||||
self.log_i(f"Left {event.target} (args: {event.arguments[0]}).")
|
self.log_i(f"Left {event.target} (args: {event.arguments[0]}).")
|
||||||
self.channels.remove(event.target)
|
self.channels.remove(event.target)
|
||||||
self.run_plugin_callbacks(event)
|
self.run_plugin_callbacks(event)
|
||||||
|
|
||||||
def on_pubmsg(self, connection, event):
|
def on_pubmsg(self, connection, event):
|
||||||
|
"""Handle a message received in a channel."""
|
||||||
channel = event.target
|
channel = event.target
|
||||||
nick = NickMask(event.source).nick
|
nick = NickMask(event.source).nick
|
||||||
message = event.arguments[0]
|
message = event.arguments[0]
|
||||||
|
@ -87,6 +93,7 @@ class Bot(irc.client.SimpleIRCClient, Logger):
|
||||||
self.run_plugin_callbacks(event)
|
self.run_plugin_callbacks(event)
|
||||||
|
|
||||||
def on_privmsg(self, connection, event):
|
def on_privmsg(self, connection, event):
|
||||||
|
"""Handle a message received privately."""
|
||||||
nick = NickMask(event.source).nick
|
nick = NickMask(event.source).nick
|
||||||
target = event.target
|
target = event.target
|
||||||
message = event.arguments[0]
|
message = event.arguments[0]
|
||||||
|
|
|
@ -81,6 +81,7 @@ class Plugin:
|
||||||
self.bot.storage[self.name][key].append(value)
|
self.bot.storage[self.name][key].append(value)
|
||||||
|
|
||||||
def remove_storage_list_value(self, key, value):
|
def remove_storage_list_value(self, key, value):
|
||||||
|
"""Remove a value from a persistent storage list."""
|
||||||
if self.name in self.bot.storage and key in self.bot.storage[self.name]:
|
if self.name in self.bot.storage and key in self.bot.storage[self.name]:
|
||||||
self.bot.storage[self.name][key].remove(value)
|
self.bot.storage[self.name][key].remove(value)
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,12 @@ class Mood(Enum):
|
||||||
|
|
||||||
|
|
||||||
class MoodPlugin(Plugin):
|
class MoodPlugin(Plugin):
|
||||||
|
"""Handle the mood of the bot.
|
||||||
|
|
||||||
|
This plugin exposes the runtime value `mood` (Mood) which can be
|
||||||
|
used to act differently upon some actions according to the bot
|
||||||
|
current mood.
|
||||||
|
"""
|
||||||
|
|
||||||
REQUIRED_CONFIGS = ["questions", "greetings", "answer"]
|
REQUIRED_CONFIGS = ["questions", "greetings", "answer"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue