Entfernung einiger Plugins
- Entfernung der AFK-Keyboards - Modifizierung des Standard Plugin-Sets - Entfernung folgender Plugins * 9gag * afk * ap * bitly_create * btc * cats * clypit * deviantart * dhl * fefe * flickr_search * get * hackernews * hello * imgur * instagram * isup * lyrics * myanimelist * pagespeed_insights * play_store * pocket * reddit * set * settings * soundcloud * streamable * tex * thetvdb * wiimmfi * yourls
This commit is contained in:
parent
6447fbd2a5
commit
331b56f883
@ -364,7 +364,7 @@ function create_plugin_set()
|
||||
'currency',
|
||||
'banhammer',
|
||||
'plugins',
|
||||
'settings',
|
||||
'respond',
|
||||
'help'
|
||||
}
|
||||
print ('enabling a few plugins - saving to redis set telegram:enabled_plugins')
|
||||
|
@ -1,59 +0,0 @@
|
||||
local ninegag = {}
|
||||
|
||||
ninegag.command = '9gag'
|
||||
|
||||
function ninegag:init(config)
|
||||
ninegag.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('9gag', true):t('9fag', true).table
|
||||
ninegag.inline_triggers = {
|
||||
"^9gag"
|
||||
}
|
||||
ninegag.doc = [[*
|
||||
]]..config.cmd_pat..[[9gag*: Gibt ein zufälliges Bild von den momentan populärsten 9GAG-Posts aus]]
|
||||
end
|
||||
|
||||
local url = "http://api-9gag.herokuapp.com/"
|
||||
|
||||
function ninegag:get_9GAG()
|
||||
local b,c = http.request(url)
|
||||
if c ~= 200 then return nil end
|
||||
local gag = json.decode(b)
|
||||
-- random max json table size
|
||||
local i = math.random(#gag)
|
||||
|
||||
local link_image = gag[i].src
|
||||
local title = gag[i].title
|
||||
local post_url = gag[i].url
|
||||
return link_image, title, post_url
|
||||
end
|
||||
|
||||
function ninegag:inline_callback(inline_query, config)
|
||||
local res, code = http.request(url)
|
||||
if code ~= 200 then abort_inline_query(inline_query) return end
|
||||
local gag = json.decode(res)
|
||||
|
||||
local results = '['
|
||||
local id = 50
|
||||
for n in pairs(gag) do
|
||||
local title = gag[n].title:gsub('"', '\\"')
|
||||
results = results..'{"type":"photo","id":"'..id..'","photo_url":"'..gag[n].src..'","thumb_url":"'..gag[n].src..'","caption":"'..title..'","reply_markup":{"inline_keyboard":[[{"text":"9GAG aufrufen","url":"'..gag[n].url..'"}]]}}'
|
||||
id = id+1
|
||||
if n < #gag then
|
||||
results = results..','
|
||||
end
|
||||
end
|
||||
local results = results..']'
|
||||
utilities.answer_inline_query(inline_query, results, 300)
|
||||
end
|
||||
|
||||
function ninegag:action(msg, config)
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local url, title, post_url = ninegag:get_9GAG()
|
||||
if not url then
|
||||
utilities.send_reply(msg, config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Post aufrufen","url":"'..post_url..'"}]]}')
|
||||
end
|
||||
|
||||
return ninegag
|
@ -80,20 +80,11 @@ function afk:pre_process(msg)
|
||||
local duration = makeHumanTime(afk_time)
|
||||
|
||||
redis:hset(hash, 'afk', false)
|
||||
local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard')
|
||||
if afk_text then
|
||||
redis:hset(hash, 'afk_text', false)
|
||||
if show_afk_keyboard == 'true' then
|
||||
utilities.send_reply(msg, user_name..' ist wieder da (war: <b>'..afk_text..'</b> für '..duration..')!', 'HTML', '{"hide_keyboard":true,"selective":true}')
|
||||
else
|
||||
utilities.send_message(chat_id, user_name..' ist wieder da (war: <b>'..afk_text..'</b> für '..duration..')!', true, nil, 'HTML')
|
||||
end
|
||||
utilities.send_message(chat_id, user_name..' ist wieder da (war: <b>'..afk_text..'</b> für '..duration..')!', true, nil, 'HTML')
|
||||
else
|
||||
if show_afk_keyboard == 'true' then
|
||||
utilities.send_reply(msg, user_name..' ist wieder da (war '..duration..' weg)!', nil, '{"hide_keyboard":true,"selective":true}')
|
||||
else
|
||||
utilities.send_message(chat_id, user_name..' ist wieder da (war '..duration..' weg)!')
|
||||
end
|
||||
utilities.send_message(chat_id, user_name..' ist wieder da (war '..duration..' weg)!')
|
||||
end
|
||||
end
|
||||
|
||||
@ -111,14 +102,8 @@ function afk:action(msg, config, matches)
|
||||
local user_name = get_name(msg)
|
||||
local timestamp = msg.date
|
||||
local uhash = 'user:'..msg.from.id
|
||||
local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard')
|
||||
if show_afk_keyboard == 'true' then
|
||||
keyboard = '{"keyboard":[[{"text":"Wieder da."}]], "one_time_keyboard":true, "selective":true, "resize_keyboard":true}'
|
||||
else
|
||||
keyboard = nil
|
||||
end
|
||||
|
||||
utilities.send_reply(msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2]), false, keyboard)
|
||||
utilities.send_reply(msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2]), false)
|
||||
end
|
||||
|
||||
return afk
|
@ -1,38 +0,0 @@
|
||||
local ap = {}
|
||||
|
||||
ap.triggers = {
|
||||
"hosted.ap.org/dynamic/stories/(.+)"
|
||||
}
|
||||
|
||||
function ap:get_article(article)
|
||||
local url = 'http://hosted.ap.org/dynamic/stories/'..article
|
||||
local res, code = http.request(url)
|
||||
if code ~= 200 then return 'HTTP-Fehler '..code..' ist aufgetreten.' end
|
||||
|
||||
local headline = res:match('<span class%=\"headline entry%-title\">(.-)</span>')
|
||||
if not headline then return end
|
||||
|
||||
local article = unescape(utilities.trim(res:match('<p class%=\"ap%-story%-p\">(.-)</p>')))
|
||||
|
||||
local pic_url = res:match('<img src%=\"(/photos/.-)" alt%=\"AP Photo\"')
|
||||
|
||||
local text = '<b>'..headline..'</b>\n'..article
|
||||
return text, pic_url
|
||||
end
|
||||
|
||||
function ap:action(msg, config, matches)
|
||||
local article_id = matches[1]
|
||||
local article, pic = ap:get_article(article_id)
|
||||
if not article then
|
||||
utilities.send_reply(msg, config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
if pic then
|
||||
local pic = pic:gsub('-small', '-big')
|
||||
utilities.send_photo(msg.chat.id, 'http://hosted.ap.org'..pic, nil, msg.message_id)
|
||||
end
|
||||
utilities.send_reply(msg, article, 'HTML')
|
||||
end
|
||||
|
||||
return ap
|
@ -1,137 +0,0 @@
|
||||
local bitly_create = {}
|
||||
|
||||
function bitly_create:init(config)
|
||||
if not cred_data.bitly_client_id then
|
||||
print('Missing config value: bitly_client_id.')
|
||||
print('bitly_create.lua will not be enabled.')
|
||||
return
|
||||
elseif not cred_data.bitly_client_secret then
|
||||
print('Missing config value: bitly_client_secret.')
|
||||
print('bitly_create.lua will not be enabled.')
|
||||
return
|
||||
elseif not cred_data.bitly_redirect_uri then
|
||||
print('Missing config value: bitly_redirect_uri.')
|
||||
print('bitly_create.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
bitly_create.triggers = {
|
||||
"^/short(auth)(.+)$",
|
||||
"^/short (auth)$",
|
||||
"^/short (unauth)$",
|
||||
"^/short (me)$",
|
||||
"^/short (j.mp) (https?://[%w-_%.%?%.:/%+=&]+)$",
|
||||
"^/short (bit.ly) (https?://[%w-_%.%?%.:/%+=&]+)$",
|
||||
"^/short (bitly.com) (https?://[%w-_%.%?%.:/%+=&]+)$",
|
||||
"^/short (https?://[%w-_%.%?%.:/%+=&]+)$"
|
||||
}
|
||||
bitly_create.doc = [[*
|
||||
]]..config.cmd_pat..[[short* _<Link>_: Kürzt einen Link mit der Standard Bitly-Adresse
|
||||
*]]..config.cmd_pat..[[short* _<j.mp|bit.ly|bitly.com>_ _[Link]_: Kürzt einen Link mit der ausgewählten Kurz-URL
|
||||
*]]..config.cmd_pat..[[short* _auth_: Loggt deinen Account ein und nutzt ihn für deine Links (empfohlen!)
|
||||
*]]..config.cmd_pat..[[short* _me_: Gibt den eingeloggten Account aus
|
||||
*]]..config.cmd_pat..[[short* _unauth_: Loggt deinen Account aus
|
||||
]]
|
||||
end
|
||||
|
||||
bitly_create.command = 'short <URL>'
|
||||
|
||||
local BASE_URL = 'https://api-ssl.bitly.com'
|
||||
|
||||
local client_id = cred_data.bitly_client_id
|
||||
local client_secret = cred_data.bitly_client_secret
|
||||
local redirect_uri = cred_data.bitly_redirect_uri
|
||||
|
||||
function bitly_create:get_bitly_access_token(hash, code)
|
||||
local req = post_petition(BASE_URL..'/oauth/access_token', 'client_id='..client_id..'&client_secret='..client_secret..'&code='..code..'&redirect_uri='..redirect_uri)
|
||||
if not req.access_token then return '*Fehler beim Einloggen!*' end
|
||||
|
||||
local access_token = req.access_token
|
||||
local login_name = req.login
|
||||
redis:hset(hash, 'bitly', access_token)
|
||||
return 'Erfolgreich als `'..login_name..'` eingeloggt!'
|
||||
end
|
||||
|
||||
function bitly_create:get_bitly_user_info(bitly_access_token)
|
||||
local url = BASE_URL..'/v3/user/info?access_token='..bitly_access_token..'&format=json'
|
||||
local res,code = https.request(url)
|
||||
if code == 401 then return 'Login fehlgeschlagen!' end
|
||||
if code ~= 200 then return 'HTTP-Fehler!' end
|
||||
|
||||
local data = json.decode(res).data
|
||||
|
||||
if data.full_name then
|
||||
name = '*'..data.full_name..'* (`'..data.login..'`)'
|
||||
else
|
||||
name = '`'..data.login..'`'
|
||||
end
|
||||
|
||||
local text = 'Eingeloggt als '..name
|
||||
|
||||
return text
|
||||
end
|
||||
|
||||
function bitly_create:create_bitlink (long_url, domain, bitly_access_atoken)
|
||||
local url = BASE_URL..'/v3/shorten?access_token='..bitly_access_token..'&domain='..domain..'&longUrl='..long_url..'&format=txt'
|
||||
local text,code = https.request(url)
|
||||
if code ~= 200 then return 'FEHLER: '..text end
|
||||
return text
|
||||
end
|
||||
|
||||
function bitly_create:action(msg, config, matches)
|
||||
local hash = 'user:'..msg.from.id
|
||||
bitly_access_token = redis:hget(hash, 'bitly')
|
||||
|
||||
if matches[1] == 'auth' and matches[2] then
|
||||
utilities.send_reply(msg, bitly_create:get_bitly_access_token(hash, matches[2]), true)
|
||||
local message_id = redis:hget(hash, 'bitly_login_msg')
|
||||
utilities.edit_message(msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true)
|
||||
redis:hdel(hash, 'bitly_login_msg')
|
||||
return
|
||||
end
|
||||
|
||||
if matches[1] == 'auth' then
|
||||
local result = utilities.send_reply(msg, '*Bitte logge dich ein und folge den Anweisungen.*', true, '{"inline_keyboard":[[{"text":"Bei Bitly anmelden","url":"https://bitly.com/oauth/authorize?client_id='..client_id..'&redirect_uri='..redirect_uri..'&state='..self.info.username..'"}]]}')
|
||||
redis:hset(hash, 'bitly_login_msg', result.result.message_id)
|
||||
return
|
||||
end
|
||||
|
||||
if matches[1] == 'unauth' and bitly_access_token then
|
||||
redis:hdel(hash, 'bitly')
|
||||
utilities.send_reply(msg, '*Erfolgreich ausgeloggt!* Du kannst den Zugriff [in deinen Kontoeinstellungen](https://bitly.com/a/settings/connected) endgültig entziehen.', true)
|
||||
return
|
||||
elseif matches[1] == 'unauth' and not bitly_access_token then
|
||||
utilities.send_reply(msg, 'Wie willst du dich ausloggen, wenn du gar nicht eingeloggt bist?', true)
|
||||
return
|
||||
end
|
||||
|
||||
if matches[1] == 'me' and bitly_access_token then
|
||||
local text = bitly_create:get_bitly_user_info(bitly_access_token)
|
||||
if text then
|
||||
utilities.send_reply(msg, text, true)
|
||||
return
|
||||
else
|
||||
return
|
||||
end
|
||||
elseif matches[1] == 'me' and not bitly_access_token then
|
||||
utilities.send_reply(msg, 'Du bist nicht eingeloggt! Logge dich ein mit\n/short auth', true)
|
||||
return
|
||||
end
|
||||
|
||||
if not bitly_access_token then
|
||||
print('Not signed in, will use global bitly access_token')
|
||||
bitly_access_token = cred_data.bitly_access_token
|
||||
end
|
||||
|
||||
if matches[2] == nil then
|
||||
long_url = URL.encode(matches[1])
|
||||
domain = 'bit.ly'
|
||||
else
|
||||
long_url = URL.encode(matches[2])
|
||||
domain = matches[1]
|
||||
end
|
||||
utilities.send_reply(msg, bitly_create:create_bitlink(long_url, domain, bitly_access_token))
|
||||
return
|
||||
end
|
||||
|
||||
return bitly_create
|
@ -1,34 +0,0 @@
|
||||
local btc = {}
|
||||
|
||||
function btc:init(config)
|
||||
btc.triggers = {
|
||||
"^/btc$"
|
||||
}
|
||||
btc.doc = [[*
|
||||
]]..config.cmd_pat..[[btc*: Zeigt aktuellen Bitcoin-Kurs an]]
|
||||
end
|
||||
|
||||
btc.command = 'btc'
|
||||
|
||||
-- See https://bitcoinaverage.com/api
|
||||
function btc:getBTCX()
|
||||
local base_url = 'https://api.bitcoinaverage.com/ticker/global/'
|
||||
-- Do request on bitcoinaverage, the final / is critical!
|
||||
local res,code = https.request(base_url.."EUR/")
|
||||
|
||||
if code ~= 200 then return nil end
|
||||
local data = json.decode(res)
|
||||
local ask = string.gsub(data.ask, "%.", ",")
|
||||
local bid = string.gsub(data.bid, "%.", ",")
|
||||
|
||||
-- Easy, it's right there
|
||||
text = 'BTC/EUR\n'..'*Kaufen:* '..ask..'\n'..'*Verkaufen:* '..bid
|
||||
return text
|
||||
end
|
||||
|
||||
|
||||
function btc:action(msg, config, matches)
|
||||
utilities.send_reply(msg, btc:getBTCX(cur), true)
|
||||
end
|
||||
|
||||
return btc
|
@ -1,112 +0,0 @@
|
||||
local cats = {}
|
||||
|
||||
cats.command = 'cat [gif]'
|
||||
|
||||
function cats:init(config)
|
||||
if not cred_data.cat_apikey then
|
||||
print('Missing config value: cat_apikey.')
|
||||
print('cats.lua will be enabled, but there are more features with a key.')
|
||||
end
|
||||
|
||||
cats.triggers = {
|
||||
"^/cat$",
|
||||
"^/cat (gif)$"
|
||||
}
|
||||
|
||||
cats.inline_triggers = {
|
||||
"^cat (gif)$",
|
||||
"^cat$"
|
||||
}
|
||||
|
||||
cats.doc = [[*
|
||||
]]..config.cmd_pat..[[cat*: Postet eine zufällige Katze
|
||||
*]]..config.cmd_pat..[[cat* _gif_: Postet eine zufällige, animierte Katze]]
|
||||
end
|
||||
|
||||
local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html
|
||||
local BASE_URL = 'http://thecatapi.com/api/images/get'
|
||||
|
||||
function cats:inline_callback(inline_query, config, matches)
|
||||
if matches[1] == 'gif' then
|
||||
img_type = 'gif'
|
||||
id = 100
|
||||
else
|
||||
img_type = 'jpg'
|
||||
id = 200
|
||||
end
|
||||
local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%27http%3A%2F%2Fthecatapi.com%2Fapi%2Fimages%2Fget%3Fformat%3Dxml%26results_per_page%3D50%26type%3D'..img_type..'%26apikey%3D'..apikey..'%27&format=json' -- no way I'm using XML, plz die
|
||||
local res, code = https.request(url)
|
||||
if code ~= 200 then return end
|
||||
local data = json.decode(res).query.results.response.data.images.image
|
||||
if not data then return end
|
||||
if not data[1] then return end
|
||||
|
||||
local results = '['
|
||||
|
||||
for n in pairs(data) do
|
||||
if img_type == 'gif' then
|
||||
results = results..'{"type":"gif","id":"'..id..'","gif_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}'
|
||||
id = id+1
|
||||
else
|
||||
results = results..'{"type":"photo","id":"'..id..'","photo_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}'
|
||||
id = id+1
|
||||
end
|
||||
if n < #data then
|
||||
results = results..','
|
||||
end
|
||||
end
|
||||
local results = results..']'
|
||||
utilities.answer_inline_query(inline_query, results, 30)
|
||||
end
|
||||
|
||||
function cats:get_cat(gif)
|
||||
if gif then
|
||||
local url = BASE_URL..'?type=gif&apikey='..apikey
|
||||
file = download_to_file(url, 'miau.gif')
|
||||
else
|
||||
local url = BASE_URL..'?type=jpg,png&apikey='..apikey
|
||||
file = download_to_file(url, 'miau.png')
|
||||
end
|
||||
return file
|
||||
end
|
||||
|
||||
function cats:callback(callback, msg, self, config, input)
|
||||
utilities.answer_callback_query(callback, 'Miau!')
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
if string.isempty(input) then
|
||||
local file = cats:get_cat()
|
||||
if not file then
|
||||
utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true)
|
||||
return
|
||||
end
|
||||
utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}')
|
||||
else
|
||||
local file = cats:get_cat(true)
|
||||
if not file then
|
||||
utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true)
|
||||
return
|
||||
end
|
||||
utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}')
|
||||
end
|
||||
end
|
||||
|
||||
function cats:action(msg, config, matches)
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
if matches[1] == 'gif' then
|
||||
local file = cats:get_cat(true)
|
||||
if not file then
|
||||
utilities.send_reply(msg, config.errors.connection)
|
||||
return
|
||||
end
|
||||
utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}')
|
||||
else
|
||||
local file = cats:get_cat()
|
||||
if not file then
|
||||
utilities.send_reply(msg, config.errors.connection)
|
||||
return
|
||||
end
|
||||
utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}')
|
||||
end
|
||||
end
|
||||
|
||||
return cats
|
@ -1,28 +0,0 @@
|
||||
local clypit = {}
|
||||
|
||||
clypit.triggers = {
|
||||
"clyp.it/([A-Za-z0-9-_-]+)"
|
||||
}
|
||||
|
||||
function clypit:get_clypit_details(shortcode)
|
||||
local BASE_URL = "http://api.clyp.it"
|
||||
local url = BASE_URL..'/'..shortcode
|
||||
local res,code = http.request(url)
|
||||
if code ~= 200 then return nil end
|
||||
local data = json.decode(res)
|
||||
|
||||
local title = data.Title
|
||||
local duration = data.Duration
|
||||
|
||||
local audio = download_to_file(data.Mp3Url)
|
||||
return audio, title, duration
|
||||
end
|
||||
|
||||
function clypit:action(msg, config, matches)
|
||||
utilities.send_typing(msg.chat.id, 'upload_audio')
|
||||
local audio, title, duration = clypit:get_clypit_details(matches[1])
|
||||
if not audio then return utilities.send_reply(msg, config.errors.connection) end
|
||||
utilities.send_audio(msg.chat.id, audio, nil, msg.message_id, duration, nil, title)
|
||||
end
|
||||
|
||||
return clypit
|
@ -1,48 +0,0 @@
|
||||
local deviantart = {}
|
||||
|
||||
deviantart.triggers = {
|
||||
"http://(.*).deviantart.com/art/(.*)"
|
||||
}
|
||||
|
||||
local BASE_URL = 'https://backend.deviantart.com'
|
||||
|
||||
function deviantart:get_da_data (da_code)
|
||||
local url = BASE_URL..'/oembed?url='..da_code
|
||||
local res,code = https.request(url)
|
||||
if code ~= 200 then return nil end
|
||||
local data = json.decode(res)
|
||||
return data
|
||||
end
|
||||
|
||||
function deviantart:send_da_data (data)
|
||||
local title = data.title
|
||||
local category = data.category
|
||||
local author_name = data.author_name
|
||||
local text = title..' von '..author_name..'\n'..category
|
||||
|
||||
if data.rating == "adult" then
|
||||
return title..' von '..author_name..'\n'..category..'\n(NSFW)'
|
||||
else
|
||||
local image_url = data.fullsize_url
|
||||
if image_url == nil then
|
||||
image_url = data.url
|
||||
end
|
||||
local file = download_to_file(image_url)
|
||||
return text, file
|
||||
end
|
||||
end
|
||||
|
||||
function deviantart:action(msg, config, matches)
|
||||
local data = deviantart:get_da_data('http://'..matches[1]..'.deviantart.com/art/'..matches[2])
|
||||
if not data then utilities.send_reply(msg, config.errors.connection) return end
|
||||
|
||||
local text, file = deviantart:send_da_data(data)
|
||||
if file then
|
||||
utilities.send_photo(msg.chat.id, file, text, msg.message_id)
|
||||
else
|
||||
utilities.send_reply(msg, text)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return deviantart
|
@ -1,34 +0,0 @@
|
||||
local dhl = {}
|
||||
|
||||
function dhl:init(config)
|
||||
dhl.triggers = {
|
||||
"/dhl (%d+)$"
|
||||
}
|
||||
dhl.doc = [[*
|
||||
]]..config.cmd_pat..[[dhl* _<Sendungsnummer>_: Aktueller Status der Sendung]]
|
||||
end
|
||||
|
||||
|
||||
local BASE_URL = 'https://mobil.dhl.de'
|
||||
|
||||
function dhl:sendungsstatus(id)
|
||||
local url = BASE_URL..'/shipmentdetails.html?shipmentId='..id
|
||||
local res,code = https.request(url)
|
||||
if code ~= 200 then return "Fehler beim Abrufen von mobil.dhl.de" end
|
||||
local status = string.match(res, "<div id%=\"detailShortStatus\">(.-)</div>")
|
||||
local status = utilities.trim(status)
|
||||
local zeit = string.match(res, "<div id%=\"detailStatusDateTime\">(.-)</div>")
|
||||
local zeit = utilities.trim(zeit)
|
||||
if not zeit or zeit == '<br />' then
|
||||
return status
|
||||
end
|
||||
return '*'..status..'*\n_Stand: '..zeit..'_'
|
||||
end
|
||||
|
||||
function dhl:action(msg, config, matches)
|
||||
local sendungs_id = matches[1]
|
||||
if string.len(sendungs_id) < 8 then return end
|
||||
utilities.send_reply(msg, dhl:sendungsstatus(sendungs_id), true)
|
||||
end
|
||||
|
||||
return dhl
|
@ -1,29 +0,0 @@
|
||||
local fefe = {}
|
||||
|
||||
fefe.triggers = {
|
||||
"blog.fefe.de/%?ts=%w%w%w%w%w%w%w%w"
|
||||
}
|
||||
|
||||
function fefe:post(id)
|
||||
local url = 'https://'..id
|
||||
local results, code = https.request(url)
|
||||
if code ~= 200 then return "HTTP-Fehler" end
|
||||
if string.match(results, "No entries found.") then return "Eintrag nicht gefunden." end
|
||||
|
||||
local line = string.sub( results, string.find(results, "<li><a href[^\n]+"))
|
||||
local text = line:gsub("<div style=.+", "")
|
||||
-- remove link at begin
|
||||
local text = text:gsub("<li><a href=\"%?ts=%w%w%w%w%w%w%w%w\">%[l]</a>", "")
|
||||
-- replace "<p>" with newline; "<b>" and "</b>" with "*"
|
||||
local text = text:gsub("<p>", "\n\n"):gsub("<p u>", "\n\n")
|
||||
-- format quotes and links markdown-like
|
||||
local text = text:gsub("<blockquote>", "\n\n> "):gsub("</blockquote>", "\n\n")
|
||||
|
||||
return text
|
||||
end
|
||||
|
||||
function fefe:action(msg, config, matches)
|
||||
utilities.send_reply(msg, fefe:post(matches[1]), 'HTML')
|
||||
end
|
||||
|
||||
return fefe
|
@ -1,73 +0,0 @@
|
||||
local flickr_search = {}
|
||||
|
||||
function flickr_search:init(config)
|
||||
if not cred_data.flickr_apikey then
|
||||
print('Missing config value: flickr_apikey.')
|
||||
print('flickr_search.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
flickr_search.triggers = {
|
||||
"^/flickr (.+)$"
|
||||
}
|
||||
end
|
||||
|
||||
flickr_search.command = 'flickr <Suchbegriff>'
|
||||
|
||||
local apikey = cred_data.flickr_apikey
|
||||
local BASE_URL = 'https://api.flickr.com/services/rest'
|
||||
|
||||
function flickr_search:get_flickr(term)
|
||||
local url = BASE_URL..'/?method=flickr.photos.search&api_key='..apikey..'&format=json&nojsoncallback=1&privacy_filter=1&safe_search=3&media=photos&sort=relevance&is_common=true&per_page=20&extras=url_l,url_o&text='..term
|
||||
local b,c = https.request(url)
|
||||
if c ~= 200 then return nil end
|
||||
local photo = json.decode(b).photos.photo
|
||||
if not photo[1] then return nil end
|
||||
|
||||
-- truly randomize
|
||||
math.randomseed(os.time())
|
||||
-- random max json table size
|
||||
local i = math.random(#photo)
|
||||
|
||||
local link_image = photo[i].url_l or photo[i].url_o
|
||||
local orig_image = photo[i].url_o or link_image
|
||||
local title = photo[i].title
|
||||
if title:len() > 200 then
|
||||
title = title:sub(1, 197) .. '...'
|
||||
end
|
||||
|
||||
return link_image, title, orig_image
|
||||
end
|
||||
|
||||
function flickr_search:callback(callback, msg, self, config, input)
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local input = URL.unescape(input)
|
||||
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
|
||||
local url, title, orig = flickr_search:get_flickr(input)
|
||||
|
||||
if not url then utilities.answer_callback_query(callback, 'Konnte nicht mit Flickr verbinden :(', true) return end
|
||||
|
||||
if string.ends(url, ".gif") then
|
||||
utilities.send_document(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Im Browser öffnen","url":"'..orig..'"},{"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(input)..'"}]]}')
|
||||
return
|
||||
else
|
||||
utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Bild öffnen","url":"'..orig..'"}, {"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(input)..'"}]]}')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
function flickr_search:action(msg, config, matches)
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local url, title, orig = flickr_search:get_flickr(matches[1])
|
||||
if not url then utilities.send_reply(msg, config.errors.results) return end
|
||||
|
||||
if string.ends(url, ".gif") then
|
||||
utilities.send_document(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Im Browser öffnen","url":"'..orig..'"},{"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(matches[1])..'"}]]}')
|
||||
return
|
||||
else
|
||||
utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Bild öffnen","url":"'..orig..'"}, {"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(matches[1])..'"}]]}')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return flickr_search
|
@ -1,56 +0,0 @@
|
||||
local get = {}
|
||||
|
||||
get.command = 'get <Variable>'
|
||||
|
||||
function get:init(config)
|
||||
get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('get', true).table
|
||||
get.doc = [[*
|
||||
]]..config.cmd_pat..[[get*: Gibt alle Variablen aus
|
||||
*]]..config.cmd_pat..[[get* _<Variable>_: Gibt _Variable_ aus
|
||||
Nutze `!set <Variable> <Wert>` zum Setzen von Variablen]]
|
||||
end
|
||||
|
||||
function get:get_value(msg, var_name)
|
||||
local hash = get_redis_hash(msg, 'variables')
|
||||
if hash then
|
||||
local value = redis:hget(hash, var_name)
|
||||
if not value then
|
||||
return'Nicht gefunden; benutze /get, um alle Variablen aufzulisten.'
|
||||
else
|
||||
return var_name..' = '..value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function get:list_variables(msg)
|
||||
local hash = get_redis_hash(msg, 'variables')
|
||||
print(hash)
|
||||
|
||||
if hash then
|
||||
print('Getting variable from redis hash '..hash)
|
||||
local names = redis:hkeys(hash)
|
||||
local text = ''
|
||||
for i=1, #names do
|
||||
variables = get:get_value(msg, names[i])
|
||||
text = text..variables.."\n"
|
||||
end
|
||||
if text == '' or text == nil then
|
||||
return 'Keine Variablen vorhanden!'
|
||||
else
|
||||
return text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function get:action(msg)
|
||||
local input = utilities.input(msg.text)
|
||||
if input then
|
||||
output = get:get_value(msg, input:match('(.+)'))
|
||||
else
|
||||
output = get:list_variables(msg)
|
||||
end
|
||||
|
||||
utilities.send_message(msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
|
||||
return get
|
@ -1,40 +0,0 @@
|
||||
local hackernews = {}
|
||||
|
||||
hackernews.triggers = {
|
||||
"news.ycombinator.com/item%?id=(%d+)"
|
||||
}
|
||||
|
||||
local BASE_URL = 'https://hacker-news.firebaseio.com/v0'
|
||||
|
||||
function hackernews:send_hackernews_post (hn_code)
|
||||
local url = BASE_URL..'/item/'..hn_code..'.json'
|
||||
local res,code = https.request(url)
|
||||
if code ~= 200 then return "HTTP-FEHLER" end
|
||||
local data = json.decode(res)
|
||||
|
||||
local by = data.by
|
||||
local title = data.title
|
||||
|
||||
if data.url then
|
||||
url = '\n[Link besuchen]('..data.url..')'
|
||||
else
|
||||
url = ''
|
||||
end
|
||||
|
||||
if data.text then
|
||||
post = '\n'..unescape_html(data.text)
|
||||
post = string.gsub(post, '<p>', ' ')
|
||||
else
|
||||
post = ''
|
||||
end
|
||||
local text = '*'..title..'* von _'..by..'_'..post..url
|
||||
|
||||
return text
|
||||
end
|
||||
|
||||
function hackernews:action(msg, config, matches)
|
||||
local hn_code = matches[1]
|
||||
utilities.send_reply(msg, hackernews:send_hackernews_post(hn_code), true)
|
||||
end
|
||||
|
||||
return hackernews
|
@ -1,11 +0,0 @@
|
||||
local hello = {}
|
||||
|
||||
hello.triggers = {
|
||||
"^[Ss][Aa][Gg] [Hh][Aa][Ll][Ll][Oo] [Zz][Uu] (.*)$"
|
||||
}
|
||||
|
||||
function hello:action(msg, config, matches)
|
||||
utilities.send_message(msg.chat.id, 'Hallo, '..matches[1]..'!')
|
||||
end
|
||||
|
||||
return hello
|
@ -1,56 +0,0 @@
|
||||
local imgur = {}
|
||||
|
||||
function imgur:init(config)
|
||||
if not cred_data.imgur_client_id then
|
||||
print('Missing config value: imgur_client_id.')
|
||||
print('imgur.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
imgur.triggers = {
|
||||
"imgur.com/([A-Za-z0-9]+).gifv",
|
||||
"https?://imgur.com/([A-Za-z0-9]+)"
|
||||
}
|
||||
end
|
||||
|
||||
local client_id = cred_data.imgur_client_id
|
||||
local BASE_URL = 'https://api.imgur.com/3'
|
||||
|
||||
function imgur:get_imgur_data(imgur_code)
|
||||
local response_body = {}
|
||||
local request_constructor = {
|
||||
url = BASE_URL..'/image/'..imgur_code,
|
||||
method = "GET",
|
||||
sink = ltn12.sink.table(response_body),
|
||||
headers = {
|
||||
Authorization = 'Client-ID '..client_id
|
||||
}
|
||||
}
|
||||
local ok, response_code, response_headers, response_status_line = https.request(request_constructor)
|
||||
if not ok then
|
||||
return nil
|
||||
end
|
||||
|
||||
local response_body = json.decode(table.concat(response_body))
|
||||
|
||||
if response_body.status ~= 200 then return nil end
|
||||
|
||||
return response_body.data.link
|
||||
end
|
||||
|
||||
function imgur:action(msg)
|
||||
local imgur_code = matches[1]
|
||||
if imgur_code == "login" then return nil end
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local link = imgur:get_imgur_data(imgur_code)
|
||||
if link then
|
||||
local file = download_to_file(link)
|
||||
if string.ends(link, ".gif") then
|
||||
utilities.send_document(msg.chat.id, file, nil, msg.message_id)
|
||||
else
|
||||
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return imgur
|
@ -1,75 +0,0 @@
|
||||
local instagram = {}
|
||||
|
||||
function instagram:init(config)
|
||||
if not cred_data.instagram_access_token then
|
||||
print('Missing config value: instagram_access_token.')
|
||||
print('instagram.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
instagram.triggers = {
|
||||
"instagram.com/p/([A-Za-z0-9-_-]+)"
|
||||
}
|
||||
end
|
||||
|
||||
local BASE_URL = 'https://api.instagram.com/v1'
|
||||
local access_token = cred_data.instagram_access_token
|
||||
|
||||
function instagram:get_insta_data(insta_code)
|
||||
local url = BASE_URL..'/media/shortcode/'..insta_code..'?access_token='..access_token
|
||||
local res,code = https.request(url)
|
||||
if code ~= 200 then return nil end
|
||||
local data = json.decode(res).data
|
||||
return data
|
||||
end
|
||||
|
||||
function instagram:send_instagram_data(data)
|
||||
-- Header
|
||||
local username = data.user.username
|
||||
local full_name = data.user.full_name
|
||||
if username == full_name then
|
||||
header = full_name..' hat ein'
|
||||
else
|
||||
header = full_name..' ('..username..') hat ein'
|
||||
end
|
||||
if data.type == 'video' then
|
||||
header = header..' Video gepostet'
|
||||
else
|
||||
header = header..' Foto gepostet'
|
||||
end
|
||||
|
||||
-- Caption
|
||||
if data.caption == nil then
|
||||
caption = ''
|
||||
else
|
||||
caption = ':\n'..data.caption.text
|
||||
end
|
||||
|
||||
-- Footer
|
||||
local comments = comma_value(data.comments.count)
|
||||
local likes = comma_value(data.likes.count)
|
||||
local footer = '\n'..likes..' Likes, '..comments..' Kommentare'
|
||||
if data.type == 'video' then
|
||||
footer = '\n'..data.videos.standard_resolution.url..footer
|
||||
end
|
||||
|
||||
-- Image
|
||||
local image_url = data.images.standard_resolution.url
|
||||
|
||||
return header..caption..footer, image_url
|
||||
end
|
||||
|
||||
function instagram:action(msg, config, matches)
|
||||
local insta_code = matches[1]
|
||||
local data = instagram:get_insta_data(insta_code)
|
||||
if not data then utilities.send_reply(msg, config.errors.connection) return end
|
||||
|
||||
local text, image_url = instagram:send_instagram_data(data)
|
||||
if not image_url then utilities.send_reply(msg, config.errors.connection) return end
|
||||
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local file = download_to_file(image_url)
|
||||
utilities.send_photo(msg.chat.id, file, text, msg.message_id)
|
||||
end
|
||||
|
||||
return instagram
|
@ -1,79 +0,0 @@
|
||||
local isup = {}
|
||||
|
||||
function isup:init(config)
|
||||
isup.triggers = {
|
||||
"^/isup (.*)$",
|
||||
"^/ping (.*)$"
|
||||
}
|
||||
|
||||
isup.doc = [[*
|
||||
]]..config.cmd_pat..[[isup* _<URL>_: Prüft, ob die URL up ist]]
|
||||
end
|
||||
|
||||
function isup:is_up_socket(ip, port)
|
||||
print('Connect to', ip, port)
|
||||
local c = socket.try(socket.tcp())
|
||||
c:settimeout(3)
|
||||
local conn = c:connect(ip, port)
|
||||
if not conn then
|
||||
return false
|
||||
else
|
||||
c:close()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function isup:is_up_http(url)
|
||||
-- Parse URL from input, default to http
|
||||
local parsed_url = URL.parse(url, { scheme = 'http', authority = '' })
|
||||
-- Fix URLs without subdomain not parsed properly
|
||||
if not parsed_url.host and parsed_url.path then
|
||||
parsed_url.host = parsed_url.path
|
||||
parsed_url.path = ""
|
||||
end
|
||||
-- Re-build URL
|
||||
local url = URL.build(parsed_url)
|
||||
|
||||
local protocols = {
|
||||
["https"] = https,
|
||||
["http"] = http
|
||||
}
|
||||
local options = {
|
||||
url = url,
|
||||
redirect = false,
|
||||
method = "GET"
|
||||
}
|
||||
local response = { protocols[parsed_url.scheme].request(options) }
|
||||
local code = tonumber(response[2])
|
||||
if code == nil or code >= 400 then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function isup:isup(url)
|
||||
local pattern = '^(%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?):?(%d?%d?%d?%d?%d?)$'
|
||||
local ip,port = string.match(url, pattern)
|
||||
local result = nil
|
||||
|
||||
-- /isup 8.8.8.8:53
|
||||
if ip then
|
||||
port = port or '80'
|
||||
result = isup:is_up_socket(ip, port)
|
||||
else
|
||||
result = isup:is_up_http(url)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function isup:action(msg, config)
|
||||
if isup:isup(matches[1]) then
|
||||
utilities.send_reply(msg, matches[1]..' ist UP! ✅')
|
||||
return
|
||||
else
|
||||
utilities.send_reply(msg, matches[1]..' ist DOWN! ❌')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return isup
|
@ -1,47 +0,0 @@
|
||||
local lyrics = {}
|
||||
|
||||
function lyrics:init(config)
|
||||
if not cred_data.lyricsnmusic_apikey then
|
||||
print('Missing config value: lyricsnmusic_apikey.')
|
||||
print('lyrics.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
lyrics.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lyrics', true).table
|
||||
lyrics.doc = [[*
|
||||
]]..config.cmd_pat..[[lyrics* _<Lied>_: Postet Liedertext]]
|
||||
end
|
||||
|
||||
lyrics.command = 'lyrics <Lied>'
|
||||
|
||||
function lyrics:getLyrics(text)
|
||||
local apikey = cred_data.lyricsnmusic_apikey
|
||||
local q = URL.encode(text)
|
||||
local b = http.request("http://api.lyricsnmusic.com/songs?api_key="..apikey.."&q=" .. q)
|
||||
response = json.decode(b)
|
||||
local reply = ""
|
||||
if #response > 0 then
|
||||
-- grab first match
|
||||
local result = response[1]
|
||||
reply = result.title .. " - " .. result.artist.name .. "\n" .. result.snippet .. "\n[Ganzen Liedertext ansehen](" .. result.url .. ")"
|
||||
else
|
||||
reply = nil
|
||||
end
|
||||
return reply
|
||||
end
|
||||
|
||||
function lyrics:action(msg, config, matches)
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
utilities.send_message(msg.chat.id, lyrics.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
utilities.send_reply(msg, lyrics:getLyrics(input), true)
|
||||
end
|
||||
|
||||
return lyrics
|
@ -1,222 +0,0 @@
|
||||
local mal = {}
|
||||
|
||||
local xml = require("xml")
|
||||
|
||||
mal.command = 'anime <Anime>, /manga <Manga>'
|
||||
|
||||
function mal:init(config)
|
||||
if not cred_data.mal_user then
|
||||
print('Missing config value: mal_user.')
|
||||
print('myanimelist.lua will not be enabled.')
|
||||
return
|
||||
elseif not cred_data.mal_pw then
|
||||
print('Missing config value: mal_pw.')
|
||||
print('myanimelist.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
mal.triggers = {
|
||||
"^/(anime) (.+)$",
|
||||
"^/(manga) (.+)$"
|
||||
}
|
||||
mal.doc = [[*
|
||||
]]..config.cmd_pat..[[anime*_ <Anime>_: Sendet Infos zum Anime
|
||||
*]]..config.cmd_pat..[[manga*_ <Manga>_: Sendet Infos zum Manga
|
||||
]]
|
||||
end
|
||||
|
||||
local user = cred_data.mal_user
|
||||
local password = cred_data.mal_pw
|
||||
|
||||
local BASE_URL = 'https://'..user..':'..password..'@myanimelist.net/api'
|
||||
|
||||
function mal:delete_tags(str)
|
||||
str = string.gsub( str, '<br />', '')
|
||||
str = string.gsub( str, '%[i%]', '')
|
||||
str = string.gsub( str, '%[/i%]', '')
|
||||
str = string.gsub( str, '—', ' — ')
|
||||
return str
|
||||
end
|
||||
|
||||
local makeOurDate = function(dateString)
|
||||
local pattern = "(%d+)%-(%d+)%-(%d+)"
|
||||
local year, month, day = dateString:match(pattern)
|
||||
return day..'.'..month..'.'..year
|
||||
end
|
||||
|
||||
function mal:get_mal_info(query, typ)
|
||||
if typ == 'anime' then
|
||||
url = BASE_URL..'/anime/search.xml?q='..query
|
||||
elseif typ == 'manga' then
|
||||
url = BASE_URL..'/manga/search.xml?q='..query
|
||||
end
|
||||
local res,code = https.request(url)
|
||||
if code ~= 200 then return "HTTP-Fehler" end
|
||||
local result = xml.load(res)
|
||||
return result
|
||||
end
|
||||
|
||||
function mal:send_anime_data(result, receiver)
|
||||
local title = xml.find(result, 'title')[1]
|
||||
local id = xml.find(result, 'id')[1]
|
||||
local mal_url = 'https://myanimelist.net/anime/'..id
|
||||
|
||||
if xml.find(result, 'synonyms')[1] then
|
||||
alt_name = '\noder: '..unescape(mal:delete_tags(xml.find(result, 'synonyms')[1]))
|
||||
else
|
||||
alt_name = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'synopsis')[1] then
|
||||
desc = '\n'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200))) .. '...'
|
||||
else
|
||||
desc = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'episodes')[1] then
|
||||
episodes = '\nEpisoden: '..xml.find(result, 'episodes')[1]
|
||||
else
|
||||
episodes = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'status')[1] then
|
||||
status = ' ('..xml.find(result, 'status')[1]..')'
|
||||
else
|
||||
status = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'score')[1] ~= "0.00" then
|
||||
score = '\nScore: '..string.gsub(xml.find(result, 'score')[1], "%.", ",")
|
||||
else
|
||||
score = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'type')[1] then
|
||||
typ = '\nTyp: '..xml.find(result, 'type')[1]
|
||||
else
|
||||
typ = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'start_date')[1] ~= "0000-00-00" then
|
||||
startdate = '\nVeröffentlichungszeitraum: '..makeOurDate(xml.find(result, 'start_date')[1])
|
||||
else
|
||||
startdate = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'end_date')[1] ~= "0000-00-00" then
|
||||
enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1])
|
||||
else
|
||||
enddate = ''
|
||||
end
|
||||
|
||||
local text = '*'..title..'*'..alt_name..typ..episodes..status..score..startdate..enddate..'_'..desc..'_\n[Auf MyAnimeList ansehen]('..mal_url..')'
|
||||
if xml.find(result, 'image') then
|
||||
local image_url = xml.find(result, 'image')[1]
|
||||
return text, image_url
|
||||
else
|
||||
return text
|
||||
end
|
||||
end
|
||||
|
||||
function mal:send_manga_data(result)
|
||||
local title = xml.find(result, 'title')[1]
|
||||
local id = xml.find(result, 'id')[1]
|
||||
local mal_url = 'https://myanimelist.net/manga/'..id
|
||||
|
||||
if xml.find(result, 'type')[1] then
|
||||
typ = ' ('..xml.find(result, 'type')[1]..')'
|
||||
else
|
||||
typ = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'synonyms')[1] then
|
||||
alt_name = '\noder: '..unescape(mal:delete_tags(xml.find(result, 'synonyms')[1]))
|
||||
else
|
||||
alt_name = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'chapters')[1] then
|
||||
chapters = '\nKapitel: '..xml.find(result, 'chapters')[1]
|
||||
else
|
||||
chapters = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'status')[1] then
|
||||
status = ' ('..xml.find(result, 'status')[1]..')'
|
||||
else
|
||||
status = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'volumes')[1] then
|
||||
volumes = '\nBände '..xml.find(result, 'volumes')[1]
|
||||
else
|
||||
volumes = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'score')[1] ~= "0.00" then
|
||||
score = '\nScore: '..xml.find(result, 'score')[1]
|
||||
else
|
||||
score = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'start_date')[1] ~= "0000-00-00" then
|
||||
startdate = '\nVeröffentlichungszeitraum: '..makeOurDate(xml.find(result, 'start_date')[1])
|
||||
else
|
||||
startdate = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'end_date')[1] ~= "0000-00-00" then
|
||||
enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1])
|
||||
else
|
||||
enddate = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'synopsis')[1] then
|
||||
desc = '\n'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200))) .. '...'
|
||||
else
|
||||
desc = ''
|
||||
end
|
||||
|
||||
local text = '*'..title..'*'..alt_name..typ..chapters..status..volumes..score..startdate..enddate..'_'..desc..'_\n[Auf MyAnimeList ansehen]('..mal_url..')'
|
||||
if xml.find(result, 'image') then
|
||||
local image_url = xml.find(result, 'image')[1]
|
||||
return text, image_url
|
||||
else
|
||||
return text
|
||||
end
|
||||
end
|
||||
|
||||
function mal:action(msg, config, matches)
|
||||
local query = URL.escape(matches[2])
|
||||
if matches[1] == 'anime' then
|
||||
local anime_info = mal:get_mal_info(query, 'anime')
|
||||
if anime_info == "HTTP-Fehler" then
|
||||
utilities.send_reply(msg, 'Anime nicht gefunden!')
|
||||
return
|
||||
else
|
||||
local text, image_url = mal:send_anime_data(anime_info)
|
||||
if image_url then
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
|
||||
end
|
||||
utilities.send_reply(msg, text, true)
|
||||
return
|
||||
end
|
||||
elseif matches[1] == 'manga' then
|
||||
local manga_info = mal:get_mal_info(query, 'manga')
|
||||
if manga_info == "HTTP-Fehler" then
|
||||
utilities.send_reply(msg, 'Manga nicht gefunden!')
|
||||
return
|
||||
else
|
||||
local text, image_url = mal:send_manga_data(manga_info)
|
||||
if image_url then
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
|
||||
end
|
||||
utilities.send_reply(msg, text, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return mal
|
@ -1,35 +0,0 @@
|
||||
local pagespeed_insights = {}
|
||||
|
||||
function pagespeed_insights:init(config)
|
||||
if not cred_data.google_apikey then
|
||||
print('Missing config value: google_apikey.')
|
||||
print('pagespeed_insights.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
pagespeed_insights.triggers = {
|
||||
"^/speed (https?://[%w-_%.%?%.:/%+=&]+)"
|
||||
}
|
||||
pagespeed_insights.doc = [[*
|
||||
]]..config.cmd_pat..[[speed* _<Seiten-URL>_: Testet Geschwindigkeit der Seite mit PageSpeed Insights]]
|
||||
end
|
||||
|
||||
local BASE_URL = 'https://www.googleapis.com/pagespeedonline/v2'
|
||||
|
||||
function pagespeed_insights:get_pagespeed(test_url)
|
||||
local apikey = cred_data.google_apikey
|
||||
local url = BASE_URL..'/runPagespeed?url='..test_url..'&key='..apikey..'&fields=id,ruleGroups(SPEED(score))'
|
||||
local res,code = https.request(url)
|
||||
if code ~= 200 then return "HTTP-FEHLER" end
|
||||
local data = json.decode(res)
|
||||
return data.id..' hat einen PageSpeed-Score von *'..data.ruleGroups.SPEED.score..' Punkten.*'
|
||||
end
|
||||
|
||||
function pagespeed_insights:action(msg, config, matches)
|
||||
utilities.send_typing(msg.chat.id, 'typing')
|
||||
local text = pagespeed_insights:get_pagespeed(matches[1])
|
||||
if not text then utilities.send_reply(msg, config.errors.connection) return end
|
||||
utilities.send_reply(msg, text, true)
|
||||
end
|
||||
|
||||
return pagespeed_insights
|
@ -1,58 +0,0 @@
|
||||
local play_store = {}
|
||||
|
||||
function play_store:init(config)
|
||||
if not cred_data.x_mashape_key then
|
||||
print('Missing config value: x_mashape_key.')
|
||||
print('play_store.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
play_store.triggers = {
|
||||
"play.google.com/store/apps/details%?id=(.*)"
|
||||
}
|
||||
end
|
||||
|
||||
local BASE_URL = 'https://apps.p.mashape.com/google/application'
|
||||
|
||||
function play_store:get_playstore_data (appid)
|
||||
local apikey = cred_data.x_mashape_key
|
||||
local url = BASE_URL..'/'..appid..'?mashape-key='..apikey
|
||||
local res,code = https.request(url)
|
||||
if code ~= 200 then return nil end
|
||||
local data = json.decode(res).data
|
||||
return data
|
||||
end
|
||||
|
||||
function play_store:send_playstore_data(data)
|
||||
local title = data.title
|
||||
local developer = data.developer.id
|
||||
local category = data.category.name
|
||||
local rating = data.rating.average
|
||||
local installs = data.performance.installs
|
||||
local description = data.description
|
||||
if data.version == "Varies with device" then
|
||||
appversion = "variiert je nach Gerät"
|
||||
else
|
||||
appversion = data.version
|
||||
end
|
||||
if data.price == 0 then
|
||||
price = "Gratis"
|
||||
else
|
||||
price = data.price
|
||||
end
|
||||
local text = '*'..title..'* von *'..developer..'* aus der Kategorie _'..category..'_, durschnittlich bewertet mit '..rating..' Sternen.\n_'..description..'_\n'..installs..' Installationen, Version '..appversion
|
||||
return text
|
||||
end
|
||||
|
||||
function play_store:action(msg, config, matches)
|
||||
local appid = matches[1]
|
||||
local data = play_store:get_playstore_data(appid)
|
||||
if data == nil then
|
||||
return
|
||||
else
|
||||
utilities.send_reply(msg, play_store:send_playstore_data(data), true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return play_store
|
@ -1,144 +0,0 @@
|
||||
local pocket = {}
|
||||
|
||||
function pocket:init(config)
|
||||
if not cred_data.pocket_consumer_key then
|
||||
print('Missing config value: pocket_consumer_key.')
|
||||
print('pocket.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
pocket.triggers = {
|
||||
"^/pocket(set)(.+)$",
|
||||
"^/pocket (add) (https?://.*)$",
|
||||
"^/pocket (archive) (%d+)$",
|
||||
"^/pocket (readd) (%d+)$",
|
||||
"^/pocket (unfavorite) (%d+)$",
|
||||
"^/pocket (favorite) (%d+)$",
|
||||
"^/pocket (delete) (%d+)$",
|
||||
"^/pocket (unauth)$",
|
||||
"^/pocket$"
|
||||
}
|
||||
|
||||
pocket.doc = [[*
|
||||
]]..config.cmd_pat..[[pocket*: Postet Liste deiner Links
|
||||
*]]..config.cmd_pat..[[pocket* add _(url)_: Fügt diese URL deiner Liste hinzu
|
||||
*]]..config.cmd_pat..[[pocket* archive _[id]_: Archiviere diesen Eintrag
|
||||
*]]..config.cmd_pat..[[pocket* readd _[id]_: De-archiviere diesen Eintrag
|
||||
*]]..config.cmd_pat..[[pocket* favorite _[id]_: Favorisiere diesen Eintrag
|
||||
*]]..config.cmd_pat..[[pocket* unfavorite _[id]_: Entfavorisiere diesen Eintrag
|
||||
*]]..config.cmd_pat..[[pocket* delete _[id]_: Lösche diesen Eintrag
|
||||
*]]..config.cmd_pat..[[pocket* unauth: Löscht deinen Account aus dem Bot]]
|
||||
end
|
||||
|
||||
pocket.command = 'pocket <siehe `/hilfe pocket`>'
|
||||
|
||||
local BASE_URL = 'https://getpocket.com/v3'
|
||||
local consumer_key = cred_data.pocket_consumer_key
|
||||
local headers = {
|
||||
["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF8",
|
||||
["X-Accept"] = "application/json"
|
||||
}
|
||||
|
||||
function pocket:set_pocket_access_token(hash, access_token)
|
||||
if string.len(access_token) ~= 30 then return '*Inkorrekter Access-Token*' end
|
||||
print('Setting pocket in redis hash '..hash..' to users access_token')
|
||||
redis:hset(hash, 'pocket', access_token)
|
||||
return '*Authentifizierung abgeschlossen!*\nDas Plugin kann jetzt verwendet werden.'
|
||||
end
|
||||
|
||||
function pocket:list_pocket_items(access_token)
|
||||
local items = post_petition(BASE_URL..'/get', 'consumer_key='..consumer_key..'&access_token='..access_token..'&state=unread&sort=newest&detailType=simple', headers)
|
||||
|
||||
if items.status == 2 then return 'Keine Elemente eingespeichert.' end
|
||||
if items.status ~= 1 then return 'Ein Fehler beim Holen der Elemente ist aufgetreten.' end
|
||||
|
||||
local text = ''
|
||||
for element in pairs(items.list) do
|
||||
title = items.list[element].given_title
|
||||
if not title or title == "" then title = items.list[element].resolved_title end
|
||||
text = text..'#'..items.list[element].item_id..': '..title..'\n— '..items.list[element].resolved_url..'\n\n'
|
||||
end
|
||||
|
||||
return text
|
||||
end
|
||||
|
||||
function pocket:add_pocket_item(access_token, url)
|
||||
local result = post_petition(BASE_URL..'/add', 'consumer_key='..consumer_key..'&access_token='..access_token..'&url='..url, headers)
|
||||
if result.status ~= 1 then return 'Ein Fehler beim Hinzufügen der URL ist aufgetreten :(' end
|
||||
local given_url = result.item.given_url
|
||||
if result.item.title == "" or not result.item.title then
|
||||
title = 'Seite'
|
||||
else
|
||||
title = '"'..result.item.title..'"'
|
||||
end
|
||||
local code = result.item.response_code
|
||||
|
||||
local text = title..' ('..given_url..') hinzugefügt!'
|
||||
if not code then return text end
|
||||
if code ~= "200" and code ~= "0" then text = text..'\nAber die Seite liefert Fehler '..code..' zurück.' end
|
||||
return text
|
||||
end
|
||||
|
||||
function pocket:modify_pocket_item(access_token, action, id)
|
||||
local result = post_petition(BASE_URL..'/send', 'consumer_key='..consumer_key..'&access_token='..access_token..'&actions=[{"action":"'..action..'","item_id":'..id..'}]', headers)
|
||||
if result.status ~= 1 then return 'Ein Fehler ist aufgetreten :(' end
|
||||
|
||||
if action == 'readd' then
|
||||
if result.action_results[1] == false then
|
||||
return 'Dieser Eintrag existiert nicht!'
|
||||
end
|
||||
local url = result.action_results[1].normal_url
|
||||
return url..' wieder de-archiviert'
|
||||
end
|
||||
if result.action_results[1] == true then
|
||||
return 'Aktion ausgeführt.'
|
||||
else
|
||||
return 'Ein Fehler ist aufgetreten.'
|
||||
end
|
||||
end
|
||||
|
||||
function pocket:action(msg, config, matches)
|
||||
local hash = 'user:'..msg.from.id
|
||||
local access_token = redis:hget(hash, 'pocket')
|
||||
|
||||
if matches[1] == 'set' then
|
||||
local access_token = matches[2]
|
||||
utilities.send_reply(msg, pocket:set_pocket_access_token(hash, access_token), true)
|
||||
local message_id = redis:hget(hash, 'pocket_login_msg')
|
||||
utilities.edit_message(msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true)
|
||||
redis:hdel(hash, 'pocket_login_msg')
|
||||
return
|
||||
end
|
||||
|
||||
if not access_token then
|
||||
local result = utilities.send_reply(msg, '*Bitte authentifiziere dich zuerst, indem du dich anmeldest.*', true, '{"inline_keyboard":[[{"text":"Bei Pocket anmelden","url":"https://brawlbot.tk/apis/callback/pocket/connect.php"}]]}')
|
||||
redis:hset(hash, 'pocket_login_msg', result.result.message_id)
|
||||
return
|
||||
end
|
||||
|
||||
if matches[1] == 'unauth' then
|
||||
redis:hdel(hash, 'pocket')
|
||||
utilities.send_reply(msg, 'Erfolgreich ausgeloggt! Du kannst den Zugriff [in deinen Einstellungen](https://getpocket.com/connected_applications) endgültig entziehen.', true)
|
||||
return
|
||||
end
|
||||
|
||||
if matches[1] == 'add' then
|
||||
utilities.send_reply(msg, pocket:add_pocket_item(access_token, matches[2]))
|
||||
return
|
||||
end
|
||||
|
||||
if matches[1] == 'archive' or matches[1] == 'delete' or matches[1] == 'readd' or matches[1] == 'favorite' or matches[1] == 'unfavorite' then
|
||||
utilities.send_reply(msg, pocket:modify_pocket_item(access_token, matches[1], matches[2]))
|
||||
return
|
||||
end
|
||||
|
||||
if msg.chat.type == 'chat' or msg.chat.type == 'supergroup' then
|
||||
utilities.send_reply(msg, 'Ausgeben deiner privaten Pocket-Liste in einem öffentlichen Chat wird feige verweigert. Bitte schreibe mich privat an!', true)
|
||||
return
|
||||
else
|
||||
utilities.send_reply(msg, pocket:list_pocket_items(access_token))
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return pocket
|
@ -1,77 +0,0 @@
|
||||
local reddit = {}
|
||||
|
||||
reddit.command = 'reddit [r/subreddit | Suchbegriff]'
|
||||
|
||||
function reddit:init(config)
|
||||
reddit.triggers = utilities.triggers(self.info.username, config.cmd_pat, {'^/r/'}):t('reddit', true):t('r', true):t('r/', true).table
|
||||
reddit.doc = [[*
|
||||
]]..config.cmd_pat..[[r* _[r/subreddit | Suchbegriff]_: Gibt Top-Posts oder Ergebnisse eines Subreddits aus. Wenn kein Argument gegeben ist, wird /r/all genommen.]]
|
||||
end
|
||||
|
||||
local format_results = function(posts)
|
||||
local output = ''
|
||||
for _,v in ipairs(posts) do
|
||||
local post = v.data
|
||||
local title = post.title:gsub('%[', '('):gsub('%]', ')'):gsub('&', '&')
|
||||
if title:len() > 256 then
|
||||
title = title:sub(1, 253)
|
||||
title = utilities.trim(title) .. '...'
|
||||
end
|
||||
local short_url = 'https://redd.it/' .. post.id
|
||||
local s = '[' .. unescape(title) .. '](' .. short_url .. ')'
|
||||
if post.domain and not post.is_self and not post.over_18 then
|
||||
s = '`[`[' .. post.domain .. '](' .. post.url:gsub('%)', '\\)') .. ')`]` ' .. s
|
||||
end
|
||||
output = output .. '• ' .. s .. '\n'
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
reddit.subreddit_url = 'https://www.reddit.com/%s/.json?limit='
|
||||
reddit.search_url = 'https://www.reddit.com/search.json?q=%s&limit='
|
||||
reddit.rall_url = 'https://www.reddit.com/.json?limit='
|
||||
|
||||
function reddit:action(msg, config)
|
||||
-- Eight results in PM, four results elsewhere.
|
||||
local limit = 4
|
||||
if msg.chat.type == 'private' then
|
||||
limit = 8
|
||||
end
|
||||
local text = msg.text_lower
|
||||
if text:match('^/r/.') then
|
||||
-- Normalize input so this hack works easily.
|
||||
text = msg.text_lower:gsub('^/r/', config.cmd_pat..'r r/')
|
||||
end
|
||||
local input = utilities.input(text)
|
||||
local source, url
|
||||
if input then
|
||||
if input:match('^r/.') then
|
||||
input = utilities.get_word(input, 1)
|
||||
url = reddit.subreddit_url:format(input) .. limit
|
||||
source = '*/' .. utilities.md_escape(input) .. '*\n'
|
||||
else
|
||||
input = utilities.input(msg.text)
|
||||
source = '*Ergebnisse für* _' .. utilities.md_escape(input) .. '_ *:*\n'
|
||||
input = URL.escape(input)
|
||||
url = reddit.search_url:format(input) .. limit
|
||||
end
|
||||
else
|
||||
url = reddit.rall_url .. limit
|
||||
source = '*/r/all*\n'
|
||||
end
|
||||
local jstr, res = https.request(url)
|
||||
if res ~= 200 then
|
||||
utilities.send_reply(msg, config.errors.results)
|
||||
else
|
||||
local jdat = json.decode(jstr)
|
||||
if #jdat.data.children == 0 then
|
||||
utilities.send_reply(msg, config.errors.results)
|
||||
else
|
||||
local output = format_results(jdat.data.children)
|
||||
output = source .. output
|
||||
utilities.send_message(msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return reddit
|
@ -1,52 +0,0 @@
|
||||
local set = {}
|
||||
|
||||
set.command = 'set <Variable> <Wert>'
|
||||
|
||||
function set:init(config)
|
||||
set.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('set', true).table
|
||||
set.doc = [[*
|
||||
]]..config.cmd_pat..[[set* _<Variable>_ _<Wert>_: Speichert eine Variable mit einem Wert
|
||||
*]]..config.cmd_pat..[[set* _<Variable>_ _nil_: Löscht Variable
|
||||
Nutze `/get <Variable>` zum Abrufen]]
|
||||
end
|
||||
|
||||
function set:save_value(msg, name, value)
|
||||
local hash = get_redis_hash(msg, 'variables')
|
||||
if hash then
|
||||
print('Saving variable to redis hash '..hash)
|
||||
redis:hset(hash, name, value)
|
||||
return "Gespeichert: "..name.." = "..value
|
||||
end
|
||||
end
|
||||
|
||||
function set:delete_value(msg, name)
|
||||
local hash = get_redis_hash(msg, 'variables')
|
||||
if redis:hexists(hash, name) == true then
|
||||
print('Deleting variable from redis hash '..hash)
|
||||
redis:hdel(hash, name)
|
||||
return 'Variable "'..name..'" erfolgreich gelöscht!'
|
||||
else
|
||||
return 'Du kannst keine Variable löschen, die nicht existiert .-.'
|
||||
end
|
||||
end
|
||||
|
||||
function set:action(msg)
|
||||
local input = utilities.input(msg.text)
|
||||
if not input or not input:match('([^%s]+) (.+)') then
|
||||
utilities.send_message(msg.chat.id, set.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
local name = input:match('([^%s]+) ')
|
||||
local value = input:match(' (.+)')
|
||||
|
||||
if value == "nil" then
|
||||
output = set:delete_value(msg, name)
|
||||
else
|
||||
output = set:save_value(msg, name, value)
|
||||
end
|
||||
|
||||
utilities.send_message(msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
|
||||
return set
|
@ -1,56 +0,0 @@
|
||||
local settings = {}
|
||||
|
||||
settings.triggers = {
|
||||
"^(⚙ [Ee]instellungen)$",
|
||||
"^(/settings)$",
|
||||
"^(💤 [Aa][Ff][Kk]%-[Kk]eyboard einschalten)",
|
||||
"^(💤 [Aa][Ff][Kk]%-[Kk]eyboard ausschalten)",
|
||||
"^(❌ [Ee]instellungen verstecken)"
|
||||
}
|
||||
|
||||
--[[
|
||||
|
||||
[
|
||||
[ "Top Left", "Top Right" ],
|
||||
[ "Bottom Left", "Bottom Right" ]
|
||||
]
|
||||
|
||||
]]
|
||||
|
||||
function settings:keyboard(user_id)
|
||||
if redis:hget('user:'..user_id, 'afk_keyboard') == 'true' then
|
||||
afk_button = '{"text":"💤 AFK-Keyboard ausschalten"}'
|
||||
else
|
||||
afk_button = '{"text":"💤 AFK-Keyboard einschalten"}'
|
||||
end
|
||||
local hide_settings_button = '{"text":"❌ Einstellungen verstecken"}'
|
||||
|
||||
local settings_keyboard = '[['..afk_button..','..hide_settings_button..']]'
|
||||
return settings_keyboard
|
||||
end
|
||||
|
||||
function settings:action(msg, config, matches)
|
||||
if msg.chat.type ~= "private" then
|
||||
return
|
||||
end
|
||||
|
||||
local hash = 'user:'..msg.from.id
|
||||
|
||||
if matches[1] == '⚙ Einstellungen' or matches[1] == '/settings' then
|
||||
utilities.send_reply(msg, 'Was möchtest du einstellen?', false, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}')
|
||||
return
|
||||
elseif matches[1] == '💤 AFK-Keyboard einschalten' then
|
||||
redis:hset(hash, 'afk_keyboard', 'true')
|
||||
utilities.send_reply(msg, 'Das AFK-Keyboard wurde erfolgreich *eingeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}')
|
||||
return
|
||||
elseif matches[1] == '💤 AFK-Keyboard ausschalten' then
|
||||
redis:hset(hash, 'afk_keyboard', 'false')
|
||||
utilities.send_reply(msg, 'Das AFK-Keyboard wurde erfolgreich *ausgeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}')
|
||||
return
|
||||
elseif matches[1] == '❌ Einstellungen verstecken' then
|
||||
utilities.send_reply(msg, 'Um die Einstellungen wieder einzublenden, führe /settings aus.', true, '{"hide_keyboard":true}')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return settings
|
@ -1,37 +0,0 @@
|
||||
local soundcloud = {}
|
||||
|
||||
soundcloud.triggers = {
|
||||
"soundcloud.com/([A-Za-z0-9-/-_-.]+)"
|
||||
}
|
||||
|
||||
local BASE_URL = 'http://api.soundcloud.com/resolve.json'
|
||||
local client_id = cred_data.soundcloud_client_id
|
||||
|
||||
function soundcloud:send_soundcloud_info(sc_url)
|
||||
local url = BASE_URL..'?url=http://soundcloud.com/'..sc_url..'&client_id='..client_id
|
||||
|
||||
local res,code = http.request(url)
|
||||
if code ~= 200 then return nil end
|
||||
local data = json.decode(res)
|
||||
|
||||
local title = data.title
|
||||
local description = data.description
|
||||
local user = data.user.username
|
||||
local user = 'Unbekannt'
|
||||
local genre = data.genre
|
||||
local playback_count = data.playback_count
|
||||
local milliseconds = data.duration
|
||||
local totalseconds = math.floor(milliseconds / 1000)
|
||||
local duration = makeHumanTime(totalseconds)
|
||||
|
||||
local text = '*'..title..'* von _'..user..'_\n_(Tag: '..genre..', '..duration..'; '..playback_count..' mal angehört)_\n'..description
|
||||
return text
|
||||
end
|
||||
|
||||
function soundcloud:action(msg, config, matches)
|
||||
local text = soundcloud:send_soundcloud_info(matches[1])
|
||||
if not text then utilities.send_reply(msg, config.errors.connection) return end
|
||||
utilities.send_reply(msg, text, true)
|
||||
end
|
||||
|
||||
return soundcloud
|
@ -1,49 +0,0 @@
|
||||
local streamable = {}
|
||||
|
||||
streamable.triggers = {
|
||||
"streamable.com/([A-Za-z0-9-_-]+)",
|
||||
}
|
||||
|
||||
function streamable:send_streamable_video(shortcode, msg)
|
||||
local BASE_URL = "https://api.streamable.com"
|
||||
local url = BASE_URL..'/videos/'..shortcode
|
||||
local res,code = https.request(url)
|
||||
if code ~= 200 then return 'HTTP-Fehler' end
|
||||
local data = json.decode(res)
|
||||
if data.status ~= 2 then utilities.send_reply(msg, "Video ist (noch) nicht verfügbar.") return end
|
||||
|
||||
if data.files.webm then
|
||||
if data.title == "" then title = shortcode..'.webm' else title = data.title..'.webm' end
|
||||
url = 'https:'..data.files.webm.url
|
||||
width = data.files.webm.width
|
||||
height = data.files.webm.height
|
||||
if data.files.webm.size > 50000000 then
|
||||
local size = math.floor(data.files.webm.size / 1000000)
|
||||
utilities.send_reply(msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true)
|
||||
return
|
||||
end
|
||||
elseif data.files.mp4 then
|
||||
if data.title == "" then title = shortcode..'.mp4' else title = data.title..'.mp4' end
|
||||
url = 'https:'..data.files.mp4.url
|
||||
width = data.files.mp4.width
|
||||
height = data.files.mp4.height
|
||||
if data.files.mp4.size > 50000000 then
|
||||
local size = math.floor(data.files.mp4.size / 1000000)
|
||||
utilities.send_reply(msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
utilities.send_typing(msg.chat.id, 'upload_video')
|
||||
local file = download_to_file(url, title)
|
||||
utilities.send_video(msg.chat.id, file, nil, msg.message_id, nil, width, height)
|
||||
return
|
||||
end
|
||||
|
||||
function streamable:action(msg, config, matches)
|
||||
local shortcode = matches[1]
|
||||
streamable:send_streamable_video(shortcode, msg)
|
||||
return
|
||||
end
|
||||
|
||||
return streamable
|
@ -1,31 +0,0 @@
|
||||
local tex = {}
|
||||
|
||||
tex.command = 'tex <LaTeX>'
|
||||
|
||||
function tex:init(config)
|
||||
tex.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('tex', true).table
|
||||
tex.doc = [[*
|
||||
]]..config.cmd_pat..[[tex* _<LaTeX>_: Konvertiert LaTeX in ein Bild]]
|
||||
end
|
||||
|
||||
function tex:action(msg, config)
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
utilities.send_message(msg.chat.id, tex.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local eq = URL.escape(input)
|
||||
|
||||
local url = "http://latex.codecogs.com/png.download?"
|
||||
.."\\dpi{300}%20\\LARGE%20"..eq
|
||||
local file = download_to_file(url, 'latex.png')
|
||||
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
|
||||
end
|
||||
|
||||
return tex
|
@ -1,92 +0,0 @@
|
||||
local tv = {}
|
||||
|
||||
local xml = require("xml")
|
||||
|
||||
tv.command = 'tv <TV-Serie>'
|
||||
|
||||
function tv:init(config)
|
||||
tv.triggers = {
|
||||
"^/tv (.+)$"
|
||||
}
|
||||
tv.doc = [[*
|
||||
]]..config.cmd_pat..[[tv*_ <TV-Serie>_: Sendet Infos zur TV-Serie]]
|
||||
end
|
||||
|
||||
local BASE_URL = 'http://thetvdb.com/api'
|
||||
|
||||
local makeOurDate = function(dateString)
|
||||
local pattern = "(%d+)%-(%d+)%-(%d+)"
|
||||
local year, month, day = dateString:match(pattern)
|
||||
return day..'.'..month..'.'..year
|
||||
end
|
||||
|
||||
|
||||
function tv:get_tv_info(series)
|
||||
local url = BASE_URL..'/GetSeries.php?seriesname='..series..'&language=de'
|
||||
local res,code = http.request(url)
|
||||
if code ~= 200 then return "HTTP-ERROR" end
|
||||
local result = xml.load(res)
|
||||
if not xml.find(result, 'seriesid') then return "NOTFOUND" end
|
||||
return result
|
||||
end
|
||||
|
||||
function tv:send_tv_data(result, msg)
|
||||
local title = xml.find(result, 'SeriesName')[1]
|
||||
local id = xml.find(result, 'seriesid')[1]
|
||||
|
||||
if xml.find(result, 'AliasNames') and xml.find(result, 'AliasNames')[1] ~= title then
|
||||
alias = '\noder: '..xml.find(result, 'AliasNames')[1]
|
||||
else
|
||||
alias = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'Overview') then
|
||||
desc = '\n_'..string.sub(xml.find(result, 'Overview')[1], 1, 250) .. '..._'
|
||||
else
|
||||
desc = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'FirstAired') then
|
||||
aired = '\n*Erstausstrahlung:* '..makeOurDate(xml.find(result, 'FirstAired')[1])
|
||||
else
|
||||
aired = ''
|
||||
end
|
||||
|
||||
|
||||
if xml.find(result, 'Network') then
|
||||
publisher = '\n*Publisher:* '..xml.find(result, 'Network')[1]
|
||||
else
|
||||
publisher = ''
|
||||
end
|
||||
|
||||
if xml.find(result, 'IMDB_ID') then
|
||||
imdb = '\n[IMDB-Seite](http://www.imdb.com/title/'..xml.find(result, 'IMDB_ID')[1]..')'
|
||||
else
|
||||
imdb = ''
|
||||
end
|
||||
|
||||
local text = '*'..title..'*'..alias..aired..publisher..imdb..desc..'\n[TVDB-Seite besuchen](http://thetvdb.com/?id='..id..'&tab=series)'
|
||||
if xml.find(result, 'banner') then
|
||||
local image_url = 'http://www.thetvdb.com/banners/'..xml.find(result, 'banner')[1]
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
|
||||
end
|
||||
utilities.send_reply(msg, text, true)
|
||||
end
|
||||
|
||||
|
||||
function tv:action(msg, config, matches)
|
||||
local series = URL.escape(matches[1])
|
||||
local tv_info = tv:get_tv_info(series)
|
||||
if tv_info == "NOTFOUND" then
|
||||
utilities.send_reply(msg, config.errors.results)
|
||||
return
|
||||
elseif tv_info == "HTTP-ERROR" then
|
||||
utilities.send_reply(msg, config.errors.connection)
|
||||
return
|
||||
else
|
||||
tv:send_tv_data(tv_info, msg)
|
||||
end
|
||||
end
|
||||
|
||||
return tv
|
@ -1,54 +0,0 @@
|
||||
local wiimmfi = {}
|
||||
|
||||
function wiimmfi:init(config)
|
||||
wiimmfi.triggers = {
|
||||
"^/(mkw)$",
|
||||
"^/wiimmfi$",
|
||||
"^/wfc$"
|
||||
}
|
||||
wiimmfi.doc = [[*
|
||||
]]..config.cmd_pat..[[wfc*: Zeigt alle Wiimmfi-Spieler an
|
||||
*]]..config.cmd_pat..[[mkw*: Zeigt alle Mario-Kart-Wii-Spieler an]]
|
||||
end
|
||||
|
||||
wiimmfi.command = 'wfc, /mkw'
|
||||
|
||||
function wiimmfi:getplayer(game)
|
||||
local url = 'http://wiimmfi.de/game'
|
||||
local res,code = http.request(url)
|
||||
if code ~= 200 then return "Fehler beim Abrufen von wiimmfi.de" end
|
||||
if game == 'mkw' then
|
||||
local players = string.match(res, "<td align%=center><a href%=\"/game/mariokartwii\".->(.-)</a>")
|
||||
if players == nil then players = 0 end
|
||||
text = 'Es spielen gerade '..players..' Spieler Mario Kart Wii'
|
||||
else
|
||||
local players = string.match(res, "</tr><tr.->(.-)<th colspan%=3")
|
||||
local players = string.gsub(players, "</a></td><td>.-<a href=\".-\">", ": ")
|
||||
local players = string.gsub(players, "<td.->", "")
|
||||
local players = string.gsub(players, "Wii</td>", "")
|
||||
local players = string.gsub(players, "WiiWare</td>", "")
|
||||
local players = string.gsub(players, "NDS</td>", "")
|
||||
local players = string.gsub(players, "<th.->", "")
|
||||
local players = string.gsub(players, "<tr.->", "")
|
||||
local players = string.gsub(players, "</tr>", "")
|
||||
local players = string.gsub(players, "</th>", "")
|
||||
local players = string.gsub(players, "<a.->", "")
|
||||
local players = string.gsub(players, "</a>", "")
|
||||
local players = string.gsub(players, "</td>", "")
|
||||
if players == nil then players = 'Momentan spielt keiner auf Wiimmfi :(' end
|
||||
text = players
|
||||
end
|
||||
return text
|
||||
end
|
||||
|
||||
function wiimmfi:action(msg, config, matches)
|
||||
if matches[1] == "mkw" then
|
||||
utilities.send_reply(msg, wiimmfi:getplayer('mkw'))
|
||||
return
|
||||
else
|
||||
utilities.send_reply(msg, wiimmfi:getplayer())
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return wiimmfi
|
@ -1,53 +0,0 @@
|
||||
local yourls = {}
|
||||
|
||||
function yourls:init(config)
|
||||
if not cred_data.yourls_site_url then
|
||||
print('Missing config value: yourls_site_url.')
|
||||
print('yourls.lua will not be enabled.')
|
||||
return
|
||||
elseif not cred_data.yourls_signature_token then
|
||||
print('Missing config value: yourls_signature_token.')
|
||||
print('yourls.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
yourls.triggers = {
|
||||
"^/yourls (https?://[%w-_%.%?%.:/%+=&]+)"
|
||||
}
|
||||
end
|
||||
|
||||
local SITE_URL = cred_data.yourls_site_url
|
||||
local signature = cred_data.yourls_signature_token
|
||||
local BASE_URL = SITE_URL..'/yourls-api.php'
|
||||
|
||||
function yourls:prot_url(url)
|
||||
local url, h = string.gsub(url, "http://", "")
|
||||
local url, hs = string.gsub(url, "https://", "")
|
||||
local protocol = "http"
|
||||
if hs == 1 then
|
||||
protocol = "https"
|
||||
end
|
||||
return url, protocol
|
||||
end
|
||||
|
||||
function yourls:create_yourls_link(long_url, protocol)
|
||||
local url = BASE_URL..'?format=simple&signature='..signature..'&action=shorturl&url='..long_url
|
||||
if protocol == "http" then
|
||||
link,code = http.request(url)
|
||||
else
|
||||
link,code = https.request(url)
|
||||
end
|
||||
if code ~= 200 then
|
||||
link = 'Ein Fehler ist aufgetreten. '..link
|
||||
end
|
||||
return link
|
||||
end
|
||||
|
||||
function yourls:action(msg, config, matches)
|
||||
local long_url = matches[1]
|
||||
local baseurl, protocol = yourls:prot_url(SITE_URL)
|
||||
utilities.send_reply(msg, yourls:create_yourls_link(long_url, protocol))
|
||||
return
|
||||
end
|
||||
|
||||
return yourls
|
Reference in New Issue
Block a user