You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.8 KiB

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.priority = -3
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)