diff --git a/README.md b/README.md index 110dbce..e9a6356 100755 --- a/README.md +++ b/README.md @@ -195,12 +195,12 @@ Additionally, antiflood can be configured to automatically ban a user after he h * * * ## Introduction -#todo +####todo ## Plugins -otouto uses a robust plugin system, similar to yagop's [Telegram-Bot](http://github.com/yagop/telegram-bot). The aim of the otouto project is to contain any desirable bot feature within one universal bot framework. +otouto uses a robust plugin system, similar to yagop's [Telegram-Bot](http://github.com/yagop/telegram-bot). -Most plugins are intended for public use, but a few are for other purposes, like those used alongside [Liberbot](#liberbot-related-plugins), or for [use by the bot's owner](#control-plugins). See [here](#list-of-plugins) for a list of plugins. +Most plugins are intended for public use, but a few are for other purposes, like those for [use by the bot's owner](#control-plugins). See [here](#list-of-plugins) for a list of plugins. A plugin can have five components, and two of them are required: diff --git a/bot.lua b/bot.lua index 1d909b1..6f81ad5 100755 --- a/bot.lua +++ b/bot.lua @@ -31,6 +31,9 @@ function bot:init() -- The function run when the bot is started or reloaded. self.database = utilities.load_data(self.info.username..'.db') end + self.database.users = self.database.users or {} -- Table to cache userdata. + self.database.users[tostring(self.info.id)] = self.info + self.plugins = {} -- Load plugins. for _,v in ipairs(self.config.plugins) do local p = require('plugins.'..v) @@ -43,8 +46,6 @@ function bot:init() -- The function run when the bot is started or reloaded. self.last_update = self.last_update or 0 -- Set loop variables: Update offset, self.last_cron = self.last_cron or os.date('%M') -- the time of the last cron job, self.is_started = true -- and whether or not the bot should be running. - self.database.users = self.database.users or {} -- Table to cache userdata. - self.database.users[tostring(self.info.id)] = self.info end @@ -105,7 +106,7 @@ function bot:run() end end else - print('Connection error fetching updates.') + print('Connection error while fetching updates.') end if self.last_cron ~= os.date('%M') then -- Run cron jobs every minute. diff --git a/plugins/administration.lua b/plugins/administration.lua index bdf2dcc..bbfceeb 100644 --- a/plugins/administration.lua +++ b/plugins/administration.lua @@ -32,6 +32,13 @@ 1.10.1 - Bug fixes and minor improvements. :^) + 1.10.2 - Fixed bug in antibot. Further, ranks 2+ will be automatically made + group admins when they join a group. + + 1.10.3 - /gadd now supports arguments to enable flags immediately, eg: + "/gadd 1 4 5" will add a grouo with the unlisted, antibot, and antiflood + flags. + ]]-- local JSON = require('dkjson') @@ -672,6 +679,7 @@ function administration.init_command(self_) utilities.send_reply(self, msg, 'I can\'t let you do that, '..msg.from.name..'.') else administration.kick_user(self, msg.chat.id, msg.from.id, 'kickme') + utilities.send_message(self, msg.chat.id, 'Goodbye, ' .. msg.from.name .. '!', true) if msg.chat.type == 'supergroup' then bindings.unbanChatMember(self, { chat_id = msg.chat.id, user_id = msg.from.id } ) end @@ -789,7 +797,7 @@ function administration.init_command(self_) command = 'changerule ', privilege = 3, interior = true, - doc = 'Changes a single rule. Pass "--" to delete the rule.', + doc = 'Changes a single rule. Pass "--" to delete the rule. If i is a number for which there is no rule, adds a rule by the next incremented number.', action = function(self, msg, group) local input = utilities.input(msg.text) @@ -1190,22 +1198,36 @@ function administration.init_command(self_) }, { -- /gadd - triggers = utilities.triggers(self_.info.username):t('gadd').table, + triggers = utilities.triggers(self_.info.username):t('gadd', true).table, - command = 'gadd', + command = 'gadd [i] ...', privilege = 5, interior = false, - doc = 'Adds a group to the administration system.', + 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) if self.database.administration.groups[msg.chat.id_str] then utilities.send_reply(self, msg, 'I am already administrating this group.') else + local flags = {} + for i = 1, #administration.flags do + flags[i] = false + end + local input = utilities.input(msg.text) + if input then + local index = utilities.index(input) + for _, i in ipairs(index) do + i = tonumber(i) + if i and i < #administration.flags and i > 0 then + flags[i] = true + end + end + end self.database.administration.groups[msg.chat.id_str] = { mods = {}, governor = msg.from.id, bans = {}, - flags = {}, + flags = flags, rules = {}, grouptype = msg.chat.type, name = msg.chat.title, @@ -1216,9 +1238,6 @@ function administration.init_command(self_) autoban = 3 } administration.update_desc(self, msg.chat.id) - for i = 1, #administration.flags do - self.database.administration.groups[msg.chat.id_str].flags[i] = false - end table.insert(self.database.administration.activity, msg.chat.id_str) utilities.send_reply(self, msg, 'I am now administrating this group.') drua.channel_set_admin(msg.chat.id, self.info.id, 2) diff --git a/plugins/help.lua b/plugins/help.lua index a30ca09..c2f3b05 100755 --- a/plugins/help.lua +++ b/plugins/help.lua @@ -39,7 +39,7 @@ function help:action(msg) if not input then local res = utilities.send_message(self, msg.from.id, help_text, true, nil, true) if not res then - utilities.send_reply(self, msg, 'Please message me privately for a list of commands.') + utilities.send_reply(self, msg, 'Please message me privately or [click here](http://telegram.me/' .. self.info.username .. '?start=help) for a list of commands.', true) elseif msg.chat.type ~= 'private' then utilities.send_reply(self, msg, 'I have sent you the requested information in a private message.') end diff --git a/plugins/patterns.lua b/plugins/patterns.lua index 4e273af..cc475c4 100644 --- a/plugins/patterns.lua +++ b/plugins/patterns.lua @@ -3,13 +3,16 @@ local patterns = {} local utilities = require('utilities') patterns.triggers = { - '^/?s/.-/.-/?$' + '^/?s/.-/.-$' } function patterns:action(msg) - if not msg.reply_to_message then return end - local output = msg.reply_to_message.text or '' + 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"', '') + output = output:gsub('"$', '') + end local m1, m2 = msg.text:match('^/?s/(.-)/(.-)/?$') if not m2 then return true end local res @@ -21,11 +24,11 @@ function patterns:action(msg) if res == false then output = 'Malformed pattern!' utilities.send_reply(self, msg, output) - return + else + output = output:sub(1, 4000) + output = 'Did you mean:\n"' .. output .. '"' + utilities.send_reply(self, msg.reply_to_message, output) end - output = 'Did you mean:\n"' .. output:sub(1, 4000) .. '"' - utilities.send_reply(self, msg.reply_to_message, output) - end return patterns