diff options
| author | 2020-02-20 18:51:20 +0000 | |
|---|---|---|
| committer | 2020-02-20 18:51:20 +0000 | |
| commit | 7b7a67bc459b531e46bcff7a2dd675e1890f982e (patch) | |
| tree | 044f8d62653016b16f4f80155b9ec75d8c2e4044 | |
| parent | `cryptography` is in requirements.txt; we dont need to check for it (diff) | |
| signature | ||
add markov-chance, 0 to 100 percent chance of randomly triggered markov chains
| -rw-r--r-- | modules/markov.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/markov.py b/modules/markov.py index 9ba9d31f..7dd486d5 100644 --- a/modules/markov.py +++ b/modules/markov.py @@ -3,6 +3,8 @@ from src import ModuleManager, utils 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): _load_thread = None @@ -20,6 +22,16 @@ class Module(ModuleManager.BaseModule): @utils.kwarg("command", "markov-trigger") @utils.kwarg("pattern", re.compile(".+")) 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): self._create(event["target"].id, event["match"].group(0)) |
