help.lua: Provides start link when unable to send a user the help message privately.

administration.lua: 1.10.3: /gadd now supports arguments.
This commit is contained in:
topkecleon 2016-06-06 23:13:26 -04:00
parent 4848c9875b
commit a1810dba86
5 changed files with 45 additions and 22 deletions

View File

@ -195,12 +195,12 @@ Additionally, antiflood can be configured to automatically ban a user after he h
* * * * * *
## Introduction ## Introduction
#todo ####todo
## Plugins ## 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: A plugin can have five components, and two of them are required:

View File

@ -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') self.database = utilities.load_data(self.info.username..'.db')
end 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. self.plugins = {} -- Load plugins.
for _,v in ipairs(self.config.plugins) do for _,v in ipairs(self.config.plugins) do
local p = require('plugins.'..v) 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_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.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.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 end
@ -105,7 +106,7 @@ function bot:run()
end end
end end
else else
print('Connection error fetching updates.') print('Connection error while fetching updates.')
end end
if self.last_cron ~= os.date('%M') then -- Run cron jobs every minute. if self.last_cron ~= os.date('%M') then -- Run cron jobs every minute.

View File

@ -32,6 +32,13 @@
1.10.1 - Bug fixes and minor improvements. :^) 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') 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..'.') utilities.send_reply(self, msg, 'I can\'t let you do that, '..msg.from.name..'.')
else else
administration.kick_user(self, msg.chat.id, msg.from.id, 'kickme') 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 if msg.chat.type == 'supergroup' then
bindings.unbanChatMember(self, { chat_id = msg.chat.id, user_id = msg.from.id } ) bindings.unbanChatMember(self, { chat_id = msg.chat.id, user_id = msg.from.id } )
end end
@ -789,7 +797,7 @@ function administration.init_command(self_)
command = 'changerule <i> <rule>', command = 'changerule <i> <rule>',
privilege = 3, privilege = 3,
interior = true, 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) action = function(self, msg, group)
local input = utilities.input(msg.text) local input = utilities.input(msg.text)
@ -1190,22 +1198,36 @@ function administration.init_command(self_)
}, },
{ -- /gadd { -- /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, privilege = 5,
interior = false, 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) action = function(self, msg)
if self.database.administration.groups[msg.chat.id_str] then if self.database.administration.groups[msg.chat.id_str] then
utilities.send_reply(self, msg, 'I am already administrating this group.') utilities.send_reply(self, msg, 'I am already administrating this group.')
else 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] = { self.database.administration.groups[msg.chat.id_str] = {
mods = {}, mods = {},
governor = msg.from.id, governor = msg.from.id,
bans = {}, bans = {},
flags = {}, flags = flags,
rules = {}, rules = {},
grouptype = msg.chat.type, grouptype = msg.chat.type,
name = msg.chat.title, name = msg.chat.title,
@ -1216,9 +1238,6 @@ function administration.init_command(self_)
autoban = 3 autoban = 3
} }
administration.update_desc(self, msg.chat.id) 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) table.insert(self.database.administration.activity, msg.chat.id_str)
utilities.send_reply(self, msg, 'I am now administrating this group.') utilities.send_reply(self, msg, 'I am now administrating this group.')
drua.channel_set_admin(msg.chat.id, self.info.id, 2) drua.channel_set_admin(msg.chat.id, self.info.id, 2)

View File

@ -39,7 +39,7 @@ function help:action(msg)
if not input then if not input then
local res = utilities.send_message(self, msg.from.id, help_text, true, nil, true) local res = utilities.send_message(self, msg.from.id, help_text, true, nil, true)
if not res then 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 elseif msg.chat.type ~= 'private' then
utilities.send_reply(self, msg, 'I have sent you the requested information in a private message.') utilities.send_reply(self, msg, 'I have sent you the requested information in a private message.')
end end

View File

@ -3,13 +3,16 @@ local patterns = {}
local utilities = require('utilities') local utilities = require('utilities')
patterns.triggers = { patterns.triggers = {
'^/?s/.-/.-/?$' '^/?s/.-/.-$'
} }
function patterns:action(msg) function patterns:action(msg)
if not msg.reply_to_message then return end 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/(.-)/(.-)/?$') local m1, m2 = msg.text:match('^/?s/(.-)/(.-)/?$')
if not m2 then return true end if not m2 then return true end
local res local res
@ -21,11 +24,11 @@ function patterns:action(msg)
if res == false then if res == false then
output = 'Malformed pattern!' output = 'Malformed pattern!'
utilities.send_reply(self, msg, output) 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 end
output = 'Did you mean:\n"' .. output:sub(1, 4000) .. '"'
utilities.send_reply(self, msg.reply_to_message, output)
end end
return patterns return patterns