Upstream # 97c3e6be von Brawlbot
This commit is contained in:
@ -10,13 +10,20 @@ local function expand_bitly_link (shorturl)
|
||||
local url = BASE_URL..'?access_token='..access_token..'&shortUrl=https://bit.ly/'..shorturl
|
||||
local res,code = https.request(url)
|
||||
if code ~= 200 then return "HTTP-FEHLER" end
|
||||
local data = json:decode(res).data
|
||||
return data.expand[1].long_url
|
||||
local data = json:decode(res).data.expand[1]
|
||||
cache_data('bitly', shorturl, data, 5184000)
|
||||
return data.long_url
|
||||
end
|
||||
|
||||
local function run(msg, matches)
|
||||
local shorturl = matches[1]
|
||||
return expand_bitly_link(shorturl)
|
||||
local hash = 'telegram:cache:bitly:'..shorturl
|
||||
if redis:exists(hash) == false then
|
||||
return expand_bitly_link(shorturl)
|
||||
else
|
||||
local data = redis:hgetall(hash)
|
||||
return data.long_url
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
|
@ -5,16 +5,17 @@ do
|
||||
|
||||
local BASE_URL = 'https://gender-api.com/get'
|
||||
|
||||
function get_gender_data (name)
|
||||
local 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)
|
||||
cache_data('gender', string.lower(name), data, 345600)
|
||||
return data
|
||||
end
|
||||
|
||||
function send_gender_data(data, receiver)
|
||||
local function send_gender_data(data, receiver)
|
||||
if data.gender == "female" then
|
||||
gender = 'weiblich'
|
||||
end
|
||||
@ -29,18 +30,26 @@ function send_gender_data(data, receiver)
|
||||
send_msg(receiver, text, ok_cb, false)
|
||||
end
|
||||
|
||||
function run(msg, matches)
|
||||
local function run(msg, matches)
|
||||
name = matches[1]
|
||||
local data = get_gender_data(name)
|
||||
local receiver = get_receiver(msg)
|
||||
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
|
||||
send_gender_data(data, receiver)
|
||||
end
|
||||
|
||||
return {
|
||||
description = "Sendet Geschlecht",
|
||||
usage = {"/geschlecht [Name]","/gender [Name]"},
|
||||
patterns = {"^/geschlecht (.*)$","^/gender (.*)$"},
|
||||
usage = "/geschlecht [Name]: Sendet Geschlecht",
|
||||
patterns = {
|
||||
"^/geschlecht (.*)$",
|
||||
"^/gender (.*)$"
|
||||
},
|
||||
run = run
|
||||
}
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user