-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added events and new stalk command also help updated
- Loading branch information
1 parent
47c088f
commit 63dc53c
Showing
6 changed files
with
254 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { escapeMarkdown } = require('../utils/markdown'); | ||
|
||
module.exports = { | ||
name: 'stalk', | ||
adminOnly: false, | ||
ownerOnly: false, | ||
category: 'Utility', | ||
description: 'Show user information', | ||
guide: 'Use /stalk to see your own info, or reply to a message with /stalk to see that user\'s info', | ||
execute: async (bot, msg) => { | ||
const chatId = msg.chat.id; | ||
let targetUser; | ||
|
||
if (msg.reply_to_message) { | ||
targetUser = msg.reply_to_message.from; | ||
} else { | ||
targetUser = msg.from; | ||
} | ||
|
||
try { | ||
const userInfo = await bot.getUserProfilePhotos(targetUser.id, 0, 1); | ||
const chatMember = await bot.getChatMember(chatId, targetUser.id); | ||
|
||
const createUserInfo = (user) => { | ||
const fullName = escapeMarkdown(`${user.first_name || ''} ${user.last_name || ''}`.trim()); | ||
const username = user.username ? escapeMarkdown(`@${user.username}`) : 'Not set'; | ||
const userLink = `tg://user?id=${user.id}`; | ||
const bio = escapeMarkdown(chatMember.user.bio || 'Not available'); | ||
|
||
return `*User Information* | ||
🆔 *User ID:* \`${user.id}\` | ||
👤 *Full Name:* ${fullName} | ||
🌟 *Username:* ${username} | ||
📝 *Bio:* ${bio} | ||
🔗 *Contact:* [${fullName}](${userLink})`; | ||
}; | ||
|
||
const userInfoText = createUserInfo(targetUser); | ||
|
||
if (userInfo && userInfo.photos && userInfo.photos.length > 0) { | ||
const photo = userInfo.photos[0][0]; | ||
await bot.sendPhoto(chatId, photo.file_id, { | ||
caption: userInfoText, | ||
parse_mode: 'Markdown' | ||
}); | ||
} else { | ||
await bot.sendMessage(chatId, userInfoText, { parse_mode: 'Markdown' }); | ||
} | ||
} catch (error) { | ||
console.error('Error in stalk command:', error); | ||
await bot.sendMessage(chatId, 'An error occurred while fetching user information. Please try again later.'); | ||
} | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const fetch = require('node-fetch'); | ||
|
||
async function execute(bot, msg, groupName, memberCount) { | ||
const chatId = msg.chat.id; | ||
const leftMember = msg.left_chat_member; | ||
const username = leftMember.username || leftMember.first_name || 'User'; | ||
const userId = leftMember.id; | ||
|
||
// Get user's profile photos | ||
let userProfilePhoto = 'https://nexalo.xyz/assets/nexa.png'; // Default image | ||
try { | ||
const userPhotos = await bot.getUserProfilePhotos(userId, 0, 1); | ||
if (userPhotos.total_count > 0) { | ||
const fileId = userPhotos.photos[0][0].file_id; | ||
const file = await bot.getFile(fileId); | ||
userProfilePhoto = `https://api.telegram.org/file/bot${bot.token}/${file.file_path}`; | ||
} | ||
} catch (error) { | ||
console.error('Error getting user profile photo:', error); | ||
} | ||
|
||
try { | ||
// Fetch the goodbye image from the API | ||
const apiUrl = `https://api.nexalo.xyz/goodbye?api=na_T51VHMGBMZJO7S2B&name=${encodeURIComponent(username)}&text=${encodeURIComponent(`Goodbye ${username}`)}&image=${encodeURIComponent(userProfilePhoto)}`; | ||
const response = await fetch(apiUrl); | ||
const imageBuffer = await response.buffer(); | ||
|
||
// Create a mention of the user | ||
const userMention = `<a href="tg://user?id=${userId}">${username}</a>`; | ||
|
||
// Send the goodbye message with the image and user mention | ||
await bot.sendPhoto(chatId, imageBuffer, { | ||
caption: `Goodbye, ${userMention}! 👋\nWe're sad to see you go. You were our ${memberCount + 1}th member.\n\nWe hope you enjoyed your time in ${groupName} and wish you all the best!`, | ||
parse_mode: 'HTML' | ||
}); | ||
} catch (error) { | ||
console.error('Error in goodbye event:', error); | ||
// Send a text-only goodbye message as fallback, still with user mention | ||
const userMention = `<a href="tg://user?id=${userId}">${username}</a>`; | ||
await bot.sendMessage(chatId, `Goodbye, ${userMention}! 👋\nWe're sad to see you go. You were our ${memberCount + 1}th member.\n\nWe hope you enjoyed your time in ${groupName} and wish you all the best!`, { | ||
parse_mode: 'HTML' | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { | ||
name: 'goodbye', | ||
execute | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const fetch = require('node-fetch'); | ||
|
||
async function execute(bot, msg, groupName, memberCount) { | ||
const chatId = msg.chat.id; | ||
const newMember = msg.new_chat_member; | ||
const username = newMember.username || newMember.first_name || 'New member'; | ||
const userId = newMember.id; | ||
|
||
try { | ||
// Fetch the welcome image from the API | ||
const apiUrl = `https://api.nexalo.xyz/welcome_v2?api=na_T51VHMGBMZJO7S2B&name=${encodeURIComponent(username)}&text=${encodeURIComponent(`Welcome to ${groupName}`)}`; | ||
const response = await fetch(apiUrl); | ||
const imageBuffer = await response.buffer(); | ||
|
||
// Create a mention of the user | ||
const userMention = `<a href="tg://user?id=${userId}">${username}</a>`; | ||
|
||
// Send the welcome message with the image and user mention | ||
await bot.sendPhoto(chatId, imageBuffer, { | ||
caption: `Welcome to ${groupName}, ${userMention}! 🎉\nYou're our ${memberCount}th member! 🌟\n\nWe're excited to have you join us. Feel free to introduce yourself and join the conversation!`, | ||
parse_mode: 'HTML' | ||
}); | ||
} catch (error) { | ||
console.error('Error in welcome event:', error); | ||
// Send a text-only welcome message as fallback, still with user mention | ||
const userMention = `<a href="tg://user?id=${userId}">${username}</a>`; | ||
await bot.sendMessage(chatId, `Welcome to ${groupName}, ${userMention}! 🎉\nYou're our ${memberCount}th member! 🌟\n\nWe're excited to have you join us. Feel free to introduce yourself and join the conversation!`, { | ||
parse_mode: 'HTML' | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { | ||
name: 'welcome', | ||
execute | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function escapeMarkdown(text) { | ||
return text.replace(/[_*[\]()~`>#+=|{}.!-]/g, '\\$&'); | ||
} | ||
|
||
module.exports = { | ||
escapeMarkdown | ||
}; | ||
|
||
|