Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F626463
nick.lua
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
nick.lua
View Options
--[[
mattata v2.0 - Nickname Plugin
Set, view, and delete your nickname.
]]
local
plugin
=
{}
plugin
.
name
=
'nick'
plugin
.
category
=
'utility'
plugin
.
description
=
'Set a custom nickname'
plugin
.
commands
=
{
'nick'
,
'nickname'
,
'setnick'
,
'nn'
}
plugin
.
help
=
'/nick <name> - Set your nickname.
\n
/nick - View your current nickname.
\n
/nick --delete - Remove your nickname.'
function
plugin
.
on_message
(
api
,
message
,
ctx
)
local
tools
=
require
(
'telegram-bot-lua.tools'
)
local
input
=
message
.
args
-- View current nickname
if
not
input
or
input
==
''
then
local
result
=
ctx
.
db
.
call
(
'sp_get_nickname'
,
{
message
.
from
.
id
})
if
result
and
result
[
1
]
and
result
[
1
].
nickname
then
return
api
.
send_message
(
message
.
chat
.
id
,
string.format
(
'Your nickname is: <b>%s</b>'
,
tools
.
escape_html
(
result
[
1
].
nickname
)),
{
parse_mode
=
'html'
}
)
end
return
api
.
send_message
(
message
.
chat
.
id
,
'You don
\'
t have a nickname set. Use /nick <name> to set one.'
)
end
-- Delete nickname
if
input
==
'--delete'
or
input
==
'-d'
then
ctx
.
db
.
call
(
'sp_clear_nickname'
,
{
message
.
from
.
id
})
return
api
.
send_message
(
message
.
chat
.
id
,
'Your nickname has been removed.'
)
end
-- Validate length
if
#
input
>
128
then
return
api
.
send_message
(
message
.
chat
.
id
,
'Nicknames must be 128 characters or fewer.'
)
end
-- Set nickname
ctx
.
db
.
call
(
'sp_set_nickname'
,
{
message
.
from
.
id
,
input
})
return
api
.
send_message
(
message
.
chat
.
id
,
string.format
(
'Your nickname has been set to: <b>%s</b>'
,
tools
.
escape_html
(
input
)),
{
parse_mode
=
'html'
}
)
end
return
plugin
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 15, 12:45 AM (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
132102
Default Alt Text
nick.lua (1 KB)
Attached To
Mode
R69 mattata
Attached
Detach File
Event Timeline