This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/gender.lua

47 lines
1.2 KiB
Lua
Raw Normal View History

2015-11-12 17:42:03 +01:00
-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 <andi (dot) b (at) outlook (dot) de>
-- DO NOT USE WITHOUT PERMISSION
do
local BASE_URL = 'https://gender-api.com/get'
function get_gender_data (name)
local apikey = cred_data.gender_apikey
local url = BASE_URL..'?name='..name..'&key='..apikey
local res,code = https.request(url)
if code ~= 200 then return "HTTP-FEHLER" end
local data = json:decode(res)
return data
end
function send_gender_data(data, receiver)
if data.gender == "female" then
gender = 'weiblich'
end
if data.gender == "male" then
gender = 'männlich'
end
if data.gender == "unknown" then
gender = 'unbekanntem Geschlechts'
end
local accuracy = data.accuracy
local text = name..' ist zu '..accuracy..'% '..gender
send_msg(receiver, text, ok_cb, false)
end
function run(msg, matches)
name = matches[1]
local data = get_gender_data(name)
local receiver = get_receiver(msg)
send_gender_data(data, receiver)
end
return {
description = "Sendet Geschlecht",
usage = {"/geschlecht [Name]","/gender [Name]"},
patterns = {"^/geschlecht (.*)$","^/gender (.*)$"},
run = run
}
end