journee_mondiale: various improvements, again…

This commit is contained in:
dece 2022-11-29 12:59:37 +01:00
parent 086ec48823
commit ea5acc28e8

View file

@ -37,35 +37,40 @@ class JourneeMondialePlugin(Plugin):
if not self.should_handle_command(event.arguments[0], no_content=True): if not self.should_handle_command(event.arguments[0], no_content=True):
return False return False
main_reply = self.get_registered_days() reg_days = self.get_registered_days()
if main_reply: if reg_days:
self.bot.say(event.target, main_reply) self.bot.say(event.target, ", ".join(reg_days))
jmcom_reply = "" jmcom_days = []
if self.config.get("jmcom", False) is True: if self.config.get("jmcom", False) is True:
jmcom_reply = self.get_jmcom_days(event.target) jmcom_days = self.get_jmcom_days(event.target)
if jmcom_reply: if jmcom_days:
self.bot.say(event.target, jmcom_reply) # Remove days already in reg_days.
lower_reg_days = [day.lower() for day in reg_days]
jmcom_days_filtered = [
day for day in jmcom_days
if day.lower() not in lower_reg_days
]
self.bot.say(event.target, ", ".join(jmcom_days_filtered))
if not (main_reply or jmcom_reply): if not (reg_days or jmcom_days):
self.bot.say(event.target, self.config["no_entry_reply"]) self.bot.say(event.target, self.config["no_entry_reply"])
return True return True
def get_registered_days(self) -> str: def get_registered_days(self) -> list[str]:
"""Get international days for the local list.""" """Get international days for the local list."""
now = datetime.datetime.now() now = datetime.datetime.now()
date_tag = f"{now.month:02}-{now.day:02}" date_tag = f"{now.month:02}-{now.day:02}"
today_obs = map( today_items = map(
lambda line: line.split(maxsplit=1)[1], lambda line: line.split(maxsplit=1)[1],
filter( filter(
lambda line: line.startswith(date_tag), lambda line: line.startswith(date_tag),
self.config["dates"], self.config["dates"],
), ),
) )
days = ", ".join(today_obs) return list(today_items)
return days
def get_jmcom_days(self, target) -> str: def get_jmcom_days(self, target) -> list[str]:
"""Get international days from journee-mondiale.com.""" """Get international days from journee-mondiale.com."""
response = http_get(JourneeMondialePlugin.JMCOM_URL) response = http_get(JourneeMondialePlugin.JMCOM_URL)
if not response: if not response:
@ -94,5 +99,5 @@ class JourneeMondialePlugin(Plugin):
plus_plugin.add_handler(target, handler) plus_plugin.add_handler(target, handler)
days = ", ".join(map(lambda i: i["title"], entries)) days = map(lambda i: i["title"], entries)
return days return list(days)