administration.lua:
Switched to drua-tg.lua. Groups are now listed according to most recent activity. whoami.lua: Displays channel/supergroup IDs properly.
This commit is contained in:
parent
9377107508
commit
5762e12a48
@ -220,7 +220,7 @@ Bot output from every plugin should follow a consistent style. This style is eas
|
||||
Titles should be either **bold** (along with their colons) or a [link](http://otou.to) (with plaintext colons) to the content's source. Names should be _italic_. Numbered lists should use bold numbers followed by a bold period followed by a space. Unnumbered lists should use the • bullet point followed by a space. Descriptions and information should be in plaintext, although "flavor" text should be italic. Technical information should be `monospace`. Links should be named.
|
||||
|
||||
## Contributors
|
||||
Everybody is free to contribute to otouto. If you are interested, you are invited to fork the [repo](http://github.com/topkecleon/otouto) and start making pull requests.. If you have an idea and you are not sure how to implement it, open an issue or bring it up in the Bot Development group.
|
||||
Everybody is free to contribute to otouto. If you are interested, you are invited to fork the [repo](http://github.com/topkecleon/otouto) and start making pull requests. If you have an idea and you are not sure how to implement it, open an issue or bring it up in the Bot Development group.
|
||||
|
||||
The creator and maintainer of otouto is [topkecleon](http://github.com/topkecleon). He can be contacted via [Telegram](http://telegram.me/topkecleon), [Twitter](http://twitter.com/topkecleon), or [email](mailto:drew@otou.to).
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
assert(HTTPS)
|
||||
assert(JSON)
|
||||
assert(URL)
|
||||
|
||||
local BASE_URL = 'https://api.telegram.org/bot' .. config.bot_api_key
|
||||
|
||||
|
14
config.lua
14
config.lua
@ -55,20 +55,6 @@ Send /help to get started.
|
||||
'thank you'
|
||||
}
|
||||
},
|
||||
moderation = {
|
||||
admins = {
|
||||
['00000000'] = 'You'
|
||||
},
|
||||
errors = {
|
||||
antisquig = 'This group is English-only.',
|
||||
moderation = 'I do not moderate this group.',
|
||||
not_mod = 'This command must be run by a moderator.',
|
||||
not_admin = 'This command must be run by an administrator.',
|
||||
},
|
||||
admin_group = -00000000,
|
||||
realm_name = 'My Realm',
|
||||
antisquig = false
|
||||
},
|
||||
plugins = {
|
||||
'control.lua',
|
||||
'blacklist.lua',
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[
|
||||
administration.lua
|
||||
Version 1.5
|
||||
Version 1.6
|
||||
Part of the otouto project.
|
||||
© 2016 topkecleon <drew@otou.to>
|
||||
GNU General Public License, version 2
|
||||
@ -17,13 +17,16 @@
|
||||
stored in a "groups" array rather than at the top level. Global data is now
|
||||
stored at the top level rather than in a "global" array. Automatic migration
|
||||
will occur in versions 1.5 and 1.6.
|
||||
|
||||
/groups will now list groups according to activity.
|
||||
]]--
|
||||
|
||||
-- Build the administration db if nonexistent.
|
||||
if not database.administration then
|
||||
database.administration = {
|
||||
admins = {},
|
||||
groups = {}
|
||||
groups = {},
|
||||
activity = {}
|
||||
}
|
||||
end
|
||||
|
||||
@ -50,8 +53,17 @@ for k,v in pairs(database.administration.groups) do
|
||||
v.rules = v.rules or {}
|
||||
end
|
||||
|
||||
local sender = dofile('lua-tg/sender.lua')
|
||||
tg = sender('localhost', config.cli_port)
|
||||
-- Migration code: Remove this in v1.8.
|
||||
-- Most recent group activity is now cached for group listings.
|
||||
if not database.administration.activity then
|
||||
database.administration.activity = {}
|
||||
for k,v in pairs(database.administration.groups) do
|
||||
table.insert(database.administration.activity, k)
|
||||
end
|
||||
end
|
||||
|
||||
drua = dofile('drua-tg/drua-tg.lua')
|
||||
drua.PORT = config.cli_port or 4567
|
||||
|
||||
local flags = {
|
||||
[1] = {
|
||||
@ -138,53 +150,6 @@ local get_target = function(msg)
|
||||
|
||||
end
|
||||
|
||||
local kick_user = function(chat, target)
|
||||
|
||||
chat = math.abs(chat)
|
||||
|
||||
if chat > 1000000000000 then
|
||||
chat = chat - 1000000000000
|
||||
tg:_send('channel_kick channel#' .. chat .. ' user#' .. target .. '\n')
|
||||
else
|
||||
tg:_send('chat_del_user chat#' .. chat .. ' user#' .. target .. '\n')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local get_photo = function(chat)
|
||||
|
||||
chat = math.abs(chat)
|
||||
|
||||
local filename
|
||||
|
||||
if chat > 1000000000000 then
|
||||
chat = chat - 1000000000000
|
||||
filename = tg:_send('load_channel_photo channel#' .. chat .. '\n', true)
|
||||
else
|
||||
filename = tg:_send('load_chat_photo chat#' .. chat .. '\n', true)
|
||||
end
|
||||
|
||||
if filename:find('FAIL') then
|
||||
print('Error downloading photo for group ' .. chat .. '.')
|
||||
return
|
||||
end
|
||||
filename = filename:gsub('Saved to ', '')
|
||||
return filename
|
||||
|
||||
end
|
||||
|
||||
local get_link = function(chat)
|
||||
|
||||
chat = math.abs(chat)
|
||||
if chat > 1000000000000 then
|
||||
chat = chat - 1000000000000
|
||||
return tg:_send('export_channel_link channel#' .. chat .. '\n', true)
|
||||
else
|
||||
return tg:_send('export_chat_link chat#' .. chat .. '\n', true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local get_desc = function(chat_id)
|
||||
|
||||
local group = database.administration.groups[tostring(chat_id)]
|
||||
@ -234,16 +199,14 @@ local commands = {
|
||||
if not group.flags[2] then
|
||||
return true
|
||||
end
|
||||
kick_user(msg.chat.id, msg.from.id)
|
||||
drua.kick_user(msg.chat.id, msg.from.id)
|
||||
local output = flags[2].kicked:gsub('GROUPNAME', msg.chat.title)
|
||||
sendMessage(msg.from.id, output)
|
||||
end
|
||||
},
|
||||
|
||||
{ -- generic
|
||||
triggers = {
|
||||
''
|
||||
},
|
||||
triggers = { '' },
|
||||
|
||||
privilege = 0,
|
||||
interior = true,
|
||||
@ -254,7 +217,7 @@ local commands = {
|
||||
|
||||
-- banned
|
||||
if rank == 0 then
|
||||
kick_user(msg.chat.id, msg.from.id)
|
||||
drua.kick_user(msg.chat.id, msg.from.id)
|
||||
sendMessage(msg.from.id, 'Sorry, you are banned from ' .. msg.chat.title .. '.')
|
||||
return
|
||||
end
|
||||
@ -264,7 +227,7 @@ local commands = {
|
||||
-- antisquig Strict
|
||||
if group.flags[3] == true then
|
||||
if msg.from.name:match('[\216-\219][\128-\191]') or msg.from.name:match('') or msg.from.name:match('') then
|
||||
kick_user(msg.chat.id, msg.from.id)
|
||||
drua.kick_user(msg.chat.id, msg.from.id)
|
||||
local output = flags[3].kicked:gsub('GROUPNAME', msg.chat.title)
|
||||
sendMessage(msg.from.id, output)
|
||||
return
|
||||
@ -282,7 +245,7 @@ local commands = {
|
||||
|
||||
-- banned
|
||||
if get_rank(msg.new_chat_participant.id, msg.chat.id) == 0 then
|
||||
kick_user(msg.chat.id, msg.new_chat_participant.id)
|
||||
drua.kick_user(msg.chat.id, msg.new_chat_participant.id)
|
||||
sendMessage(msg.new_chat_participant.id, 'Sorry, you are banned from ' .. msg.chat.title .. '.')
|
||||
return
|
||||
end
|
||||
@ -290,7 +253,7 @@ local commands = {
|
||||
-- antisquig Strict
|
||||
if group.flags[3] == true then
|
||||
if msg.new_chat_participant.name:match('[\216-\219][\128-\191]') or msg.new_chat_participant.name:match('') or msg.new_chat_participant.name:match('') then
|
||||
kick_user(msg.chat.id, msg.new_chat_participant.id)
|
||||
drua.kick_user(msg.chat.id, msg.new_chat_participant.id)
|
||||
local output = flags[3].kicked:gsub('GROUPNAME', msg.chat.title)
|
||||
sendMessage(msg.new_chat_participant.id, output)
|
||||
return
|
||||
@ -300,7 +263,7 @@ local commands = {
|
||||
-- antibot
|
||||
if msg.new_chat_participant.username and msg.new_chat_participant.username:match('bot$') then
|
||||
if rank < 2 and group.flags[4] == true then
|
||||
kick_user(msg.chat.id, msg.new_chat_participant.id)
|
||||
drua.kick_user(msg.chat.id, msg.new_chat_participant.id)
|
||||
return
|
||||
end
|
||||
else
|
||||
@ -312,7 +275,7 @@ local commands = {
|
||||
elseif msg.new_chat_title then
|
||||
|
||||
if rank < 3 then
|
||||
tg:rename_chat(msg.chat.id, group.name)
|
||||
drua.rename_chat(msg.chat.id, group.name)
|
||||
else
|
||||
group.name = msg.new_chat_title
|
||||
end
|
||||
@ -322,12 +285,12 @@ local commands = {
|
||||
|
||||
if group.grouptype == 'group' then
|
||||
if rank < 3 then
|
||||
tg:chat_set_photo(msg.chat.id, group.photo)
|
||||
drua.set_photo(msg.chat.id, group.photo)
|
||||
else
|
||||
group.photo = get_photo(msg.chat.id)
|
||||
group.photo = drua.get_photo(msg.chat.id)
|
||||
end
|
||||
else
|
||||
group.photo = get_photo(msg.chat.id)
|
||||
group.photo = drua.get_photo(msg.chat.id)
|
||||
end
|
||||
return
|
||||
|
||||
@ -335,7 +298,7 @@ local commands = {
|
||||
|
||||
if group.grouptype == 'group' then
|
||||
if rank < 3 then
|
||||
tg:chat_set_photo(msg.chat.id, group.photo)
|
||||
drua.set_photo(msg.chat.id, group.photo)
|
||||
else
|
||||
group.photo = nil
|
||||
end
|
||||
@ -346,6 +309,14 @@ local commands = {
|
||||
|
||||
end
|
||||
|
||||
-- Last active time for group listing.
|
||||
for i,v in pairs(database.administration.activity) do
|
||||
if v == msg.chat.id_str then
|
||||
table.remove(database.administration.activity, i)
|
||||
table.insert(database.administration.activity, 1, msg.chat.id_str)
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
end
|
||||
@ -353,8 +324,7 @@ local commands = {
|
||||
|
||||
{ -- groups
|
||||
triggers = {
|
||||
'^/groups[@'..bot.username..']*$',
|
||||
'^/glist[@'..bot.username..']*$'
|
||||
'^/groups[@'..bot.username..']*$'
|
||||
},
|
||||
|
||||
command = 'groups',
|
||||
@ -363,13 +333,13 @@ local commands = {
|
||||
|
||||
action = function(msg)
|
||||
local output = ''
|
||||
for k,v in pairs(database.administration.groups) do
|
||||
-- no unlisted groups
|
||||
if not v.flags[1] then
|
||||
if v.link then
|
||||
output = output .. '• [' .. v.name .. '](' .. v.link .. ')\n'
|
||||
for i,v in ipairs(database.administration.activity) do
|
||||
local group = database.administration.groups[v]
|
||||
if not group.flags[1] then -- no unlisted groups
|
||||
if group.link then
|
||||
output = output .. '• [' .. group.name .. '](' .. group.link .. ')\n'
|
||||
else
|
||||
output = output .. '• ' .. v.name .. '\n'
|
||||
output = output .. '• ' .. group.name .. '\n'
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -495,8 +465,7 @@ local commands = {
|
||||
|
||||
{ -- motd
|
||||
triggers = {
|
||||
'^/motd[@'..bot.username..']*',
|
||||
'^/description[@'..bot.username..']*'
|
||||
'^/motd[@'..bot.username..']*'
|
||||
},
|
||||
|
||||
command = 'motd',
|
||||
@ -548,7 +517,7 @@ local commands = {
|
||||
local output = 'Leave this group manually or you will be unable to rejoin.'
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
else
|
||||
kick_user(msg.chat.id, msg.from.id)
|
||||
drua.kick_user(msg.chat.id, msg.from.id)
|
||||
end
|
||||
end
|
||||
},
|
||||
@ -571,7 +540,7 @@ local commands = {
|
||||
sendReply(msg, target.name .. ' is too privileged to be kicked.')
|
||||
return
|
||||
end
|
||||
kick_user(msg.chat.id, target.id)
|
||||
drua.kick_user(msg.chat.id, target.id)
|
||||
sendMessage(msg.chat.id, target.name .. ' has been kicked.')
|
||||
end
|
||||
},
|
||||
@ -601,7 +570,7 @@ local commands = {
|
||||
sendReply(msg, target.name .. ' has been unbanned.')
|
||||
else
|
||||
group.bans[target.id_str] = true
|
||||
kick_user(msg.chat.id, target.id)
|
||||
drua.kick_user(msg.chat.id, target.id)
|
||||
sendReply(msg, target.name .. ' has been banned.')
|
||||
end
|
||||
end
|
||||
@ -733,7 +702,7 @@ local commands = {
|
||||
sendReply(msg, 'Please specify the new link.')
|
||||
return
|
||||
elseif input == '--' or input == '—' then
|
||||
group.link = get_link(msg.chat.id)
|
||||
group.link = drua.export_link(msg.chat.id)
|
||||
sendReply(msg, 'The link has been regenerated.')
|
||||
return
|
||||
end
|
||||
@ -797,7 +766,7 @@ local commands = {
|
||||
end
|
||||
if group.mods[target.id_str] then
|
||||
if group.grouptype == 'supergroup' then
|
||||
tg:channel_set_admin(msg.chat.id, target, 0)
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 0)
|
||||
end
|
||||
group.mods[target.id_str] = nil
|
||||
sendReply(msg, target.name .. ' is no longer a moderator.')
|
||||
@ -807,7 +776,7 @@ local commands = {
|
||||
return
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
tg:channel_set_admin(msg.chat.id, target, 1)
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 1)
|
||||
end
|
||||
group.mods[target.id_str] = true
|
||||
sendReply(msg, target.name .. ' is now a moderator.')
|
||||
@ -833,7 +802,7 @@ local commands = {
|
||||
end
|
||||
if group.govs[target.id_str] then
|
||||
if group.grouptype == 'supergroup' then
|
||||
tg:channel_set_admin(msg.chat.id, target, 0)
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 0)
|
||||
end
|
||||
group.govs[target.id_str] = nil
|
||||
sendReply(msg, target.name .. ' is no longer a governor.')
|
||||
@ -846,7 +815,7 @@ local commands = {
|
||||
group.mods[target.id_str] = nil
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
tg:channel_set_admin(msg.chat.id, target, 1)
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 1)
|
||||
end
|
||||
group.govs[target.id_str] = true
|
||||
sendReply(msg, target.name .. ' is now a governor.')
|
||||
@ -880,7 +849,7 @@ local commands = {
|
||||
else
|
||||
database.blacklist[target.id_str] = true
|
||||
for k,v in pairs(database.administration.groups) do
|
||||
kick_user(k, target.id)
|
||||
drua.kick_user(k, target.id)
|
||||
end
|
||||
sendReply(msg, target.name .. ' has been globally banned.')
|
||||
end
|
||||
@ -943,10 +912,11 @@ local commands = {
|
||||
rules = {},
|
||||
grouptype = msg.chat.type,
|
||||
name = msg.chat.title,
|
||||
link = get_link(msg.chat.id),
|
||||
photo = get_photo(msg.chat.id),
|
||||
link = drua.export_link(msg.chat.id),
|
||||
photo = drua.get_photo(msg.chat.id),
|
||||
founded = os.time()
|
||||
}
|
||||
table.insert(database.administration.activity, msg.chat.id_str)
|
||||
sendReply(msg, 'I am now administrating this group.')
|
||||
end
|
||||
},
|
||||
@ -1043,17 +1013,12 @@ local action = function(msg)
|
||||
return true
|
||||
end
|
||||
|
||||
local cron = function()
|
||||
tg = sender(localhost, config.cli_port)
|
||||
end
|
||||
|
||||
local command = 'groups'
|
||||
local doc = '`Returns a list of administrated groups.\nUse /ahelp for more administrative commands.`'
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
cron = cron,
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -23,9 +23,14 @@ local action = function(msg)
|
||||
end
|
||||
from_name = from_name .. ' (' .. msg.from.id .. ')'
|
||||
|
||||
local chat_id = math.abs(msg.chat.id)
|
||||
if chat_id > 1000000000000 then
|
||||
chat_id = chat_id - 1000000000000
|
||||
end
|
||||
|
||||
local to_name
|
||||
if msg.chat.title then
|
||||
to_name = msg.chat.title .. ' (' .. math.abs(msg.chat.id) .. ').'
|
||||
to_name = msg.chat.title .. ' (' .. chat_id .. ').'
|
||||
else
|
||||
to_name = '@' .. bot.username .. ', AKA ' .. bot.first_name .. ' (' .. bot.id .. ').'
|
||||
end
|
||||
|
@ -7,7 +7,7 @@
|
||||
echo 'Requesting root privileges to install necessary packages:'
|
||||
echo 'libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make'
|
||||
sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make
|
||||
git clone http://github.com/topkecleon/lua-tg
|
||||
git clone http://github.com/topkecleon/drua-tg
|
||||
git clone http://github.com/vysheng/tg --recursive -b test
|
||||
cd tg
|
||||
./configure
|
||||
|
Reference in New Issue
Block a user