insults: add plugin

This commit is contained in:
dece 2020-11-04 21:18:54 +01:00
parent 2b6ef89b9b
commit d00bab19a6
2 changed files with 60 additions and 0 deletions

View file

@ -32,6 +32,12 @@
"url": "http://zwergf.elynx.fr/bots/horobot/", "url": "http://zwergf.elynx.fr/bots/horobot/",
"delay": 2 "delay": 2
}, },
"insults": {
"commands": ["insult"],
"sentences": ["idiot"],
"pissed_rate": 33,
"deny_message": "No."
},
"journeemondiale": { "journeemondiale": {
"commands": ["journée mondiale"], "commands": ["journée mondiale"],
"url": "https://www.journee-mondiale.com/" "url": "https://www.journee-mondiale.com/"

54
edmond/plugins/insults.py Normal file
View file

@ -0,0 +1,54 @@
import random
from edmond.plugin import Plugin
from edmond.plugins.mood import Mood
from edmond.utils import proc
class InsultsPlugin(Plugin):
REQUIRED_CONFIGS = ["commands", "sentences", "pissed_rate", "deny_message"]
def __init__(self, bot):
super().__init__(bot)
self.mood_plugin = None
def on_welcome(self, event):
self.mood_plugin = self.bot.get_plugin("mood")
def on_pubmsg(self, event):
message = event.arguments[0]
if self.should_handle_command(message):
self.handle_insult_command(event.target)
return True
content = self.should_read_message(message)
if content is None:
return False
if content in self.config["sentences"]:
self.react_to_insult(event.source.nick, event.target)
return True
return False
def handle_insult_command(self, target):
if self.mood_plugin is not None:
mood = self.get_runtime_value("mood", ns="mood")
if mood == Mood.CALM:
self.bot.say(target, self.config["deny_message"])
return
insult_target = self.command.content
if not insult_target:
return
insult = random.choice(self.config["sentences"])
reply = f"{insult_target} {insult}"
self.bot.say(target, reply)
def react_to_insult(self, sender, target):
if self.mood_plugin is not None:
mood = self.get_runtime_value("mood", ns="mood")
if mood == Mood.CALM and proc(self.config["pissed_rate"]):
self.mood_plugin.get_pissed(target)
insult = random.choice(self.config["sentences"])
reply = f"{sender} {insult}"
self.bot.say(target, reply)