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

55 lines
1.4 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'
2015-12-05 21:36:56 +01:00
local function get_gender_data (name)
2015-11-12 17:42:03 +01:00
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)
2015-12-05 21:36:56 +01:00
cache_data('gender', string.lower(name), data, 345600)
2015-11-12 17:42:03 +01:00
return data
end
2015-12-05 21:36:56 +01:00
local function send_gender_data(data, receiver)
2015-11-12 17:42:03 +01:00
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
2015-12-05 21:36:56 +01:00
local function run(msg, matches)
2015-11-12 17:42:03 +01:00
name = matches[1]
local receiver = get_receiver(msg)
2015-12-05 21:36:56 +01:00
local hash = 'telegram:cache:gender:'..string.lower(name)
if redis:exists(hash) == false then
data = get_gender_data(name)
else
data = redis:hgetall(hash)
end
2015-11-12 17:42:03 +01:00
send_gender_data(data, receiver)
end
return {
description = "Sendet Geschlecht",
2015-12-05 21:36:56 +01:00
usage = "/geschlecht [Name]: Sendet Geschlecht",
patterns = {
"^/geschlecht (.*)$",
"^/gender (.*)$"
},
2015-11-12 17:42:03 +01:00
run = run
}
2015-12-05 21:36:56 +01:00
end