local question, answer = rest:match('^(.-)%s*|%s*(.+)$')
if not question or question == '' or not answer or answer == '' then
- return api.send_message(chat_id, 'Please separate the question and answer with a pipe character (|).\nExample: <code>/customcaptcha set What colour is the sky? | blue</code>', { parse_mode = 'html' })
+ local err_text = 'Please separate the question and answer with a pipe character (|).\n'
+ .. 'Example: <code>/customcaptcha set What colour is the sky? | blue</code>'
'Welcome, <a href="tg://user?id=%d">%s</a>! To verify you\'re human, please answer the following question:\n\n<b>%s</b>\n\nType your answer in the chat. You have %d seconds.',
new_member.id,
tools.escape_html(new_member.first_name),
tools.escape_html(question),
timeout
)
local sent = api.send_message(chat_id, text, { parse_mode = 'html' })
+ Batch-deletes messages using delete_messages API for efficiency.
]]
local plugin = {}
plugin.name = 'purge'
plugin.category = 'admin'
plugin.description = 'Delete messages in bulk'
plugin.commands = { 'purge' }
plugin.help = '/purge - Deletes all messages from the replied-to message up to the command message.'
plugin.group_only = true
plugin.admin_only = true
+local BATCH_SIZE = 100
+
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
+ -- Batch into groups of up to 100 and use delete_messages
+ local batch = {}
for msg_id = start_id, end_id do
- local success = api.delete_message(message.chat.id, msg_id)
+ table.insert(batch, msg_id)
+ if #batch >= BATCH_SIZE then
+ local success = api.delete_messages(message.chat.id, batch)
+ if success then
+ count = count + #batch
+ else
+ failed = failed + #batch
+ end
+ batch = {}
+ end
+ end
+ -- Delete remaining messages
+ if #batch > 0 then
+ local success = api.delete_messages(message.chat.id, batch)
plugin.help = '/reactions <on|off> - Toggle reaction karma tracking for this group.'
plugin.group_only = true
plugin.admin_only = true
local THUMBS_UP = '\xF0\x9F\x91\x8D'
local THUMBS_DOWN = '\xF0\x9F\x91\x8E'
function plugin.on_message(api, message, ctx)
if not message.args or message.args == '' then
-- Show current status
local enabled = session.get_cached_setting(message.chat.id, 'reactions_enabled', function()
local result = ctx.db.call('sp_get_chat_setting', { message.chat.id, 'reactions_enabled' })
if result and #result > 0 then
return result[1].value
end
return nil
end)
local status = (enabled == 'true') and 'enabled' or 'disabled'
return api.send_message(message.chat.id,
string.format('Reaction karma is currently <b>%s</b> for this group.\nUse <code>/reactions on</code> or <code>/reactions off</code> to toggle.', status),
+ local tenor_key = ctx.config.get('TENOR_API_KEY')
+ if not tenor_key or tenor_key == '' then
+ return api.send_message(message.chat.id, 'The Tenor API key is not configured. Please set <code>TENOR_API_KEY</code> in the bot configuration.', 'html')
+ end
+
if not message.args or message.args == '' then
return api.send_message(message.chat.id, 'Please specify a search query, e.g. <code>/gif funny cats</code>.', { parse_mode = 'html' })
plugin.description = 'View your Last.fm now playing and recent tracks'
plugin.commands = { 'lastfm', 'np', 'fmset' }
plugin.help = '/np - Show your currently playing or most recent track.\n/fmset <username> - Link your Last.fm account.\n/lastfm [username] - View recent tracks for a Last.fm user.'
function plugin.on_message(api, message, ctx)
local http = require('src.core.http')
local url = require('socket.url')
local tools = require('telegram-bot-lua.tools')
local config = require('src.core.config')
local api_key = config.get('LASTFM_API_KEY')
if not api_key or api_key == '' then
return api.send_message(message.chat.id, 'Last.fm is not configured. The bot admin needs to set LASTFM_API_KEY.')
end
-- /fmset: link Last.fm username
if message.command == 'fmset' then
local username = message.args
if not username or username == '' then
return api.send_message(message.chat.id, 'Please provide your Last.fm username. Usage: /fmset <username>')