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:
@@ -119,3 +119,10 @@ module = "plugins.markov"
|
|||||||
# set. e.g. with a value of 0.01, a user may set their reply chance to 0.001.
|
# set. e.g. with a value of 0.01, a user may set their reply chance to 0.001.
|
||||||
# default: 0.01
|
# default: 0.01
|
||||||
# reply_chance = 0.01
|
# reply_chance = 0.01
|
||||||
|
|
||||||
|
# help_timeout
|
||||||
|
# The number of seconds between a "help" command that's allowed. This is only
|
||||||
|
# here because running `!markov help` sends like 10 messages in a row and it's
|
||||||
|
# to prevent a denial-of-service attack. Generally you should not need to worry
|
||||||
|
# about changing this.
|
||||||
|
# help_timeout = 300
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
from collections import defaultdict
|
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
from pathlib import Path
|
|
||||||
import random
|
import random
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import time
|
||||||
|
from collections import defaultdict
|
||||||
|
from pathlib import Path
|
||||||
from typing import Any, DefaultDict, List, Sequence
|
from typing import Any, DefaultDict, List, Sequence
|
||||||
|
|
||||||
from asyncirc.protocol import IrcProtocol
|
from asyncirc.protocol import IrcProtocol
|
||||||
from irclib.parser import Prefix
|
from irclib.parser import Prefix
|
||||||
|
|
||||||
from omnibot.plugin import Plugin
|
from omnibot.plugin import Plugin
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
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.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.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.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):
|
async def on_message(self, conn: IrcProtocol, channel: str, who: Prefix, line: str):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
@@ -273,6 +274,34 @@ class Markov(Plugin):
|
|||||||
):
|
):
|
||||||
# handle markov commands
|
# handle markov commands
|
||||||
match parts[1:]:
|
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"]:
|
case ["force"]:
|
||||||
message = self.chain.generate(channel, who.nick)
|
message = self.chain.generate(channel, who.nick)
|
||||||
if message:
|
if message:
|
||||||
|
|||||||
Reference in New Issue
Block a user