Übernehme einige Änderungen von Brawl345/Brawlbot-v2
This commit is contained in:
parent
8db9a30d13
commit
d99c805c3d
@ -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.',
|
||||
@ -71,8 +75,7 @@ Sende /hilfe, um zu starten
|
||||
'adfly',
|
||||
'twitter',
|
||||
-- Put new plugins above this line.
|
||||
'help',
|
||||
'greetings'
|
||||
'help'
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
local bindings = {}
|
||||
|
||||
local HTTPS = require('ssl.https')
|
||||
HTTPS.timeout = 10
|
||||
local JSON = require('dkjson')
|
||||
local ltn12 = require('ltn12')
|
||||
local MP_ENCODE = require('multipart-post').encode
|
||||
|
36
miku/bot.lua
36
miku/bot.lua
@ -5,7 +5,7 @@ local bindings -- Load Telegram bindings.
|
||||
local utilities -- Load miscellaneous and cross-plugin functions.
|
||||
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.
|
||||
|
||||
@ -31,21 +31,6 @@ function bot:init(config) -- The function run when the bot is started or reloade
|
||||
if not self.database then
|
||||
self.database = utilities.load_data(self.info.username..'.db')
|
||||
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).
|
||||
self.database.users = self.database.users or {}
|
||||
@ -230,7 +215,7 @@ function match_inline_plugins(self, inline_query, config, plugin)
|
||||
break;
|
||||
end
|
||||
end
|
||||
print('Inline: '..plugin.name..' triggered')
|
||||
print('Inline: '..plugin.name..' ausgelöst')
|
||||
return plugin.inline_callback(self, inline_query, config, matches)
|
||||
end)
|
||||
if not success then
|
||||
@ -253,7 +238,8 @@ function match_plugins(self, msg, config, plugin)
|
||||
break;
|
||||
end
|
||||
end
|
||||
print(plugin.name..' triggered')
|
||||
print(plugin.name..' ausgelöst')
|
||||
plugin_name = plugin.name
|
||||
return plugin.action(self, msg, config, matches)
|
||||
end)
|
||||
if not success then
|
||||
@ -265,9 +251,19 @@ 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
|
||||
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
miku/plugins/botan.lua
Normal file
34
miku/plugins/botan.lua
Normal 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
|
@ -1,5 +1,4 @@
|
||||
-- This plugin should go at the end of your plugin list in
|
||||
-- config.lua, but not after greetings.lua.
|
||||
-- This plugin should go at the end of your plugin list in config.lua.
|
||||
|
||||
local help = {}
|
||||
|
||||
@ -8,11 +7,10 @@ local utilities = require('miku.utilities')
|
||||
local help_text
|
||||
|
||||
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
|
||||
|
||||
function help:action(msg, config)
|
||||
|
||||
local commandlist = {}
|
||||
help_text = '*Verfügbare Befehle:*\n• '..config.cmd_pat
|
||||
|
||||
@ -20,11 +18,10 @@ function help:action(msg, config)
|
||||
if plugin.command then
|
||||
|
||||
table.insert(commandlist, plugin.command)
|
||||
--help_text = help_text .. '\n• '..config.cmd_pat .. plugin.command:gsub('%[', '\\[')
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(commandlist, 'hilfe [Plugin]')
|
||||
table.insert(commandlist, 'hilfe [Befehl]')
|
||||
table.sort(commandlist)
|
||||
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
|
||||
|
||||
utilities.send_reply(self, msg, 'Für diesen Befehl gibt es keine Hilfe.')
|
||||
|
||||
end
|
||||
|
||||
return help
|
||||
return help
|
@ -13,6 +13,8 @@ local serpent = require("serpent")
|
||||
local bindings = require('miku.bindings')
|
||||
local redis = (loadfile "./miku/redis.lua")()
|
||||
local mimetype = (loadfile "./miku/mimetype.lua")()
|
||||
local OAuth = require "OAuth"
|
||||
local helpers = require "OAuth.helpers"
|
||||
|
||||
HTTP.timeout = 10
|
||||
|
||||
@ -646,9 +648,8 @@ 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"
|
||||
|
Reference in New Issue
Block a user