Compare commits
No commits in common. "97c930ff090abfa1a64ce99759338656b3866c9a" and "c8c54f2e3765960e1c7b740860d071b662818916" have entirely different histories.
97c930ff09
...
c8c54f2e37
|
@ -126,7 +126,7 @@ class Bot(irc.client.SimpleIRCClient, Logger):
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.log_i("Caught keyboard interrupt.")
|
self.log_i("Caught keyboard interrupt.")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.log_c(f"Caught unhandled {type(exc).__name__}: {exc}")
|
self.log_c(f"Caught unhandled {type(exc)}: {exc}")
|
||||||
_, _, exc_traceback = sys.exc_info()
|
_, _, exc_traceback = sys.exc_info()
|
||||||
for line in traceback.format_tb(exc_traceback):
|
for line in traceback.format_tb(exc_traceback):
|
||||||
self.log_d(line.rstrip())
|
self.log_d(line.rstrip())
|
||||||
|
|
|
@ -37,40 +37,35 @@ 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
|
||||||
|
|
||||||
reg_days = self.get_registered_days()
|
main_reply = self.get_registered_days()
|
||||||
if reg_days:
|
if main_reply:
|
||||||
self.bot.say(event.target, ", ".join(reg_days))
|
self.bot.say(event.target, main_reply)
|
||||||
|
|
||||||
jmcom_days = []
|
jmcom_reply = ""
|
||||||
if self.config.get("jmcom", False) is True:
|
if self.config.get("jmcom", False) is True:
|
||||||
jmcom_days = self.get_jmcom_days(event.target)
|
jmcom_reply = self.get_jmcom_days(event.target)
|
||||||
if jmcom_days:
|
if jmcom_reply:
|
||||||
# Remove days already in reg_days.
|
self.bot.say(event.target, jmcom_reply)
|
||||||
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 (reg_days or jmcom_days):
|
if not (main_reply or jmcom_reply):
|
||||||
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) -> list[str]:
|
def get_registered_days(self) -> 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_items = 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"],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return list(today_items)
|
days = ", ".join(today_obs)
|
||||||
|
return days
|
||||||
|
|
||||||
def get_jmcom_days(self, target) -> list[str]:
|
def get_jmcom_days(self, target) -> 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:
|
||||||
|
@ -99,5 +94,5 @@ class JourneeMondialePlugin(Plugin):
|
||||||
|
|
||||||
plus_plugin.add_handler(target, handler)
|
plus_plugin.add_handler(target, handler)
|
||||||
|
|
||||||
days = map(lambda i: i["title"], entries)
|
days = ", ".join(map(lambda i: i["title"], entries))
|
||||||
return list(days)
|
return days
|
||||||
|
|
|
@ -100,7 +100,7 @@ class PlaylistOfTheDayPlugin(Plugin):
|
||||||
html_items = map(lambda item: f"<li>{item}</li>", linkified_items)
|
html_items = map(lambda item: f"<li>{item}</li>", linkified_items)
|
||||||
html_list = "<ol>" + "".join(html_items) + "</ol>"
|
html_list = "<ol>" + "".join(html_items) + "</ol>"
|
||||||
data = HTML_TEMPLATE.format(html_list).encode()
|
data = HTML_TEMPLATE.format(html_list).encode()
|
||||||
url = self.shrlok_plugin.post({"type": "raw", "ext": "html"}, data)
|
url = self.shrlok_plugin.post({"type": "raw"}, data)
|
||||||
if not url:
|
if not url:
|
||||||
self.bot.log_e("Shrlok returned None.")
|
self.bot.log_e("Shrlok returned None.")
|
||||||
self.signal_failure(target)
|
self.signal_failure(target)
|
||||||
|
|
|
@ -230,16 +230,13 @@ class TaxrefPlugin(Plugin):
|
||||||
+ "\n"
|
+ "\n"
|
||||||
)
|
)
|
||||||
reply = shrlok.post({"type": "txt"}, text.encode())
|
reply = shrlok.post({"type": "txt"}, text.encode())
|
||||||
if not reply:
|
|
||||||
self.bot.log_d("shrlok plugin returned an empty string.")
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
reply = self.get_ambiguous_reply(items)
|
reply = self.get_ambiguous_reply(items)
|
||||||
|
|
||||||
self.bot.say(target, reply)
|
self.bot.say(target, reply)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def item_to_full_name(item: dict) -> str:
|
def item_to_full_name(item):
|
||||||
family_name = item.get("familyName")
|
family_name = item.get("familyName")
|
||||||
sci_name = item.get("scientificName")
|
sci_name = item.get("scientificName")
|
||||||
return f"{family_name} {sci_name}"
|
return f"{family_name} {sci_name}"
|
||||||
|
|
|
@ -1,20 +1,14 @@
|
||||||
import random
|
import random
|
||||||
from typing import Callable, Optional
|
from typing import Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
def http_get(url: str, log_e: Optional[Callable] = None) -> Optional[str]:
|
def http_get(url: str) -> Optional[str]:
|
||||||
"""Get the HTML as text from this URL.
|
response = requests.get(url)
|
||||||
log_e is an optional error logging function."""
|
if response.status_code == 200:
|
||||||
try:
|
return response.text
|
||||||
response = requests.get(url)
|
return None
|
||||||
response.raise_for_status()
|
|
||||||
except OSError as exc:
|
|
||||||
if log_e:
|
|
||||||
log_e(f"http_get error: {exc}")
|
|
||||||
return None
|
|
||||||
return response.text
|
|
||||||
|
|
||||||
|
|
||||||
def proc(proba_percentage: int) -> bool:
|
def proc(proba_percentage: int) -> bool:
|
||||||
|
|
Loading…
Reference in a new issue