Add Markov.add function

This is basically just a shorthand, but also abstracts away adding a
line to a markov chain

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-05-25 19:18:37 -07:00
parent 5c594fc03e
commit 85d48d368c
2 changed files with 5 additions and 2 deletions

View File

@@ -104,7 +104,10 @@ class Markov(Plugin):
self.handle_command(conn, channel, who, parts) self.handle_command(conn, channel, who, parts)
elif line[0] != "!": elif line[0] != "!":
# ignore other commands # ignore other commands
self.chains[channel][who.nick].add(line) self.add(channel, who.nick, line)
def add(self, channel: str, who: str, line: str):
self.chains[channel][who].add(line)
def handle_command( def handle_command(
self, conn: IrcProtocol, channel: str, who: Prefix, parts: Sequence[str] self, conn: IrcProtocol, channel: str, who: Prefix, parts: Sequence[str]

View File

@@ -37,5 +37,5 @@ if __name__ == "__main__":
if mat := LINE_RE.search(line): if mat := LINE_RE.search(line):
name = mat["name"] name = mat["name"]
message = mat["message"] message = mat["message"]
plugin.chains[channel][name].add(message) plugin.add(channel, name, message)
plugin.save() plugin.save()