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
|
else
|
||||||
|
output = target.name .. ' currently has no nickname.'
|
||||||
if string.len(input) > 32 then
|
end
|
||||||
sendReply(msg, 'The character limit for nicknames is 32.')
|
elseif string.len(input) > 32 then
|
||||||
return true
|
output = 'The character limit for nicknames is 32.'
|
||||||
end
|
elseif input == '--' or input == '—' then
|
||||||
|
database.nicknames[target.id_str] = nil
|
||||||
if input == '-' then
|
output = target.name .. '\'s nickname has been deleted.'
|
||||||
database.nicknames[msg.from.id_str] = nil
|
|
||||||
sendReply(msg, 'Your nickname has been deleted.')
|
|
||||||
else
|
else
|
||||||
database.nicknames[msg.from.id_str] = input
|
database.nicknames[target.id_str] = input
|
||||||
sendReply(msg, 'Your nickname has been set to "' .. 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