Seeeeehr großes Update

Meiste Änderungen von Brawl345/Brawlbot-v2
Einige Pattern angepasst
Einiges übersetzt
Und noch einiges mehr
Stabilitätsverbesserungen
This commit is contained in:
Akamaru 2016-08-01 21:07:27 +02:00
parent d99c805c3d
commit 5856804891
121 changed files with 742 additions and 1063 deletions

View File

@ -25,10 +25,6 @@ Sende /hilfe, um zu starten
-- NOTE that it doesn't matter, if the chat is whitelisted! The USER must be whitelisted!
enable_inline_for_everyone = true,
-- Botan.io statistics
enable_statistics = false,
botan_token = '',
errors = { -- Generic error messages used in various plugins.
generic = 'An unexpected error occurred.',
connection = 'Verbindungsfehler.',

View File

@ -1,17 +1,11 @@
local bot = {}
-- Requires are moved to init to allow for reloads.
local bindings -- Load Telegram bindings.
local utilities -- Load miscellaneous and cross-plugin functions.
local redis = (loadfile "./miku/redis.lua")()
bindings = require('miku.bindings')
utilities = require('miku.utilities')
bot.version = '160726'
bot.version = '160801'
function bot:init(config) -- The function run when the bot is started or reloaded.
bindings = require('miku.bindings')
utilities = require('miku.utilities')
redis = (loadfile "./miku/redis.lua")()
cred_data = load_cred()
assert(
@ -239,7 +233,6 @@ function match_plugins(self, msg, config, plugin)
end
end
print(plugin.name..' ausgelöst')
plugin_name = plugin.name
return plugin.action(self, msg, config, matches)
end)
if not success then
@ -255,15 +248,6 @@ function match_plugins(self, msg, config, plugin)
return
end
-- Analytics
if config.enable_analytics and config.botan_token ~= '' then
for _,plugin in ipairs(self.plugins) do
if plugin.name == 'botan' then
plugin.action(self, msg, config, nil, plugin_name)
end
end
end
-- If the action returns a table, make that table the new msg.
if type(result) == 'table' then
msg = result

View File

@ -1,11 +1,5 @@
local ninegag = {}
local HTTP = require('socket.http')
local URL = require('socket.url')
local JSON = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
ninegag.command = '9gag'
function ninegag:init(config)
@ -23,9 +17,9 @@ end
local url = "http://api-9gag.herokuapp.com/"
function ninegag:get_9GAG()
local b,c = HTTP.request(url)
local b,c = http.request(url)
if c ~= 200 then return nil end
local gag = JSON.decode(b)
local gag = json.decode(b)
-- random max json table size
local i = math.random(#gag)
@ -36,9 +30,9 @@ function ninegag:get_9GAG()
end
function ninegag:inline_callback(inline_query, config)
local res, code = HTTP.request(url)
local res, code = http.request(url)
if code ~= 200 then return end
local gag = JSON.decode(res)
local gag = json.decode(res)
local results = '['
for n in pairs(gag) do

View File

@ -1,7 +1,6 @@
local about = {}
local bot = require('miku.bot')
local utilities = require('miku.utilities')
about.command = 'about'
about.doc = '`Sendet Informationen über den Bot.`'
@ -18,7 +17,7 @@ function about:action(msg, config)
-- disabled to restore old behaviour
-- if msg.forward_from then return end
local output = config.about_text .. '\n[Mikudayobot](https://github.com/Akamaru/Mikubot-V2) v'..bot.version..' von @Akamaru, basierend auf [Otouto](https://github.com/topkecleon/otouto) von topkecleon.'
local output = config.about_text .. '\n[Mikudayobot](https://github.com/Akamaru/Mikubot-V2) v'..bot.version..' von @Akamaru, basierend auf [miku](https://github.com/topkecleon/miku) von topkecleon.'
if
(msg.new_chat_member and msg.new_chat_member.id == self.info.id)

View File

@ -1,9 +1,5 @@
local adfly = {}
local utilities = require('miku.utilities')
local HTTPS = require('ssl.https')
local redis = (loadfile "./miku/redis.lua")()
function adfly:init(config)
adfly.triggers = {
'adf.ly/([A-Za-z0-9-_-]+)'
@ -15,7 +11,7 @@ end
function adfly:expand_adfly_link(adfly_code)
local BASE_URL = 'https://andibi.tk/dl/adfly.php'
local url = BASE_URL..'/?url=http://adf.ly/'..adfly_code
local res,code = HTTPS.request(url)
local res,code = https.request(url)
if code ~= 200 then return nil end
if res == 'Fehler: Keine Adf.ly-URL gefunden!' then return 'NOTFOUND' end
cache_data('adfly', adfly_code, res, 31536000, 'key')

View File

@ -3,9 +3,6 @@
local afk = {}
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
function afk:init(config)
afk.triggers = {
"^/([Aa][Ff][Kk])$",
@ -80,17 +77,7 @@ function afk:pre_process(msg, self)
local timestamp = redis:hget(hash, 'time')
local current_timestamp = msg.date
local afk_time = current_timestamp - timestamp
local seconds = afk_time % 60
local minutes = math.floor(afk_time / 60)
local minutes = minutes % 60
local hours = math.floor(afk_time / 3600)
if minutes == 00 and hours == 00 then
duration = seconds..' Sekunden'
elseif hours == 00 and minutes ~= 00 then
duration = string.format("%02d:%02d", minutes, seconds)..' Minuten'
elseif hours ~= 00 then
duration = string.format("%02d:%02d:%02d", hours, minutes, seconds)..' Stunden'
end
local duration = makeHumanTime(afk_time)
redis:hset(hash, 'afk', false)
if afk_text then

View File

@ -1,10 +1,5 @@
local app_store = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
app_store.triggers = {
"itunes.apple.com/(.*)/app/(.*)/id(%d+)",
"^/[Ii][Tt][Uu][Nn][Ee][Ss] (%d+)$",

View File

@ -1,17 +1,9 @@
local bImages = {}
local HTTPS = require('ssl.https')
HTTPS.timeout = 10
local URL = require('socket.url')
local JSON = require('dkjson')
local redis = (loadfile "./miku/redis.lua")()
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
function bImages:init(config)
if not cred_data.bing_search_key then
print('Missing config value: bing_search_key.')
print('bImages.lua will not be enabled.')
print('Fehlender Key: bing_search_key.')
print('bImages.lua wird nicht aktiviert.')
return
end
@ -36,9 +28,9 @@ function bImages:getImages(query)
["Ocp-Apim-Subscription-Key"] = apikey
}
}
local ok, response_code, response_headers = HTTPS.request(request_constructor)
local ok, response_code, response_headers = https.request(request_constructor)
if not ok then return end
local images = JSON.decode(table.concat(response_body)).value
local images = json.decode(table.concat(response_body)).value
if not images[1] then return end

View File

@ -1,9 +1,5 @@
local banhammer = {}
local bindings = require('miku.bindings')
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
banhammer.command = 'banhammer <nur für Superuser>'
function banhammer:init(config)

View File

@ -1,14 +1,9 @@
local bitly = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
function bitly:init(config)
if not cred_data.bitly_access_token then
print('Missing config value: bitly_access_token.')
print('bitly.lua will not be enabled.')
print('Fehlender Key: bitly_access_token.')
print('bitly.lua wird nicht aktiviert.')
return
end

View File

@ -1,26 +1,17 @@
local bitly_create = {}
local http = require('socket.http')
local https = require('ssl.https')
local URL = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
local OAuth = require "OAuth"
local redis = (loadfile "./miku/redis.lua")()
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.')
print('Fehlender Key: bitly_client_id.')
print('bitly_create.lua wird nicht aktiviert.')
return
elseif not cred_data.bitly_client_secret then
print('Missing config value: bitly_client_secret.')
print('bitly_create.lua will not be enabled.')
print('Fehlender Key: bitly_client_secret.')
print('bitly_create.lua wird nicht aktiviert.')
return
elseif not cred_data.bitly_redirect_uri then
print('Missing config value: bitly_redirect_uri.')
print('bitly_create.lua will not be enabled.')
print('Fehlender Key: bitly_redirect_uri.')
print('bitly_create.lua wird nicht aktiviert.')
return
end

View File

@ -1,34 +0,0 @@
local botan = {}
local https = require('ssl.https')
local URL = require('socket.url')
local redis = (loadfile "./miku/redis.lua")()
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
function botan:init(config)
if not config.botan_token then
print('Fehlender Key: botan_token.')
print('botan.lua wird nicht aktiviert.')
return
end
botan.triggers = {
"^/nil$"
}
end
local BASE_URL = 'https://api.botan.io/track'
function botan:appmetrica(text, token, plugin_name)
https.request(BASE_URL..'/?token='..token..'&uid=1&name='..plugin_name)
end
function botan:action(msg, config, matches, plugin_name)
if not plugin_name then
return
end
botan:appmetrica(msg.text, config.botan_token, plugin_name)
end
return botan

View File

@ -1,11 +1,5 @@
local br = {}
local https = require('ssl.https')
local URL = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
br.triggers = {
"br.de/nachrichten/(.*).html$"
}

View File

@ -1,11 +1,5 @@
local btc = {}
local https = require('ssl.https')
local URL = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
function btc:init(config)
btc.triggers = {
"^/[Bb][Tt][Cc]$"

View File

@ -1,9 +1,5 @@
local calc = {}
local URL = require('socket.url')
local http = require('socket.http')
local utilities = require('miku.utilities')
calc.command = 'calc <Ausdruck>'
function calc:init(config)

View File

@ -1,13 +1,10 @@
local cats = {}
local HTTP = require('socket.http')
local utilities = require('miku.utilities')
cats.command = 'kitty [gif]'
function cats:init(config)
if not cred_data.cat_apikey then
print('Missing config value: cat_apikey.')
print('Fehlender Key: cat_apikey.')
print('cats.lua will be enabled, but there are more features with a key.')
end
@ -16,6 +13,11 @@ function cats:init(config)
"^/[Kk][Ii][Tt][Tt][Yy] (gif)$"
}
cats.inline_triggers = {
"^[Kk][Ii][Tt][Tt][Yy] (gif)$",
"^[Kk][Ii][Tt][Tt][Yy]$"
}
cats.doc = [[*
]]..config.cmd_pat..[[kitty*: Postet eine zufällige Katze
*]]..config.cmd_pat..[[kitty* _gif_: Postet eine zufällige, animierte Katze]]
@ -24,6 +26,35 @@ end
local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html
function cats:inline_callback(inline_query, config, matches)
if matches[1] == 'gif' then
img_type = 'gif'
else
img_type = 'jpg'
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":"'..math.random(100000000000000000)..'","gif_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}'
else
results = results..'{"type":"photo","id":"'..math.random(100000000000000000)..'","photo_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}'
end
if n < #data then
results = results..','
end
end
local results = results..']'
utilities.answer_inline_query(self, inline_query, results, 120)
end
function cats:action(msg, config)
if matches[1] == 'gif' then
local url = 'http://thecatapi.com/api/images/get?type=gif&apikey='..apikey

View File

@ -1,63 +1,66 @@
local channel = {}
local bindings = require('miku.bindings')
local utilities = require('miku.utilities')
channel.command = 'ch <Kanal> \\n <Nachricht>'
channel.doc = [[*
/ch*_ <Kanal>_
/ch*_ <Kanal>_|_[Inline-Keyboard]_
_<Nachricht>_
Sendet eine Nachricht in den Kanal. Der Kanal kann per Username oder ID bestimmt werden, Markdown wird unterstützt. Du musst Administrator oder Besitzer des Kanals sein.
Markdown-Syntax:
*Fetter Text*
_Kursiver Text_
[Text](URL)
`Inline-Codeblock`
```Größere Code-Block über mehrere Zeilen```
Inline-Keyboards sind OPTIONAL, in dem Falle einfach den Strich weglassen. Es werden NUR URL-Buttons unterstützt! Eine Beispielsyntax für einen Button findest du [auf GitHub](https://gist.githubusercontent.com/Brawl345/e671b60e24243da81934/raw/Inline-Keyboard.json).
*Der Kanalname muss mit einem @ beginnen!*]]
function channel:init(config)
channel.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('ch', true).table
channel.triggers = {
"^/ch @([A-Za-z0-9-_-]+)|(.+)\n(.*)",
"^/ch @([A-Za-z0-9-_-]+)\n(.*)"
}
end
function channel:action(msg, config)
local input = utilities.input(msg.text)
local output
if input then
local chat_id = utilities.get_word(input, 1)
local admin_list, t = bindings.getChatAdministrators(self, { chat_id = chat_id } )
if admin_list then
local is_admin = false
for _, admin in ipairs(admin_list.result) do
if admin.user.id == msg.from.id then
is_admin = true
end
end
if is_admin then
local text = input:match('\n(.+)')
if text then
local success, result = utilities.send_message(self, chat_id, text, true, nil, true)
if success then
output = 'Deine Nachricht wurde versendet!'
else
output = 'Sorry, ich konnte deine Nachricht nicht senden.\n`' .. result.description .. '`'
end
else
output = 'Bitte gebe deine Nachricht ein. Markdown wird unterstützt.'
end
else
output = 'Es sieht nicht so aus, als wärst du der Administrator dieses Kanals.'
end
else
output = 'Sorry, ich konnte die Administratorenliste nicht abrufen. Falls du den Kanalnamen benutzt: Beginnt er mit einem @?\n`' .. t.description .. '`'
end
else
output = channel.doc
local input = utilities.input(msg.text)
local output
local chat_id = '@'..matches[1]
local admin_list, gca_results = utilities.get_chat_administrators(self, chat_id)
if admin_list then
local is_admin = false
for _, admin in ipairs(admin_list.result) do
if admin.user.id == msg.from.id then
is_admin = true
end
end
utilities.send_reply(self, msg, output, true)
if is_admin then
if matches[3] then
text = matches[3]
reply_markup = matches[2]
-- Yeah, channels don't allow this buttons currently, but when they're ready
-- this plugin will also be ready :P
-- Also, URL buttons work!? Maybe beta?
if reply_markup:match('"callback_data":"') then
utilities.send_reply(self, msg, 'callback_data ist in Buttons nicht erlaubt.')
return
elseif reply_markup:match('"switch_inline_query":"') then
utilities.send_reply(self, msg, 'switch_inline_query ist in Buttons nicht erlaubt.')
return
end
else
text = matches[2]
reply_markup = nil
end
local success, result = utilities.send_message(self, chat_id, text, true, nil, true, reply_markup)
if success then
output = 'Deine Nachricht wurde versendet!'
else
output = 'Sorry, ich konnte deine Nachricht nicht senden.\n`' .. result.description .. '`'
end
else
output = 'Es sieht nicht so aus, als wärst du der Administrator dieses Kanals.'
end
else
output = 'Sorry, ich konnte die Administratorenliste nicht abrufen!\n`'..gca_results.description..'`'
end
utilities.send_reply(self, msg, output, true)
end
return channel

View File

@ -1,9 +1,5 @@
local channels = {}
local bindings = require('miku.bindings')
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
channels.command = 'channel <nur für Superuser>'
function channels:init(config)

View File

@ -1,10 +1,5 @@
local cleverbot = {}
local https = require('ssl.https')
local URL = require('socket.url')
local utilities = require('miku.utilities')
local json = require('dkjson')
function cleverbot:init(config)
cleverbot.triggers = {
"^/[Cc][Bb][Oo][Tt] (.*)$"

View File

@ -1,10 +1,5 @@
local clypit = {}
local http = require('socket.http')
local json = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
clypit.triggers = {
"clyp.it/([A-Za-z0-9-_-]+)"
}

View File

@ -1,7 +1,6 @@
local control = {}
local bot = require('miku.bot')
local utilities = require('miku.utilities')
local cmd_pat -- Prevents the command from being uncallable.

View File

@ -1,8 +1,5 @@
local creds_manager = {}
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
function creds_manager:init(config)
creds_manager.triggers = {
"^(/creds)$",

View File

@ -1,8 +1,5 @@
local currency = {}
local HTTPS = require('ssl.https')
local utilities = require('miku.utilities')
currency.command = 'cash [Menge] <von> <zu>'
function currency:init(config)
@ -42,7 +39,7 @@ function currency:action(msg, config)
end
local url = BASE_URL..'?from='..from..'&to='..to..'&a='..amount
local str, res = HTTPS.request(url)
local str, res = https.request(url)
if res ~= 200 then
utilities.send_reply(self, msg, config.errors.connection)
return

View File

@ -1,9 +1,5 @@
local dailymotion = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
dailymotion.triggers = {
"dailymotion.com/video/([A-Za-z0-9-_-]+)"
}

View File

@ -1,9 +1,5 @@
local deviantart = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
deviantart.triggers = {
"http://(.*).deviantart.com/art/(.*)"
}

View File

@ -1,12 +1,8 @@
local dhl = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
function dhl:init(config)
dhl.triggers = {
"/[Dd][Hh][Ll] (%d+)$"
'/[Dd][Hh][Ll] (%d+)$'
}
dhl.doc = [[*
]]..config.cmd_pat..[[dhl* _<Sendungsnummer>_: Aktueller Status der Sendung]]
@ -18,10 +14,10 @@ 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>")
if code ~= 200 then return 'Fehler beim Abrufen von mobil.dhl.de' end
local status = string.match(res, '<div id%=\"detailShortStatus\">(.-)</div>')
local status = all_trim(status)
local zeit = string.match(res, "<div id%=\"detailStatusDateTime\">(.-)</div>")
local zeit = string.match(res, '<div id%=\"detailStatusDateTime\">(.-)</div>')
local zeit = all_trim(zeit)
if not zeit or zeit == '<br />' then
return status

View File

@ -2,27 +2,23 @@
local dropbox = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
dropbox.triggers = {
"dropbox.com/s/([a-z0-9]+)/(.*)"
'dropbox.com/s/([a-z0-9]+)/(.*)'
}
function dropbox:action(msg, config, matches)
local folder = matches[1]
local file = string.gsub(matches[2], "?dl=0", "")
local file = string.gsub(matches[2], '?dl=0', '')
local link = 'https://dl.dropboxusercontent.com/s/'..folder..'/'..file
local v,code = https.request(link)
if code == 200 then
if string.ends(link, ".png") or string.ends(link, ".jpe?g")then
if string.ends(link, '.png') or string.ends(link, '.jpe?g')then
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(link)
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
return
elseif string.ends(link, ".webp") or string.ends(link, ".gif") then
elseif string.ends(link, '.webp') or string.ends(link, '.gif') then
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(link)
utilities.send_document(self, msg.chat.id, file, nil, msg.message_id)

View File

@ -1,14 +1,12 @@
local echo = {}
local utilities = require('miku.utilities')
echo.command = 'echo <Text>'
function echo:init(config)
echo.triggers = {"/[Ee][Cc][Hh][Oo] (.*)$"}
echo.triggers = {'/[Ee][Cc][Hh][Oo] (.*)$'}
echo.inline_triggers = {
"^echo (.*)",
"^bold (.*)"
'^echo (.*)',
'^bold (.*)'
}
echo.doc = [[*
]]..config.cmd_pat..[[echo* _<Text>_: Gibt den Text aus]]
@ -35,6 +33,8 @@ function echo:action(msg)
local output
if msg.chat.type == 'supergroup' then
output = '*Echo:*\n"' .. utilities.md_escape(input) .. '"'
utilities.send_message(self, msg.chat.id, output, true, nil, true)
return
end
utilities.send_message(self, msg.chat.id, input, true, nil, true)
end

View File

@ -1,8 +1,5 @@
local entergroup = {}
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
entergroup.triggers = {
'/nil'
}

View File

@ -1,14 +1,11 @@
local expand = {}
local http = require('socket.http')
local utilities = require('miku.utilities')
function expand:init(config)
expand.triggers = {
"^/[Ee][Xx][Pp][Aa][Nn][Dd] (https?://[%w-_%.%?%.:/%+=&]+)$"
'^/[Ee][Xx][Pp][Aa][Nn][Dd] (https?://[%w-_%.%?%.:/%+=&]+)$'
}
expand.inline_triggers = {
"^ex (https?://[%w-_%.%?%.:/%+=&]+)$"
'^ex (https?://[%w-_%.%?%.:/%+=&]+)$'
}
expand.doc = [[*
@ -53,7 +50,7 @@ function expand:action(msg, config, matches)
utilities.send_reply(self, msg, response_headers.location)
return
else
utilities.send_reply(self, msg, "Fehler beim Erweitern der URL.")
utilities.send_reply(self, msg, 'Fehler beim Erweitern der URL.')
return
end
end

View File

@ -1,28 +1,20 @@
local facebook = {}
local http = require('socket.http')
local https = require('ssl.https')
local URL = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
local redis = (loadfile "./miku/redis.lua")()
function facebook:init(config)
if not cred_data.fb_access_token then
print('Missing config value: fb_access_token.')
print('facebook.lua will not be enabled.')
print('Fehlender Key: fb_access_token.')
print('facebook.lua wird nicht aktiviert.')
return
end
facebook.triggers = {
"facebook.com/([A-Za-z0-9-._-]+)/(posts)/(%d+)",
"facebook.com/(permalink).php%?(story_fbid)=(%d+)&id=(%d+)",
"facebook.com/(photo).php%?fbid=(%d+)",
"facebook.com/([A-Za-z0-9-._-]+)/(photos)/a.(%d+[%d%.]*)/(%d+)",
"facebook.com/(video).php%?v=(%d+)",
"facebook.com/([A-Za-z0-9-._-]+)/(videos)/(%d+[%d%.]*)",
"facebook.com/([A-Za-z0-9-._-]+)"
'facebook.com/([A-Za-z0-9-._-]+)/(posts)/(%d+)',
'facebook.com/(permalink).php%?(story_fbid)=(%d+)&id=(%d+)',
'facebook.com/(photo).php%?fbid=(%d+)',
'facebook.com/([A-Za-z0-9-._-]+)/(photos)/a.(%d+[%d%.]*)/(%d+)',
'facebook.com/(video).php%?v=(%d+)',
'facebook.com/([A-Za-z0-9-._-]+)/(videos)/(%d+[%d%.]*)',
'facebook.com/([A-Za-z0-9-._-]+)'
}
end
@ -30,7 +22,7 @@ local BASE_URL = 'https://graph.facebook.com/v2.5'
local fb_access_token = cred_data.fb_access_token
local makeOurDate = function(dateString)
local pattern = "(%d+)%/(%d+)%/(%d+)"
local pattern = '(%d+)%/(%d+)%/(%d+)'
local month, day, year = dateString:match(pattern)
return day..'.'..month..'.'..year
end
@ -55,13 +47,13 @@ function facebook:fb_post (id, story_id)
if data.link then
link = '\n'..data.name..':\n'..utilities.md_escape(data.link)
else
link = ""
link = ''
end
if data.story then
story = ' ('..data.story..')'
else
story = ""
story = ''
end
local text = '*'..from..'*'..story..':\n'..message..'\n'..link
@ -112,13 +104,13 @@ function facebook:facebook_info(name)
if data.about then
about = '\n'..data.about
else
about = ""
about = ''
end
if data.general_info then
general_info = '\n'..data.general_info
else
general_info = ""
general_info = ''
end
if data.birthday and data.founded then
@ -128,7 +120,7 @@ function facebook:facebook_info(name)
elseif data.founded and not data.birthday then
birth = '\nGegründet: '..data.founded
else
birth = ""
birth = ''
end
local text = '*'..name..'* ('..category..')_'..about..'_'..general_info..birth

View File

@ -1,26 +1,21 @@
local flickr = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
function flickr:init(config)
if not cred_data.flickr_apikey then
print('Missing config value: flickr_apikey.')
print('flickr.lua will not be enabled.')
print('Fehlender Key: flickr_apikey.')
print('flickr.lua wird nicht aktiviert.')
return
end
flickr.triggers = {
"flickr.com/photos/([A-Za-z0-9-_-]+)/([0-9]+)"
'flickr.com/photos/([A-Za-z0-9-_-]+)/([0-9]+)'
}
end
local BASE_URL = 'https://api.flickr.com/services/rest'
local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+) (%d+)%:(%d+)%:(%d+)"
local pattern = '(%d+)%-(%d+)%-(%d+) (%d+)%:(%d+)%:(%d+)'
local year, month, day, hours, minutes, seconds = dateString:match(pattern)
return day..'.'..month..'.'..year..' um '..hours..':'..minutes..':'..seconds..' Uhr'
end

View File

@ -1,19 +1,14 @@
local flickr_search = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
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.')
print('Fehlender Key: flickr_apikey.')
print('flickr_search.lua wird nicht aktiviert.')
return
end
flickr_search.triggers = {
"^/flickr (.*)$"
'^/[Ff][Ll][Ii][Cc][Kk][Rr] (.*)'
}
end
@ -41,7 +36,7 @@ function flickr_search:action(msg, config, matches)
local file = download_to_file(url)
if string.ends(url, ".gif") then
if string.ends(url, '.gif') then
utilities.send_document(self, msg.chat.id, file, url)
return
else

View File

@ -1,20 +1,13 @@
local forecast = {}
local HTTPS = require('ssl.https')
local URL = require('socket.url')
local JSON = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
local redis = (loadfile "./miku/redis.lua")()
function forecast:init(config)
if not cred_data.forecastio_apikey then
print('Missing config value: forecastio_apikey.')
print('weather.lua will not be enabled.')
print('Fehlender Key: forecastio_apikey.')
print('weather.lua wird nicht aktiviert.')
return
elseif not cred_data.google_apikey then
print('Missing config value: google_apikey.')
print('weather.lua will not be enabled.')
print('Fehlender Key: google_apikey.')
print('weather.lua wird nicht aktiviert.')
return
end
@ -46,9 +39,9 @@ function get_city_name(lat, lng)
local city = redis:hget('telegram:cache:weather:pretty_names', lat..','..lng)
if city then return city end
local url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='..lat..','..lng..'&result_type=political&language=de&key='..google_apikey
local res, code = HTTPS.request(url)
local res, code = https.request(url)
if code ~= 200 then return 'Unbekannte Stadt' end
local data = JSON.decode(res).results[1]
local data = json.decode(res).results[1]
local city = data.formatted_address
print('Setting '..lat..','..lng..' in redis hash telegram:cache:weather:pretty_names to "'..city..'"')
redis:hset('telegram:cache:weather:pretty_names', lat..','..lng, city)
@ -107,9 +100,9 @@ function forecast:get_forecast(lat, lng)
method = "GET",
sink = ltn12.sink.table(response_body)
}
local ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor)
local ok, response_code, response_headers, response_status_line = https.request(request_constructor)
if not ok then return nil end
local data = JSON.decode(table.concat(response_body))
local data = json.decode(table.concat(response_body))
local ttl = string.sub(response_headers["cache-control"], 9)
@ -153,9 +146,9 @@ function forecast:get_forecast_hourly(lat, lng)
method = "GET",
sink = ltn12.sink.table(response_body)
}
local ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor)
local ok, response_code, response_headers, response_status_line = https.request(request_constructor)
if not ok then return nil end
local data = JSON.decode(table.concat(response_body))
local data = json.decode(table.concat(response_body))
local ttl = string.sub(response_headers["cache-control"], 9)

View File

@ -3,22 +3,14 @@
local gImages = {}
local HTTPS = require('ssl.https')
HTTPS.timeout = 10
local URL = require('socket.url')
local JSON = require('dkjson')
local redis = (loadfile "./miku/redis.lua")()
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
function gImages:init(config)
if not cred_data.google_apikey then
print('Missing config value: google_apikey.')
print('gImages.lua will not be enabled.')
print('Fehlender Key: google_apikey.')
print('gImages.lua wird nicht aktiviert.')
return
elseif not cred_data.google_cse_id then
print('Missing config value: google_cse_id.')
print('gImages.lua will not be enabled.')
print('Fehlender Key: google_cse_id.')
print('gImages.lua wird nicht aktiviert.')
return
end
@ -97,7 +89,7 @@ function gImages:callback(callback, msg, self, config, input)
end
if failed then
utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}')
utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true)
return
end
@ -114,12 +106,12 @@ function gImages:callback(callback, msg, self, config, input)
end
function gImages:get_image(input)
local apikey = cred_data.google_apikey -- 100 requests is RIDICULOUS, Google!
local apikey = cred_data.google_apikey
local cseid = cred_data.google_cse_id
local BASE_URL = 'https://www.googleapis.com/customsearch/v1'
local url = BASE_URL..'/?searchType=image&alt=json&num=10&key='..apikey..'&cx='..cseid..'&safe=high'..'&q=' .. input .. '&fields=items(link,mime,image(contextLink))'
local jstr, res = HTTPS.request(url)
local jdat = JSON.decode(jstr).items
local jstr, res = https.request(url)
local jdat = json.decode(jstr).items
if not jdat then
return 'NORESULTS'
@ -160,9 +152,9 @@ function gImages:action(msg, config, matches)
end
end
print ('Checking if search contains blacklisted word: '..input)
print ('Überprüfe, ob das Wort auf der Blackliste steht: '..input)
if is_blacklisted(input) then
utilities.send_reply(self, msg, 'Vergiss es! ._.')
utilities.send_reply(self, msg, 'Vergiss es!')
return
end
@ -204,11 +196,11 @@ function gImages:action(msg, config, matches)
-- It's important to save the image with the right ending!
if mimetype == 'image/gif' then
file = download_to_file(img_url, 'img.gif')
file = download_to_file(img_url)
elseif mimetype == 'image/png' then
file = download_to_file(img_url, 'img.png')
file = download_to_file(img_url)
elseif mimetype == 'image/jpeg' then
file = download_to_file(img_url, 'img.jpg')
file = download_to_file(img_url)
else
file = nil
end
@ -226,7 +218,7 @@ function gImages:action(msg, config, matches)
end
if failed then
utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}')
utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true)
return
end

View File

@ -3,22 +3,14 @@
local gImages_nsfw = {}
local HTTPS = require('ssl.https')
HTTPS.timeout = 10
local URL = require('socket.url')
local JSON = require('dkjson')
local redis = (loadfile "./miku/redis.lua")()
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
function gImages_nsfw:init(config)
if not cred_data.google_apikey then
print('Missing config value: google_apikey.')
print('gImages_nsfw.lua will not be enabled.')
print('Fehlender Key: google_apikey.')
print('gImages_nsfw.lua wird nicht aktiviert.')
return
elseif not cred_data.google_cse_id then
print('Missing config value: google_cse_id.')
print('gImages_nsfw.lua will not be enabled.')
print('Fehlender Key: google_cse_id.')
print('gImages_nsfw.lua wird nicht aktiviert.')
return
end
@ -97,7 +89,7 @@ function gImages_nsfw:callback(callback, msg, self, config, input)
end
if failed then
utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}')
utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true)
return
end
@ -114,12 +106,12 @@ function gImages_nsfw:callback(callback, msg, self, config, input)
end
function gImages_nsfw:get_image(input)
local apikey = cred_data.google_apikey -- 100 requests is RIDICULOUS, Google!
local apikey = cred_data.google_apikey
local cseid = cred_data.google_cse_id
local BASE_URL = 'https://www.googleapis.com/customsearch/v1'
local url = BASE_URL..'/?searchType=image&alt=json&num=10&key='..apikey..'&cx='..cseid..'&q=' .. input .. '&fields=items(link,mime,image(contextLink))'
local jstr, res = HTTPS.request(url)
local jdat = JSON.decode(jstr).items
local jstr, res = https.request(url)
local jdat = json.decode(jstr).items
if not jdat then
return 'NORESULTS'
@ -160,9 +152,9 @@ function gImages_nsfw:action(msg, config, matches)
end
end
print ('Checking if search contains blacklisted word: '..input)
print ('Überprüfe, ob das Wort auf der Blackliste steht: '..input)
if is_blacklisted(input) then
utilities.send_reply(self, msg, 'Vergiss es! ._.')
utilities.send_reply(self, msg, 'Vergiss es!')
return
end
@ -204,11 +196,11 @@ function gImages_nsfw:action(msg, config, matches)
-- It's important to save the image with the right ending!
if mimetype == 'image/gif' then
file = download_to_file(img_url, 'img.gif')
file = download_to_file(img_url)
elseif mimetype == 'image/png' then
file = download_to_file(img_url, 'img.png')
file = download_to_file(img_url)
elseif mimetype == 'image/jpeg' then
file = download_to_file(img_url, 'img.jpg')
file = download_to_file(img_url)
else
file = nil
end
@ -226,7 +218,7 @@ function gImages_nsfw:action(msg, config, matches)
end
if failed then
utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}')
utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true)
return
end

View File

@ -1,12 +1,9 @@
local gMaps = {}
local URL = require('socket.url')
local utilities = require('miku.utilities')
gMaps.command = 'loc <Ort>'
function gMaps:init(config)
gMaps.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('loc', true).table
gMaps.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ll][Oo][Cc]', true).table
gMaps.doc = [[*
]]..config.cmd_pat..[[loc* _<Ort>_: Sendet Ort via Google Maps]]
end

View File

@ -1,14 +1,9 @@
local gSearch = {}
local HTTPS = require('ssl.https')
local URL = require('socket.url')
local JSON = require('dkjson')
local utilities = require('miku.utilities')
gSearch.command = 'google <Suchbegriff>'
function gSearch:init(config)
gSearch.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('g', true):t('google', true).table
gSearch.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Gg]', true):t('[Gg][Oo][Oo][Gg][Ll][Ee]', true).table
gSearch.doc = [[*
]]..config.cmd_pat..[[google* _<Suchbegriff>_: Sendet Suchergebnisse von Google
Alias: _]]..config.cmd_pat..[[g_]]
@ -23,7 +18,7 @@ function gSearch:googlethat(query, config)
local api = BASE_URL.."/?key="..apikey.."&cx="..cseid.."&gl=de&num="..number.."&safe=medium&fields=searchInformation%28formattedSearchTime,formattedTotalResults%29,items%28title,link,displayLink%29&"
local parameters = "q=".. (URL.escape(query) or "")
-- Do the request
local res, code = HTTPS.request(api..parameters)
local res, code = https.request(api..parameters)
if code == 403 then
return '403'
end
@ -31,7 +26,7 @@ function gSearch:googlethat(query, config)
utilities.send_reply(self, msg, config.errors.connection)
return
end
local data = JSON.decode(res)
local data = json.decode(res)
if data.searchInformation.formattedTotalResults == "0" then return nil end
local results={}

View File

@ -1,10 +1,6 @@
local games = {}
local http = require('socket.http')
local URL = require('socket.url')
local xml = require("xml")
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
games.command = 'game <Spiel>'

View File

@ -1,15 +1,9 @@
local gdrive = {}
local utilities = require('miku.utilities')
local https = require('ssl.https')
local ltn12 = require('ltn12')
local json = require('dkjson')
local bindings = require('miku.bindings')
function gdrive:init(config)
if not cred_data.google_apikey then
print('Missing config value: google_apikey.')
print('gdrive.lua will not be enabled.')
print('Fehlender Key: google_apikey.')
print('gdrive.lua wird nicht aktiviert.')
return
end

View File

@ -1,12 +1,9 @@
local get = {}
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
get.command = 'get <Variable>'
function get:init(config)
get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('get', true).table
get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Gg][Ee][Tt]', true).table
get.doc = [[*
]]..config.cmd_pat..[[get*: Gibt alle Variablen aus
*]]..config.cmd_pat..[[get* _<Variable>_: Gibt _Variable_ aus
@ -30,7 +27,7 @@ function get:list_variables(msg)
print(hash)
if hash then
print('Getting variable from redis hash '..hash)
print('Hole Variable von Redis Hash '..hash)
local names = redis:hkeys(hash)
local text = ''
for i=1, #names do

View File

@ -4,12 +4,6 @@
local media_download = {}
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
local ltn12 = require('ltn12')
local HTTPS = require('ssl.https')
local redis = (loadfile "./miku/redis.lua")()
media_download.triggers = {
'/nil'
}
@ -22,7 +16,7 @@ function media_download:download_to_file_permanently(url, file_name)
redirect = false
}
local response = nil
response = {HTTPS.request(options)}
response = {https.request(options)}
local code = response[2]
local headers = response[3]
@ -65,14 +59,14 @@ function media_download:pre_process(msg, self)
end
if file_size > 19922944 then
print('File is over 20 MB - can\'t download :(')
print('Datei ist größer als 20 MB - Nicht downloadbar!')
return
end
-- Check if file has already been downloaded
local already_downloaded = redis:sismember('telegram:file_id', file_id)
if already_downloaded == true then
print('File has already been downloaded in the past, skipping...')
print('Datei wurde bereits gedownloadet')
return
end
@ -83,7 +77,7 @@ function media_download:pre_process(msg, self)
-- Getting file from the Telegram Cloud
if not request then
print('Download failed!')
print('Download fehlgeschlagen!')
return
end
@ -98,7 +92,7 @@ function media_download:pre_process(msg, self)
local download_url = 'https://api.telegram.org/file/bot'..cred_data.bot_api_key..'/'..request.result.file_path
local ok = media_download:download_to_file_permanently(download_url, file_path)
if not ok then
print('Download failed!')
print('Download fehlgeschlagen!')
return
end

View File

@ -2,10 +2,6 @@
local gfycat = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
gfycat.triggers = {
"gfycat.com/([A-Za-z0-9-_-]+)"
}

View File

@ -1,10 +1,5 @@
local giphy = {}
local http = require('socket.http')
local URL = require('socket.url')
local JSON = require('dkjson')
local utilities = require('miku.utilities')
function giphy:init(config)
giphy.triggers = {
"/nil"
@ -26,7 +21,7 @@ function giphy:get_gifs(query)
end
local res, code = http.request(url)
if code ~= 200 then return nil end
return JSON.decode(res).data
return json.decode(res).data
end
function giphy:inline_callback(inline_query, config, matches)

View File

@ -1,13 +1,5 @@
local github = {}
local http = require('socket.http')
local https = require('ssl.https')
local URL = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
local redis = (loadfile "./miku/redis.lua")()
function github:init(config)
github.triggers = {
"github.com/([A-Za-z0-9-_-.-._.]+)/([A-Za-z0-9-_-.-._.]+)/commit/([a-z0-9-]+)",

View File

@ -0,0 +1,302 @@
local gh_feed = {}
gh_feed.command = 'gh <sub/del>'
function gh_feed:init(config)
if not cred_data.github_token then
print('Fehlender Key: github_token.')
print('github_feed.lua wird nicht aktiviert.')
return
elseif not cred_data.github_username then
print('Fehlender Key: github_username.')
print('github_feed.lua wird nicht aktiviert.')
return
end
gh_feed.triggers = {
"^/(gh) @(.*)$",
"^/gh$",
"^/gh (sub) ([A-Za-z0-9-_-.-._.]+/[A-Za-z0-9-_-.-._.]+) @(.*)$",
"^/gh (sub) ([A-Za-z0-9-_-.-._.]+/[A-Za-z0-9-_-.-._.]+)$",
"^/gh (del) (%d+) @(.*)$",
"^/gh (del) (%d+)$",
"^/gh (del)",
"^/gh (sync)$"
}
gh_feed.doc = [[*
]]..config.cmd_pat..[[gh* _@[Kanalname]_: GitHub-Abonnements anzeigen
*]]..config.cmd_pat..[[gh* _sub_ _<URL>_ _@[Kanalname]_: Diese Repo abonnieren
*]]..config.cmd_pat..[[gh* _del_ _<#>_ _@[Kanalname]_: Diese Repo deabonnieren
*]]..config.cmd_pat..[[gh* _sync_: Repos syncen (nur Superuser)
Der Kanalname ist optional]]
end
local token = cred_data.github_token -- get a token here: https://github.com/settings/tokens/new (you don't need any scopes)
local BASE_URL = 'https://api.github.com/repos'
function gh_feed_get_base_redis(id, option, extra)
local ex = ''
if option ~= nil then
ex = ex .. ':' .. option
if extra ~= nil then
ex = ex .. ':' .. extra
end
end
return 'github:' .. id .. ex
end
function gh_feed_check_modified(repo, cur_etag, last_date)
local url = BASE_URL..'/'..repo
local response_body = {}
local request_constructor = {
url = url,
method = "HEAD",
redirect = false,
headers = {
Authorization = 'token '..token,
["If-None-Match"] = cur_etag
}
}
local ok, response_code = https.request(request_constructor)
if not ok then return nil end
if response_code == 304 then return true end
local url = BASE_URL..'/'..repo..'/commits?since='..last_date
local response_body = {}
local request_constructor = {
url = url,
method = "GET",
sink = ltn12.sink.table(response_body),
headers = {
Authorization = 'token '..token
}
}
local ok, response_code, response_headers = https.request(request_constructor)
if not response_headers then return nil end
local data = json.decode(table.concat(response_body))
return false, data, response_headers.etag
end
function gh_feed:check_repo(repo)
local url = BASE_URL..'/'..repo
local response_body = {}
local request_constructor = {
url = url,
method = "GET",
sink = ltn12.sink.table(response_body),
headers = {
Authorization = 'token '..token
}
}
local ok, response_code, response_headers = https.request(request_constructor)
if not ok then return nil end
return json.decode(table.concat(response_body)), response_headers.etag
end
function gh_feed:subscribe(id, repo)
local lasthash = gh_feed_get_base_redis(repo, "last_commit")
local lastetag = gh_feed_get_base_redis(repo, "etag")
local lastdate = gh_feed_get_base_redis(repo, "date")
local lhash = gh_feed_get_base_redis(repo, "subs")
local uhash = gh_feed_get_base_redis(id)
if redis:sismember(uhash, repo) then
return "Du hast `"..repo.."` bereits abonniert."
end
local data, etag = gh_feed:check_repo(repo)
if not data or not data.full_name then return 'Diese Repo gibt es nicht!' end
if not etag then return 'Ein Fehler ist aufgetreten.' end
local last_commit = ""
local pushed_at = data.pushed_at
local name = data.full_name
redis:set(lasthash, last_commit)
redis:set(lastdate, pushed_at)
redis:set(lastetag, etag)
redis:sadd(lhash, id)
redis:sadd(uhash, repo)
return "_"..utilities.md_escape(name) .."_ abonniert!"
end
function gh_feed:unsubscribe(id, n)
if #n > 3 then
return "Du kannst nicht mehr als drei Repos abonnieren!"
end
n = tonumber(n)
local uhash = gh_feed_get_base_redis(id)
local subs = redis:smembers(uhash)
if n < 1 or n > #subs then
return "Abonnement-ID zu hoch!"
end
local sub = subs[n]
local lhash = gh_feed_get_base_redis(sub, "subs")
redis:srem(uhash, sub)
redis:srem(lhash, id)
local left = redis:smembers(lhash)
if #left < 1 then -- no one subscribed, remove it
local lastetag = gh_feed_get_base_redis(sub, "etag")
local lastdate = gh_feed_get_base_redis(sub, "date")
local lasthash = gh_feed_get_base_redis(sub, "last_commit")
redis:del(lastetag)
redis:del(lasthash)
redis:del(lastdate)
end
return "Du hast `"..utilities.md_escape(sub).."` deabonniert."
end
function gh_feed:print_subs(id, chat_name)
local uhash = gh_feed_get_base_redis(id)
local subs = redis:smembers(uhash)
if not subs[1] then
return 'Keine GitHub-Repos abonniert!'
end
local keyboard = '{"keyboard":[['
local keyboard_buttons = ''
local text = '*'..chat_name..'* hat abonniert:\n---------\n'
for k,v in pairs(subs) do
text = text .. k .. ") ["..v.."](https://github.com/"..v..')\n'
if k == #subs then
keyboard_buttons = keyboard_buttons..'{"text":"/gh del '..k..'"}'
break;
end
keyboard_buttons = keyboard_buttons..'{"text":"/gh del '..k..'"},'
end
local keyboard = keyboard..keyboard_buttons..']], "one_time_keyboard":true, "selective":true, "resize_keyboard":true}'
return text, keyboard
end
function gh_feed:action(msg, config, matches)
local id = msg.from.id
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
id = msg.chat.id
end
-- For channels
if matches[1] == 'sub' and matches[2] and matches[3] then
if msg.from.id ~= config.admin then
utilities.send_reply(self, msg, config.errors.sudo)
return
end
local id = '@'..matches[3]
local result = utilities.get_chat_info(self, id)
if not result then
utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!')
return
end
local output = gh_feed:subscribe(id, matches[2])
utilities.send_reply(self, msg, output, true)
return
elseif matches[1] == 'del' and matches[2] and matches[3] then
if msg.from.id ~= config.admin then
utilities.send_reply(self, msg, config.errors.sudo)
return
end
local id = '@'..matches[3]
local result = utilities.get_chat_info(self, id)
if not result then
utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!')
return
end
local output = gh_feed:unsubscribe(id, matches[2])
utilities.send_reply(self, msg, output, true)
return
elseif matches[1] == 'gh' and matches[2] then
local id = '@'..matches[2]
local result = utilities.get_chat_info(self, id)
if not result then
utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!')
return
end
local chat_name = result.result.title
local output = gh_feed:print_subs(id, chat_name)
utilities.send_reply(self, msg, output, true)
return
end
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
chat_name = msg.chat.title
else
chat_name = msg.chat.first_name
end
if matches[1] == 'sub' and matches[2] then
if msg.from.id ~= config.admin then
utilities.send_reply(self, msg, config.errors.sudo)
return
end
local output = gh_feed:subscribe(id, matches[2])
utilities.send_reply(self, msg, output, true)
return
elseif matches[1] == 'del' and matches[2] then
if msg.from.id ~= config.admin then
utilities.send_reply(self, msg, config.errors.sudo)
return
end
local output = gh_feed:unsubscribe(id, matches[2])
utilities.send_reply(self, msg, output, true, '{"hide_keyboard":true}')
return
elseif matches[1] == 'del' and not matches[2] then
local list_subs, keyboard = gh_feed:print_subs(id, chat_name)
utilities.send_reply(self, msg, list_subs, true, keyboard)
return
elseif matches[1] == 'sync' then
if msg.from.id ~= config.admin then
utilities.send_reply(self, msg, config.errors.sudo)
return
end
gh_feed:cron(self)
return
end
local output = gh_feed:print_subs(id, chat_name)
utilities.send_reply(self, msg, output, true)
return
end
function gh_feed:cron(self_plz)
if not self.BASE_URL then
self = self_plz
end
local keys = redis:keys(gh_feed_get_base_redis("*", "subs"))
for k,v in pairs(keys) do
local repo = string.match(v, "github:(.+):subs")
print('GitHub: '..repo)
local cur_etag = redis:get(gh_feed_get_base_redis(repo, "etag"))
local last_date = redis:get(gh_feed_get_base_redis(repo, "date"))
local was_not_modified, data, last_etag = gh_feed_check_modified(repo, cur_etag, last_date)
if not was_not_modified then
if not data or not last_etag then return end
-- When there are new commits
local last_commit = redis:get(gh_feed_get_base_redis(repo, "last_commit"))
text = ''
for n in ipairs(data) do
if data[n].sha ~= last_commit then
local sha = data[n].sha
local author = data[n].commit.author.name
local message = utilities.md_escape(data[n].commit.message)
local link = data[n].html_url
text = text..'\n#GitHub: `'..repo..'@'..sha..'` von *'..author..'*:\n'..message..'\n[GitHub aufrufen]('..link..')\n'
end
end
if text ~= '' then
local last_commit = data[1].sha
local last_date = data[1].commit.author.date
redis:set(gh_feed_get_base_redis(repo, "last_commit"), last_commit)
redis:set(gh_feed_get_base_redis(repo, "etag"), last_etag)
redis:set(gh_feed_get_base_redis(repo, "date"), last_date)
for k2, receiver in pairs(redis:smembers(v)) do
utilities.send_message(self, receiver, text, true, nil, true)
end
end
end
end
end
return gh_feed

View File

@ -1,19 +1,17 @@
local googl = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
function googl:init(config)
if not cred_data.google_apikey then
print('Missing config value: google_apikey.')
print('googl.lua will not be enabled.')
print('Fehlender Key: google_apikey.')
print('googl.lua wird nicht aktiviert.')
return
end
googl.triggers = {
"goo.gl/([A-Za-z0-9-_-/-/]+)"
}
googl.inline_triggers = googl.triggers
end
local BASE_URL = 'https://www.googleapis.com/urlshortener/v1'
@ -24,11 +22,20 @@ local makeOurDate = function(dateString)
return day..'.'..month..'.'..year
end
function googl:inline_callback(inline_query, config, matches)
local shorturl = matches[1]
local text, longUrl = googl:send_googl_info(shorturl)
if not longUrl then return end
local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"Verlängerte URL","description":"'..longUrl..'","url":"'..longUrl..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":165,"thumb_height":150,"hide_url":true,"input_message_content":{"message_text":"'..text..'"}}]'
utilities.answer_inline_query(self, inline_query, results, 1)
end
function googl:send_googl_info (shorturl)
local apikey = cred_data.google_apikey
local url = BASE_URL..'/url?key='..apikey..'&shortUrl=http://goo.gl/'..shorturl..'&projection=FULL&fields=longUrl,created,analytics(allTime(shortUrlClicks))'
local res,code = https.request(url)
if code ~= 200 then return "HTTP-FEHLER" end
if code ~= 200 then return nil end
local data = json.decode(res)
local longUrl = data.longUrl
@ -36,12 +43,14 @@ function googl:send_googl_info (shorturl)
local created = makeOurDate(data.created)
local text = longUrl..'\n'..shortUrlClicks..' mal geklickt (erstellt am '..created..')'
return text
return text, longUrl
end
function googl:action(msg, config, matches)
local shorturl = matches[1]
utilities.send_reply(self, msg, googl:send_googl_info(shorturl))
local text = googl:send_googl_info(shorturl)
if not text then utilities.send_reply(self, msg, config.errors.connection) return end
utilities.send_reply(self, msg, text)
end
return googl

View File

@ -1,8 +1,5 @@
local gps = {}
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
gps.command = 'gps <Breitengrad>,<Längengrad>'
function gps:init(config)

View File

@ -2,8 +2,6 @@
local help = {}
local utilities = require('miku.utilities')
local help_text
function help:init(config)

View File

@ -1,9 +1,5 @@
local id = {}
local redis = (loadfile "./miku/redis.lua")()
local bindings = require('miku.bindings')
local utilities = require('miku.utilities')
id.command = 'id'
function id:init(config)
@ -104,7 +100,7 @@ function id:action(msg)
end
end
local result = id:get_member_count(self, msg, chat_id)
local member_count = result.result - 1 -- minus the bot
local member_count = result.result
if member_count == 1 then
member_count = 'ist *1 Mitglied'
else
@ -115,12 +111,12 @@ function id:action(msg)
if table.contains(admins, tostring(user.id)) then
text = text..'*'..user.name..'* `['..user.id..']` _Administrator_\n'
elseif tostring(creator_id) == user.id then
text = text..'*'..user.name..'* `['..user.id..']` _Gruppenersteller_\n'
text = text..'*'..user.name..'* `['..user.id..']` _Gründer_\n'
else
text = text..'*'..user.name..'* `['..user.id..']`\n'
end
end
utilities.send_reply(self, msg, text, true)
utilities.send_reply(self, msg, text..'_(Bots sind nicht gelistet)_', true)
end
end

View File

@ -1,6 +1,5 @@
local images = {}
local utilities = require('miku.utilities')
images.triggers = {
"(https?://[%w-_%%%.%?%.:,/%+=~&%[%]]+%.[Pp][Nn][Gg])$",
"(https?://[%w-_%%%.%?%.:,/%+=~&%[%]]+%.[Jj][Pp][Ee]?[Gg])$"

View File

@ -1,18 +1,12 @@
local imdb = {}
local HTTP = require('socket.http')
local URL = require('socket.url')
local JSON = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
imdb.command = 'imdb <query>'
function imdb:init(config)
imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('imdb', true).table
imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ii][Mm][Dd][Bb]', true).table
imdb.doc = [[*
]]..config.cmd_pat..[[imdb* _<Film>_
Sucht _Film_ bei IMDB]]
Sucht einen _Film_ bei IMDB]]
end
function imdb:action(msg, config)
@ -29,13 +23,13 @@ function imdb:action(msg, config)
local url = 'http://www.omdbapi.com/?t=' .. URL.escape(input)
local jstr, res = HTTP.request(url)
local jstr, res = http.request(url)
if res ~= 200 then
utilities.send_reply(self, msg, config.errors.connection)
return
end
local jdat = JSON.decode(jstr)
local jdat = json.decode(jstr)
if jdat.Response ~= 'True' then
utilities.send_reply(self, msg, config.errors.results)

View File

@ -1,15 +1,12 @@
local imgblacklist = {}
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
imgblacklist.command = 'imgblacklist'
function imgblacklist:init(config)
imgblacklist.triggers = {
"^/imgblacklist show$",
"^/imgblacklist (add) (.*)$",
"^/imgblacklist (remove) (.*)$"
"^/[Ii][Mm][Gg][Bb][Ll][Aa][Cc][Kk][Ll][Ii][Ss][Tt] show$",
"^/[Ii][Mm][Gg][Bb][Ll][Aa][Cc][Kk][Ll][Ii][Ss][Tt] (add) (.*)$",
"^/[Ii][Mm][Gg][Bb][Ll][Aa][Cc][Kk][Ll][Ii][Ss][Tt] (remove) (.*)$"
}
imgblacklist.doc = [[*
]]..config.cmd_pat..[[imgblacklist* _show_: Zeige Blacklist
@ -32,7 +29,7 @@ function imgblacklist:show_blacklist()
end
function imgblacklist:add_blacklist(word)
print('Blacklisting '..word..' - saving to redis set telegram:img_blacklist')
print('Blackliste '..word..' - Speicher in Redis Hash telegram:img_blacklist')
if redis:sismember("telegram:img_blacklist", word) == true then
return '"'..word..'" steht schon auf der Blacklist.'
else
@ -42,7 +39,7 @@ function imgblacklist:add_blacklist(word)
end
function imgblacklist:remove_blacklist(word)
print('De-blacklisting '..word..' - removing from redis set telegram:img_blacklist')
print('Deblackliste '..word..' - Lösche aus Redis Hash telegram:img_blacklist')
if redis:sismember("telegram:img_blacklist", word) == true then
redis:srem("telegram:img_blacklist", word)
return '"'..word..'" erfolgreich von der Blacklist gelöscht!'

View File

@ -1,19 +1,14 @@
local imgur = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
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.')
print('Fehlender Key: imgur_client_id.')
print('imgur.lua wird nicht aktiviert.')
return
end
imgur.triggers = {
"imgur.com/([A-Za-z0-9]+).gifv",
"https?://imgur.com/([A-Za-z0-9]+)"
"imgur.com/([A-Za-z0-9]+)"
}
end

View File

@ -1,14 +1,9 @@
local ip_info = {}
local http = require('socket.http')
local json = require('dkjson')
local URL = require('socket.url')
local utilities = require('miku.utilities')
function ip_info:init(config)
ip_info.triggers = {
"^/ip (.*)$",
"^/dns (.*)$"
"^/[Ii][Pp] (.*)$",
"^/[Dd][Nn][Ss] (.*)$"
}
ip_info.doc = [[*

View File

@ -1,11 +1,5 @@
local isup = {}
local http = require('socket.http')
local https = require('ssl.https')
local socket = require('socket')
local URL = require('socket.url')
local utilities = require('miku.utilities')
function isup:init(config)
isup.triggers = {
"^/[Ii][Ss][Uu][Pp] (.*)$",
@ -17,7 +11,7 @@ function isup:init(config)
end
function isup:is_up_socket(ip, port)
print('Connect to', ip, port)
print('Verbinde zu ', ip, port)
local c = socket.try(socket.tcp())
c:settimeout(3)
local conn = c:connect(ip, port)

View File

@ -1,8 +1,5 @@
local leave_group = {}
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
leave_group.triggers = {
'/nil'
}
@ -15,7 +12,7 @@ function leave_group:check_for_admin(msg, self, config)
user_id = config.admin
} )
if not result.ok then
print('Konnte nicht prüfen, ob Admin in Gruppe ist! Verlasse sie sicherheitshalber...')
print('Konnte nicht prüfen, ob Admin in Gruppe ist. Verlasse Gruppe.')
return false
end
if result.result.status ~= "member" and result.result.status ~= "administrator" and result.result.status ~= "creator" then

View File

@ -1,8 +1,5 @@
local loc_manager = {}
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
function loc_manager:init(config)
loc_manager.triggers = {
"^/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn] (set) (.*)$",
@ -24,7 +21,7 @@ function loc_manager:set_location(user_id, location)
if set_location == location then
return 'Dieser Ort wurde bereits gesetzt.'
else
print('Setting location in redis hash '..hash..' to location')
print('Setze location in redis hash '..hash..' zu '..location)
redis:hset(hash, 'location', location)
return 'Dein Wohnort wurde auf *'..location..'* festgelegt.'
end
@ -36,7 +33,7 @@ function loc_manager:del_location(user_id)
if not set_location then
return 'Du hast keinen Ort gesetzt'
else
print('Setting location in redis hash '..hash..' to false')
print('Setze location in redis hash '..hash..' auf false')
-- We set the location to false, because deleting the value blocks redis for a few milliseconds
redis:hset(hash, 'location', false)
return 'Dein Wohnort *'..set_location..'* wurde gelöscht!'

View File

@ -1,17 +1,13 @@
local lyrics = {}
local http = require('socket.http')
local json = require('dkjson')
local utilities = require('miku.utilities')
function lyrics:init(config)
if not cred_data.lyricsnmusic_apikey then
print('Missing config value: lyricsnmusic_apikey.')
print('lyrics.lua will not be enabled.')
print('Fehlender Key: lyricsnmusic_apikey.')
print('lyrics.lua wird nicht aktiviert.')
return
end
lyrics.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lyrics', true).table
lyrics.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ll][Yy][Rr][Ii][Cc][Ss]', true).table
lyrics.doc = [[*
]]..config.cmd_pat..[[lyrics* _<Lied>_: Postet Liedertext]]
end

View File

@ -1,7 +1,5 @@
local muschel = {}
local utilities = require('miku.utilities')
muschel.triggers = {
"^[Mm][Aa][Gg][Ii][Ss][Cc][Hh][Ee] [Mm][Ii][Ee][Ss][Mm][Uu][Ss][Cc][Hh][Ee][Ll] (.*)$"
}

View File

@ -1,14 +1,10 @@
local media = {}
local HTTP = require('socket.http')
local HTTPS = require('ssl.https')
local redis = (loadfile "./miku/redis.lua")()
local utilities = require('miku.utilities')
local mimetype = (loadfile "./miku/mimetype.lua")()
mimetype = (loadfile "./miku/mimetype.lua")()
media.triggers = {
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(gif))$",
"^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(mp4))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(mp4))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(pdf))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogg))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(zip))$",
@ -18,12 +14,12 @@ media.triggers = {
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(rar))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(wmv))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(doc))$",
"^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(avi))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(avi))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(wav))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(apk))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ipa))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webm))$",
"^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogv))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogv))$",
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webp))$"
}
@ -45,16 +41,19 @@ function media:action(msg)
if not file then return end
if ext == 'gif' then
print('send gif')
print('Sende GIF')
result = utilities.send_document(self, receiver, file, nil, msg.message_id)
elseif ext == 'ogg' then
print('Sende OGG')
result = utilities.send_voice(self, receiver, file, nil, msg.message_id)
elseif mime_type == 'audio' then
print('send_audio')
print('Sende Audio')
result = utilities.send_audio(self, receiver, file, nil, msg.message_id)
elseif mime_type == 'video' then
print('send_video')
print('Sende Video')
result = utilities.send_video(self, receiver, file, nil, msg.message_id)
else
print('send_file')
print('Sende Datei')
result = utilities.send_document(self, receiver, file, nil, msg.message_id)
end

View File

@ -1,11 +1,5 @@
local mc_server = {}
local http = require('socket.http')
local ltn12 = require('ltn12')
local URL = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
function mc_server:init(config)
mc_server.triggers = {
"^/mine (.*)$"

View File

@ -1,9 +1,7 @@
local mc_skin = {}
local utilities = require('miku.utilities')
function mc_skin:init(config)
mc_skin.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('skin', true).table
mc_skin.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ss][Kk][Ii][Nn]', true).table
mc_skin.doc = [[*
]]..config.cmd_pat..[[skin* _<Username>_: Sendet Minecraft-Skin dieses Nutzers]]
end
@ -24,7 +22,7 @@ function mc_skin:action(msg, config, matches)
end
local url = 'http://www.minecraft-skin-viewer.net/3d.php?layers=true&aa=true&a=0&w=330&wt=10&abg=330&abd=40&ajg=340&ajd=20&ratio=13&format=png&login='..input..'&headOnly=false&displayHairs=true&randomness=341.png'
local file = download_to_file(url)
local file = download_to_file(url, input..'.png')
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
end

View File

@ -1,21 +1,17 @@
local mal = {}
local http = require('socket.http')
local URL = require('socket.url')
local xml = require("xml")
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
mal.command = 'anime <Anime>, /manga <Manga>'
function mal:init(config)
if not cred_data.mal_username then
print('Missing config value: mal_username.')
print('myanimelist.lua will not be enabled.')
print('Fehlender Key: mal_username.')
print('myanimelist.lua wird nicht aktiviert.')
return
elseif not cred_data.mal_pw then
print('Missing config value: mal_pw.')
print('myanimelist.lua will not be enabled.')
print('Fehlender Key: mal_pw.')
print('myanimelist.lua wird nicht aktiviert.')
return
end

View File

@ -3,13 +3,10 @@
local notify = {}
local redis = (loadfile "./miku/redis.lua")()
local utilities = require('miku.utilities')
function notify:init(config)
notify.triggers = {
"^/notify (del)$",
"^/notify$"
"^/[Nn][Oo][Tt][Ii][Ff][Yy] (del)$",
"^/[Nn][Oo][Tt][Ii][Ff][Yy]$"
}
notify.doc = [[*
@ -49,7 +46,7 @@ function notify:pre_process(msg, self)
local from = string.gsub(msg.from.name, "%_", " ")
local chat_name = string.gsub(msg.chat.title, "%_", " ")
local text = from..' am '..send_date..' in "'..chat_name..'":\n\n'..msg.text
utilities.send_message(self, id, text)
utilities.send_message(self, id, text, true)
end
end
end
@ -74,9 +71,9 @@ function notify:action(msg, config, matches)
utilities.send_reply(self, msg, 'Du wirst noch gar nicht benachrichtigt!')
return
end
print('Setting notify in redis hash '..hash..' to false')
print('Setze notify redis hash '..hash..' auf false')
redis:hset(hash, 'notify', false)
print('Removing '..username..' from redis set notify:ls')
print('Lösche '..username..' von redis set notify:ls')
redis:srem('notify:ls', username)
utilities.send_reply(self, msg, 'Du erhälst jetzt keine Benachrichtigungen mehr, wenn du angesprochen wirst.')
return
@ -85,11 +82,11 @@ function notify:action(msg, config, matches)
utilities.send_reply(self, msg, 'Du wirst schon benachrichtigt!')
return
end
print('Setting notify in redis hash '..hash..' to true')
print('Setze notify in redis hash '..hash..' auf true')
redis:hset(hash, 'notify', true)
print('Setting id in redis hash '..hash..' to '..msg.from.id)
print('Setze id in redis hash '..hash..' auf '..msg.from.id)
redis:hset(hash, 'id', msg.from.id)
print('Adding '..username..' to redis set notify:ls')
print('Adde '..username..' zu redis set notify:ls')
redis:sadd('notify:ls', username)
local res = utilities.send_message(self, msg.from.id, 'Du erhälst jetzt Benachrichtigungen, wenn du angesprochen wirst, nutze `/notify del` zum Deaktivieren.', true, nil, true)
if not res then

View File

@ -1,18 +1,14 @@
local pagespeed_insights = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
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.')
print('Fehlender Key: google_apikey.')
print('pagespeed_insights.lua wird nicht aktiviert.')
return
end
pagespeed_insights.triggers = {
"^/speed (https?://[%w-_%.%?%.:/%+=&]+)"
"^/[Ss][Pp][Ee][Ee][Dd] (https?://[%w-_%.%?%.:/%+=&]+)"
}
pagespeed_insights.doc = [[*
]]..config.cmd_pat..[[speed* _<Seiten-URL>_: Testet Geschwindigkeit der Seite mit PageSpeed Insights]]

View File

@ -1,12 +1,9 @@
local pasteee = {}
local bot = require('miku.bot')
local utilities = require('miku.utilities')
function pasteee:init(config)
if not cred_data.pasteee_key then
print('Missing config value: pasteee_key.')
print('pasteee.lua will not be enabled, listquotes won\'t be available.')
print('Fehlender Key: pasteee_key.')
print('pasteee.lua wird nicht aktiviert, listquotes won\'t be available.')
return
end

View File

@ -1,7 +1,5 @@
local patterns = {}
local utilities = require('miku.utilities')
patterns.triggers = {
'^/?s/.-/.-$'
}
@ -25,8 +23,8 @@ function patterns:action(msg)
utilities.send_reply(self, msg, 'Falsches Pattern!')
else
output = output:sub(1, 4000)
output = 'Du meintest wohl:\n"' .. output .. '"'
utilities.send_reply(self, msg.reply_to_message, output)
output = '*Du meintest wohl*:\n"'..utilities.md_escape(utilities.trim(output))..'"'
utilities.send_reply(self, msg.reply_to_message, output, true)
end
end

View File

@ -1,14 +1,9 @@
local pixabay = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
function pixabay:init(config)
if not cred_data.pixabay_apikey then
print('Missing config value: pixabay_apikey.')
print('pixabay.lua will not be enabled.')
print('Fehlender Key: pixabay_apikey.')
print('pixabay.lua wird nicht aktiviert.')
return
end

View File

@ -1,13 +1,9 @@
local play_store = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
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.')
print('Fehlender Key: x_mashape_key.')
print('play_store.lua wird nicht aktiviert.')
return
end

View File

@ -1,9 +1,6 @@
local plugin_manager = {}
local bot = require('miku.bot')
local bindings = require('miku.bindings')
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
function plugin_manager:init(config)
plugin_manager.triggers = {

View File

@ -1,15 +1,9 @@
local pocket = {}
local https = require('ssl.https')
local URL = require('socket.url')
local redis = (loadfile "./miku/redis.lua")()
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
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.')
print('Fehlender Key: pocket_consumer_key.')
print('pocket.lua wird nicht aktiviert.')
return
end

View File

@ -1,10 +1,5 @@
local pokedex = {}
local HTTP = require('socket.http')
local JSON = require('dkjson')
local bindings = require('miku.bindings')
local utilities = require('miku.utilities')
pokedex.command = 'pokedex <query>'
function pokedex:init(config)
@ -33,22 +28,22 @@ function pokedex:action(msg, config)
local url = 'http://pokeapi.co'
local dex_url = url .. '/api/v1/pokemon/' .. input
local dex_jstr, res = HTTP.request(dex_url)
local dex_jstr, res = http.request(dex_url)
if res ~= 200 then
utilities.send_reply(self, msg, config.errors.connection)
return
end
local dex_jdat = JSON.decode(dex_jstr)
local dex_jdat = json.decode(dex_jstr)
local desc_url = url .. dex_jdat.descriptions[math.random(#dex_jdat.descriptions)].resource_uri
local desc_jstr, _ = HTTP.request(desc_url)
local desc_jstr, _ = http.request(desc_url)
if res ~= 200 then
utilities.send_reply(self, msg, config.errors.connection)
return
end
local desc_jdat = JSON.decode(desc_jstr)
local desc_jdat = json.decode(desc_jstr)
local poke_type
for _,v in ipairs(dex_jdat.types) do

View File

@ -1,8 +1,5 @@
local preview = {}
local HTTP = require('socket.http')
local utilities = require('miku.utilities')
preview.command = 'preview <link>'
function preview:init(config)
@ -27,7 +24,7 @@ function preview:action(msg)
input = 'http://' .. input
end
local res = HTTP.request(input)
local res = http.request(input)
if not res then
utilities.send_reply(self, msg, 'Please provide a valid link.')
return

View File

@ -1,9 +1,5 @@
local qr = {}
local http = require('socket.http')
local URL = require('socket.url')
local utilities = require('miku.utilities')
function qr:init(config)
qr.triggers = {
'^/qr "(%w+)" "(%w+)" (.+)$',

View File

@ -1,8 +1,5 @@
local quotes = {}
local bot = require('miku.bot')
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
require("./miku/plugins/pasteee")
function quotes:init(config)

View File

@ -1,7 +1,5 @@
local fun = {}
local utilities = require('miku.utilities')
function fun:init(config)
fun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('random', true).table
fun.doc = [[*

View File

@ -1,10 +1,5 @@
local reddit = {}
local https = require('ssl.https')
local URL = require('socket.url')
local JSON = require('dkjson')
local utilities = require('miku.utilities')
reddit.command = 'reddit [r/subreddit | Suchbegriff]'
function reddit:init(config)
@ -68,7 +63,7 @@ function reddit:action(msg, config)
if res ~= 200 then
utilities.send_reply(self, msg, config.errors.results)
else
local jdat = JSON.decode(jstr)
local jdat = json.decode(jstr)
if #jdat.data.children == 0 then
utilities.send_reply(self, msg, config.errors.results)
else

View File

@ -1,10 +1,5 @@
local reddit_post = {}
local https = require('ssl.https')
local URL = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
reddit_post.triggers = {
"reddit.com/r/([A-Za-z0-9-/-_-.]+)/comments/([A-Za-z0-9-/-_-.]+)"
}

View File

@ -1,7 +1,5 @@
local remind = {}
local utilities = require('miku.utilities')
remind.command = 'remind <Länge> <Nachricht>'
function remind:init(config)

View File

@ -1,9 +1,5 @@
local respond = {}
local https = require('ssl.https')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
function respond:init(config)
respond.triggers = {
"([Ff][Gg][Tt].? [Ss][Ww][Ii][Ff][Tt])",

View File

@ -1,7 +1,5 @@
local roll = {}
local utilities = require('miku.utilities')
roll.command = 'roll'
function roll:init(config)

View File

@ -1,11 +1,5 @@
local rss = {}
local http = require('socket.http')
local https = require('ssl.https')
local url = require('socket.url')
local bindings = require('miku.bindings')
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
local feedparser = require("feedparser")
rss.command = 'rss <sub/del>'
@ -60,24 +54,6 @@ function to_utf8(a)
end
end
function unescape_for_rss(str)
str = string.gsub( str, '&lt;', '<' )
str = string.gsub( str, '&gt;', '>' )
str = string.gsub( str, '&quot;', '"' )
str = string.gsub( str, '&apos;', "'" )
str = string.gsub( str, "&Auml;", "Ä")
str = string.gsub( str, "&auml;", "ä")
str = string.gsub( str, "&Ouml;", "Ö")
str = string.gsub( str, "&ouml;", "ö")
str = string.gsub( str, "Uuml;", "Ü")
str = string.gsub( str, "&uuml;", "ü")
str = string.gsub( str, "&szlig;", "ß")
str = string.gsub(str, '&#(%d+);', to_utf8)
str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end )
str = string.gsub( str, '&amp;', '&' ) -- Be sure to do this after all others
return str
end
function cleanRSS(str)
str = string.gsub(str, '%[mehr%]', '')
str = string.gsub(str, '%[video%]', '')
@ -344,23 +320,23 @@ function rss:cron(self_plz)
local subscribers = {}
local text = '' -- Send one message per feed with the latest entries
for k2, v2 in pairs(newentr) do
local title = v2.title or 'Kein Titel'
local title = unescape(v2.title) or 'Kein Titel'
local link = v2.link or v2.id or 'Kein Link'
if v2.content then
content = v2.content:gsub("%b<>", "")
if string.len(v2.content) > 250 then
content = unescape_for_rss(content)
content = string.sub(content, 1, 250)..'...'
if string.len(v2.content) > 300 then
content = unescape(content)
content = string.sub(content, 1, 300)..'...'
else
content = unescape_for_rss(content)
content = unescape(content)
end
elseif v2.summary then
content = v2.summary:gsub("%b<>", "")
if string.len(v2.summary) > 250 then
content = unescape_for_rss(content)
content = string.sub(content, 1, 250)..'...'
if string.len(v2.summary) > 300 then
content = unescape(content)
content = string.sub(content, 1, 300)..'...'
else
content = unescape_for_rss(content)
content = unescape(content)
end
else
content = ''

View File

@ -1,8 +1,5 @@
local set = {}
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
set.command = 'set <Variable> <Wert>'
function set:init(config)

View File

@ -1,7 +1,5 @@
local shell = {}
local utilities = require('miku.utilities')
function shell:init(config)
shell.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('sh', true).table
end

View File

@ -1,7 +1,5 @@
local site_header = {}
local utilities = require('miku.utilities')
function site_header:init(config)
site_header.triggers = {
"^/(head) ([%w-_%.%?%.:,/%+=&#!]+)$",

View File

@ -1,9 +1,5 @@
local soundcloud = {}
local http = require('socket.http')
local json = require('dkjson')
local utilities = require('miku.utilities')
soundcloud.triggers = {
"soundcloud.com/([A-Za-z0-9-/-_-.]+)"
}

View File

@ -1,7 +1,5 @@
local speedtest = {}
local utilities = require('miku.utilities')
speedtest.triggers = {
"speedtest.net/my%-result/(%d+)",
"speedtest.net/my%-result/i/(%d+)"

View File

@ -1,9 +1,5 @@
local spotify = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
spotify.triggers = {
"open.spotify.com/track/([A-Za-z0-9-]+)",
"play.spotify.com/track/([A-Za-z0-9-]+)"

View File

@ -1,8 +1,5 @@
local stats = {}
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
function stats:init(config)
stats.triggers = {
"^/([Ss]tats)$",
@ -57,6 +54,13 @@ function stats:chat_stats(chat_id)
table.insert(users_info, user_info)
end
-- Get total message count
local all_msgs = 0
for n, user in pairs(users_info) do
local msg_num = users_info[n].msgs
all_msgs = all_msgs + msg_num
end
-- Sort users by msgs number
table.sort(users_info, function(a, b)
if a.msgs and b.msgs then
@ -66,10 +70,11 @@ function stats:chat_stats(chat_id)
local text = ''
for k,user in pairs(users_info) do
text = text..user.name..': '..user.msgs..'\n'
text = text..user.name..': '..comma_value(user.msgs)..'\n'
text = string.gsub(text, "%_", " ") -- Bot API doesn't use underscores anymore! Yippie!
end
if text:isempty() then return 'Keine Stats für diesen Chat verfügbar!'end
local text = utilities.md_escape(text)..'\n*TOTAL*: '..comma_value(all_msgs)
return text
end
@ -124,7 +129,7 @@ function stats:action(msg, config, matches)
return
else
local chat_id = msg.chat.id
utilities.send_reply(self, msg, stats:chat_stats(chat_id))
utilities.send_reply(self, msg, stats:chat_stats(chat_id), true)
return
end
end
@ -134,7 +139,7 @@ function stats:action(msg, config, matches)
utilities.send_reply(self, msg, config.errors.sudo)
return
else
utilities.send_reply(self, msg, stats:chat_stats(matches[3]))
utilities.send_reply(self, msg, stats:chat_stats(matches[3]), true)
return
end
end

View File

@ -1,10 +1,5 @@
local steam = {}
local utilities = require('miku.utilities')
local http = require('socket.http')
local json = require('dkjson')
local bindings = require('miku.bindings')
steam.triggers = {
"store.steampowered.com/app/([0-9]+)",
"steamcommunity.com/app/([0-9]+)"

View File

@ -1,9 +1,5 @@
local streamable = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
streamable.triggers = {
"streamable.com/([A-Za-z0-9-_-]+)",
}

View File

@ -1,7 +1,5 @@
local surrogate = {}
local utilities = require('miku.utilities')
surrogate.triggers = {
"^/s (%-%d+) +(.+)$",
"^/s (%d+) +(.+)$"

View File

@ -1,15 +1,11 @@
local tagesschau = {}
local https = require('ssl.https')
local URL = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
local bindings = require('miku.bindings')
tagesschau.triggers = {
"tagesschau.de/([A-Za-z0-9-_-_-/]+).html"
}
tagesschau.inline_triggers = tagesschau.triggers
local BASE_URL = 'https://www.tagesschau.de/api'
local makeOurDate = function(dateString)
@ -36,12 +32,33 @@ function tagesschau:get_tagesschau_article(article)
local text = '*'..title..'*\n_'..posted_at..'_\n'..news
if data.banner[1] then
return text, data.banner[1].variants[1].modPremium
return text, data.banner[1].variants[1].modPremium, data.shortheadline, data.shorttext
else
return text
return text, nil, data.shortheadline, data.shorttext
end
end
function tagesschau:inline_callback(inline_query, config, matches)
local article = matches[1]
local full_url = 'http://www.tagesschau.de/'..article..'.html'
local text, img_url, headline, shorttext = tagesschau:get_tagesschau_article(article)
if text == 'HTTP-Fehler' or text == 'Artikel nicht gefunden!' then return end
if text:match('"') then
text = text:gsub('"', '\\"')
end
if shorttext:match('"') then
shorttext = shorttext:gsub('"', '\\"')
end
if headline:match('"') then
headline = headline:gsub('"', '\\"')
end
local text = text:gsub('\n', '\\n')
local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"'..headline..'","description":"'..shorttext..'","url":"'..full_url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/tagesschau/tagesschau.jpg","thumb_width":150,"thumb_height":150,"hide_url":true,"reply_markup":{"inline_keyboard":[[{"text":"Artikel aufrufen","url":"'..full_url..'"}]]},"input_message_content":{"message_text":"'..text..'","parse_mode":"Markdown"}}]'
utilities.answer_inline_query(self, inline_query, results, 7200)
end
function tagesschau:action(msg, config, matches)
local article = matches[1]
local text, image_url = tagesschau:get_tagesschau_article(article)

View File

@ -1,112 +0,0 @@
local tagesschau_eil = {}
local http = require('socket.http')
local https = require('ssl.https')
local url = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
local redis = (loadfile "./miku/redis.lua")()
tagesschau_eil.command = 'eil <sub/del>'
function tagesschau_eil:init(config)
tagesschau_eil.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('eil', true).table
tagesschau_eil.doc = [[*
]]..config.cmd_pat..[[eil* _sub_: Eilmeldungen abonnieren
*]]..config.cmd_pat..[[eil* _del_: Eilmeldungen deabonnieren
*]]..config.cmd_pat..[[eil* _sync_: Nach neuen Eilmeldungen prüfen (nur Superuser)]]
end
local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)T(%d+)%:(%d+)%:(%d+)"
local year, month, day, hours, minutes, seconds = dateString:match(pattern)
return day..'.'..month..'.'..year..' um '..hours..':'..minutes..':'..seconds
end
local url = 'http://www.tagesschau.de/api'
local hash = 'telegram:tagesschau'
function tagesschau_eil:abonnieren(id)
if redis:sismember(hash..':subs', id) == false then
redis:sadd(hash..':subs', id)
return '*Eilmeldungen abonniert.*'
else
return 'Die Eilmeldungen wurden hier bereits abonniert.'
end
end
function tagesschau_eil:deabonnieren(id)
if redis:sismember(hash..':subs', id) == true then
redis:srem(hash..':subs', id)
return '*Eilmeldungen deabonniert.*'
else
return 'Die Eilmeldungen wurden hier noch nicht abonniert.'
end
end
function tagesschau_eil: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(self, msg.chat.id, tagesschau_eil.doc, true, msg.message_id, true)
return
end
end
local id = "user#id" .. msg.from.id
if msg.chat.type == 'channel' then
print('Kanäle werden momentan nicht unterstützt')
end
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
id = 'chat#id'..msg.chat.id
end
if input:match('(sub)$') then
local output = tagesschau_eil:abonnieren(id)
utilities.send_reply(self, msg, output, true)
elseif input:match('(del)$') then
local output = tagesschau_eil:deabonnieren(id)
utilities.send_reply(self, msg, output, true)
elseif input:match('(sync)$') then
if msg.from.id ~= config.admin then
utilities.send_reply(self, msg, config.errors.sudo)
return
end
tagesschau_eil:cron(self)
end
return
end
function tagesschau_eil:cron(self_plz)
if not self.BASE_URL then
self = self_plz
end
-- print('EIL: Prüfe...')
local last_eil = redis:get(hash..':last_entry')
local res,code = http.request(url)
if code ~= 200 then return end
local data = json.decode(res)
if not data then return end
if data.breakingnews[1] then
if data.breakingnews[1].date ~= last_eil then
local title = '#EIL: *'..data.breakingnews[1].headline..'*'
local news = data.breakingnews[1].shorttext
local posted_at = makeOurDate(data.breakingnews[1].date)..' Uhr'
local post_url = string.gsub(data.breakingnews[1].details, '/api/', '/')
local post_url = string.gsub(post_url, '.json', '.html')
local eil = title..'\n_'..posted_at..'_\n'..news
redis:set(hash..':last_entry', data.breakingnews[1].date)
for _,user in pairs(redis:smembers(hash..':subs')) do
local user = string.gsub(user, 'chat%#id', '')
local user = string.gsub(user, 'user%#id', '')
utilities.send_message(self, user, eil, true, nil, true, '{"inline_keyboard":[[{"text":"Eilmeldung aufrufen","url":"'..post_url..'"}]]}')
end
end
end
end
return tagesschau_eil

View File

@ -1,34 +0,0 @@
local tex = {}
local URL = require('socket.url')
local utilities = require('miku.utilities')
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(self, msg.chat.id, tex.doc, true, msg.message_id, true)
return
end
end
utilities.send_typing(self, 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(self, msg.chat.id, file, nil, msg.message_id)
end
return tex

View File

@ -1,9 +1,6 @@
local tv = {}
local http = require('socket.http')
local URL = require('socket.url')
local xml = require("xml")
local utilities = require('miku.utilities')
tv.command = 'tv <TV-Serie>'

View File

@ -1,9 +1,5 @@
local time = {}
local HTTPS = require('ssl.https')
local JSON = require('dkjson')
local utilities = require('miku.utilities')
time.command = 'time <Ort>'
function time:init(config)
@ -67,13 +63,13 @@ function time:action(msg, config)
local utc = os.time(os.date("!*t", now))
local url = 'https://maps.googleapis.com/maps/api/timezone/json?location=' .. coords.lat ..','.. coords.lon .. '&timestamp='..utc..'&language=de'
local jstr, res = HTTPS.request(url)
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)
local jdat = json.decode(jstr)
local timezoneid = '*'..string.gsub(jdat.timeZoneId, '_', ' ' )..'*'
local timestamp = now + jdat.rawOffset + jdat.dstOffset
local utcoff = (jdat.rawOffset + jdat.dstOffset) / 3600

View File

@ -1,15 +1,15 @@
local translate = {}
local https = require('ssl.https')
local URL = require('socket.url')
local json = require('dkjson')
local utilities = require('miku.utilities')
local mime = require("mime")
require("./miku/plugins/pasteee")
translate.command = 'translate [Text]'
function translate:init(config)
if not cred_data.bing_key then
print('Fehlender Key: bing_key.')
print('translate.lua wird nicht aktiviert.')
return
end
translate.triggers = {
"^/translate ([%w]+),([%a]+) (.+)",
"^/translate (to%:)([%w]+) (.+)",

View File

@ -1,28 +1,21 @@
local tweet = {}
local utilities = require('miku.utilities')
local HTTPS = require('ssl.https')
local JSON = require('dkjson')
local redis = (loadfile "./miku/redis.lua")()
local OAuth = (require "OAuth")
local bindings = require('miku.bindings')
function tweet:init(config)
if not cred_data.tw_consumer_key then
print('Missing config value: tw_consumer_key.')
print('tweet.lua will not be enabled.')
print('Fehlender Key: tw_consumer_key.')
print('tweet.lua wird nicht aktiviert.')
return
elseif not cred_data.tw_consumer_secret then
print('Missing config value: tw_consumer_secret.')
print('tweet.lua will not be enabled.')
print('Fehlender Key: tw_consumer_secret.')
print('tweet.lua wird nicht aktiviert.')
return
elseif not cred_data.tw_access_token then
print('Missing config value: tw_access_token.')
print('tweet.lua will not be enabled.')
print('Fehlender Key: tw_access_token.')
print('tweet.lua wird nicht aktiviert.')
return
elseif not cred_data.tw_access_token_secret then
print('Missing config value: tw_access_token_secret.')
print('tweet.lua will not be enabled.')
print('Fehlender Key: tw_access_token_secret.')
print('tweet.lua wird nicht aktiviert.')
return
end
@ -145,7 +138,7 @@ function tweet:getTweet(self, msg, base, all)
return "Konnte nicht verbinden, evtl. existiert der User nicht?"
end
local response = JSON.decode(response_body)
local response = json.decode(response_body)
if #response == 0 then
return "Konnte keinen Tweet bekommen, sorry"
end

Some files were not shown because too many files have changed in this diff Show More