Merge upstream
This commit is contained in:
commit
ebd806a1b8
@ -26,6 +26,7 @@ Ubuntu und Debian liefern Luarocks nur für Lua 5.1 aus. Um Luarocks für Lua 5.
|
|||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
Du benötigst **Lua 5.2+**, eine aktive **Redis-Instanz** und die folgenden **LuaRocks-Module**:
|
Du benötigst **Lua 5.2+**, eine aktive **Redis-Instanz** und die folgenden **LuaRocks-Module**:
|
||||||
|
* luautf8
|
||||||
* luasocket
|
* luasocket
|
||||||
* luasec
|
* luasec
|
||||||
* multipart-post
|
* multipart-post
|
||||||
|
@ -18,9 +18,16 @@ Willkommen bei Mikubot v2!
|
|||||||
|
|
||||||
Sende /hilfe, um zu starten
|
Sende /hilfe, um zu starten
|
||||||
]],
|
]],
|
||||||
-- The symbol that starts a command. Usually noted as '/' in documentation.
|
|
||||||
|
-- DO NOT CHANGE THIS
|
||||||
cmd_pat = '/',
|
cmd_pat = '/',
|
||||||
|
|
||||||
|
-- Text for users, who are not approved
|
||||||
|
banhammer_text = [[
|
||||||
|
Dies ist ein privater Bot, der erst nach einer Freischaltung benutzt werden kann.
|
||||||
|
This is a private bot, which can only be used after an approval.
|
||||||
|
]],
|
||||||
|
|
||||||
-- false = only whitelisted users can use inline querys
|
-- false = only whitelisted users can use inline querys
|
||||||
-- 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,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
# Launch Brawlbot
|
||||||
|
# Restart Brawlbot five seconds after halted.
|
||||||
while true; do
|
while true; do
|
||||||
lua main.lua
|
lua main.lua
|
||||||
echo 'Miku wurde gestoppt. ^C zum beenden.'
|
echo 'Miku wurde gestoppt. ^C zum beenden.'
|
||||||
|
@ -23,8 +23,14 @@ local bot = {}
|
|||||||
bot.version = '160824'
|
bot.version = '160824'
|
||||||
|
|
||||||
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.
|
||||||
|
<<<<<<< HEAD:miku/bot.lua
|
||||||
bindings = require('miku.bindings').init(config.bot_api_key)
|
bindings = require('miku.bindings').init(config.bot_api_key)
|
||||||
utilities = require('miku.utilities')
|
utilities = require('miku.utilities')
|
||||||
|
=======
|
||||||
|
assert(config.bot_api_key, 'Dein Bot-Token ist nicht in der Config gesetzt!')
|
||||||
|
bindings = require('otouto.bindings').init(config.bot_api_key)
|
||||||
|
utilities = require('otouto.utilities')
|
||||||
|
>>>>>>> upstream/master:otouto/bot.lua
|
||||||
cred_data = load_cred()
|
cred_data = load_cred()
|
||||||
|
|
||||||
-- Fetch bot information. Try until it succeeds.
|
-- Fetch bot information. Try until it succeeds.
|
||||||
|
@ -155,7 +155,14 @@ function banhammer:pre_process(msg, config)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
if not has_been_warned then
|
if not has_been_warned then
|
||||||
|
<<<<<<< HEAD:miku/plugins/banhammer.lua
|
||||||
utilities.send_reply(msg, "Dies ist ein privater Bot, der erst nach einer Freischaltung benutzt werden kann.\nThis is a private bot, which can only be used after an approval.")
|
utilities.send_reply(msg, "Dies ist ein privater Bot, der erst nach einer Freischaltung benutzt werden kann.\nThis is a private bot, which can only be used after an approval.")
|
||||||
|
=======
|
||||||
|
utilities.send_reply(msg, config.banhammer_text or [[
|
||||||
|
Dies ist ein privater Bot, der erst nach einer Freischaltung benutzt werden kann.
|
||||||
|
This is a private bot, which can only be used after an approval.
|
||||||
|
]])
|
||||||
|
>>>>>>> upstream/master:otouto/plugins/banhammer.lua
|
||||||
redis:hset('user:'..user_id, 'has_been_warned', true)
|
redis:hset('user:'..user_id, 'has_been_warned', true)
|
||||||
else
|
else
|
||||||
print('User has already been warned!')
|
print('User has already been warned!')
|
||||||
|
@ -2,9 +2,15 @@ local cleverbot = {}
|
|||||||
|
|
||||||
function cleverbot:init(config)
|
function cleverbot:init(config)
|
||||||
cleverbot.triggers = {
|
cleverbot.triggers = {
|
||||||
|
<<<<<<< HEAD:miku/plugins/cleverbot.lua
|
||||||
"^/[Cc][Bb][Oo][Tt] (.*)$",
|
"^/[Cc][Bb][Oo][Tt] (.*)$",
|
||||||
"^[Mm][Ii][Kk][Uu][Bb][Oo][Tt], (.+)$",
|
"^[Mm][Ii][Kk][Uu][Bb][Oo][Tt], (.+)$",
|
||||||
"^[Mm][Ii][Kk][Uu], (.+)$"
|
"^[Mm][Ii][Kk][Uu], (.+)$"
|
||||||
|
=======
|
||||||
|
"^/cbot (.+)$",
|
||||||
|
"^[Bb]rawlbot, (.+)$",
|
||||||
|
"^[Bb]ot, (.+)$"
|
||||||
|
>>>>>>> upstream/master:otouto/plugins/cleverbot.lua
|
||||||
}
|
}
|
||||||
cleverbot.url = config.chatter.cleverbot_api
|
cleverbot.url = config.chatter.cleverbot_api
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<<<<<<< HEAD:miku/plugins/luarun.lua
|
||||||
local luarun = {}
|
local luarun = {}
|
||||||
|
|
||||||
function luarun:init(config)
|
function luarun:init(config)
|
||||||
@ -56,4 +57,78 @@ function luarun:action(msg, config)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=======
|
||||||
|
local luarun = {}
|
||||||
|
|
||||||
|
local utilities = require('otouto.utilities')
|
||||||
|
local URL = require('socket.url')
|
||||||
|
local JSON, serpent
|
||||||
|
|
||||||
|
function luarun:init(config)
|
||||||
|
luarun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lua', true):t('return', true).table
|
||||||
|
if config.luarun_serpent then
|
||||||
|
serpent = require('serpent')
|
||||||
|
luarun.serialize = function(t)
|
||||||
|
return serpent.block(t, {comment=false})
|
||||||
|
end
|
||||||
|
else
|
||||||
|
JSON = require('dkjson')
|
||||||
|
luarun.serialize = function(t)
|
||||||
|
return JSON.encode(t, {indent=true})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function luarun:action(msg, config)
|
||||||
|
|
||||||
|
if msg.from.id ~= config.admin then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local input = utilities.input(msg.text)
|
||||||
|
if not input then
|
||||||
|
utilities.send_reply(msg, 'Bitte tätige eine Eingabe.')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if msg.text_lower:match('^'..config.cmd_pat..'return') then
|
||||||
|
input = 'return ' .. input
|
||||||
|
end
|
||||||
|
|
||||||
|
local output, success =
|
||||||
|
load("local bot = require('otouto.bot')\n\z
|
||||||
|
local bindings = require('otouto.bindings')\n\z
|
||||||
|
local utilities = require('otouto.utilities')\n\z
|
||||||
|
local json = require('dkjson')\n\z
|
||||||
|
local URL = require('socket.url')\n\z
|
||||||
|
local http = require('socket.http')\n\z
|
||||||
|
local https = require('ssl.https')\n\z
|
||||||
|
return function (self, msg, config)\n" .. input .. "\nend")
|
||||||
|
|
||||||
|
local function err_msg(x)
|
||||||
|
return "Fehler:\n" .. tostring(x)
|
||||||
|
end
|
||||||
|
|
||||||
|
if output == nil then
|
||||||
|
output = success
|
||||||
|
else
|
||||||
|
success, output = xpcall(output(), err_msg, self, msg, config)
|
||||||
|
end
|
||||||
|
|
||||||
|
if output == nil then
|
||||||
|
output = 'Fertig!'
|
||||||
|
else
|
||||||
|
if type(output) == 'table' then
|
||||||
|
local s = luarun.serialize(output)
|
||||||
|
if URL.escape(s):len() < 4000 then
|
||||||
|
output = s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
output = '<code>' .. utilities.html_escape(tostring(output)) .. '</code>'
|
||||||
|
end
|
||||||
|
utilities.send_message(msg.chat.id, output, true, msg.message_id, 'html')
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
>>>>>>> upstream/master:otouto/plugins/luarun.lua
|
||||||
return luarun
|
return luarun
|
@ -2,7 +2,9 @@ local leave_group = {}
|
|||||||
|
|
||||||
leave_group.triggers = {
|
leave_group.triggers = {
|
||||||
'^//tgservice group_chat_created$',
|
'^//tgservice group_chat_created$',
|
||||||
'^//tgservice supergroup_chat_created$'
|
'^//tgservice supergroup_chat_created$',
|
||||||
|
'^//tgservice new_chat_member$',
|
||||||
|
'^//tgservice (left_chat_member)$'
|
||||||
}
|
}
|
||||||
|
|
||||||
local report_to_admin = true -- set to false to not be notified, when Bot leaves groups without you
|
local report_to_admin = true -- set to false to not be notified, when Bot leaves groups without you
|
||||||
@ -23,9 +25,17 @@ function leave_group:check_for_admin(msg, config)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function leave_group:action(msg, config)
|
function leave_group:action(msg, config, matches)
|
||||||
if not is_service_msg(msg) then return end -- Bad attempt at trolling!
|
if not is_service_msg(msg) then return end -- Bad attempt at trolling!
|
||||||
local admin_in_group = leave_group:check_for_admin(msg, config)
|
if matches[1] == 'left_chat_member' then
|
||||||
|
if msg.left_chat_member.id == config.admin then
|
||||||
|
admin_in_group = false
|
||||||
|
else
|
||||||
|
admin_in_group = leave_group:check_for_admin(msg, config)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
admin_in_group = leave_group:check_for_admin(msg, config)
|
||||||
|
end
|
||||||
if not admin_in_group then
|
if not admin_in_group then
|
||||||
print('Admin ist nicht in der Gruppe, verlasse sie deshalb...')
|
print('Admin ist nicht in der Gruppe, verlasse sie deshalb...')
|
||||||
utilities.send_reply(msg, 'Dieser Bot wurde in eine fremde Gruppe hinzugefügt. Dies wird gemeldet!\nThis bot was added to foreign group. This incident will be reported!')
|
utilities.send_reply(msg, 'Dieser Bot wurde in eine fremde Gruppe hinzugefügt. Dies wird gemeldet!\nThis bot was added to foreign group. This incident will be reported!')
|
||||||
|
@ -1,33 +1,54 @@
|
|||||||
local xkcd = {}
|
local xkcd = {}
|
||||||
|
|
||||||
xkcd.command = 'xkcd [i]'
|
xkcd.command = 'xkcd [i]'
|
||||||
|
xkcd.base_url = 'https://xkcd.com/info.0.json'
|
||||||
|
xkcd.strip_url = 'https://xkcd.com/%s/info.0.json'
|
||||||
|
|
||||||
function xkcd:init(config)
|
function xkcd:init(config)
|
||||||
xkcd.triggers = {
|
xkcd.triggers = {
|
||||||
|
"xkcd.com/(%d+)",
|
||||||
"^/xkcd (%d+)",
|
"^/xkcd (%d+)",
|
||||||
"xkcd.com/(%d+)"
|
"^/xkcd (r)",
|
||||||
|
"^/xkcd"
|
||||||
}
|
}
|
||||||
xkcd.doc = [[*
|
xkcd.doc = [[*
|
||||||
]]..config.cmd_pat..[[xkcd* _[i]_: Gibt diesen XKCD-Comic aus]]
|
]]..config.cmd_pat..[[xkcd* _[i]_: Gibt den aktuellen XKCD-Comic aus, oder die Nummer, wenn eine gegeben ist. Wenn "r" übergeben wird, wird ein zufälliger Comic zurückgegeben.]]
|
||||||
|
local jstr = https.request(xkcd.base_url)
|
||||||
|
if jstr then
|
||||||
|
local data = json.decode(jstr)
|
||||||
|
if data then
|
||||||
|
xkcd.latest = data.num
|
||||||
end
|
end
|
||||||
|
|
||||||
function xkcd:get_xkcd(id)
|
|
||||||
local res,code = https.request("https://xkcd.com/"..id.."/info.0.json")
|
|
||||||
if code ~= 200 then return nil end
|
|
||||||
local data = json.decode(res)
|
|
||||||
local link_image = data.img
|
|
||||||
if link_image:sub(0,2) == '//' then
|
|
||||||
link_image = link_image:sub(3,-1)
|
|
||||||
end
|
end
|
||||||
return link_image, data.title, data.alt
|
xkcd.latest = xkcd.latest or 1700
|
||||||
end
|
end
|
||||||
|
|
||||||
function xkcd:action(msg, config, matches)
|
function xkcd:action(msg, config, matches)
|
||||||
local url, title, alt = xkcd:get_xkcd(matches[1])
|
if matches[1] == 'r' then
|
||||||
if not url then utilities.send_reply(msg, config.errors.connection) return end
|
input = math.random(xkcd.latest)
|
||||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
elseif tonumber(matches[1]) then
|
||||||
local file = download_to_file(url)
|
input = tonumber(matches[1])
|
||||||
utilities.send_photo(msg.chat.id, file, title..'\n'..alt, msg.message_id)
|
else
|
||||||
|
input = xkcd.latest
|
||||||
|
end
|
||||||
|
|
||||||
|
local url = xkcd.strip_url:format(input)
|
||||||
|
local jstr, code = https.request(url)
|
||||||
|
if code == 404 then
|
||||||
|
utilities.send_reply(msg, config.errors.results)
|
||||||
|
elseif code ~= 200 then
|
||||||
|
utilities.send_reply(msg, config.errors.connection)
|
||||||
|
else
|
||||||
|
local data = json.decode(jstr)
|
||||||
|
local output = string.format(
|
||||||
|
'<b>%s</b> (<a href="%s">%s</a>)\n<i>%s</i>',
|
||||||
|
utilities.html_escape(utilities.fix_utf8(data.safe_title)),
|
||||||
|
utilities.html_escape(data.img),
|
||||||
|
data.num,
|
||||||
|
utilities.html_escape(utilities.fix_utf8(data.alt))
|
||||||
|
)
|
||||||
|
utilities.send_message(msg.chat.id, output, false, nil, 'html')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return xkcd
|
return xkcd
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
local utilities = {}
|
local utilities = {}
|
||||||
|
|
||||||
|
utf8 = require 'lua-utf8'
|
||||||
ltn12 = require('ltn12')
|
ltn12 = require('ltn12')
|
||||||
http = require('socket.http')
|
http = require('socket.http')
|
||||||
https = require('ssl.https')
|
https = require('ssl.https')
|
||||||
@ -1130,4 +1131,10 @@ function is_channel_disabled(msg)
|
|||||||
return disabled
|
return disabled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Converts a gross string back into proper UTF-8.
|
||||||
|
-- Useful for fixing improper encoding caused by bad JSON escaping.
|
||||||
|
function utilities.fix_utf8(str)
|
||||||
|
return string.char(utf8.codepoint(str, 1, -1))
|
||||||
|
end
|
||||||
|
|
||||||
return utilities
|
return utilities
|
Reference in New Issue
Block a user