Edm0nd/edmond/plugins/journee_mondiale.py

45 lines
1.3 KiB
Python
Raw Normal View History

import datetime
from edmond.plugin import Plugin
class JourneeMondialePlugin(Plugin):
"""This plugin shows today's international observance.
It used to fetch data from the website journee-mondiale.com but it is
regularly broken so it is now loading a static list as a resource. This
list uses the format "MM-DD Name", one per line, e.g.:
```
01-01 NYE
08-03 Something the 3rd of August
12-25 Christmas
```
A list can be found on the UN website but it has to be converted by hand:
https://www.un.org/en/observances/list-days-weeks
"""
REQUIRED_CONFIGS = ["commands", "dates", "no_entry_reply"]
def __init__(self, bot):
super().__init__(bot)
def on_pubmsg(self, event):
if not self.should_handle_command(event.arguments[0], no_content=True):
return False
now = datetime.datetime.now()
date_tag = f"{now.month:02}-{now.day:02}"
today_obs = map(
lambda line: line.split(maxsplit=1)[1],
filter(
lambda line: line.startswith(date_tag), self.config["dates"]
),
)
reply = ", ".join(today_obs)
if not reply:
reply = self.config["no_entry_reply"]
self.bot.say(event.target, reply)
return True