random: add plugin
This commit is contained in:
parent
985ac401b4
commit
7eca5da533
|
@ -32,6 +32,10 @@
|
||||||
"pissed": "Pissed off..."
|
"pissed": "Pissed off..."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"random": {
|
||||||
|
"commands": ["choose"],
|
||||||
|
"separator": "or"
|
||||||
|
},
|
||||||
"wikipedia": {
|
"wikipedia": {
|
||||||
"commands": ["science", "define"],
|
"commands": ["science", "define"],
|
||||||
"lang": "en",
|
"lang": "en",
|
||||||
|
|
26
edmond/plugins/random.py
Normal file
26
edmond/plugins/random.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import random
|
||||||
|
|
||||||
|
from edmond.plugin import Plugin
|
||||||
|
|
||||||
|
|
||||||
|
class RandomPlugin(Plugin):
|
||||||
|
|
||||||
|
REQUIRED_CONFIGS = ["commands", "separator"]
|
||||||
|
|
||||||
|
def __init__(self, bot):
|
||||||
|
super().__init__(bot)
|
||||||
|
|
||||||
|
def on_pubmsg(self, event):
|
||||||
|
if not self.should_handle_command(event.arguments[0]):
|
||||||
|
return False
|
||||||
|
if self.command.ident == "choose":
|
||||||
|
self.pick_random(event.target)
|
||||||
|
|
||||||
|
def pick_random(self, target):
|
||||||
|
separator = self.config["separator"]
|
||||||
|
choices = self.command.content.split(f" {separator} ")
|
||||||
|
self.bot.log_d(f"Choices: {choices}")
|
||||||
|
if len(choices):
|
||||||
|
choice = random.choice(choices)
|
||||||
|
if choice:
|
||||||
|
self.bot.say(target, choice)
|
Loading…
Reference in a new issue