nick.lua:
Less stupidly written. Owner can now set other users' nicknames via reply. patterns.lua: Minor code changes.
This commit is contained in:
parent
7813564209
commit
a2bdecb7bb
@ -5,7 +5,7 @@ end
|
|||||||
local command = 'nick <nickname>'
|
local command = 'nick <nickname>'
|
||||||
local doc = [[```
|
local doc = [[```
|
||||||
/nick <nickname>
|
/nick <nickname>
|
||||||
Set your nickname. Use "/whoami" to check your nickname and "/nick -" to delete it.
|
Set your nickname. Use "/nick --" to delete it.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
local triggers = {
|
local triggers = {
|
||||||
@ -14,26 +14,36 @@ local triggers = {
|
|||||||
|
|
||||||
local action = function(msg)
|
local action = function(msg)
|
||||||
|
|
||||||
|
local target = msg.from
|
||||||
|
|
||||||
|
if msg.from.id == config.admin and msg.reply_to_message then
|
||||||
|
target = msg.reply_to_message.from
|
||||||
|
target.id_str = tostring(target.id)
|
||||||
|
target.name = target.first_name
|
||||||
|
if target.last_name then
|
||||||
|
target.name = target.first_name .. ' ' .. target.last_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local output
|
||||||
local input = msg.text:input()
|
local input = msg.text:input()
|
||||||
if not input then
|
if not input then
|
||||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
if database.nicknames[target.id_str] then
|
||||||
return true
|
output = target.name .. '\'s nickname is "' .. database.nicknames[target.id_str] .. '".'
|
||||||
end
|
|
||||||
|
|
||||||
if string.len(input) > 32 then
|
|
||||||
sendReply(msg, 'The character limit for nicknames is 32.')
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if input == '-' then
|
|
||||||
database.nicknames[msg.from.id_str] = nil
|
|
||||||
sendReply(msg, 'Your nickname has been deleted.')
|
|
||||||
else
|
else
|
||||||
database.nicknames[msg.from.id_str] = input
|
output = target.name .. ' currently has no nickname.'
|
||||||
sendReply(msg, 'Your nickname has been set to "' .. input .. '".')
|
end
|
||||||
|
elseif string.len(input) > 32 then
|
||||||
|
output = 'The character limit for nicknames is 32.'
|
||||||
|
elseif input == '--' or input == '—' then
|
||||||
|
database.nicknames[target.id_str] = nil
|
||||||
|
output = target.name .. '\'s nickname has been deleted.'
|
||||||
|
else
|
||||||
|
database.nicknames[target.id_str] = input
|
||||||
|
output = target.name .. '\'s nickname has been set to "' .. input .. '".'
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
sendReply(msg, output)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ local triggers = {
|
|||||||
local action = function(msg)
|
local action = function(msg)
|
||||||
|
|
||||||
if not msg.reply_to_message then return end
|
if not msg.reply_to_message then return end
|
||||||
msg.reply_to_message.text = msg.reply_to_message.text or ''
|
local output = msg.reply_to_message.text or ''
|
||||||
local output = msg.reply_to_message.text:gsub(
|
output = output:gsub(
|
||||||
msg.text:match('^/s/(.-)/(.-)/?$')
|
msg.text:match('^/s/(.-)/(.-)/?$')
|
||||||
)
|
)
|
||||||
output = 'Did you mean:\n"' .. output:sub(1, 4000) .. '"'
|
output = 'Did you mean:\n"' .. output:sub(1, 4000) .. '"'
|
||||||
|
Reference in New Issue
Block a user