whoami.lua: Rewrite. Added markdown support.

administration.lua: Bugfixes and improvements. v1.6.1.
This commit is contained in:
topkecleon 2016-03-28 02:15:46 -04:00
parent 5762e12a48
commit 6b3e3ae8a6
2 changed files with 75 additions and 59 deletions

View File

@ -1,6 +1,6 @@
--[[ --[[
administration.lua administration.lua
Version 1.6 Version 1.6.1
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
@ -150,33 +150,59 @@ local get_target = function(msg)
end 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
name = markdown_escape(name)
local output = '' .. name .. ' `[' .. id .. ']`\n'
return output
end
local get_desc = function(chat_id) local get_desc = function(chat_id)
local group = database.administration.groups[tostring(chat_id)] local group = database.administration.groups[tostring(chat_id)]
local output local t = {}
if group.link then if group.link then
output = '*Welcome to* [' .. group.name .. '](' .. group.link .. ')*!*' table.insert(t, '*Welcome to* [' .. group.name .. '](' .. group.link .. ')*!*')
else else
output = '*Welcome to* _' .. group.name .. '_*!*' table.insert(t, '*Welcome to* _' .. group.name .. '_*!*')
end end
if group.motd then if group.motd then
output = output .. '\n\n*Message of the Day:*\n' .. group.motd table.insert(t, '*Message of the Day:*\n' .. group.motd)
end end
if #group.rules > 0 then if #group.rules > 0 then
output = output .. '\n\n*Rules:*' local rulelist = '*Rules:*\n'
for i,v in ipairs(group.rules) do for i,v in ipairs(group.rules) do
output = output .. '\n*' .. i .. '.* ' .. v rulelist = rulelist .. '*' .. i .. '.* ' .. v .. '\n'
end
table.insert(t, rulelist:trim())
end
local flaglist = ''
for i = 1, #flags do
if group.flags[i] then
output = output .. '' .. flags[i].short .. '\n'
end end
end end
if group.flags then if flaglist ~= '' then
output = output .. '\n\n*Flags:*\n' table.insert(t, '*Flags:*\n' .. flaglist:trim())
for i = 1, #flags do
if group.flags[i] then
output = output .. '' .. flags[i].short .. '\n'
end
end
end end
return output local modstring = ''
for k,v in pairs(group.mods) do
modstring = modstring .. mod_format(k)
end
if modstring ~= '' then
table.insert(t, '*Moderators:*\n' .. modstring:trim())
end
local govstring = ''
for k,v in pairs(group.govs) do
govstring = govstring .. mod_format(k)
end
if govstring ~= '' then
table.insert(t, '*Governors:*\n' .. govstring:trim())
end
return table.concat(t, '\n\n')
end end
@ -389,15 +415,6 @@ local commands = {
interior = true, interior = true,
action = function(msg, group) action = function(msg, group)
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
name = markdown_escape(name)
local output = '' .. name .. ' `[' .. id .. ']`\n'
return output
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)
@ -412,11 +429,10 @@ local commands = {
if govstring ~= '' then if govstring ~= '' then
govstring = '*Governors for* _' .. msg.chat.title .. '_ *:*\n' .. govstring govstring = '*Governors for* _' .. msg.chat.title .. '_ *:*\n' .. govstring
end end
local adminstring = '*Administrators:*\n' .. mod_format(config.admin) local output = modstring .. govstring
for k,v in pairs(database.administration.admins) do if output == '' then
adminstring = adminstring .. mod_format(k) output = 'There are currently no moderators for this group.'
end end
local output = modstring .. govstring .. adminstring
sendMessage(msg.chat.id, output, true, nil, true) sendMessage(msg.chat.id, output, true, nil, true)
end end
@ -634,14 +650,14 @@ local commands = {
'^/setrules[@'..bot.username..']*' '^/setrules[@'..bot.username..']*'
}, },
command = 'setrules <rule1> \\n \\[rule2] ...', command = 'setrules\\n<rule1>\\n\\[rule2]\\n...',
privilege = 3, privilege = 3,
interior = true, interior = true,
action = function(msg, group) action = function(msg, group)
local input = msg.text:match('^/setrules[@'..bot.username..']* (.+)') local input = msg.text:match('^/setrules[@'..bot.username..']* (.+)')
if not input then if not input then
sendReply(msg, '/setrules [rule]\n<rule>\n[rule]\n...') sendMessage(msg.chat.id, '```\n/setrules\n<rule1>\n[rule2]\n...\n```', true, msg.message_id, true)
return return
elseif input == '--' or input == '' then elseif input == '--' or input == '' then
group.rules = {} group.rules = {}
@ -807,10 +823,6 @@ local commands = {
group.govs[target.id_str] = nil group.govs[target.id_str] = nil
sendReply(msg, target.name .. ' is no longer a governor.') sendReply(msg, target.name .. ' is no longer a governor.')
else else
if target.rank > 3 then
sendReply(msg, target.name .. ' is greater than a governor.')
return
end
if target.rank == 2 then if target.rank == 2 then
group.mods[target.id_str] = nil group.mods[target.id_str] = nil
end end
@ -932,21 +944,17 @@ local commands = {
interior = true, interior = true,
action = function(msg) action = function(msg)
local input = msg.text:input() local input = msg.text:input() or msg.chat.id_str
if input then if database.administration.groups[input] then
if database.administration.groups[input] then database.administration.groups[input] = nil
database.administration.groups[input] = nil for i,v in ipairs(database.administration.activity) do
sendReply(msg, 'I am no longer administrating that group.') if v == input then
else table.remove(database.administration.activity, i)
sendReply(msg, 'I do not administrate that group.') end
end end
sendReply(msg, 'I am no longer administrating that group.')
else else
if database.administration.groups[msg.chat.id_str] then sendReply(msg, 'I do not administrate that group.')
database.administration.groups[msg.chat.id_str] = nil
sendReply(msg, 'I am no longer administrating this group.')
else
sendReply(msg, 'I do not administrate this group.')
end
end end
end end
}, },

View File

@ -14,30 +14,38 @@ local action = function(msg)
msg = msg.reply_to_message msg = msg.reply_to_message
end end
local from_name = msg.from.first_name
if msg.from.last_name then if msg.from.last_name then
from_name = from_name .. ' ' .. msg.from.last_name msg.from.name = msg.from.first_name .. ' ' .. msg.from.last_name
else
msg.from.name = msg.from.first_name
end end
if msg.from.username then
from_name = '@' .. msg.from.username .. ', AKA ' .. from_name
end
from_name = from_name .. ' (' .. msg.from.id .. ')'
local chat_id = math.abs(msg.chat.id) local chat_id = math.abs(msg.chat.id)
if chat_id > 1000000000000 then if chat_id > 1000000000000 then
chat_id = chat_id - 1000000000000 chat_id = chat_id - 1000000000000
end end
local to_name local user = 'You are @%s, also known as *%s* `[%s]`'
if msg.chat.title then if msg.from.username then
to_name = msg.chat.title .. ' (' .. chat_id .. ').' user = user:format(msg.from.username, msg.from.name, msg.from.id)
else else
to_name = '@' .. bot.username .. ', AKA ' .. bot.first_name .. ' (' .. bot.id .. ').' user = 'You are *%s* `[%s]`,'
user = user:format(msg.from.name, msg.from.id)
end end
local message = 'You are ' .. from_name .. ' and you are messaging ' .. to_name local group = '@%s, also known as *%s* `[%s]`.'
if msg.chat.type == 'private' then
group = group:format(bot.username, bot.first_name, bot.id)
elseif msg.chat.username then
group = group:format(msg.chat.username, msg.chat.title, chat_id)
else
group = '*%s* `[%s]`.'
group = group:format(msg.chat.title, chat_id)
end
sendReply(msg, message) local output = user .. ', and you are messaging ' .. group
sendMessage(msg.chat.id, output, true, msg.message_id, true)
end end