Compare commits

..

No commits in common. "85ce2902a71d67aa40179fdf1d261d2de839a407" and "dd3ebcaa35368303e7a7a6fe2bc3c8721e588533" have entirely different histories.

3 changed files with 7 additions and 86 deletions

View file

@ -41,16 +41,16 @@
"capture_sentence": "Catch!", "capture_sentence": "Catch!",
"captured_sentence": "Well done {winner}, you got that {thing}!" "captured_sentence": "Well done {winner}, you got that {thing}!"
}, },
"capturegive": {
"commands": ["give"],
"content_regex": "my (?P<thing>\\S+) to (?P<person>\\S+)",
"no_such_thing_reply": "You don't have such {thing}."
},
"capturelist": { "capturelist": {
"commands": ["collection"], "commands": ["collection"],
"reply": "{target} captured {num} things : {things}", "reply": "{target} captured {num} things : {things}",
"empty_reply": "{target} did not capture anything yet!" "empty_reply": "{target} did not capture anything yet!"
}, },
"capturegive": {
"commands": ["give"],
"content_regex": "my (?P<thing>\\S+) to (?P<person>\\S+)",
"no_such_thing_reply": "You don't have such {thing}."
},
"common": { "common": {
"command_suffix": "please", "command_suffix": "please",
"handling_conditions": { "handling_conditions": {
@ -159,12 +159,6 @@
"wakeup_messages": ["/me wakes up"], "wakeup_messages": ["/me wakes up"],
"snore_rate": 1.0 "snore_rate": 1.0
}, },
"taxref": {
"commands": ["taxref"],
"not_found_reply": "Not found!",
"reply": "{sci_name}, {fr_name}, {family}, {cd_nom}, {cd_ref}",
"ambiguous_reply": "Ambiguous! It can be: "
},
"translate": { "translate": {
"commands": ["translate"], "commands": ["translate"],
"default_dest": "en", "default_dest": "en",

View file

@ -118,8 +118,8 @@ class Bot(irc.client.SimpleIRCClient, Logger):
self.start() self.start()
except KeyboardInterrupt: except KeyboardInterrupt:
self.log_i("Caught keyboard interrupt.") self.log_i("Caught keyboard interrupt.")
except Exception as exc: # Yes, I know, who are you going to call? except: # Yes, I know, who are you going to call?
self.log_c(f"Caught unhandled exception: {exc}") self.log_i("Caught unhandled exception.")
finally: finally:
self.cleanup() self.cleanup()

View file

@ -1,73 +0,0 @@
import urllib.parse
import requests
from edmond.plugin import Plugin
BASE_URL = "https://taxref.mnhn.fr/api"
class TaxrefPlugin(Plugin):
REQUIRED_CONFIGS = [
"commands", "not_found_reply", "reply", "ambiguous_reply"
]
def __init__(self, bot):
super().__init__(bot)
def on_pubmsg(self, event):
if not self.should_handle_command(event.arguments[0]):
return False
if self.command.ident == self.config["commands"][0]:
self.search_by_name(self.command.content, event.target)
return True
def search_by_name(self, name, target):
name = urllib.parse.quote(name.lower())
url = f"{BASE_URL}/taxa/search?scientificNames={name}&page=1&size=100"
response = requests.get(url)
if response.status_code != 200:
self.signal_failure(target)
return
data = response.json()
items = data.get("_embedded", {}).get("taxa", [])
if not items:
self.bot.say(target, self.config["not_found_reply"])
return
if len(items) == 1:
# Only one result: use it.
item_to_use = items[0]
else:
# More than one result: if the results contain a corresponding
# species, use it, else return names for sub-species etc.
species_items = []
for item in items:
if item["rankId"] == "ES":
species_items.append(item)
if len(species_items) == 1:
item_to_use = species_items[0]
else:
reply = self.config["ambiguous_reply"]
append = ""
if len(items) > 5:
append = f"… (+{len(items)})"
items = items[:5]
reply += ", ".join(
item["scientificName"] for item in items
)
if append:
reply += append
self.bot.say(target, reply)
return
reply = self.config["reply"].format(
sci_name=item_to_use["scientificName"],
fr_name=item_to_use["frenchVernacularName"],
family=item_to_use["familyName"],
cd_nom=item_to_use["id"],
cd_ref=item_to_use["referenceId"],
)
self.bot.say(target, reply)