administration.lua: 1.8. See file for changes.
This commit is contained in:
parent
9f9ca12e8f
commit
8fe72b3a64
@ -36,7 +36,7 @@ Note that certain plugins, such as translate.lua and greetings.lua, will require
|
||||
- lastfm.lua: [last.fm](http://last.fm) API key (`lastfm_api_key`)
|
||||
- bible.lua: [Biblia](http://biblia.com) API key (`biblia_api_key`)
|
||||
- cats.lua: [The Cat API](http://thecatapi.com) API key (optional) (`thecatapi_key`)
|
||||
- gImages.lua: [Google](http://console.developers.google.com) API and [CSE](https://cse.google.com/cse) keys (`google_api_key`, `google_cse_key`)
|
||||
- gImages.lua: Google [API](http://console.developers.google.com) and [CSE](https://cse.google.com/cse) keys (`google_api_key`, `google_cse_key`)
|
||||
- apod.lua: [NASA](http://api.nasa.gov) API key (`nasa_api_key`)
|
||||
- translate.lua: [Yandex](https://tech.yandex.com/keys/get/?service=trnsl) API key (`yandex_key`)
|
||||
- chatter.lua: [SimSimi](http://developer.simsimi.com/signUp) API key (`simsimi_key`)
|
||||
|
2
bot.lua
2
bot.lua
@ -75,7 +75,7 @@ on_msg_receive = function(msg) -- The fn run whenever a message is received.
|
||||
|
||||
if msg.reply_to_message and msg.reply_to_message.caption then
|
||||
msg.reply_to_message.text = msg.reply_to_message.caption
|
||||
end -- If the reply_to_msg contains a caption, set it as its text
|
||||
end -- If the replied-to message has a caption, make that its text.
|
||||
|
||||
if msg.text:match('^/start .+') then
|
||||
msg.text = '/' .. msg.text:input()
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[
|
||||
administration.lua
|
||||
Version 1.7
|
||||
Version 1.8
|
||||
Part of the otouto project.
|
||||
© 2016 topkecleon <drew@otou.to>
|
||||
GNU General Public License, version 2
|
||||
@ -18,6 +18,9 @@
|
||||
administrators. Back to single-governor groups as originally intended. Auto-
|
||||
matic migration through 1.8.
|
||||
|
||||
1.8 - Group descriptions will be updated automatically. Fixed markdown
|
||||
stuff. Removed /kickme.
|
||||
|
||||
]]--
|
||||
|
||||
-- Build the administration db if nonexistent.
|
||||
@ -166,8 +169,7 @@ end
|
||||
local mod_format = function(id)
|
||||
id = tostring(id)
|
||||
local user = database.users[id] or { first_name = 'Unknown' }
|
||||
local name = user.first_name
|
||||
if user.last_name then name = user.first_name .. ' ' .. user.last_name end
|
||||
local name = build_name(user.first_name, user.last_name)
|
||||
name = markdown_escape(name)
|
||||
local output = '• ' .. name .. ' `[' .. id .. ']`\n'
|
||||
return output
|
||||
@ -201,6 +203,11 @@ local get_desc = function(chat_id)
|
||||
if flaglist ~= '' then
|
||||
table.insert(t, '*Flags:*\n' .. flaglist:trim())
|
||||
end
|
||||
if group.governor then
|
||||
local gov = database.users[tostring(group.governor)]
|
||||
local s = build_name(gov.first_name, gov.last_name):md_escape() .. ' `[' .. gov.id .. ']`'
|
||||
table.insert(t, '*Governor:* ' .. s)
|
||||
end
|
||||
local modstring = ''
|
||||
for k,v in pairs(group.mods) do
|
||||
modstring = modstring .. mod_format(k)
|
||||
@ -208,15 +215,23 @@ local get_desc = function(chat_id)
|
||||
if modstring ~= '' then
|
||||
table.insert(t, '*Moderators:*\n' .. modstring:trim())
|
||||
end
|
||||
if group.governor then
|
||||
local gov = database.users[tostring(group.governor)]
|
||||
local s = build_name(gov.first_name, gov.last_name):md_escape() .. ' `[' .. gov.id .. ']`'
|
||||
table.insert(t, '*Governor:* ' .. s)
|
||||
end
|
||||
return table.concat(t, '\n\n')
|
||||
|
||||
end
|
||||
|
||||
update_desc = function(chat)
|
||||
local group = database.administration.groups[tostring(chat)]
|
||||
local desc = 'Welcome to ' .. group.name .. '!\n'
|
||||
if group.motd then desc = desc .. group.motd .. '\n' end
|
||||
if group.governor then
|
||||
local gov = database.users[tostring(group.governor)]
|
||||
desc = desc .. '\nGovernor: ' .. build_name(gov.first_name, gov.last_name) .. ' [' .. gov.id .. ']\n'
|
||||
end
|
||||
local s = '\n/desc@' .. bot.username .. ' for more information.'
|
||||
desc = desc:sub(1, 250-s:len()) .. s
|
||||
drua.channel_set_about(chat, desc)
|
||||
end
|
||||
|
||||
local commands = {
|
||||
|
||||
{ -- antisquig
|
||||
@ -314,10 +329,7 @@ local commands = {
|
||||
|
||||
if msg.new_chat_participant then
|
||||
|
||||
msg.new_chat_participant.name = msg.new_chat_participant.first_name
|
||||
if msg.new_chat_participant.last_name then
|
||||
msg.new_chat_participant.name = msg.new_chat_participant.first_name .. ' ' .. msg.new_chat_participant.last_name
|
||||
end
|
||||
msg.new_chat_participant.name = build_name(msg.new_chat_participant.first_name, msg.new_chat_participant.last_name)
|
||||
|
||||
-- banned
|
||||
if get_rank(msg.new_chat_participant.id, msg.chat.id) == 0 then
|
||||
@ -354,6 +366,9 @@ local commands = {
|
||||
drua.rename_chat(msg.chat.id, group.name)
|
||||
else
|
||||
group.name = msg.new_chat_title
|
||||
if group.grouptype == 'supergroup' then
|
||||
update_desc(msg.chat.id)
|
||||
end
|
||||
end
|
||||
return
|
||||
|
||||
@ -573,29 +588,6 @@ local commands = {
|
||||
end
|
||||
},
|
||||
|
||||
{ -- kickme
|
||||
triggers = {
|
||||
'^/leave[@'..bot.username..']*',
|
||||
'^/kickme[@'..bot.username..']*'
|
||||
},
|
||||
|
||||
command = 'leave',
|
||||
privilege = 1,
|
||||
interior = true,
|
||||
|
||||
action = function(msg)
|
||||
if get_rank(msg.from.id) == 5 then
|
||||
local output = 'I can\'t let you do that, ' .. msg.from.first_name .. '.'
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
elseif msg.chat.type == 'supergroup' then
|
||||
local output = 'Leave this group manually or you will be unable to rejoin.'
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
else
|
||||
drua.kick_user(msg.chat.id, msg.from.id)
|
||||
end
|
||||
end
|
||||
},
|
||||
|
||||
{ -- kick
|
||||
triggers = {
|
||||
'^/kick[@'..bot.username..']*'
|
||||
@ -753,15 +745,19 @@ local commands = {
|
||||
sendReply(msg, 'Please specify the new message of the day.')
|
||||
return
|
||||
end
|
||||
elseif input == '--' or input == '—' then
|
||||
end
|
||||
if input == '--' or input == '—' then
|
||||
group.motd = nil
|
||||
sendReply(msg, 'The MOTD has been cleared.')
|
||||
return
|
||||
else
|
||||
input = input:trim()
|
||||
group.motd = input
|
||||
local output = '*MOTD for* _' .. msg.chat.title .. '_ *:*\n' .. input
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
update_desc(msg.chat.id)
|
||||
end
|
||||
input = input:trim()
|
||||
group.motd = input
|
||||
local output = '*MOTD for* _' .. msg.chat.title .. '_ *:*\n' .. input
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
end
|
||||
},
|
||||
|
||||
@ -939,7 +935,7 @@ local commands = {
|
||||
if group.grouptype == 'supergroup' then
|
||||
drua.channel_set_admin(msg.chat.id, target.id, 0)
|
||||
end
|
||||
group.governor = nil
|
||||
group.governor = config.admin
|
||||
sendReply(msg, target.name .. ' is no longer the governor.')
|
||||
else
|
||||
if group.grouptype == 'supergroup' then
|
||||
@ -954,6 +950,9 @@ local commands = {
|
||||
group.governor = target.id
|
||||
sendReply(msg, target.name .. ' is the new governor.')
|
||||
end
|
||||
if group.grouptype == 'supergroup' then
|
||||
update_desc(msg.chat.id)
|
||||
end
|
||||
end
|
||||
},
|
||||
|
||||
@ -1050,6 +1049,9 @@ local commands = {
|
||||
photo = drua.get_photo(msg.chat.id),
|
||||
founded = os.time()
|
||||
}
|
||||
for i = 1, #flags do
|
||||
database.administration.groups[msg.chat.id_str].flags[i] = false
|
||||
end
|
||||
table.insert(database.administration.activity, msg.chat.id_str)
|
||||
sendReply(msg, 'I am now administrating this group.')
|
||||
end
|
||||
@ -1098,7 +1100,7 @@ local commands = {
|
||||
output = output .. '[' .. v.name:md_escape() .. '](' .. v.link .. ') `[' .. k .. ']`\n'
|
||||
if v.governor then
|
||||
local gov = database.users[tostring(v.governor)]
|
||||
output = output .. '• Governor: ' .. build_name(gov.first_name, gov.last_name):md_escape() .. ' `[' .. gov.id .. ']`\n'
|
||||
output = output .. '★ ' .. build_name(gov.first_name, gov.last_name):md_escape() .. ' `[' .. gov.id .. ']`\n'
|
||||
end
|
||||
end
|
||||
else
|
||||
|
Reference in New Issue
Block a user