millswelbeck148/SireimadeBotPublic · Bot Template
AISireImade appears to be a Telegram automation bot. Commands include /start, /about, /support, /id, /admin, /ban, /unban, /x. Observed in code: messaging, keyboards, games.
Utilityutility
112 commands3 envUpdated 1h agoCreated Aug 27, 2026
commands/_users.js
javascript · 877 lines
1/**#command2name: /users3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// ==========================================================13// 👑 GIFT AI — /users14// ADMIN-ONLY USER DATABASE15//16// FEATURES:17// • Owner + saved bot admins18// • Reads existing broadcast_users database19// • Supports OLD + NEW database formats20// • Supports string, number and object records21// • Extracts multiple possible ID fields22// • Extracts username safely23// • Extracts first/last/display/name fields24// • Works without usernames25// • Duplicate-free by Telegram ID26// • Ignores invalid database records27// • Never overwrites broadcast_users28// • Escapes HTML safely29// • Clickable Telegram users30// • Shows database statistics31// • Continues if one user message fails32// • Replies directly to /users33// ==========================================================34 35 36// ==========================================================37// 👑 BOT OWNER38// ==========================================================39 40var OWNER_ID = "8031061590";41 42 43// ==========================================================44// 🛡️ BASIC SAFETY45// ==========================================================46 47if (!user) {48 return;49}50 51 52// ==========================================================53// 👤 CURRENT USER ID54// ==========================================================55 56var senderId = String(57 user.telegramid || ""58).trim();59 60 61// ==========================================================62// 🚫 INVALID SENDER63// ==========================================================64 65if (!/^\d+$/.test(senderId)) {66 return;67}68 69 70// ==========================================================71// 👑 GET SAVED BOT ADMINS72// ==========================================================73 74var admins = Bot.getProperty(75 "GIFT_BOT_ADMINS"76);77 78if (!Array.isArray(admins)) {79 admins = [];80}81 82 83// ==========================================================84// 🔐 ADMIN CHECK85// ==========================================================86 87var isAdmin = false;88 89 90// Owner always has access91if (senderId === OWNER_ID) {92 isAdmin = true;93}94 95 96// Check saved admins97if (!isAdmin) {98 99 for (100 var a = 0;101 a < admins.length;102 a++103 ) {104 105 var adminId = "";106 107 var adminItem = admins[a];108 109 110 // ------------------------------------------------------111 // Support simple admin IDs112 // ------------------------------------------------------113 114 if (115 typeof adminItem === "string" ||116 typeof adminItem === "number"117 ) {118 119 adminId = String(120 adminItem121 ).trim();122 123 }124 125 126 // ------------------------------------------------------127 // Support object admin records128 // ------------------------------------------------------129 130 else if (131 adminItem &&132 typeof adminItem === "object"133 ) {134 135 adminId = String(136 adminItem.id ||137 adminItem.telegramid ||138 adminItem.userId ||139 adminItem.user_id ||140 ""141 ).trim();142 }143 144 145 if (146 adminId === senderId147 ) {148 149 isAdmin = true;150 break;151 }152 }153}154 155 156// ==========================================================157// ❌ ACCESS DENIED158// ==========================================================159 160if (!isAdmin) {161 162 var deniedData = {163 164 chat_id:165 senderId,166 167 text:168 "⛔ <b>ACCESS DENIED</b>\n\n" +169 "Only the bot owner and authorized bot admins " +170 "can use <code>/users</code>.",171 172 parse_mode:173 "HTML"174 };175 176 177 if (178 request &&179 request.message_id180 ) {181 182 deniedData.reply_to_message_id =183 request.message_id;184 }185 186 187 try {188 189 Api.sendMessage(190 deniedData191 );192 193 } catch (error) {194 // Ignore failed denial message195 }196 197 return;198}199 200 201// ==========================================================202// 📂 LOAD EXISTING USER DATABASE203// ==========================================================204//205// IMPORTANT:206// This command ONLY READS the database.207// It never modifies or overwrites broadcast_users.208//209 210var users = Bot.getProperty(211 "broadcast_users"212);213 214 215if (!Array.isArray(users)) {216 users = [];217}218 219 220// ==========================================================221// 🧹 CLEAN USER LIST222// ==========================================================223 224var cleanUsers = [];225 226var seen = {};227 228var invalidRecords = 0;229 230var duplicateRecords = 0;231 232 233// ==========================================================234// 🔤 HTML ESCAPE FUNCTION235// ==========================================================236 237function escapeHTML(value) {238 239 return String(240 value || ""241 )242 .replace(/&/g, "&")243 .replace(/</g, "<")244 .replace(/>/g, ">")245 .replace(/"/g, """)246 .replace(/'/g, "'");247}248 249 250// ==========================================================251// 🧹 CLEAN USERNAME252// ==========================================================253 254function cleanUsername(value) {255 256 if (257 value === null ||258 value === undefined259 ) {260 261 return "";262 }263 264 265 var result = String(266 value267 ).trim();268 269 270 if (271 result === "" ||272 result.toLowerCase() === "null" ||273 result.toLowerCase() === "undefined" ||274 result.toLowerCase() === "no username" ||275 result.toLowerCase() === "none"276 ) {277 278 return "";279 }280 281 282 // Remove accidental spaces283 result = result.replace(/\s+/g, "");284 285 286 // Remove leading @ before normalizing287 result = result.replace(/^@+/, "");288 289 290 if (291 result === ""292 ) {293 294 return "";295 }296 297 298 return "@" + result;299}300 301 302// ==========================================================303// 👥 READ EVERY DATABASE RECORD304// ==========================================================305 306for (307 var i = 0;308 i < users.length;309 i++310) {311 312 var item = users[i];313 314 315 // --------------------------------------------------------316 // Ignore null/undefined317 // --------------------------------------------------------318 319 if (320 item === null ||321 item === undefined322 ) {323 324 invalidRecords++;325 continue;326 }327 328 329 var id = "";330 331 var username = "";332 333 var displayName = "";334 335 336 // ========================================================337 // OLD FORMAT338 // ========================================================339 //340 // "8031061590"341 // 8031061590342 //343 // ========================================================344 345 if (346 typeof item === "string" ||347 typeof item === "number"348 ) {349 350 id = String(351 item352 ).trim();353 }354 355 356 // ========================================================357 // NEW / OBJECT FORMAT358 // ========================================================359 360 else if (361 typeof item === "object"362 ) {363 364 // ------------------------------------------------------365 // Telegram ID366 // ------------------------------------------------------367 368 id = String(369 item.id ||370 item.telegramid ||371 item.telegramId ||372 item.userId ||373 item.user_id ||374 item.chat_id ||375 item.chatId ||376 ""377 ).trim();378 379 380 // ------------------------------------------------------381 // Username382 // ------------------------------------------------------383 384 username = cleanUsername(385 item.username ||386 item.user_username ||387 item.userUsername ||388 ""389 );390 391 392 // ------------------------------------------------------393 // First name394 // ------------------------------------------------------395 396 var firstName = String(397 item.first_name ||398 item.firstName ||399 ""400 ).trim();401 402 403 // ------------------------------------------------------404 // Last name405 // ------------------------------------------------------406 407 var lastName = String(408 item.last_name ||409 item.lastName ||410 ""411 ).trim();412 413 414 // ------------------------------------------------------415 // Display/name fields416 // ------------------------------------------------------417 418 var possibleName = String(419 item.name ||420 item.display_name ||421 item.displayName ||422 ""423 ).trim();424 425 426 // ------------------------------------------------------427 // Build best display name428 // ------------------------------------------------------429 430 if (431 possibleName432 ) {433 434 displayName =435 possibleName;436 437 } else if (438 firstName &&439 lastName440 ) {441 442 displayName =443 firstName +444 " " +445 lastName;446 447 } else if (448 firstName449 ) {450 451 displayName =452 firstName;453 454 } else if (455 lastName456 ) {457 458 displayName =459 lastName;460 }461 }462 463 464 // ========================================================465 // VALIDATE TELEGRAM ID466 // ========================================================467 468 if (469 !/^\d+$/.test(id)470 ) {471 472 invalidRecords++;473 continue;474 }475 476 477 // Telegram IDs should not be empty478 if (479 id === ""480 ) {481 482 invalidRecords++;483 continue;484 }485 486 487 // ========================================================488 // DUPLICATE CHECK489 // ========================================================490 491 if (492 seen[id]493 ) {494 495 duplicateRecords++;496 continue;497 }498 499 500 seen[id] = true;501 502 503 // ========================================================504 // FALLBACK DISPLAY NAME505 // ========================================================506 507 if (508 !displayName509 ) {510 511 if (512 username513 ) {514 515 displayName =516 username;517 518 } else {519 520 displayName =521 "Telegram User";522 }523 }524 525 526 // ========================================================527 // CLEAN DISPLAY NAME528 // ========================================================529 530 displayName =531 String(532 displayName533 )534 .trim()535 .replace(/\s+/g, " ");536 537 538 if (539 !displayName540 ) {541 542 displayName =543 "Telegram User";544 }545 546 547 // ========================================================548 // SAVE CLEAN USER549 // ========================================================550 551 cleanUsers.push({552 553 id:554 id,555 556 username:557 username,558 559 displayName:560 displayName561 });562}563 564 565// ==========================================================566// 📊 DATABASE STATISTICS567// ==========================================================568 569var totalUsers =570 cleanUsers.length;571 572var rawRecords =573 users.length;574 575var status =576 "🟢 Healthy";577 578 579if (580 totalUsers === 0581) {582 583 status =584 "🟠 Empty";585 586} else if (587 invalidRecords > 0 ||588 duplicateRecords > 0589) {590 591 status =592 "🟡 Healthy • Cleaned";593}594 595 596// ==========================================================597// 📊 SUMMARY MESSAGE598// ==========================================================599 600var summaryText =601 602 "╭━━━━━━━━━━━━━━━━━━━━╮\n" +603 " 👑 <b>GIFT AI</b>\n" +604 " 👥 <b>USER DATABASE</b>\n" +605 "╰━━━━━━━━━━━━━━━━━━━━╯\n\n" +606 607 "👥 <b>Total Users:</b> " +608 totalUsers +609 "\n\n" +610 611 "📦 <b>Raw Records:</b> " +612 rawRecords +613 "\n" +614 615 "♻️ <b>Duplicates Ignored:</b> " +616 duplicateRecords +617 "\n" +618 619 "⚠️ <b>Invalid Records Ignored:</b> " +620 invalidRecords +621 "\n\n" +622 623 "💾 <b>Database:</b> " +624 "<code>broadcast_users</code>\n" +625 626 "📊 <b>Status:</b> " +627 status +628 "\n\n" +629 630 "🆔 <b>Telegram IDs:</b> ✅\n" +631 "🔗 <b>Clickable Users:</b> ✅\n" +632 "👤 <b>Username Detection:</b> ✅\n" +633 "🧹 <b>Duplicate Protection:</b> ✅\n\n" +634 635 "━━━━━━━━━━━━━━━━━━━━";636 637 638// ==========================================================639// 📤 SEND SUMMARY640// ==========================================================641 642var summaryData = {643 644 chat_id:645 senderId,646 647 text:648 summaryText,649 650 parse_mode:651 "HTML"652};653 654 655if (656 request &&657 request.message_id658) {659 660 summaryData.reply_to_message_id =661 request.message_id;662}663 664 665try {666 667 Api.sendMessage(668 summaryData669 );670 671} catch (error) {672 673 // Continue processing users674}675 676 677// ==========================================================678// ⚠️ EMPTY DATABASE679// ==========================================================680 681if (682 totalUsers === 0683) {684 685 var emptyData = {686 687 chat_id:688 senderId,689 690 text:691 692 "⚠️ <b>NO REGISTERED USERS</b>\n\n" +693 694 "The existing " +695 "<code>broadcast_users</code> " +696 "database contains no valid Telegram user IDs.\n\n" +697 698 "No database changes were made.",699 700 parse_mode:701 "HTML"702 };703 704 705 if (706 request &&707 request.message_id708 ) {709 710 emptyData.reply_to_message_id =711 request.message_id;712 }713 714 715 try {716 717 Api.sendMessage(718 emptyData719 );720 721 } catch (error) {722 723 // Ignore724 }725 726 return;727}728 729 730// ==========================================================731// 👥 SEND USER CARDS732// ==========================================================733 734for (735 var x = 0;736 x < cleanUsers.length;737 x++738) {739 740 var currentUser =741 cleanUsers[x];742 743 744 // ========================================================745 // 🔗 CLICKABLE USER NAME746 // ========================================================747 748 var safeDisplayName =749 escapeHTML(750 currentUser.displayName751 );752 753 754 var clickableUser =755 756 '<a href="tg://user?id=' +757 currentUser.id +758 '">' +759 safeDisplayName +760 "</a>";761 762 763 // ========================================================764 // 👤 USERNAME765 // ========================================================766 767 var usernameDisplay;768 769 770 if (771 currentUser.username772 ) {773 774 usernameDisplay =775 escapeHTML(776 currentUser.username777 );778 779 } else {780 781 usernameDisplay =782 "<i>No public username</i>";783 }784 785 786 // ========================================================787 // 📋 USER CARD788 // ========================================================789 790 var userText =791 792 "╭━━━━━━━━━━━━━━━━━━━━╮\n" +793 794 " 👤 <b>USER " +795 (x + 1) +796 "</b>\n" +797 798 "╰━━━━━━━━━━━━━━━━━━━━╯\n\n" +799 800 "👤 <b>User:</b> " +801 clickableUser +802 "\n\n" +803 804 "🆔 <b>Telegram ID:</b>\n" +805 806 "<code>" +807 escapeHTML(808 currentUser.id809 ) +810 "</code>\n\n" +811 812 "🔗 <b>Username:</b> " +813 usernameDisplay +814 "\n\n" +815 816 "━━━━━━━━━━━━━━━━━━━━\n" +817 818 "💡 <i>Tap the user's name to open " +819 "their Telegram profile.</i>";820 821 822 823 var userData = {824 825 chat_id:826 senderId,827 828 text:829 userText,830 831 parse_mode:832 "HTML"833 };834 835 836 // ========================================================837 // ↩️ REPLY TO /users838 // ========================================================839 840 if (841 request &&842 request.message_id843 ) {844 845 userData.reply_to_message_id =846 request.message_id;847 }848 849 850 // ========================================================851 // 📤 SEND USER CARD852 // ========================================================853 854 try {855 856 Api.sendMessage(857 userData858 );859 860 } catch (error) {861 862 // ------------------------------------------------------863 // One failed user must NOT stop the entire list.864 // ------------------------------------------------------865 866 continue;867 }868}869 870 871// ==========================================================872// ✅ COMPLETE873// ==========================================================874//875// broadcast_users was READ ONLY.876// No records were added, removed or overwritten.877// ==========================================================