add markov-chance, 0 to 100 percent chance of randomly triggered markov chains
This commit is contained in:
parent
8a6270fc97
commit
7b7a67bc45
1 changed files with 12 additions and 0 deletions
|
@ -3,6 +3,8 @@ from src import ModuleManager, utils
|
||||||
|
|
||||||
NO_MARKOV = "Markov chains not enabled in this channel"
|
NO_MARKOV = "Markov chains not enabled in this channel"
|
||||||
|
|
||||||
|
@utils.export("channelset", utils.IntRangeSetting(0, 100, "markov-chance",
|
||||||
|
"0 to 100 percent chance of markov chains being generated at random"))
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_load_thread = None
|
_load_thread = None
|
||||||
|
|
||||||
|
@ -20,6 +22,16 @@ class Module(ModuleManager.BaseModule):
|
||||||
@utils.kwarg("command", "markov-trigger")
|
@utils.kwarg("command", "markov-trigger")
|
||||||
@utils.kwarg("pattern", re.compile(".+"))
|
@utils.kwarg("pattern", re.compile(".+"))
|
||||||
def channel_message(self, event):
|
def channel_message(self, event):
|
||||||
|
markov_chance = event["target"].get_setting("markov-chance", 0)
|
||||||
|
if random.randint(0, 99) < markov_chance:
|
||||||
|
words = event["message"].split()
|
||||||
|
random.shuffle(words)
|
||||||
|
for word in words:
|
||||||
|
out = self._generate(event["target"].id, [word])
|
||||||
|
if out:
|
||||||
|
event["stdout"].write(out)
|
||||||
|
break
|
||||||
|
|
||||||
if event["target"].get_setting("markov", False):
|
if event["target"].get_setting("markov", False):
|
||||||
self._create(event["target"].id, event["match"].group(0))
|
self._create(event["target"].id, event["match"].group(0))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue