def self.lookup(word, fetch_json: RabbotHttp.method(:fetch_json))
text = word.to_s.strip
return usage_message if text.empty?
url = "https://en.wiktionary.org/api/rest_v1/page/definition/#{URI.encode_www_form_component(text)}"
data = fetch_json.call(url)
definitions = Array(data["en"]).flat_map { |entry| Array(entry["definitions"]) }
definition = definitions.find { |item| item["definition"].to_s.strip.length.positive? }
return "No definition found for #{text}" unless definition
snippet = definition["definition"].to_s.gsub(/<[^>]+>/, " ").squeeze(" ").strip
snippet = snippet[0, 300]
header = IrcFormat.report_header(tag: "DEFINE", title: text, style: STYLE_TITLE)
footer = IrcFormat.report_footer("Wiktionary")
[header, snippet, footer].join("\n")
rescue StandardError
"Could not look up #{word}"
end