(gordon) Add soupe command
parent
ad5d026047
commit
82c9476fa5
|
@ -1,5 +1,6 @@
|
|||
local irc = require("itte")
|
||||
local folia = require("folia")
|
||||
local soupe = require("soupe")
|
||||
|
||||
itte_config = {
|
||||
debug = false,
|
||||
|
@ -9,11 +10,14 @@ itte_config = {
|
|||
quit = "Master Chef under maintenance.",
|
||||
reload = "Config reloaded.",
|
||||
},
|
||||
foils_dir = "/home/mio/bin/itte/examples/gordon/commands",
|
||||
nouns_file = "/home/mio/bin/itte/examples/gordon/words/nouns.txt",
|
||||
}
|
||||
|
||||
itte_handlers = {}
|
||||
|
||||
folia.foils_dir = "/home/mio/bin/itte/examples/gordon/commands"
|
||||
folia.foils_dir = itte_config.foils_dir
|
||||
soupe.nouns_file = itte_config.nouns_file
|
||||
|
||||
|
||||
local gordon = {}
|
||||
|
@ -37,4 +41,11 @@ function gordon.generate_handlers(handlers, foils_dir)
|
|||
end
|
||||
|
||||
|
||||
-- Add separate handler
|
||||
function itte_handlers.soupe(cxt, msg)
|
||||
local resp = "Here! A" .. soupe.make_soup() .. "!"
|
||||
irc.message(cxt, { msg.reply_to }, resp)
|
||||
end
|
||||
|
||||
|
||||
gordon.generate_handlers(itte_handlers, folia.foils_dir)
|
||||
|
|
|
@ -0,0 +1,171 @@
|
|||
local util = require("itteutil")
|
||||
|
||||
|
||||
local soupe = {
|
||||
max_ingred = 7,
|
||||
nouns_file = "nouns.txt",
|
||||
}
|
||||
|
||||
soupe.servings = {
|
||||
bowl = {
|
||||
"bronze",
|
||||
"copper",
|
||||
"ceramic",
|
||||
"crystal",
|
||||
"earthenware",
|
||||
"golden",
|
||||
"stone",
|
||||
"glass",
|
||||
"plastic",
|
||||
"silver",
|
||||
"styrofoam",
|
||||
"tin",
|
||||
"tupperware",
|
||||
},
|
||||
cauldron = {
|
||||
"bronze",
|
||||
"cast iron",
|
||||
"charred",
|
||||
"copper",
|
||||
"golden",
|
||||
"rusty",
|
||||
"silver",
|
||||
},
|
||||
chalice = {
|
||||
"bronze",
|
||||
"copper",
|
||||
"crystal",
|
||||
"golden",
|
||||
"stone",
|
||||
"silver",
|
||||
},
|
||||
cup = {
|
||||
"bronze",
|
||||
"copper",
|
||||
"ceramic",
|
||||
"crystal",
|
||||
"earthenware",
|
||||
"golden",
|
||||
"glass",
|
||||
"plastic",
|
||||
"silver",
|
||||
"styrofoam",
|
||||
"tin",
|
||||
},
|
||||
mug = {
|
||||
"ceramic",
|
||||
"earthenware",
|
||||
"glass",
|
||||
"tin",
|
||||
},
|
||||
pot = {
|
||||
"bronze",
|
||||
"copper",
|
||||
"ceramic",
|
||||
"earthenware",
|
||||
"stone",
|
||||
"plastic",
|
||||
"tin",
|
||||
},
|
||||
portion = {
|
||||
"giant",
|
||||
"large",
|
||||
"medium",
|
||||
"small",
|
||||
"tiny",
|
||||
},
|
||||
serving = {
|
||||
"large",
|
||||
"small",
|
||||
},
|
||||
}
|
||||
|
||||
soupe.temps = {
|
||||
"chilled",
|
||||
"cold",
|
||||
"hot",
|
||||
"scalding hot",
|
||||
"warm",
|
||||
}
|
||||
|
||||
soupe.articles = {
|
||||
"brimming with",
|
||||
"filled with",
|
||||
"full of",
|
||||
"glistening with",
|
||||
"nearly overflowing with",
|
||||
"of",
|
||||
}
|
||||
|
||||
|
||||
-- Read a parts of speech file and turn a table of nouns.
|
||||
function soupe.filter_nouns(mode)
|
||||
local ns = util.read_file(soupe.nouns_file)
|
||||
-- The delimiter does not remove the second section of hyphenated words,
|
||||
-- this is done when looping through the table and comparing the first letter
|
||||
-- of each word to the previous and next words' first letters. Since the list
|
||||
-- is in alphabetical order, out-of-order words are excluded.
|
||||
local nt = util.split_str(ns, "(%a*)[\\N]%S+")
|
||||
local nouns = {}
|
||||
if mode == "common" then
|
||||
for i = 1, #nt do
|
||||
if (#nt[i] > 4) and
|
||||
((string.sub(nt[i - 1], 1, 1) == string.sub(nt[i], 1, 1)) or
|
||||
(string.sub(nt[i], 1, 1) == string.sub(nt[i + 1], 1, 1))) and
|
||||
(string.match(string.sub(nt[i], 1, 1), "%l") ~= nil) then
|
||||
table.insert(nouns, nt[i])
|
||||
end
|
||||
end
|
||||
-- Includes both proper and common nouns
|
||||
else
|
||||
for i = 1, #nt do
|
||||
if (#nt[i] > 4) and
|
||||
((string.sub(nt[i - 1], 1, 1) == string.sub(nt[i], 1, 1)) or
|
||||
(string.sub(nt[i], 1, 1) == string.sub(nt[i + 1], 1, 1))) then
|
||||
table.insert(nouns, nt[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
return nouns
|
||||
end
|
||||
|
||||
|
||||
-- Return a string description of soup.
|
||||
function soupe.make_soup(items)
|
||||
local ingred = items
|
||||
if ingred == nil then ingred = math.random(1, soupe.max_ingred) end
|
||||
local nouns = soupe.filter_nouns("common")
|
||||
local servings = util.table_keys(soupe.servings)
|
||||
local serving = servings[math.random(1, #servings)]
|
||||
local adj = ""
|
||||
local which_adj = math.random(1, 4)
|
||||
if which_adj == 2 then
|
||||
adj = soupe.temps[math.random(1, #soupe.temps)] .. " "
|
||||
elseif which_adj == 3 then
|
||||
adj = soupe.servings[serving][math.random(1, #soupe.servings[serving])] ..
|
||||
" "
|
||||
elseif which_adj == 4 then
|
||||
adj = soupe.temps[math.random(1, #soupe.temps)] .. " " ..
|
||||
soupe.servings[serving][math.random(1, #soupe.servings[serving])] ..
|
||||
" "
|
||||
end
|
||||
|
||||
local soup = adj .. serving .. " " ..
|
||||
soupe.articles[math.random(1, #soupe.articles)] .. " "
|
||||
if ingred == 1 then
|
||||
soup = soup .. nouns[math.random(1, #nouns)]
|
||||
elseif ingred == 2 then
|
||||
soup = soup .. nouns[math.random(1, #nouns)] .. " and " ..
|
||||
nouns[math.random(1, #nouns)]
|
||||
elseif ingred > 2 then
|
||||
for i = 1, (ingred - 2) do
|
||||
soup = soup .. nouns[math.random(1, #nouns)] .. ", "
|
||||
end
|
||||
soup = soup .. nouns[math.random(1, #nouns)] .. " and " ..
|
||||
nouns[math.random(1, #nouns)]
|
||||
end
|
||||
return soup
|
||||
end
|
||||
|
||||
|
||||
return soupe
|
|
@ -0,0 +1,14 @@
|
|||
# Nouns
|
||||
|
||||
The `nouns.txt` file is based on the [Moby Part of Speech List] by Grady Ward,
|
||||
released into the public domain and available on [Project Gutenburg].
|
||||
|
||||
Commands to generate the `nouns.txt` file:
|
||||
|
||||
```
|
||||
curl -LO https://www.gutenberg.org/files/3203/files/mobypos.txt
|
||||
cat mobypos.txt | grep "\N" > nouns.txt
|
||||
```
|
||||
|
||||
[Moby Part of Speech List]: https://web.archive.org/web/20170930060409/http://icon.shef.ac.uk/Moby/
|
||||
[Project Gutenburg]: https://www.gutenberg.org/ebooks/3203
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue