caretaker: add plugin

This commit is contained in:
dece 2020-11-05 23:04:39 +01:00
parent bc8cf0e465
commit cc81956b58
3 changed files with 59 additions and 2 deletions

View file

@ -53,6 +53,6 @@ Missing features
- [ ] Simple word mappings for fun
- ~~[ ] Lyrics~~
- [ ] Phonétique
- [ ] Greet other people joining
- [ ] Mourn other people parting
- [x] Greet other people joining
- [x] Mourn other people parting
- [ ] unknown questions

View file

@ -14,6 +14,14 @@
"beers": ["Paix-Dieu"],
"opening_text": "/me cracks open a {beer} for {target}"
},
"caretaker": {
"warm_welcome": ["Hi {target}!"],
"cold_welcome": ["Oh no..."],
"nice_farewell": [":("],
"bad_farewell": ["Good riddance."],
"welcome_rate": 10,
"farewell_rate": 10
},
"common": {
"command_suffix": "please",
"handling_conditions": {

View file

@ -0,0 +1,49 @@
import random
from edmond.plugin import Plugin
from edmond.plugins.mood import Mood
from edmond.utils import proc
class CaretakerPlugin(Plugin):
"""Say hello and farewall on people joining/parting."""
REQUIRED_CONFIGS = [
"warm_welcome", "cold_welcome", "nice_farewell", "bad_farewell",
"welcome_rate", "farewell_rate"
]
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_join(self, event):
if event.source.nick == self.bot.nick:
return
if not proc(self.config["welcome_rate"]):
return
welcome_type = "warm_welcome"
if self.mood_plugin:
if self.get_runtime_value("mood", ns="mood") == Mood.PISSED:
welcome_type = "cold_welcome"
welcome = random.choice(self.config[welcome_type])
if "{target}" in welcome:
welcome = welcome.format(target=event.source.nick)
self.bot.say(event.target, welcome)
def on_part(self, event):
if event.source.nick == self.bot.nick:
return
if not proc(self.config["farewell_rate"]):
return
farewell_type = "nice_farewell"
if self.mood_plugin:
if self.get_runtime_value("mood", ns="mood") == Mood.PISSED:
farewell_type = "bad_farewell"
farewell = random.choice(self.config[farewell_type])
if "{target}" in farewell:
farewell = farewell.format(target=event.source.nick)
self.bot.say(event.target, farewell)