This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/otouto/plugins/control.lua
topkecleon acc7046d64 administration 1.13.1
Added optional target for kick/ban logs. Added flag 7 to use default log
 per group. This way, a realm can have a public kick/ban log but governors
 are able to opt out. Added flag 8, antilink. Kicks for Telegram join links
 which do not refer to groups within the realm. Added flag 9, modrights, to
 give moderators access to changing the group photo, title, link, and motd
 (config option is deprecated. RIP). /unban will reset the target's autokick
 counter. Added configuration for default flag settings.

Revision to bindings.lua.
BASE_URL has been moved to bindings. There is no real reason for it to remain
in instance. Token is passed to bindings.init at load. All plugins have been
updated accordingly.
2016-08-23 00:16:32 -04:00

60 lines
1.8 KiB
Lua

local control = {}
local bot = require('otouto.bot')
local utilities = require('otouto.utilities')
local cmd_pat -- Prevents the command from being uncallable.
function control:init(config)
cmd_pat = config.cmd_pat
control.triggers = utilities.triggers(self.info.username, cmd_pat,
{'^'..cmd_pat..'script'}):t('reload', true):t('halt').table
end
function control:action(msg, config)
if msg.from.id ~= config.admin then
return
end
if msg.date < os.time() - 2 then return end
if msg.text_lower:match('^'..cmd_pat..'reload') then
for pac, _ in pairs(package.loaded) do
if pac:match('^otouto%.plugins%.') then
package.loaded[pac] = nil
end
end
package.loaded['otouto.bindings'] = nil
package.loaded['otouto.utilities'] = nil
package.loaded['otouto.drua-tg'] = nil
package.loaded['config'] = nil
if not msg.text_lower:match('%-config') then
for k, v in pairs(require('config')) do
config[k] = v
end
end
bot.init(self, config)
utilities.send_reply(msg, 'Bot reloaded!')
elseif msg.text_lower:match('^'..cmd_pat..'halt') then
self.is_started = false
utilities.send_reply(msg, 'Stopping bot!')
elseif msg.text_lower:match('^'..cmd_pat..'script') then
local input = msg.text_lower:match('^'..cmd_pat..'script\n(.+)')
if not input then
utilities.send_reply(msg, 'usage: ```\n'..cmd_pat..'script\n'..cmd_pat..'command <arg>\n...\n```', true)
return
end
input = input .. '\n'
for command in input:gmatch('(.-)\n') do
command = utilities.trim(command)
msg.text = command
bot.on_msg_receive(self, msg, config)
end
end
end
return control