Page MenuHomePhabricator (Chris)

addcommand.lua
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

addcommand.lua

--[[
Copyright 2020 Matthew Hesketh <matthew@matthewhesketh.com>
This code is licensed under the MIT. See LICENSE for details.
]]
local addcommand = {}
local mattata = require('mattata')
function addcommand:init()
addcommand.commands = mattata.commands(self.info.username):command('addcommand').table
end
function addcommand.on_message(_, message, _, language)
if not mattata.is_global_admin(message.from.id) then
return false
end
local input = mattata.input(message.text)
if not input or not input:match('^[/!#]?[%w_]+ %- .-$') then
return mattata.send_reply(message, language['addcommand']['1'], 'html')
end
local commands = mattata.get_my_commands()
if not commands then
return mattata.send_reply(message, language['addcommand']['2'])
end
commands = type(commands.result) == 'table' and commands.result or {}
local command, description = input:match('^/?([%w_]+) %- (.-)$')
if description:len() > 256 then
return mattata.send_reply(message, language['addcommand']['3'])
end
commands = table.insert(commands, { ['command'] = command, ['description'] = description })
local success = mattata.set_my_commands(commands)
if not success then
return mattata.send_reply(message, language['addcommand']['4'])
end
return mattata.send_reply(message, language['addcommand']['5'])
end
return addcommand

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 14, 11:11 PM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
119797
Default Alt Text
addcommand.lua (1 KB)

Event Timeline