summaryrefslogtreecommitdiff
path: root/waifu.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-11-12 15:30:49 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-11-12 15:30:49 +0100
commit9ef2b8fe1f3a13784c12f8fbdcbbc1b0154ca689 (patch)
tree7ceccd945c8e6e4b945c569aaa085d5dd63e8017 /waifu.lua
parent19cd4e7ea97d08d61b5ba650a471bbd2e814d779 (diff)
downloadfurrybot-master.tar.xz
Japanese waifu namesHEADmaster
Diffstat (limited to 'waifu.lua')
-rw-r--r--waifu.lua62
1 files changed, 39 insertions, 23 deletions
diff --git a/waifu.lua b/waifu.lua
index 4f78ba9..a92b46d 100644
--- a/waifu.lua
+++ b/waifu.lua
@@ -1,24 +1,40 @@
local http, env, storage
local C = minetest.get_color_escape_sequence
-furrybot.alphabeth = {
- vowels = {},
- consonants = {},
+furrybot.hiragana = {
+ map = {},
+ probability = {},
}
function furrybot.get_waifu_name()
- local state = math.random() < 0.5
- local r = math.random(3, 8)
- local str = ""
+ local r = math.floor(1
+ + math.random()
+ + math.random()
+ + math.random()
+ + math.random()
+ + math.random()
+ )
+
+ local jp = ""
+
+ for i = 1, r do
+ jp = jp .. furrybot.hiragana.list[math.random(#furrybot.hiragana.list)]
+ end
+
+ local en = ""
for i = 1, r do
- local tbl = state and furrybot.alphabeth.vowels or furrybot.alphabeth.consonants
- str = str .. tbl[math.random(#tbl)]
+ local combo = furrybot.hiragana.map[utf8.sub(jp, i, i + 1)]
- state = not state
+ if combo then
+ en = en .. combo
+ i = i + 1
+ else
+ en = en .. furrybot.hiragana.map[utf8.sub(jp, i, i)]
+ end
end
- return furrybot.uppercase(str)
+ return jp .. " (" .. furrybot.uppercase(en) .. ")"
end
function furrybot.random_distribution(tbl)
@@ -129,24 +145,24 @@ furrybot.commands.waifu = {
return function(_http, _env, _storage)
http, env, storage = _http, _env, _storage
- local is_vowel = {
- a = true,
- e = true,
- i = true,
- o = true,
- u = true,
- }
+ local function read_file(path)
+ local f = env.io.open("clientmods/furrybot/" .. path, "r")
+ local data = f:read("*a")
+ f:close()
+
+ return data
+ end
- local bounds = "az"
+ furrybot.hiragana.map = minetest.deserialize(read_file("hiragana"))
+ furrybot.hiragana.list = {}
- local f = env.io.open("clientmods/furrybot/LICENSE", "r")
- local src = f:read("*a")
+ local src = read_file("Japanese-Lipsum.txt")
for i = 1, #src do
- local c = src:sub(i, i):lower()
+ local c = utf8.sub(src, i, i)
- if c:byte(1) >= bounds:byte(1) and c:byte(1) <= bounds:byte(2) then
- table.insert(is_vowel[c] and furrybot.alphabeth.vowels or furrybot.alphabeth.consonants, c)
+ if furrybot.hiragana.map[c] then
+ table.insert(furrybot.hiragana.list, c)
end
end
end