otouto 3.10

Plugins can now silence error messages or set their own.
  administration.lua now silences error messages.
  administration kick notifications now include user IDs.
This commit is contained in:
topkecleon 2016-06-14 17:57:36 -04:00
parent 31a8e220ac
commit 101eb70eae
4 changed files with 41 additions and 15 deletions

View File

@ -43,7 +43,8 @@ Send /help to get started.
simsimi_key = '',
simsimi_trial = true,
errors = { -- Generic error messages used in various plugins.
errors = { -- Generic error messages.
generic = 'An unexpected error occurred.',
connection = 'Connection error.',
results = 'No results found.',
argument = 'Invalid argument.',

View File

@ -4,7 +4,7 @@ local bot = {}
local bindings -- Load Telegram bindings.
local utilities -- Load miscellaneous and cross-plugin functions.
bot.version = '3.9'
bot.version = '3.10'
function bot:init(config) -- The function run when the bot is started or reloaded.
@ -66,14 +66,21 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec
msg.text_lower = msg.text:lower()
end
for _,v in ipairs(self.plugins) do
for _,w in pairs(v.triggers) do
if string.match(msg.text_lower, w) then
for _, plugin in ipairs(self.plugins) do
for _, trigger in pairs(plugin.triggers) do
if string.match(msg.text_lower, trigger) then
local success, result = pcall(function()
return v.action(self, msg, config)
return plugin.action(self, msg, config)
end)
if not success then
utilities.send_reply(self, msg, 'Sorry, an unexpected error occurred.')
-- If the plugin has an error message, send it. If it does
-- not, use the generic one specified in config. If it's set
-- to false, do nothing.
if plugin.error then
utilities.send_reply(self, msg, plugin.error)
elseif plugin.error == nil then
utilities.send_reply(self, msg, config.errors.generic)
end
utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config)
return
end

View File

@ -71,6 +71,9 @@ function administration:init(config)
administration.doc = '`Returns a list of administrated groups.\nUse '..config.cmd_pat..'ahelp for more administrative commands.`'
-- In the worst case, don't send errors in reply to random messages.
administration.error = false
end
function administration.init_flags(cmd_pat) return {
@ -263,9 +266,9 @@ function administration:kick_user(chat, target, reason, config)
local victim = target
if self.database.users[tostring(target)] then
victim = utilities.build_name(
self.database.users[tostring(target)].first_name,
self.database.users[tostring(target)].last_name
)
self.database.users[tostring(target)].first_name,
self.database.users[tostring(target)].last_name
) .. ' [' .. victim .. ']'
end
local group = self.database.administration.groups[tostring(chat)].name
utilities.handle_exception(self, victim..' kicked from '..group, reason, config)
@ -917,7 +920,9 @@ function administration.init_command(self_, config)
if input then
input = utilities.get_word(input, 1)
input = tonumber(input)
if not input or not administration.flags[input] then input = false end
if not input or not administration.flags[input] then
input = false
end
end
if not input then
local output = '*Flags for ' .. msg.chat.title .. ':*\n'
@ -1209,7 +1214,9 @@ function administration.init_command(self_, config)
doc = 'Adds a group to the administration system. Pass numbers as arguments to enable those flags immediately. For example, this would add the group and enable the unlisted flag, antibot, and antiflood:\n/gadd 1 4 5',
action = function(self, msg, group, config)
if self.database.administration.groups[msg.chat.id_str] then
if msg.chat.id == msg.from.id then
utilities.send_message(self, msg.chat.id, 'No.')
elseif self.database.administration.groups[msg.chat.id_str] then
utilities.send_reply(self, msg, 'I am already administrating this group.')
else
local flags = {}
@ -1327,6 +1334,18 @@ function administration.init_command(self_, config)
end
end
end
},
{ -- /buildwall :^)
triggers = utilities.triggers(self_.info.username, config.cmd_pat):t('buildwall').table,
privilege = 3,
interior = true,
action = function(self, msg, group, config)
for i = 2, 5 do
group.flags[i] = true
end
utilities.send_message(self, msg.chat.id, 'antisquig, antisquig++, antibot, and antiflood have been enabled.')
end
}
}

View File

@ -7,7 +7,7 @@ patterns.triggers = {
}
function patterns:action(msg)
if not msg.reply_to_message then return end
if not msg.reply_to_message then return true end
local output = msg.reply_to_message.text
if msg.reply_to_message.from.id == self.info.id then
output = output:gsub('Did you mean:\n"', '')
@ -22,8 +22,7 @@ function patterns:action(msg)
end
)
if res == false then
output = 'Malformed pattern!'
utilities.send_reply(self, msg, output)
utilities.send_reply(self, msg, 'Malformed pattern!')
else
output = output:sub(1, 4000)
output = 'Did you mean:\n"' .. output .. '"'