{ text = 'Yes, delete it', callback_data = callback_data_yes },
{ text = 'No, cancel', callback_data = callback_data_no }
} }
}
return api.send_message(
message.chat.id,
string.format(
'Are you sure you want to delete the federation <b>%s</b>?\n\nThis will remove all bans, chats, and admins associated with it. This action cannot be undone.',
tools.escape_html(fed.name)
),
'html',
nil, nil, nil, nil,
json.encode(keyboard)
)
end
function plugin.on_callback_query(api, callback_query, message, ctx)
local data = json.decode(callback_query.data)
if not data or data.plugin ~= 'delfed' then
return
end
if callback_query.from.id ~= message.reply_to_message_from_id and callback_query.from.id ~= (message.from and message.from.id) then
return api.answer_callback_query(callback_query.id, 'This button is not for you.')
local user_id = ctx.redis.get('username:' .. username)
if user_id then
return tonumber(user_id), '@' .. username
end
end
return nil, nil
end
local function get_chat_federation(db, chat_id)
- local result = db.execute(
- 'SELECT f.id, f.name, f.owner_id FROM federations f JOIN federation_chats fc ON f.id = fc.federation_id WHERE fc.chat_id = $1',
- { chat_id }
- )
+ local result = db.call('sp_get_chat_federation', { chat_id })
if result and #result > 0 then return result[1] end
return nil
end
local function is_fed_admin(db, fed_id, user_id)
- local result = db.execute(
- 'SELECT 1 FROM federation_admins WHERE federation_id = $1 AND user_id = $2',
- { fed_id, user_id }
- )
+ local result = db.call('sp_check_federation_admin', { fed_id, user_id })
return result and #result > 0
end
function plugin.on_message(api, message, ctx)
local fed = get_chat_federation(ctx.db, message.chat.id)
if not fed then
return api.send_message(
message.chat.id,
'This chat is not part of any federation.',
'html'
)
end
local from_id = message.from.id
if fed.owner_id ~= from_id and not is_fed_admin(ctx.db, fed.id, from_id) then
return api.send_message(
message.chat.id,
'Only the federation owner or a federation admin can manage the allowlist.',
'html'
)
end
local target_id, target_name = resolve_user(message, ctx)
if not target_id then
return api.send_message(
message.chat.id,
'Please specify a user to toggle on the allowlist by replying to their message or providing a user ID/username.\nUsage: <code>/fallowlist [user]</code>',
'html'
)
end
- -- Check if already allowlisted
- local existing = ctx.db.execute(
- 'SELECT 1 FROM federation_allowlist WHERE federation_id = $1 AND user_id = $2',
- { fed.id, target_id }
- )
+ local existing = ctx.db.call('sp_check_federation_allowlist', { fed.id, target_id })
if existing and #existing > 0 then
- -- Remove from allowlist
- ctx.db.execute(
- 'DELETE FROM federation_allowlist WHERE federation_id = $1 AND user_id = $2',
+ 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.',
plugin.help = '/purge - Deletes all messages from the replied-to message up to the command message.'
plugin.group_only = true
plugin.admin_only = true
function plugin.on_message(api, message, ctx)
local permissions = require('src.core.permissions')
if not permissions.can_delete(api, message.chat.id) then
return api.send_message(message.chat.id, 'I need the "Delete Messages" admin permission to use this command.')
end
if not message.reply then
return api.send_message(message.chat.id, 'Please reply to the first message you want to delete, and all messages from that point to your command will be purged.')
end
local start_id = message.reply.message_id
local end_id = message.message_id
local count = 0
local failed = 0
for msg_id = start_id, end_id do
local success = api.delete_message(message.chat.id, msg_id)