Compare commits
No commits in common. "0f0ab90062066d725f24cff2ea54e181959cdcea" and "7f2fa0817e5eb0234675abfd33dbe4752b5d7cde" have entirely different histories.
0f0ab90062
...
7f2fa0817e
|
@ -152,7 +152,11 @@
|
||||||
"not_fresh_reply": "It's not from today but here it is: {url}"
|
"not_fresh_reply": "It's not from today but here it is: {url}"
|
||||||
},
|
},
|
||||||
"plus": {
|
"plus": {
|
||||||
"commands": ["plus"]
|
"commands": ["plus"],
|
||||||
|
"aliases": {
|
||||||
|
"plus": "more"
|
||||||
|
},
|
||||||
|
"shortcut": "+"
|
||||||
},
|
},
|
||||||
"randomchoice": {
|
"randomchoice": {
|
||||||
"commands": ["choose"],
|
"commands": ["choose"],
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import datetime
|
import datetime
|
||||||
from typing import cast
|
|
||||||
|
|
||||||
# BS is optional and only for scrapping journee-mondiale.com, thus why we do not
|
# BS is optional and only for scrapping journee-mondiale.com, thus why we do not
|
||||||
# mark the dependencies flag here.
|
# mark the dependencies flag here.
|
||||||
|
@ -9,7 +8,6 @@ except ImportError:
|
||||||
BeautifulSoup = None
|
BeautifulSoup = None
|
||||||
|
|
||||||
from edmond.plugin import Plugin
|
from edmond.plugin import Plugin
|
||||||
from edmond.plugins.plus import PlusPlugin
|
|
||||||
from edmond.utils import http_get
|
from edmond.utils import http_get
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +31,6 @@ class JourneeMondialePlugin(Plugin):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
REQUIRED_CONFIGS = ["commands", "dates", "no_entry_reply"]
|
REQUIRED_CONFIGS = ["commands", "dates", "no_entry_reply"]
|
||||||
JMCOM_URL = "https://www.journee-mondiale.com"
|
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
|
@ -48,7 +45,7 @@ class JourneeMondialePlugin(Plugin):
|
||||||
|
|
||||||
jmcom_reply = ""
|
jmcom_reply = ""
|
||||||
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_reply = self.get_jmcom_days()
|
||||||
if jmcom_reply:
|
if jmcom_reply:
|
||||||
self.bot.say(event.target, jmcom_reply)
|
self.bot.say(event.target, jmcom_reply)
|
||||||
|
|
||||||
|
@ -63,16 +60,15 @@ class JourneeMondialePlugin(Plugin):
|
||||||
today_obs = map(
|
today_obs = 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)
|
days = ", ".join(today_obs)
|
||||||
return days
|
return reply
|
||||||
|
|
||||||
def get_jmcom_days(self, target) -> str:
|
def get_jmcom_days(self) -> str:
|
||||||
"""Get international days from journee-mondiale.com."""
|
"""Get international days from journee-mondiale.com."""
|
||||||
response = http_get(JourneeMondialePlugin.JMCOM_URL)
|
response = http_get(self.config["url"])
|
||||||
if not response:
|
if not response:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@ -81,22 +77,13 @@ class JourneeMondialePlugin(Plugin):
|
||||||
try:
|
try:
|
||||||
items = soup.find("div", id="journeesDuJour").find_all("article")
|
items = soup.find("div", id="journeesDuJour").find_all("article")
|
||||||
for item in items:
|
for item in items:
|
||||||
entries.append(
|
entries.append({
|
||||||
{
|
"url": item.find("a").href,
|
||||||
"url": item.find("a")["href"],
|
|
||||||
"title": item.find("h2").string,
|
"title": item.find("h2").string,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
except (ValueError, KeyError):
|
except (ValueError, KeyError):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
if plus_plugin := cast(PlusPlugin, self.bot.get_plugin("plus")):
|
# TODO add plus plugin support
|
||||||
|
|
||||||
def handler(plus_event):
|
return ", ".join(map(lambda i: i["title"], entries))
|
||||||
urls = map(lambda i: i["url"], entries)
|
|
||||||
self.bot.say(plus_event.target, " — ".join(urls))
|
|
||||||
|
|
||||||
plus_plugin.add_handler(target, handler)
|
|
||||||
|
|
||||||
days = ", ".join(map(lambda i: i["title"], entries))
|
|
||||||
return days
|
|
||||||
|
|
|
@ -20,12 +20,16 @@ class PlusPlugin(Plugin):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
self.handlers = {}
|
self.handlers = {}
|
||||||
|
self.shortcut = self.config.get("shortcut")
|
||||||
|
|
||||||
def on_pubmsg(self, event):
|
def on_pubmsg(self, event):
|
||||||
if not self.should_handle_command(event.arguments[0], no_content=True):
|
if (
|
||||||
return False
|
(self.shortcut and event.arguments[0].strip() == self.shortcut)
|
||||||
|
or self.should_handle_command(event.arguments[0], no_content=True)
|
||||||
|
):
|
||||||
self.process_handler(event)
|
self.process_handler(event)
|
||||||
return True
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def process_handler(self, event):
|
def process_handler(self, event):
|
||||||
if handler := self.handlers.pop(event.target, None):
|
if handler := self.handlers.pop(event.target, None):
|
||||||
|
|
Loading…
Reference in a new issue