diff --git a/config.lua.example b/config.lua.example index 3b230f3..8ee023f 100644 --- a/config.lua.example +++ b/config.lua.example @@ -21,7 +21,9 @@ Sende /hilfe, um zu starten -- The symbol that starts a command. Usually noted as '/' in documentation. cmd_pat = '/', +<<<<<<< HEAD:config.lua.example errors = { -- Generic error messages used in various plugins. + generic = 'An unexpected error occurred.', connection = 'Verbindungsfehler.', quotaexceeded = 'API-Quota aufgebraucht.', results = 'Keine Ergebnisse gefunden.', @@ -30,7 +32,7 @@ Sende /hilfe, um zu starten syntax = 'Invalide Syntax.', chatter_connection = 'Ich möchte gerade nicht reden', chatter_response = 'Ich weiß nicht, was ich darauf antworten soll.' - }, + } plugins = { -- To enable a plugin, add its name to the list. 'control', diff --git a/otouto/bot.lua b/otouto/bot.lua index ad8810c..bb1aa67 100644 --- a/otouto/bot.lua +++ b/otouto/bot.lua @@ -69,21 +69,28 @@ 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() -- trying to port matches to otouto - for k, pattern in pairs(v.triggers) do + for k, pattern in pairs(plugin.triggers) do matches = match_pattern(pattern, msg.text) if matches then break; end end - return v.action(self, msg, config, matches) + return plugin.action(self, msg, config, matches) end) if not success then - utilities.send_reply(self, msg, 'Ein unbekannter Fehler ist aufgetreten, bitte [melde diesen Bug](https://github.com/Brawl345/Brawlbot-v2/issues).', true) + -- 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, true) + end utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config) return end diff --git a/otouto/plugins/administration.lua b/otouto/plugins/administration.lua index f7dca82..62dbb3f 100644 --- a/otouto/plugins/administration.lua +++ b/otouto/plugins/administration.lua @@ -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 } } diff --git a/otouto/plugins/patterns.lua b/otouto/plugins/patterns.lua index bfffcd4..82eb8fd 100644 --- a/otouto/plugins/patterns.lua +++ b/otouto/plugins/patterns.lua @@ -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 .. '"'