Word Definition Lookup Script

Share your scripts and packages with other Mudlet users.
Post Reply
Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Word Definition Lookup Script

Post by Jor'Mox »

I saw a thread on here that supposedly had a script that did this, but when I tried it, it didn't work. I think the Google lookup API it used was changed or removed. So I found an alternative API, and created a script to do the job. Note that this has multiple possible dictionaries that can be used to lookup words in, and you can choose any of the options listed in the dicts table, and use it as a second argument to search in that dictionary. If no dictionary is chosen (or one is given that isn't in the list), the default one is used instead.
Code: [show] | [select all] lua
-- Word Definition Lookup Script
-- 1/29/2018

local dicts = {
    devils = "THE DEVIL'S DICTIONARY ((C)1911 Released April 15 1993)",
    easton = "Easton's 1897 Bible Dictionary",
    elements = "Elements database 20001107",
    foldoc = "The Free On-line Dictionary of Computing (27 SEP 03)",
    gazetteer = "U.S. Gazetteer (1990)",
    gcide = "The Collaborative International Dictionary of English v.0.44",
    hitchcock = "Hitchcock's Bible Names Dictionary (late 1800's)",
    jargon = "Jargon File (4.3.1, 29 Jun 2001)",
    vera = "Virtual Entity of Relevant Acronyms (Version 1.9, June 2002)",
    wn = "WordNet (r) 2.0",
    world02 = "CIA World Factbook 2002",
}
local default_dict = "gcide"

if exists("Define Alias","alias") == 0 then
    permAlias("Define Alias","",[[^define (\w+)(?: (\w+))?$]],"define(matches[2],matches[3])")
end

function define(word, dict)
    if dict and not dicts[dict] then
        print("No such dictionary, using default...")
        dict = default_dict
    else
        dict = dict or default_dict
    end
    downloadFile(getMudletHomeDir() .. "/define_" .. word, string.format("http://services.aonaware.com/DictService/DictService.asmx/DefineInDict?dictId=%s&word=%s",dict,word))
end

function downloadedDefinition(_, filename)
    if not filename:find("define", 1, true) then return end
    local word = string.match(filename,"define_(.*)")
    local f, text, ln = io.open(filename)
    if f then text = f:read("*a"); io.close(f) end
    text = string.match(text,"<WordDefinition>([^<]*)</WordDefinition>")
    if text then
        print(text)
    else
        print("No definition found for " .. word .. ".")
    end
end

registerAnonymousEventHandler("sysDownloadDone", "downloadedDefinition")
This script makes its own alias automatically, just copy the script into Mudlet, save it, and you should be good to go.

Post Reply