Integriere Botan.io, der Key von Botan muss in die config.lua eingetragen werden.

Es wird nur der Name des Plugin geloggt, keine Befehle und auch keine Userdaten!
This commit is contained in:
Andreas Bielawski 2016-07-26 16:39:18 +02:00
parent 5a261a87f4
commit e57a4fd520
4 changed files with 86 additions and 4 deletions

View File

@ -24,6 +24,10 @@ Sende /hilfe, um zu starten
-- false = only whitelisted users can use inline querys
-- 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.',

View File

@ -239,6 +239,7 @@ function match_plugins(self, msg, config, plugin)
end
end
print(plugin.name..' triggered')
plugin_name = plugin.name
return plugin.action(self, msg, config, matches)
end)
if not success then
@ -250,9 +251,20 @@ function match_plugins(self, msg, config, plugin)
elseif plugin.error == nil then
utilities.send_reply(self, msg, config.errors.generic, true)
end
utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config)
return
utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config)
return
end
-- Analytics
if config.enable_analytics and config.botan_token ~= '' then
for _,plugin in ipairs(self.plugins) do
if plugin.name == 'botan' then
print('Analytics')
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

34
otouto/plugins/botan.lua Normal file
View File

@ -0,0 +1,34 @@
local botan = {}
local https = require('ssl.https')
local URL = require('socket.url')
local redis = (loadfile "./otouto/redis.lua")()
local utilities = require('otouto.utilities')
local bindings = require('otouto.bindings')
function botan:init(config)
if not config.botan_token then
print('Missing config value: botan_token.')
print('botan.lua will not be enabled.')
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

@ -13,6 +13,8 @@ local serpent = require("serpent")
local bindings = require('otouto.bindings')
local redis = (loadfile "./otouto/redis.lua")()
local mimetype = (loadfile "./otouto/mimetype.lua")()
local OAuth = require "OAuth"
local helpers = require "OAuth.helpers"
HTTP.timeout = 10
@ -628,6 +630,36 @@ function is_sudo(msg, config)
return var
end
-- http://stackoverflow.com/a/6081639/3146627
function serializeTable(val, name, skipnewlines, depth)
skipnewlines = skipnewlines or false
depth = depth or 0
local tmp = string.rep(" ", depth)
if name then tmp = tmp .. name .. " = " end
if type(val) == "table" then
tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
for k, v in pairs(val) do
tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
end
tmp = tmp .. string.rep(" ", depth) .. "}"
elseif type(val) == "number" then
tmp = tmp .. tostring(val)
elseif type(val) == "string" then
tmp = tmp .. string.format("%q", val)
elseif type(val) == "boolean" then
tmp = tmp .. (val and "true" or "false")
else
tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
end
return tmp
end
function post_petition(url, arguments, headers)
local url, h = string.gsub(url, "http://", "")
local url, hs = string.gsub(url, "https://", "")
@ -646,9 +678,9 @@ function post_petition(url, arguments, headers)
local source = arguments
if type(arguments) == "table" then
local source = helpers.url_encode_arguments(arguments)
source = helpers.url_encode_arguments(arguments)
end
if not headers then
request_constructor.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF8"
request_constructor.headers["X-Accept"] = "application/json"