markov: Add !markov help and help_timeout config
* !markov help will display a pretty crude help message. It's funny to me, I dunno. * help_timeout config option limits the number of times that `!markov help` is allowed to run. This is because the help message is a lot of lines, and it could cause problems if `!markov help` is spammed or abused. It can be set to 0 or less to disable. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
from collections import defaultdict
|
||||
import logging
|
||||
import math
|
||||
from pathlib import Path
|
||||
import random
|
||||
import sqlite3
|
||||
import time
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
from typing import Any, DefaultDict, List, Sequence
|
||||
|
||||
from asyncirc.protocol import IrcProtocol
|
||||
from irclib.parser import Prefix
|
||||
|
||||
from omnibot.plugin import Plugin
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -244,6 +243,8 @@ class Markov(Plugin):
|
||||
self.sql_path = Path(self.plugin_config.get("sql_path", "data/markov/db.sql"))
|
||||
self.reply_chance = float(self.plugin_config.get("reply_chance", 0.01))
|
||||
self.chain = Chain(self.order, self.reply_chance, self.data_path, self.sql_path)
|
||||
self.help_timeout_expire = 0
|
||||
self.help_timeout = self.plugin_config.get("help_timeout", 300)
|
||||
|
||||
async def on_message(self, conn: IrcProtocol, channel: str, who: Prefix, line: str):
|
||||
line = line.strip()
|
||||
@@ -273,6 +274,34 @@ class Markov(Plugin):
|
||||
):
|
||||
# handle markov commands
|
||||
match parts[1:]:
|
||||
case ["help"]:
|
||||
print(time.time())
|
||||
if self.help_timeout_expire > time.time():
|
||||
return
|
||||
self.help_timeout_expire = time.time() + self.help_timeout
|
||||
# TODO - add help messages config to the TOML file
|
||||
help_messages = [
|
||||
"Markov is filmed in front of a live studio audience.",
|
||||
"Help! I'm having a heart attack!",
|
||||
"Where is that gun?",
|
||||
"I'm walkin' heah!",
|
||||
"Any resemblance to persons, living or fictional, is entirely coincidental.",
|
||||
"ge8hg809wga987haw4go9hag897hagndfnam3n342ui128",
|
||||
"intercal die",
|
||||
]
|
||||
lines = [
|
||||
random.choice(help_messages),
|
||||
"`!markov help` - idiot",
|
||||
"`!markov force` - force markov to say something",
|
||||
"`!markov force username` - force markov to say something, using someone else's words",
|
||||
"`!markov trigger` - synonym for `!markov force`",
|
||||
f"`!markov chance n` - set your reply chance to some number between 0.0 and {self.chain.reply_chance}",
|
||||
"`!markov listen on|off` - tell markov to start or stop listening to what you say",
|
||||
"`!markov all` - force markov to say something based off of everything said in the server",
|
||||
"Also, kill yourself!",
|
||||
]
|
||||
for line in lines:
|
||||
self.send_to(conn, channel, line)
|
||||
case ["force"]:
|
||||
message = self.chain.generate(channel, who.nick)
|
||||
if message:
|
||||
|
||||
Reference in New Issue
Block a user