This commit is contained in:
oddluck 2019-12-05 06:11:57 +00:00
parent 8c21ce61b5
commit 658e7f3ce0
8 changed files with 65 additions and 5 deletions

15
Markovgen/README.md Normal file
View File

@ -0,0 +1,15 @@
Forked from: https://github.com/ProgVal/Supybot-plugins/tree/master/Markovgen
Additions:
plugins.Markovgen.ignorePattern (set regex patterns for the bot to ignore)
plugins.Markovgen.stripPattern (set regex patterns for the bot to strip)
plugins.Markovgen.stripURL (determine if the bot will strip URLs)
plugins.Markovgen.ignoreNicks (list of nicks to ignore)
plugins.Markovgen.ignoreCommands (ignore commands sent to the bot)
plugins.Markovgen.stripFormatting (strip bold, underline, and color from messages)

View File

@ -41,14 +41,18 @@ import supybot.world as world
__version__ = ""
# XXX Replace this with an appropriate author or supybot.Author instance.
__author__ = supybot.authors.unknown
__author__ = getattr(supybot.authors, 'progval',
supybot.Author('Valentin Lorentz', 'ProgVal', 'progval@gmail.com'))
__maintainer__ = getattr(supybot.authors, 'oddluck',
supybot.Author('oddluck', 'oddluck', 'oddluck@riseup.net'))
# This is a dictionary mapping supybot.Author instances to lists of
# contributions.
__contributors__ = {}
# This is a url where the most recent plugin package can be downloaded.
__url__ = ''
__url__ = 'https://github.com/oddluck/limnoria-plugins/'
from . import config
from . import plugin

View File

@ -61,6 +61,20 @@ conf.registerChannelValue(Markovgen, 'probability',
conf.registerChannelValue(Markovgen, 'stripRelayedNick',
registry.Boolean(True, _("""Determines whether the bot will strip
strings like <XXX> at the beginning of messages.""")))
conf.registerChannelValue(Markovgen, 'ignorePattern',
registry.Regexp("", _("""Mesages matching this pattern will be ignored.""")))
conf.registerChannelValue(Markovgen, 'stripPattern',
registry.Regexp("", _("""Text matching this pattern will be stripped.""")))
conf.registerChannelValue(Markovgen, 'stripURL',
registry.Boolean(True, _("""Determines whether the bot will strip
URLs from messages.""")))
conf.registerChannelValue(Markovgen, 'ignoreNicks',
registry.SpaceSeparatedListOfStrings([], _("""A list of nicks to be ignored by the bot""")))
conf.registerChannelValue(Markovgen, 'stripFormatting',
registry.Boolean(True, _("""Determines whether the bot will strip
bold, underline, and colors from messages.""")))
conf.registerChannelValue(Markovgen, 'ignoreCommands',
registry.Boolean(True, _("""Determines whether the bot will ignore commands.""")))
conf.registerGroup(Markovgen, 'onNick')
conf.registerChannelValue(Markovgen.onNick, 'probability',
@ -71,5 +85,4 @@ conf.registerChannelValue(Markovgen.onNick, 'replaceNick',
nick by the original author's when replying to a message containing
its nick.""")))
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -43,6 +43,7 @@ from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
import supybot.log as log
try:
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('Markovgen')
@ -139,7 +140,35 @@ class Markovgen(callbacks.Plugin):
return
if not self.registryValue('enable', channel):
return
if self.registryValue('ignoreCommands', channel) and callbacks.addressed(irc.nick, msg):
return
match = False
ignore = self.registryValue("ignorePattern", channel)
strip = self.registryValue("stripPattern", channel)
if ignore:
match = re.search(ignore, message)
if match:
log.debug("Markovgen: %s matches ignorePattern for %s" % (message, channel))
return
if msg.nick.lower() in self.registryValue('ignoreNicks', channel):
log.debug("Markovgen: nick %s in ignoreNicks for %s" % (msg.nick, channel))
return
m = self._get_markov(irc, channel)
if self.registryValue('stripFormatting', channel):
message = ircutils.stripFormatting(message)
if strip:
match = re.findall(strip, message)
if match:
for x in match:
message = message.replace(x, '')
message = re.sub('\s+', ' ', message)
log.debug("Markovgen: %s matches stripPattern for %s. New message text: %s" % (x, channel, message))
if self.registryValue('stripURL', channel):
new_message = re.sub(r'(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))', '', message)
new_message = re.sub('\s+', ' ', new_message)
if new_message != message:
log.debug("Markovgen: url(s) stripped from message for %s. New message text: %s" % (channel, new_message))
message = new_message
if self.registryValue('stripRelayedNick', channel):
message = MATCH_MESSAGE_STRIPNICK.match(message).group('message')
m.feed(message)

View File

@ -0,0 +1 @@
markovgen

View File

@ -1,2 +0,0 @@
Insert a description of your plugin here, with any notes, etc. about
using it.