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
ProfileTelegram
112 commands3 envUpdated 2h agoCreated Aug 27, 2026
Back to folder

commands/_antilink_message_handler.js

javascript · 450 lines

Raw
1/**#command2name: /antilink_message_handler3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: true8need_reply: false9is_web: 110#command**/11 12// ==========================================================13// 🔗 GIFT — STANDALONE ANTI-LINK MESSAGE HANDLER14// TELEBOTHOST15//16// Put this in its OWN message handler.17//18// FEATURES:19// • Automatic link detection20// • HTTP / HTTPS links21// • www links22// • t.me / telegram.me / telegram.dog links23// • Detects clickable Telegram URL entities24// • Deletes offending messages25// • 3 warnings = kick26// • Admins + group owner are protected27// • Warnings are stored per group + user28// • No external libraries29// • Does NOT interfere with Gift AI30// ==========================================================31 32 33// ==========================================================34// ⚙️ CONFIG35// ==========================================================36 37var ANTILINK_ENABLED = true;38 39var MAX_WARNINGS = 3;40 41 42// ==========================================================43// 🛑 BASIC SAFETY44// ==========================================================45 46if (!ANTILINK_ENABLED) {47  return;48}49 50if (!message || !chat || !user) {51  return;52}53 54 55// ==========================================================56// 👥 GROUP / SUPERGROUP ONLY57// ==========================================================58 59if (60  chat.type !== "group" &&61  chat.type !== "supergroup"62) {63  return;64}65 66 67// ==========================================================68// 👤 USER ID CHECK69// ==========================================================70 71if (!user.telegramid) {72  return;73}74 75 76// ==========================================================77// 🔗 LINK DETECTION78// ==========================================================79 80function containsLink(msg) {81 82  if (!msg) {83    return false;84  }85 86  var text = "";87 88  // Text messages89  if (msg.text) {90    text += " " + msg.text;91  }92 93  // Photo/video/document captions94  if (msg.caption) {95    text += " " + msg.caption;96  }97 98 99  // --------------------------------------------------------100  // Normal URLs101  // --------------------------------------------------------102 103  var urlRegex =104    /(?:https?:\/\/|www\.)[^\s<>"']+/i;105 106  if (urlRegex.test(text)) {107    return true;108  }109 110 111  // --------------------------------------------------------112  // Telegram URLs without https://113  // Example:114  // t.me/example115  // telegram.me/example116  // telegram.dog/example117  // --------------------------------------------------------118 119  var telegramRegex =120    /(?:^|\s)(?:t\.me|telegram\.me|telegram\.dog)\/[^\s<>"']+/i;121 122  if (telegramRegex.test(text)) {123    return true;124  }125 126 127  // --------------------------------------------------------128  // Telegram message entities129  //130  // "url"       = normal clickable URL131  // "text_link" = hidden/clickable URL132  // --------------------------------------------------------133 134  var entities = [];135 136  if (msg.entities) {137    entities = entities.concat(msg.entities);138  }139 140  if (msg.caption_entities) {141    entities = entities.concat(msg.caption_entities);142  }143 144 145  for (var i = 0; i < entities.length; i++) {146 147    if (148      entities[i].type === "url" ||149      entities[i].type === "text_link"150    ) {151      return true;152    }153 154  }155 156 157  return false;158}159 160 161// ==========================================================162// 🔗 STOP IF THERE IS NO LINK163// ==========================================================164 165if (!containsLink(message)) {166  return;167}168 169 170// ==========================================================171// 🛡️ CHECK MEMBER STATUS172//173// ADMINS AND GROUP OWNER ARE EXEMPT.174// ==========================================================175 176var member;177 178try {179 180  member = Api.getChatMember({181    chat_id: chat.id,182    user_id: user.telegramid183  });184 185} catch (e) {186 187  // If Gift cannot verify the user's status,188  // do nothing instead of accidentally punishing someone.189  return;190}191 192 193// ==========================================================194// 👑 ADMIN / OWNER PROTECTION195// ==========================================================196 197if (198  member &&199  (200    member.status === "creator" ||201    member.status === "administrator"202  )203) {204  return;205}206 207 208// ==========================================================209// 🗑️ DELETE THE LINK MESSAGE210// ==========================================================211 212try {213 214  Api.deleteMessage({215    chat_id: chat.id,216    message_id: message.message_id217  });218 219} catch (e) {220 221  // If Gift cannot delete the message,222  // continue so the warning system can still work.223 224}225 226 227// ==========================================================228// 🔑 WARNING STORAGE KEY229// ==========================================================230 231var warningKey =232  "GIFT_ANTILINK_WARNINGS_" +233  String(chat.id) +234  "_" +235  String(user.telegramid);236 237 238// ==========================================================239// 📊 GET CURRENT WARNINGS240// ==========================================================241 242var warnings =243  Bot.getProperty(warningKey);244 245if (246  warnings === undefined ||247  warnings === null ||248  isNaN(Number(warnings))249) {250  warnings = 0;251}252 253warnings = Number(warnings);254 255 256// ==========================================================257// ➕ ADD WARNING258// ==========================================================259 260warnings++;261 262 263// ==========================================================264// 🔨 THIRD WARNING = KICK265// ==========================================================266 267if (warnings >= MAX_WARNINGS) {268 269  var kicked = false;270 271 272  try {273 274    Api.banChatMember({275      chat_id: chat.id,276      user_id: user.telegramid277    });278 279    kicked = true;280 281 282    // ------------------------------------------------------283    // Immediately unban.284    //285    // This removes the user from the group without leaving286    // them permanently banned.287    // ------------------------------------------------------288 289    try {290 291      Api.unbanChatMember({292        chat_id: chat.id,293        user_id: user.telegramid,294        only_if_banned: true295      });296 297    } catch (e) {298      // Ignore unban failure.299    }300 301  } catch (e) {302 303    kicked = false;304 305  }306 307 308  // --------------------------------------------------------309  // Reset warnings310  // --------------------------------------------------------311 312  Bot.deleteProperty(warningKey);313 314 315  // ========================================================316  // KICK SUCCESS317  // ========================================================318 319  if (kicked) {320 321    Api.sendMessage({322 323      chat_id: chat.id,324 325      text:326        "🚫 <b>ANTI-LINK</b>\n\n" +327 328        "👤 " +329        escapeHtml(330          user.first_name || "User"331        ) +332        "\n\n" +333 334        "🔗 Link detected.\n" +335 336        "⚠️ Warnings: <b>" +337        MAX_WARNINGS +338        "/" +339        MAX_WARNINGS +340        "</b>\n\n" +341 342        "🔨 Action: <b>Kicked</b>",343 344      parse_mode: "HTML"345 346    });347 348  }349 350 351  // ========================================================352  // KICK FAILED353  // ========================================================354 355  else {356 357    Api.sendMessage({358 359      chat_id: chat.id,360 361      text:362        "⚠️ <b>ANTI-LINK</b>\n\n" +363 364        "👤 " +365        escapeHtml(366          user.first_name || "User"367        ) +368        "\n\n" +369 370        "🔗 Link detected.\n" +371 372        "⚠️ Warnings: <b>" +373        MAX_WARNINGS +374        "/" +375        MAX_WARNINGS +376        "</b>\n\n" +377 378        "❌ I couldn't kick this user.\n" +379 380        "Make sure Gift has " +381        "<b>Ban Users</b> permission.",382 383      parse_mode: "HTML"384 385    });386 387  }388 389 390  return;391}392 393 394// ==========================================================395// 💾 SAVE WARNING396// ==========================================================397 398Bot.setProperty(399  warningKey,400  warnings,401  "integer"402);403 404 405// ==========================================================406// ⚠️ SEND WARNING407// ==========================================================408 409Api.sendMessage({410 411  chat_id: chat.id,412 413  text:414    "⚠️ <b>ANTI-LINK WARNING</b>\n\n" +415 416    "👤 " +417    escapeHtml(418      user.first_name || "User"419    ) +420    "\n\n" +421 422    "🔗 Links are not allowed in this group.\n\n" +423 424    "📊 Warning: <b>" +425    warnings +426    "/" +427    MAX_WARNINGS +428    "</b>\n\n" +429 430    "🚫 <i>3 warnings = kick.</i>",431 432  parse_mode: "HTML"433 434});435 436 437// ==========================================================438// 🛡️ HTML ESCAPE439// ==========================================================440 441function escapeHtml(text) {442 443  return String(text || "")444    .replace(/&/g, "&amp;")445    .replace(/</g, "&lt;")446    .replace(/>/g, "&gt;")447    .replace(/"/g, "&quot;")448    .replace(/'/g, "&#039;");449 450  }