administration.lua: 1.8. See file for changes.

This commit is contained in:
topkecleon 2016-04-05 03:42:16 -04:00
parent 9f9ca12e8f
commit 8fe72b3a64
3 changed files with 47 additions and 45 deletions

View File

@ -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`) - lastfm.lua: [last.fm](http://last.fm) API key (`lastfm_api_key`)
- bible.lua: [Biblia](http://biblia.com) API key (`biblia_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`) - 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`) - 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`) - 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`) - chatter.lua: [SimSimi](http://developer.simsimi.com/signUp) API key (`simsimi_key`)

View File

@ -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 if msg.reply_to_message and msg.reply_to_message.caption then
msg.reply_to_message.text = msg.reply_to_message.caption 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 if msg.text:match('^/start .+') then
msg.text = '/' .. msg.text:input() msg.text = '/' .. msg.text:input()

View File

@ -1,6 +1,6 @@
--[[ --[[
administration.lua administration.lua
Version 1.7 Version 1.8
Part of the otouto project. Part of the otouto project.
© 2016 topkecleon <drew@otou.to> © 2016 topkecleon <drew@otou.to>
GNU General Public License, version 2 GNU General Public License, version 2
@ -18,6 +18,9 @@
administrators. Back to single-governor groups as originally intended. Auto- administrators. Back to single-governor groups as originally intended. Auto-
matic migration through 1.8. matic migration through 1.8.
1.8 - Group descriptions will be updated automatically. Fixed markdown
stuff. Removed /kickme.
]]-- ]]--
-- Build the administration db if nonexistent. -- Build the administration db if nonexistent.
@ -166,8 +169,7 @@ end
local mod_format = function(id) local mod_format = function(id)
id = tostring(id) id = tostring(id)
local user = database.users[id] or { first_name = 'Unknown' } local user = database.users[id] or { first_name = 'Unknown' }
local name = user.first_name local name = build_name(user.first_name, user.last_name)
if user.last_name then name = user.first_name .. ' ' .. user.last_name end
name = markdown_escape(name) name = markdown_escape(name)
local output = '' .. name .. ' `[' .. id .. ']`\n' local output = '' .. name .. ' `[' .. id .. ']`\n'
return output return output
@ -201,6 +203,11 @@ local get_desc = function(chat_id)
if flaglist ~= '' then if flaglist ~= '' then
table.insert(t, '*Flags:*\n' .. flaglist:trim()) table.insert(t, '*Flags:*\n' .. flaglist:trim())
end 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 = '' local modstring = ''
for k,v in pairs(group.mods) do for k,v in pairs(group.mods) do
modstring = modstring .. mod_format(k) modstring = modstring .. mod_format(k)
@ -208,15 +215,23 @@ local get_desc = function(chat_id)
if modstring ~= '' then if modstring ~= '' then
table.insert(t, '*Moderators:*\n' .. modstring:trim()) table.insert(t, '*Moderators:*\n' .. modstring:trim())
end 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') return table.concat(t, '\n\n')
end 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 = { local commands = {
{ -- antisquig { -- antisquig
@ -314,10 +329,7 @@ local commands = {
if msg.new_chat_participant then if msg.new_chat_participant then
msg.new_chat_participant.name = msg.new_chat_participant.first_name msg.new_chat_participant.name = build_name(msg.new_chat_participant.first_name, msg.new_chat_participant.last_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
-- banned -- banned
if get_rank(msg.new_chat_participant.id, msg.chat.id) == 0 then 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) drua.rename_chat(msg.chat.id, group.name)
else else
group.name = msg.new_chat_title group.name = msg.new_chat_title
if group.grouptype == 'supergroup' then
update_desc(msg.chat.id)
end
end end
return return
@ -573,29 +588,6 @@ local commands = {
end 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 { -- kick
triggers = { triggers = {
'^/kick[@'..bot.username..']*' '^/kick[@'..bot.username..']*'
@ -753,15 +745,19 @@ local commands = {
sendReply(msg, 'Please specify the new message of the day.') sendReply(msg, 'Please specify the new message of the day.')
return return
end end
elseif input == '--' or input == '' then end
if input == '--' or input == '' then
group.motd = nil group.motd = nil
sendReply(msg, 'The MOTD has been cleared.') 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 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 end
}, },
@ -939,7 +935,7 @@ local commands = {
if group.grouptype == 'supergroup' then if group.grouptype == 'supergroup' then
drua.channel_set_admin(msg.chat.id, target.id, 0) drua.channel_set_admin(msg.chat.id, target.id, 0)
end end
group.governor = nil group.governor = config.admin
sendReply(msg, target.name .. ' is no longer the governor.') sendReply(msg, target.name .. ' is no longer the governor.')
else else
if group.grouptype == 'supergroup' then if group.grouptype == 'supergroup' then
@ -954,6 +950,9 @@ local commands = {
group.governor = target.id group.governor = target.id
sendReply(msg, target.name .. ' is the new governor.') sendReply(msg, target.name .. ' is the new governor.')
end end
if group.grouptype == 'supergroup' then
update_desc(msg.chat.id)
end
end end
}, },
@ -1050,6 +1049,9 @@ local commands = {
photo = drua.get_photo(msg.chat.id), photo = drua.get_photo(msg.chat.id),
founded = os.time() 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) table.insert(database.administration.activity, msg.chat.id_str)
sendReply(msg, 'I am now administrating this group.') sendReply(msg, 'I am now administrating this group.')
end end
@ -1098,7 +1100,7 @@ local commands = {
output = output .. '[' .. v.name:md_escape() .. '](' .. v.link .. ') `[' .. k .. ']`\n' output = output .. '[' .. v.name:md_escape() .. '](' .. v.link .. ') `[' .. k .. ']`\n'
if v.governor then if v.governor then
local gov = database.users[tostring(v.governor)] 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
end end
else else