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/_broadcast.js
javascript · 659 lines
1/**#command2name: /broadcast3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// ==========================================================13// 💜 GIFT AI — /broadcast14// RELIABLE ADMIN-ONLY BROADCAST15//16// OWNER + SAVED BOT ADMINS17//18// FEATURES:19// • Sends to ALL users saved by /start20// • Uses broadcast_users database21// • Removes duplicates22// • Ignores invalid IDs23// • Attempts every saved user24// • Retries failed sends25// • Detects permanently unreachable users26// • Keeps temporary failures in database27// • Prevents accidental database wipe28// • Final delivery report29// • TeleBotHost-safe30// ==========================================================31 32 33// ==========================================================34// 👑 BOT OWNER35// ==========================================================36 37var OWNER_ID = "8031061590";38 39 40// ==========================================================41// 👑 GET SAVED BOT ADMINS42// ==========================================================43 44var admins = Bot.getProperty("GIFT_BOT_ADMINS");45 46if (!Array.isArray(admins)) {47 admins = [];48}49 50 51// ==========================================================52// 🔐 ADMIN CHECK53// ==========================================================54 55var senderId = String(56 user.telegramid || ""57).trim();58 59var isAdmin = false;60 61 62// ----------------------------------------------------------63// OWNER64// ----------------------------------------------------------65 66if (senderId === OWNER_ID) {67 isAdmin = true;68}69 70 71// ----------------------------------------------------------72// SAVED ADMINS73// ----------------------------------------------------------74 75if (!isAdmin) {76 77 for (var a = 0; a < admins.length; a++) {78 79 if (80 String(admins[a] || "").trim() === senderId81 ) {82 83 isAdmin = true;84 break;85 86 }87 88 }89 90}91 92 93// ==========================================================94// ❌ DENY NON-ADMINS95// ==========================================================96 97if (!isAdmin) {98 99 var deniedData = {100 chat_id: user.telegramid,101 102 text:103 "⛔ <b>ACCESS DENIED</b>\n\n" +104 "You don't have permission to use " +105 "<code>/broadcast</code>.",106 107 parse_mode: "HTML"108 };109 110 111 if (112 request &&113 request.message_id114 ) {115 116 deniedData.reply_to_message_id =117 request.message_id;118 119 }120 121 122 Api.sendMessage(deniedData);123 124 return;125}126 127 128// ==========================================================129// 📢 GET BROADCAST MESSAGE130// ==========================================================131 132var broadcastMessage =133 String(params || "").trim();134 135 136// ==========================================================137// ⚠️ NO MESSAGE138// ==========================================================139 140if (!broadcastMessage) {141 142 var usageData = {143 144 chat_id: user.telegramid,145 146 text:147 "⚠️ <b>BROADCAST USAGE</b>\n\n" +148 149 "<code>/broadcast Your message here</code>\n\n" +150 151 "Example:\n" +152 "<code>/broadcast Hello everyone! 💜</code>",153 154 parse_mode: "HTML"155 };156 157 158 if (159 request &&160 request.message_id161 ) {162 163 usageData.reply_to_message_id =164 request.message_id;165 166 }167 168 169 Api.sendMessage(usageData);170 171 return;172}173 174 175// ==========================================================176// 👥 GET SAVED USERS177// ==========================================================178 179var users =180 Bot.getProperty("broadcast_users");181 182 183// ----------------------------------------------------------184// MAKE SURE DATABASE IS AN ARRAY185// ----------------------------------------------------------186 187if (!Array.isArray(users)) {188 users = [];189}190 191 192// ==========================================================193// 🧹 CLEAN + DEDUPLICATE USER IDS194// ==========================================================195 196var cleanUsers = [];197var seen = {};198 199for (200 var i = 0;201 i < users.length;202 i++203) {204 205 if (206 users[i] === null ||207 users[i] === undefined208 ) {209 210 continue;211 212 }213 214 215 var id =216 String(users[i]).trim();217 218 219 // --------------------------------------------------------220 // TELEGRAM IDS MUST BE NUMERIC221 // --------------------------------------------------------222 223 if (224 !/^\d+$/.test(id)225 ) {226 227 continue;228 229 }230 231 232 // --------------------------------------------------------233 // PREVENT DUPLICATES234 // --------------------------------------------------------235 236 if (seen[id]) {237 continue;238 }239 240 241 seen[id] = true;242 243 cleanUsers.push(id);244 245}246 247 248// ==========================================================249// 💾 SAVE CLEANED DATABASE250// ==========================================================251 252Bot.setProperty(253 "broadcast_users",254 cleanUsers,255 "json"256);257 258 259// ==========================================================260// ⚠️ NO SAVED USERS261// ==========================================================262 263if (264 cleanUsers.length === 0265) {266 267 var emptyData = {268 269 chat_id: user.telegramid,270 271 text:272 "⚠️ <b>NO SAVED USERS</b>\n\n" +273 274 "Nobody has successfully used " +275 "<code>/start</code> yet.",276 277 parse_mode: "HTML"278 };279 280 281 if (282 request &&283 request.message_id284 ) {285 286 emptyData.reply_to_message_id =287 request.message_id;288 289 }290 291 292 Api.sendMessage(emptyData);293 294 return;295}296 297 298// ==========================================================299// 📢 BROADCAST STARTED300// ==========================================================301 302var startBroadcastData = {303 304 chat_id: user.telegramid,305 306 text:307 "📢 <b>BROADCAST STARTED</b>\n\n" +308 309 "👥 Saved users: <b>" +310 cleanUsers.length +311 "</b>\n\n" +312 313 "🚀 Attempting delivery to every saved user...\n" +314 "⏳ Please wait for the final report.",315 316 parse_mode: "HTML"317};318 319 320if (321 request &&322 request.message_id323) {324 325 startBroadcastData.reply_to_message_id =326 request.message_id;327 328}329 330 331Api.sendMessage(startBroadcastData);332 333 334// ==========================================================335// 📊 BROADCAST COUNTERS336// ==========================================================337 338var sent = 0;339var failed = 0;340var retrySent = 0;341var permanentlyFailed = 0;342 343 344// ==========================================================345// 🗑️ PERMANENTLY FAILED USERS346// ==========================================================347 348var removeUsers = {};349 350 351// ==========================================================352// 🔍 CHECK PERMANENT FAILURE353// ==========================================================354 355function isPermanentFailure(error) {356 357 var errorText = "";358 359 try {360 361 if (362 error &&363 error.message364 ) {365 366 errorText =367 String(error.message).toLowerCase();368 369 } else if (370 error &&371 error.description372 ) {373 374 errorText =375 String(error.description).toLowerCase();376 377 } else {378 379 errorText =380 String(error || "").toLowerCase();381 382 }383 384 } catch (e) {385 386 errorText = "";387 388 }389 390 391 if (392 errorText.indexOf("bot was blocked") !== -1393 ) {394 return true;395 }396 397 398 if (399 errorText.indexOf("user is deactivated") !== -1400 ) {401 return true;402 }403 404 405 if (406 errorText.indexOf("chat not found") !== -1407 ) {408 return true;409 }410 411 412 if (413 errorText.indexOf("user not found") !== -1414 ) {415 return true;416 }417 418 419 if (420 errorText.indexOf("forbidden") !== -1421 ) {422 return true;423 }424 425 426 return false;427}428 429 430// ==========================================================431// 📤 SEND TO EVERY SAVED USER432// ==========================================================433 434for (435 var k = 0;436 k < cleanUsers.length;437 k++438) {439 440 var chatId =441 cleanUsers[k];442 443 var delivered = false;444 445 446 // ========================================================447 // 🔵 FIRST ATTEMPT448 // ========================================================449 450 try {451 452 Api.sendMessage({453 454 chat_id: chatId,455 456 text: broadcastMessage457 458 });459 460 461 delivered = true;462 463 sent++;464 465 } catch (error1) {466 467 468 // ======================================================469 // 🔁 SECOND ATTEMPT470 //471 // No await / Promise / setTimeout.472 // This keeps it compatible with TeleBotHost.473 // ======================================================474 475 try {476 477 Api.sendMessage({478 479 chat_id: chatId,480 481 text: broadcastMessage482 483 });484 485 486 delivered = true;487 488 sent++;489 490 retrySent++;491 492 } catch (error2) {493 494 495 // ====================================================496 // ❌ BOTH ATTEMPTS FAILED497 // ====================================================498 499 failed++;500 501 502 // ----------------------------------------------------503 // ONLY REMOVE PERMANENTLY UNREACHABLE USERS504 // ----------------------------------------------------505 506 if (507 isPermanentFailure(error2)508 ) {509 510 removeUsers[chatId] = true;511 512 permanentlyFailed++;513 514 }515 516 }517 518 }519 520}521 522 523// ==========================================================524// 🧹 UPDATE DATABASE525//526// IMPORTANT:527// Temporary failures stay saved.528// Only permanent failures are removed.529// ==========================================================530 531var updatedUsers = [];532 533for (534 var x = 0;535 x < cleanUsers.length;536 x++537) {538 539 var savedUser =540 cleanUsers[x];541 542 543 if (544 !removeUsers[savedUser]545 ) {546 547 updatedUsers.push(548 savedUser549 );550 551 }552 553}554 555 556// ==========================================================557// 💾 SAVE FINAL DATABASE558// ==========================================================559 560Bot.setProperty(561 "broadcast_users",562 updatedUsers,563 "json"564);565 566 567// ==========================================================568// 📊 FINAL DATABASE COUNT569// ==========================================================570 571var finalUsers =572 Bot.getProperty("broadcast_users");573 574if (!Array.isArray(finalUsers)) {575 finalUsers = [];576}577 578 579// ==========================================================580// ✅ FINAL BROADCAST REPORT581// ==========================================================582 583var finalData = {584 585 chat_id: user.telegramid,586 587 text:588 589 "╭━━━━━━━━━━━━━━━━━━━━╮\n" +590 " 💜 <b>GIFT AI</b>\n" +591 " 📢 <b>BROADCAST COMPLETE</b>\n" +592 "╰━━━━━━━━━━━━━━━━━━━━╯\n\n" +593 594 "👥 <b>USERS AT START</b>\n" +595 "<code>" +596 cleanUsers.length +597 "</code>\n\n" +598 599 "✅ <b>DELIVERED</b>\n" +600 "<code>" +601 sent +602 "</code>\n\n" +603 604 "🔁 <b>DELIVERED AFTER RETRY</b>\n" +605 "<code>" +606 retrySent +607 "</code>\n\n" +608 609 "❌ <b>FAILED</b>\n" +610 "<code>" +611 failed +612 "</code>\n\n" +613 614 "🗑️ <b>REMOVED FROM DATABASE</b>\n" +615 "<code>" +616 permanentlyFailed +617 "</code>\n\n" +618 619 "💾 <b>USERS REMAINING</b>\n" +620 "<code>" +621 finalUsers.length +622 "</code>\n\n" +623 624 "━━━━━━━━━━━━━━━━━━━━\n\n" +625 626 (627 failed === 0628 629 ? "💜 <b>Every saved user received the broadcast.</b>"630 631 : "⚠️ <b>Some users could not receive the message.</b>\n\n" +632 "Permanent failures were removed.\n" +633 "Temporary failures remain saved for future broadcasts."634 ),635 636 parse_mode: "HTML"637};638 639 640// ==========================================================641// ↩️ REPLY TO /BROADCAST642// ==========================================================643 644if (645 request &&646 request.message_id647) {648 649 finalData.reply_to_message_id =650 request.message_id;651 652}653 654 655// ==========================================================656// 📤 SEND FINAL REPORT657// ==========================================================658 659Api.sendMessage(finalData);