- Ein paar überflüssige Plugins entfernt

- Bitly_create + Pocket: Login-Flow überarbeitet, Deep-Linking von der Website zurück in Telegram
This commit is contained in:
Andreas Bielawski 2016-07-08 19:18:09 +02:00
parent 0a94c93560
commit 730e0dbf75
7 changed files with 14 additions and 1735 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,87 +0,0 @@
-- Credit to Heitor (tg:Wololo666; gh:heitorPB) for this plugin.
local apod = {}
local HTTPS = require('ssl.https')
local JSON = require('dkjson')
local URL = require('socket.url')
local utilities = require('otouto.utilities')
apod.command = 'apod [date]'
function apod:init(config)
apod.triggers = utilities.triggers(self.info.username, config.cmd_pat)
:t('apod', true):t('apodhd', true):t('apodtext', true).table
apod.doc = [[```
]]..config.cmd_pat..[[apod [query]
Returns the Astronomy Picture of the Day.
If the query is a date, in the format YYYY-MM-DD, the APOD of that day is returned.
]]..config.cmd_pat..[[apodhd [query]
Returns the image in HD, if available.
]]..config.cmd_pat..[[apodtext [query]
Returns the explanation of the APOD.
Source: nasa.gov
```]]
end
function apod:action(msg, config)
if not config.nasa_api_key then
config.nasa_api_key = 'DEMO_KEY'
end
local input = utilities.input(msg.text)
local date = '*'
local disable_page_preview = false
local url = 'https://api.nasa.gov/planetary/apod?api_key=' .. config.nasa_api_key
if input then
if input:match('(%d+)%-(%d+)%-(%d+)$') then
url = url .. '&date=' .. URL.escape(input)
date = date .. input
else
utilities.send_message(self, msg.chat.id, apod.doc, true, msg.message_id, true)
return
end
else
date = date .. os.date("%F")
end
date = date .. '*\n'
local jstr, res = HTTPS.request(url)
if res ~= 200 then
utilities.send_reply(self, msg, config.errors.connection)
return
end
local jdat = JSON.decode(jstr)
if jdat.error then
utilities.send_reply(self, msg, config.errors.results)
return
end
local img_url = jdat.url
if string.match(msg.text, '^'..config.cmd_pat..'apodhd*') then
img_url = jdat.hdurl or jdat.url
end
local output = date .. '[' .. jdat.title .. '](' .. img_url .. ')'
if string.match(msg.text, '^'..config.cmd_pat..'apodtext*') then
output = output .. '\n' .. jdat.explanation
disable_page_preview = true
end
if jdat.copyright then
output = output .. '\nCopyright: ' .. jdat.copyright
end
utilities.send_message(self, msg.chat.id, output, disable_page_preview, nil, true)
end
return apod

View File

@ -1,35 +0,0 @@
local bandersnatch = {}
local utilities = require('otouto.utilities')
bandersnatch.command = 'bandersnatch'
function bandersnatch:init(config)
bandersnatch.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('bandersnatch'):t('bc').table
bandersnatch.doc = [[```
Shun the frumious Bandersnatch.
Alias: ]]..config.cmd_pat..[[bc
```]]
end
local fullnames = { "Wimbledon Tennismatch", "Rinkydink Curdlesnoot", "Butawhiteboy Cantbekhan", "Benadryl Claritin", "Bombadil Rivendell", "Wanda's Crotchfruit", "Biblical Concubine", "Syphilis Cankersore", "Buckminster Fullerene", "Bourgeoisie Capitalist" }
local firstnames = { "Bumblebee", "Bandersnatch", "Broccoli", "Rinkydink", "Bombadil", "Boilerdang", "Bandicoot", "Fragglerock", "Muffintop", "Congleton", "Blubberdick", "Buffalo", "Benadryl", "Butterfree", "Burberry", "Whippersnatch", "Buttermilk", "Beezlebub", "Budapest", "Boilerdang", "Blubberwhale", "Bumberstump", "Bulbasaur", "Cogglesnatch", "Liverswort", "Bodybuild", "Johnnycash", "Bendydick", "Burgerking", "Bonaparte", "Bunsenburner", "Billiardball", "Bukkake", "Baseballmitt", "Blubberbutt", "Baseballbat", "Rumblesack", "Barister", "Danglerack", "Rinkydink", "Bombadil", "Honkytonk", "Billyray", "Bumbleshack", "Snorkeldink", "Anglerfish", "Beetlejuice", "Bedlington", "Bandicoot", "Boobytrap", "Blenderdick", "Bentobox", "Anallube", "Pallettown", "Wimbledon", "Buttercup", "Blasphemy", "Snorkeldink", "Brandenburg", "Barbituate", "Snozzlebert", "Tiddleywomp", "Bouillabaisse", "Wellington", "Benetton", "Bendandsnap", "Timothy", "Brewery", "Bentobox", "Brandybuck", "Benjamin", "Buckminster", "Bourgeoisie", "Bakery", "Oscarbait", "Buckyball", "Bourgeoisie", "Burlington", "Buckingham", "Barnoldswick" }
local lastnames = { "Coddleswort", "Crumplesack", "Curdlesnoot", "Calldispatch", "Humperdinck", "Rivendell", "Cuttlefish", "Lingerie", "Vegemite", "Ampersand", "Cumberbund", "Candycrush", "Clombyclomp", "Cragglethatch", "Nottinghill", "Cabbagepatch", "Camouflage", "Creamsicle", "Curdlemilk", "Upperclass", "Frumblesnatch", "Crumplehorn", "Talisman", "Candlestick", "Chesterfield", "Bumbersplat", "Scratchnsniff", "Snugglesnatch", "Charizard", "Carrotstick", "Cumbercooch", "Crackerjack", "Crucifix", "Cuckatoo", "Cockletit", "Collywog", "Capncrunch", "Covergirl", "Cumbersnatch", "Countryside", "Coggleswort", "Splishnsplash", "Copperwire", "Animorph", "Curdledmilk", "Cheddarcheese", "Cottagecheese", "Crumplehorn", "Snickersbar", "Banglesnatch", "Stinkyrash", "Cameltoe", "Chickenbroth", "Concubine", "Candygram", "Moldyspore", "Chuckecheese", "Cankersore", "Crimpysnitch", "Wafflesmack", "Chowderpants", "Toodlesnoot", "Clavichord", "Cuckooclock", "Oxfordshire", "Cumbersome", "Chickenstrips", "Battleship", "Commonwealth", "Cunningsnatch", "Custardbath", "Kryptonite", "Curdlesnoot", "Cummerbund", "Coochyrash", "Crackerdong", "Crackerdong", "Curdledong", "Crackersprout", "Crumplebutt", "Colonist", "Coochierash", "Thundersnatch" }
function bandersnatch:action(msg)
local output
if math.random(10) == 10 then
output = fullnames[math.random(#fullnames)]
else
output = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)]
end
utilities.send_message(self, msg.chat.id, '_'..output..'_', true, nil, true)
end
return bandersnatch

View File

@ -1,53 +0,0 @@
local bible = {}
local HTTP = require('socket.http')
local URL = require('socket.url')
local utilities = require('otouto.utilities')
function bible:init(config)
if not config.biblia_api_key then
print('Missing config value: biblia_api_key.')
print('bible.lua will not be enabled.')
return
end
bible.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('bible', true):t('b', true).table
bible.doc = [[```
]]..config.cmd_pat..[[bible <reference>
Returns a verse from the American Standard Version of the Bible, or an apocryphal verse from the King James Version. Results from biblia.com.
Alias: ]]..config.cmd_pat..[[b
```]]
end
bible.command = 'bible <reference>'
function bible:action(msg, config)
local input = utilities.input(msg.text)
if not input then
utilities.send_message(self, msg.chat.id, bible.doc, true, msg.message_id, true)
return
end
local url = 'http://api.biblia.com/v1/bible/content/ASV.txt?key=' .. config.biblia_api_key .. '&passage=' .. URL.escape(input)
local output, res = HTTP.request(url)
if not output or res ~= 200 or output:len() == 0 then
url = 'http://api.biblia.com/v1/bible/content/KJVAPOC.txt?key=' .. config.biblia_api_key .. '&passage=' .. URL.escape(input)
output, res = HTTP.request(url)
end
if not output or res ~= 200 or output:len() == 0 then
output = config.errors.results
end
if output:len() > 4000 then
output = 'The text is too long to post here. Try being more specific.'
end
utilities.send_reply(self, msg, output)
end
return bible

View File

@ -1,70 +0,0 @@
-- Credit to Juan (tg:JuanPotato; gh:JuanPotato) for this plugin.
-- Or rather, the seven lines that actually mean anything.
local bing = {}
local URL = require('socket.url')
local JSON = require('dkjson')
local mime = require('mime')
local https = require('ssl.https')
local ltn12 = require('ltn12')
local utilities = require('otouto.utilities')
bing.command = 'bing <query>'
bing.doc = [[```
/bing <query>
Returns the top web search results from Bing.
Aliases: /g, /google
```]]
bing.search_url = 'https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?Query=\'%s\'&$format=json'
function bing:init(config)
if not config.bing_api_key then
print('Missing config value: bing_api_key.')
print('bing.lua will not be enabled.')
return
end
bing.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('bing', true):t('g', true):t('google', true).table
end
function bing: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_reply(self, msg, bing.doc, true)
return
end
end
local url = bing.search_url:format(URL.escape(input))
local resbody = {}
local _,b,_ = https.request{
url = url,
headers = { ["Authorization"] = "Basic " .. mime.b64(":" .. config.bing_api_key) },
sink = ltn12.sink.table(resbody),
}
if b ~= 200 then
utilities.send_reply(self, msg, config.errors.results)
return
end
local dat = JSON.decode(table.concat(resbody))
local limit = 4
if msg.chat.type == 'private' then
limit = 8
end
if limit > #dat.d.results then
limit = #dat.d.results
end
local reslist = {}
for i = 1, limit do
local result = dat.d.results[i]
local s = '• [' .. result.Title:gsub('%]', '\\]') .. '](' .. result.Url:gsub('%)', '\\)') .. ')'
table.insert(reslist, s)
end
local output = '*Search results for* _' .. utilities.md_escape(input) .. '_ *:*\n' .. table.concat(reslist, '\n')
utilities.send_message(self, msg.chat.id, output, true, nil, true)
end
return bing

View File

@ -25,7 +25,7 @@ function bitly_create:init(config)
end end
bitly_create.triggers = { bitly_create.triggers = {
"^/short (auth) (.+)$", "^/short(auth)(.+)$",
"^/short (auth)$", "^/short (auth)$",
"^/short (unauth)$", "^/short (unauth)$",
"^/short (me)$", "^/short (me)$",
@ -93,11 +93,15 @@ function bitly_create:action(msg, config, matches)
if matches[1] == 'auth' and matches[2] then if matches[1] == 'auth' and matches[2] then
utilities.send_reply(self, msg, bitly_create:get_bitly_access_token(hash, matches[2]), true) utilities.send_reply(self, msg, bitly_create:get_bitly_access_token(hash, matches[2]), true)
local message_id = redis:hget(hash, 'bitly_login_msg')
utilities.edit_message(self, msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true)
redis:hdel(hash, 'bitly_login_msg')
return return
end end
if matches[1] == 'auth' then if matches[1] == 'auth' then
utilities.send_reply(self, msg, 'Bitte logge dich ein und folge den Anweisungen:\n[Bei Bitly anmelden](https://bitly.com/oauth/authorize?client_id='..client_id..'&redirect_uri='..redirect_uri..')', true) local result = utilities.send_reply(self, 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 return
end end

View File

@ -14,7 +14,7 @@ function pocket:init(config)
end end
pocket.triggers = { pocket.triggers = {
"^/pocket (set) (.+)$", "^/pocket(set)(.+)$",
"^/pocket (add) (https?://.*)$", "^/pocket (add) (https?://.*)$",
"^/pocket (archive) (%d+)$", "^/pocket (archive) (%d+)$",
"^/pocket (readd) (%d+)$", "^/pocket (readd) (%d+)$",
@ -109,11 +109,15 @@ function pocket:action(msg, config, matches)
if matches[1] == 'set' then if matches[1] == 'set' then
local access_token = matches[2] local access_token = matches[2]
utilities.send_reply(self, msg, pocket:set_pocket_access_token(hash, access_token), true) utilities.send_reply(self, msg, pocket:set_pocket_access_token(hash, access_token), true)
local message_id = redis:hget(hash, 'pocket_login_msg')
utilities.edit_message(self, msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true)
redis:hdel(hash, 'pocket_login_msg')
return return
end end
if not access_token then if not access_token then
utilities.send_reply(self, msg, 'Bitte authentifiziere dich zuerst, indem du dich anmeldest:\n[Bei Pocket anmelden](https://brawlbot.tk/apis/callback/pocket/connect.php)', true) local result = utilities.send_reply(self, 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 return
end end