Remove keyboard buttons for users in groups when pressed
This commit is contained in:
@@ -223,17 +223,45 @@ bot.onText(/\/lottosettings/, async (msg) => {
|
|||||||
// TEXT MESSAGES
|
// TEXT MESSAGES
|
||||||
// ═══════════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
// Keyboard button texts that should trigger keyboard removal in groups
|
||||||
|
const KEYBOARD_BUTTON_TEXTS = [
|
||||||
|
'🎰 Upcoming Jackpot',
|
||||||
|
'🎟 Buy Tickets',
|
||||||
|
'🧾 My Tickets',
|
||||||
|
'🏆 My Wins',
|
||||||
|
'⚡ Lightning Address',
|
||||||
|
'⚙️ Settings',
|
||||||
|
'ℹ️ Help',
|
||||||
|
];
|
||||||
|
|
||||||
// Handle keyboard button presses (text messages)
|
// Handle keyboard button presses (text messages)
|
||||||
bot.on('message', async (msg) => {
|
bot.on('message', async (msg) => {
|
||||||
if (!msg.text || msg.text.startsWith('/')) return;
|
if (!msg.text || msg.text.startsWith('/')) return;
|
||||||
if (!shouldProcessMessage(msg.message_id)) return;
|
if (!shouldProcessMessage(msg.message_id)) return;
|
||||||
|
|
||||||
// Ignore group messages for button handling
|
|
||||||
if (isGroupChat(msg)) return;
|
|
||||||
|
|
||||||
const text = msg.text.trim();
|
const text = msg.text.trim();
|
||||||
const userId = msg.from?.id;
|
const userId = msg.from?.id;
|
||||||
|
|
||||||
|
// Handle keyboard button presses in groups - remove the keyboard for that user
|
||||||
|
if (isGroupChat(msg)) {
|
||||||
|
// Only trigger if the message matches an exact keyboard button text
|
||||||
|
if (KEYBOARD_BUTTON_TEXTS.includes(text)) {
|
||||||
|
try {
|
||||||
|
// Send a temporary message to remove the keyboard for this user only
|
||||||
|
const sentMessage = await bot.sendMessage(msg.chat.id, '⚡', {
|
||||||
|
reply_to_message_id: msg.message_id,
|
||||||
|
reply_markup: { remove_keyboard: true, selective: true },
|
||||||
|
});
|
||||||
|
// Delete the message immediately so nothing is visible in the group
|
||||||
|
await bot.deleteMessage(msg.chat.id, sentMessage.message_id);
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - bot might not have delete permissions
|
||||||
|
logger.error('Error removing keyboard in group', { error, chatId: msg.chat.id, userId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!userId) return;
|
if (!userId) return;
|
||||||
|
|
||||||
// Handle menu button presses
|
// Handle menu button presses
|
||||||
|
|||||||
Reference in New Issue
Block a user