millswelbeck148/SireimadeBotPublic · Bot Template

ProfileTelegram

AIGift AI is a command‑based Telegram bot that offers a mix of moderation tools and light‑hearted features. It lets group admins ban, unban, and promote users by replying to messages, while also providing user‑ID lookup and a support link that enforces a forced‑join check. In addition, the bot includes simple games such as tic‑tac‑toe (commands /x and /o) and a Magic 8‑Ball (/8ball). The code uses the TeleBotHost TBL APIs (Bot, Api, db, etc.) and contains no long‑running listeners or external frameworks.

Moderationmoderationadminbanunbanpromoteuser-info
118 commands3 envUpdated 17d agoCreated Aug 27, 2026
Back to folder

commands/_clear.js

javascript · 228 lines

Raw
1/**#command2name: /clear3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// ==========================================================13// 🗑️ GIFT — /CLEAR14// TELEBOTHOST • ADMIN ONLY15//16// Usage:17//   /clear18//19// • No reply required20// • Admin/creator only21// • Deletes the /clear command22// • Attempts to clear recent group messages23// • Does not send a success message24// • Failed deletions are safely ignored25//26// IMPORTANT:27// Telegram does not provide a "delete entire chat history"28// API method for bots. This command therefore attempts to29// delete a large range of recent message IDs.30// ==========================================================31 32// ==========================================================33// 🛡️ BASIC CHECK34// ==========================================================35 36if (37!request ||38!request.message_id ||39!chat ||40!chat.id ||41!request.from ||42!request.from.id43) {44return;45}46 47// ==========================================================48// 🚫 PRIVATE CHAT CHECK49// ==========================================================50 51if (52chat.type !== "group" &&53chat.type !== "supergroup"54) {55return;56}57 58// ==========================================================59// 📌 GET IDs60// ==========================================================61 62var chatId = chat.id;63var adminId = request.from.id;64 65// ==========================================================66// 👑 CHECK ADMIN67// ==========================================================68 69var adminCheck = null;70 71try {72 73adminCheck = await Api.getChatMember({74chat_id: chatId,75user_id: adminId76});77 78} catch (e) {79 80return;81}82 83// ==========================================================84// ❌ ADMIN CHECK FAILED85// ==========================================================86 87if (88!adminCheck ||89!adminCheck.ok ||90!adminCheck.result91) {92 93return;94}95 96// ==========================================================97// 🔐 ADMIN STATUS98// ==========================================================99 100var status = adminCheck.result.status;101 102if (103status !== "administrator" &&104status !== "creator"105) {106 107return;108}109 110// ==========================================================111// 🤖 MAKE SURE GIFT CAN DELETE112// ==========================================================113 114var botId = null;115 116try {117 118var me = await Api.getMe();119 120if (121me &&122me.ok &&123me.result &&124me.result.id125) {126 127botId = me.result.id;128 129}130 131} catch (e) {132 133// Continue without bot ID.134}135 136// ==========================================================137// 🗑️ DELETE /CLEAR COMMAND FIRST138// ==========================================================139 140try {141 142await Api.deleteMessage({143chat_id: chatId,144message_id: request.message_id145});146 147} catch (e) {148 149// Ignore failure.150}151 152// ==========================================================153// ⚙️ CLEAR RANGE154//155// Telegram does not expose the latest message ID of a chat.156// We therefore use the /clear message ID as the upper bound157// and walk backwards.158//159// Increase CLEAR_LIMIT if desired, but very large values can160// make the command slower and hit Telegram API limits.161// ==========================================================162 163var CLEAR_LIMIT = 1000;164 165var startMessageId =166request.message_id - 1;167 168if (startMessageId < 1) {169return;170}171 172// ==========================================================173// 🚀 DELETE MESSAGES174// ==========================================================175 176for (177var i = 0;178i < CLEAR_LIMIT;179i++180) {181 182var messageId =183startMessageId - i;184 185if (messageId < 1) {186break;187}188 189try {190 191var result =192  await Api.deleteMessage({193    chat_id: chatId,194    message_id: messageId195  });196 197 198// ------------------------------------------------------199// SMALL DELAY200// Helps avoid hammering Telegram too quickly.201// ------------------------------------------------------202 203if (204  typeof Bot !== "undefined" &&205  Bot.sleep206) {207 208  await Bot.sleep(30);209 210}211 212} catch (e) {213 214// ------------------------------------------------------215// Some message IDs won't exist or cannot be deleted.216// Simply continue with the next one.217// ------------------------------------------------------218 219continue;220 221}222}223 224// ==========================================================225// ✅ FINISHED226// ==========================================================227 228return;