Übernehme einige Änderungen von Brawl345/Brawlbot-v2

This commit is contained in:
Akamaru 2016-07-26 19:06:16 +02:00
parent 8db9a30d13
commit d99c805c3d
6 changed files with 64 additions and 33 deletions

View File

@ -25,6 +25,10 @@ Sende /hilfe, um zu starten
-- NOTE that it doesn't matter, if the chat is whitelisted! The USER must be whitelisted! -- NOTE that it doesn't matter, if the chat is whitelisted! The USER must be whitelisted!
enable_inline_for_everyone = true, enable_inline_for_everyone = true,
-- Botan.io statistics
enable_statistics = false,
botan_token = '',
errors = { -- Generic error messages used in various plugins. errors = { -- Generic error messages used in various plugins.
generic = 'An unexpected error occurred.', generic = 'An unexpected error occurred.',
connection = 'Verbindungsfehler.', connection = 'Verbindungsfehler.',
@ -71,8 +75,7 @@ Sende /hilfe, um zu starten
'adfly', 'adfly',
'twitter', 'twitter',
-- Put new plugins above this line. -- Put new plugins above this line.
'help', 'help'
'greetings'
} }
} }

View File

@ -10,6 +10,7 @@
local bindings = {} local bindings = {}
local HTTPS = require('ssl.https') local HTTPS = require('ssl.https')
HTTPS.timeout = 10
local JSON = require('dkjson') local JSON = require('dkjson')
local ltn12 = require('ltn12') local ltn12 = require('ltn12')
local MP_ENCODE = require('multipart-post').encode local MP_ENCODE = require('multipart-post').encode

View File

@ -5,7 +5,7 @@ local bindings -- Load Telegram bindings.
local utilities -- Load miscellaneous and cross-plugin functions. local utilities -- Load miscellaneous and cross-plugin functions.
local redis = (loadfile "./miku/redis.lua")() local redis = (loadfile "./miku/redis.lua")()
bot.version = '160717' bot.version = '160726'
function bot:init(config) -- The function run when the bot is started or reloaded. function bot:init(config) -- The function run when the bot is started or reloaded.
@ -32,21 +32,6 @@ function bot:init(config) -- The function run when the bot is started or reloade
self.database = utilities.load_data(self.info.username..'.db') self.database = utilities.load_data(self.info.username..'.db')
end end
-- MIGRATION CODE 2.0 -> 2.1
if self.database.users and self.database.version ~= '2.1' then
self.database.userdata = {}
for id, user in pairs(self.database.users) do
self.database.userdata[id] = {}
self.database.userdata[id].nickname = user.nickname
self.database.userdata[id].lastfm = user.lastfm
user.nickname = nil
user.lastfm = nil
user.id_str = nil
user.name = nil
end
end
-- END MIGRATION CODE
-- Table to cache user info (usernames, IDs, etc). -- Table to cache user info (usernames, IDs, etc).
self.database.users = self.database.users or {} self.database.users = self.database.users or {}
-- Table to store userdata (nicknames, lastfm usernames, etc). -- Table to store userdata (nicknames, lastfm usernames, etc).
@ -230,7 +215,7 @@ function match_inline_plugins(self, inline_query, config, plugin)
break; break;
end end
end end
print('Inline: '..plugin.name..' triggered') print('Inline: '..plugin.name..' ausgelöst')
return plugin.inline_callback(self, inline_query, config, matches) return plugin.inline_callback(self, inline_query, config, matches)
end) end)
if not success then if not success then
@ -253,7 +238,8 @@ function match_plugins(self, msg, config, plugin)
break; break;
end end
end end
print(plugin.name..' triggered') print(plugin.name..' ausgelöst')
plugin_name = plugin.name
return plugin.action(self, msg, config, matches) return plugin.action(self, msg, config, matches)
end) end)
if not success then if not success then
@ -268,6 +254,16 @@ function match_plugins(self, msg, config, plugin)
utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config) utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config)
return return
end 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 the action returns a table, make that table the new msg.
if type(result) == 'table' then if type(result) == 'table' then
msg = result msg = result

34
miku/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 "./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,5 +1,4 @@
-- This plugin should go at the end of your plugin list in -- This plugin should go at the end of your plugin list in config.lua.
-- config.lua, but not after greetings.lua.
local help = {} local help = {}
@ -8,11 +7,10 @@ local utilities = require('miku.utilities')
local help_text local help_text
function help:init(config) function help:init(config)
help.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('hilfe', true):t('help', true).table help.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Hh][Ii][Ll][Ff][Ee]', true):t('[Hh][Ee][Ll][Pp]', true).table
end end
function help:action(msg, config) function help:action(msg, config)
local commandlist = {} local commandlist = {}
help_text = '*Verfügbare Befehle:*\n'..config.cmd_pat help_text = '*Verfügbare Befehle:*\n'..config.cmd_pat
@ -20,11 +18,10 @@ function help:action(msg, config)
if plugin.command then if plugin.command then
table.insert(commandlist, plugin.command) table.insert(commandlist, plugin.command)
--help_text = help_text .. '\n• '..config.cmd_pat .. plugin.command:gsub('%[', '\\[')
end end
end end
table.insert(commandlist, 'hilfe [Plugin]') table.insert(commandlist, 'hilfe [Befehl]')
table.sort(commandlist) table.sort(commandlist)
help_text = help_text .. table.concat(commandlist, '\n'..config.cmd_pat) .. '\nParameter: <benötigt> [optional]' help_text = help_text .. table.concat(commandlist, '\n'..config.cmd_pat) .. '\nParameter: <benötigt> [optional]'
@ -52,7 +49,6 @@ function help:action(msg, config)
end end
utilities.send_reply(self, msg, 'Für diesen Befehl gibt es keine Hilfe.') utilities.send_reply(self, msg, 'Für diesen Befehl gibt es keine Hilfe.')
end end
return help return help

View File

@ -13,6 +13,8 @@ local serpent = require("serpent")
local bindings = require('miku.bindings') local bindings = require('miku.bindings')
local redis = (loadfile "./miku/redis.lua")() local redis = (loadfile "./miku/redis.lua")()
local mimetype = (loadfile "./miku/mimetype.lua")() local mimetype = (loadfile "./miku/mimetype.lua")()
local OAuth = require "OAuth"
local helpers = require "OAuth.helpers"
HTTP.timeout = 10 HTTP.timeout = 10
@ -646,9 +648,8 @@ function post_petition(url, arguments, headers)
local source = arguments local source = arguments
if type(arguments) == "table" then if type(arguments) == "table" then
local source = helpers.url_encode_arguments(arguments) source = helpers.url_encode_arguments(arguments)
end end
if not headers then if not headers then
request_constructor.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF8" request_constructor.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF8"
request_constructor.headers["X-Accept"] = "application/json" request_constructor.headers["X-Accept"] = "application/json"