inmsuvo/pcvdbotPublic · Bot Template

ProfileTelegram

Advanced AI Group Security & Moderation Bot with Anti-Link, Anti-NSFW, Anti-Spam & Auto-Warn features.

Moderationmoderationantilinkantiforwardantisnsantispamwelcome
12 commands0 envUpdated 25d agoCreated Oct 2, 2026
Back to folder

commands/_.js

javascript · 226 lines

Raw
1/**#command2name: *3answer: 4keyboard: 5parse_mode: html6aliases: 7allow_only_group: true8need_reply: false9is_web: 010#command**/11 12// Global Message Interceptor / Filter Check13let msg = request;14if (!msg || chat.chat_type === "private") { return; }15 16let chat_id = chat.id;17let userObj = msg.from;18if (!userObj) { return; }19 20let userId = userObj.id;21let firstName = userObj.first_name || "User";22 23// 1. Foolproof Admin & Owner Check using await Api.getChatMember24let isAdmin = false;25try {26  let member = await Api.getChatMember({ chat_id: chat_id, user_id: userId });27  let status = "";28  if (member) {29    if (member.status) { status = member.status; }30    else if (member.result && member.result.status) { status = member.result.status; }31  }32  33  if (status === "creator" || status === "administrator") {34    isAdmin = true;35  }36} catch (e) {}37 38if (isAdmin) {39  return;40}41 42// Feature 12: Service Message Cleaner (Clean join/left notifications)43if (msg.new_chat_members || msg.left_chat_member || msg.new_chat_member) {44  try {45    Api.deleteMessage({ chat_id: chat_id, message_id: msg.message_id });46  } catch(e) {}47  return;48}49 50// Feature 11: Anti-Spam / Anti-Flood Detector (4 messages in 5 seconds -> 1 min mute)51let spamKey = "spam_" + chat_id + "_" + userId;52let now = Math.floor(Date.now() / 1000);53let timestamps = Bot.getProperty(spamKey, []);54if (!Array.isArray(timestamps)) { timestamps = []; }55timestamps = timestamps.filter(t => (now - t) <= 5);56timestamps.push(now);57Bot.setProperty(spamKey, timestamps, "json");58 59if (timestamps.length >= 4) {60  try {61    Api.deleteMessage({ chat_id: chat_id, message_id: msg.message_id });62    await Api.restrictChatMember({63      chat_id: chat_id,64      user_id: userId,65      until_date: now + 60,66      permissions: { can_send_messages: false, can_send_media_messages: false }67    });68    Api.sendMessage({69      chat_id: chat_id,70      receiver_user_id: userId,71      text: `${firstName}, please stop flooding! You have been muted for 1 minute.`,72      parse_mode: "HTML"73    });74  } catch(e) {}75  Bot.setProperty(spamKey, [], "json");76  return;77}78 79let text = msg.text || msg.caption || "";80let entities = msg.entities || msg.caption_entities || [];81 82// Feature 5: Anti-Raid / Lockdown Mode Check83let antiraid = Bot.getProperty("antiraid_" + chat_id, "off");84if (antiraid === "on") {85  try {86    Api.deleteMessage({ chat_id: chat_id, message_id: msg.message_id });87    Api.sendMessage({88      chat_id: chat_id,89      receiver_user_id: userId,90      text: `${firstName}, Anti-Raid mode is active! All messages are temporarily restricted.`,91      parse_mode: "HTML"92    });93  } catch(e) {}94  return;95}96 97// Helper function for Warn / Action system with Auto-Punish (Feature 13)98async function punishUser(reasonText) {99  try {100    Api.deleteMessage({ chat_id: chat_id, message_id: msg.message_id });101    102    let warnKey = "warns_" + chat_id + "_" + userId;103    let warns = Bot.getProperty(warnKey, 0) + 1;104    Bot.setProperty(warnKey, warns, "integer");105 106    if (warns >= 3) {107      Bot.setProperty(warnKey, 0, "integer");108      let untilTime = Math.floor(Date.now() / 1000) + 300; // 5 mins mute on 3rd warning109      await Api.restrictChatMember({110        chat_id: chat_id,111        user_id: userId,112        until_date: untilTime,113        permissions: { can_send_messages: false, can_send_media_messages: false }114      });115      Api.sendMessage({116        chat_id: chat_id,117        receiver_user_id: userId,118        text: `${firstName}, reached 3 warnings for <b>${reasonText}</b>! You are muted for 5 minutes.`,119        parse_mode: "HTML"120      });121    } else {122      Api.sendMessage({123        chat_id: chat_id,124        receiver_user_id: userId,125        text: `${firstName}, warning <b>(${warns}/3)</b>: ${reasonText} is not allowed!`,126        parse_mode: "HTML"127      });128    }129  } catch(err) {}130}131 132// 1. Anti-Link Check133let antilink = Bot.getProperty("antilink_" + chat_id, "off");134if (antilink === "on") {135  let hasLink = false;136  if (entities && entities.length > 0) {137    for (let i = 0; i < entities.length; i++) {138      let type = entities[i].type;139      if (type === "url" || type === "text_link" || type === "mention" || type === "email") {140        hasLink = true;141        break;142      }143    }144  }145  if (!hasLink && /https?:\/\/|www\.|t\.me\/|telegram\.dog|[a-zA-Z0-9-]+\.(com|net|org|io|me|in|xyz|ru|co|biz|info)/i.test(text)) {146    hasLink = true;147  }148 149  if (hasLink) {150    await punishUser("Sharing Links");151    return;152  }153}154 155// 2. Anti-Forward Check156let antiforward = Bot.getProperty("antiforward_" + chat_id, "off");157if (antiforward === "on") {158  if (msg.forward_from || msg.forward_from_chat || msg.forward_date || msg.forward_sender_name) {159    await punishUser("Forwarded Content");160    return;161  }162}163 164// 3. Advanced Anti-NSFW / Adult Content Detector with 1-Min Mute165let antisns = Bot.getProperty("antisns_" + chat_id, "off");166if (antisns === "on") {167  let nsfwPatterns = [168    /\b(porn|sex|xxx|nude|nsfw|pussy|dick|cock|boobs|ass|blowjob|handjob|cum|orgasm|bdsm|milf|slut|whore|horny|vagina|penis|anal|masturbat|gangbang)\b/i,169    /\b(18\+|onlyfans|xvideos|pornhub|xnxx|stripchat|cammodel)\b/i,170    /(lingerie|bra|panties|undies)/i171  ];172 173  let lowerText = text.toLowerCase();174  let cleanText = lowerText.replace(/[^a-z0-9\s]/g, "");175  176  let isNsfw = false;177  for (let i = 0; i < nsfwPatterns.length; i++) {178    if (nsfwPatterns[i].test(lowerText) || nsfwPatterns[i].test(cleanText)) {179      isNsfw = true;180      break;181    }182  }183 184  if (msg.has_media_spoiler && (msg.caption || "").length > 0) {185    isNsfw = true;186  }187 188  if (isNsfw) {189    try {190      Api.deleteMessage({ chat_id: chat_id, message_id: msg.message_id });191      let untilTime = Math.floor(Date.now() / 1000) + 60;192      await Api.restrictChatMember({193        chat_id: chat_id,194        user_id: userId,195        until_date: untilTime,196        permissions: { can_send_messages: false, can_send_media_messages: false }197      });198      Api.sendMessage({ 199        chat_id: chat_id, 200        receiver_user_id: userId,201        text: `${firstName}, adult/NSFW content is prohibited! Muted for 1 minute.`, 202        parse_mode: "HTML"203      });204    } catch(err) {}205    return;206  }207}208 209// Feature 14: Custom Blacklisted Words Censor210let customBlacklist = Bot.getProperty("blacklist_" + chat_id, "");211if (customBlacklist) {212  let words = customBlacklist.toLowerCase().split(",");213  let lowerText = text.toLowerCase();214  let matched = false;215  for (let w = 0; w < words.length; w++) {216    let word = words[w].trim();217    if (word && lowerText.indexOf(word) !== -1) {218      matched = true;219      break;220    }221  }222  if (matched) {223    await punishUser("Blacklisted Word");224    return;225  }226}