Page MenuHomePhabricator (Chris)

newfed.lua
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

newfed.lua

--[[
mattata v2.0 - Federation: newfed
Creates a new federation. Any user can create up to 5 federations.
]]
local tools = require('telegram-bot-lua.tools')
local plugin = {}
plugin.name = 'newfed'
plugin.category = 'admin'
plugin.description = 'Create a new federation.'
plugin.commands = { 'newfed' }
plugin.help = '/newfed <name> - Create a new federation with the given name.'
plugin.group_only = false
plugin.admin_only = false
function plugin.on_message(api, message, ctx)
local name = message.args
if not name or name == '' then
return api.send_message(
message.chat.id,
'Please specify a name for the federation.\nUsage: <code>/newfed &lt;name&gt;</code>',
'html'
)
end
if #name > 128 then
return api.send_message(
message.chat.id,
'Federation name must be 128 characters or fewer.',
'html'
)
end
local user_id = message.from.id
local existing = ctx.db.call('sp_count_user_federations', { user_id })
if existing and existing[1] and tonumber(existing[1].count) >= 5 then
return api.send_message(
message.chat.id,
'You already own 5 federations, which is the maximum allowed.',
'html'
)
end
local result = ctx.db.call('sp_create_federation', { name, user_id })
if not result or #result == 0 then
return api.send_message(
message.chat.id,
'Failed to create the federation. Please try again later.',
'html'
)
end
local fed_id = result[1].id
local output = string.format(
'Federation <b>%s</b> created successfully!\n\nFederation ID: <code>%s</code>\n\nUse <code>/joinfed %s</code> in a group to add it to this federation.',
tools.escape_html(name),
tools.escape_html(fed_id),
tools.escape_html(fed_id)
)
return api.send_message(message.chat.id, output, 'html')
end
return plugin

File Metadata

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

Event Timeline