← back to browse
goat command

notification

Send stylish notification with media to all groups

0
views
0
likes
0
installs

Aliases: notify, noti

raw source
const { getStreamsFromAttachment } = global.utils;
const moment = require("moment-timezone");

module.exports = {
  config: {
    name: "notification",
    aliases: ["notify", "noti"],
    version: "2.3",
    author: "xalmam",
    countDown: 5,
    role: 1,
    shortDescription: {
      en: "Send stylish notification with media to all groups"
    },
    longDescription: {
      en: "Send notification (text, photo, video, audio, etc.) from admin to all groups with aesthetic style"
    },
    category: "owner",
    guide: { en: "{pn} <message or reply to media>" },
    envConfig: { delayPerGroup: 300 }
  },

  langs: {
    en: {
      missingMessage: "Please enter a message or reply to a media file to send.",
      sendingNotification: "๐Ÿ“ข Sending notification to %1 groups...",
      sentNotification: "โœ… Successfully sent notification to %1 groups.",
      errorSendingNotification: "โš ๏ธ Error while sending to %1 groups:\n%2"
    }
  },

  onStart: async function ({ message, api, event, args, commandName, envCommands, threadsData, getLang, usersData, config }) {
    const { delayPerGroup } = envCommands[commandName];
    const senderID = event.senderID;
    const senderName = await usersData.getName(senderID) || "Unknown User";

    const now = moment().tz("Asia/Dhaka");
    const timeString = now.format("hh:mm A");
    const dateString = now.format("DD/MM/YYYY");

    // Handle message text
    const msgText = args.join(" ") || "";

    // Collect attachments from message or reply
    const attachments = [
      ...(event.attachments || []),
      ...(event.messageReply?.attachments || [])
    ].filter(item => ["photo", "animated_image", "video", "audio", "sticker"].includes(item.type));

    if (!msgText && attachments.length === 0)
      return message.reply(getLang("missingMessage"));

    let streamAttachments = [];
    if (attachments.length > 0) {
      try {
        streamAttachments = await getStreamsFromAttachment(attachments);
      } catch (err) {
        console.error("Attachment processing error:", err);
      }
    }

    
    const owner = "ร—แทผร—๏ผญ๏ผกโ˜‚๏ผญโ˜‚๏ผต๏ผฎโ˜†"; 
    const fb = "MA M UN Bb'z";

    
    const formSend = {
      body:
`โ•ญโ”โ”โ”ใ€” ๐—ก๐—ข๐—ง๐—œ๐—™๐—œ๐—–๐—”๐—ง๐—œ๐—ข๐—ก  ใ€•โ”โ”โ”โ•ฎ
โ”‚ OWNER: ${owner}
โ”‚MESSENGER: ${fb}
โ•ฐโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•ฏ

๐Ÿ•’ Time: ${timeString} - ${dateString}

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

${msgText || "(media only)"}

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•ฏ`,
      attachment: streamAttachments
    };

    // Get all active threads
    const allThreads = (await threadsData.getAll()).filter(
      t => t.isGroup && t.members.find(m => m.userID == api.getCurrentUserID())?.inGroup
    );

    message.reply(getLang("sendingNotification", allThreads.length));

    let sent = 0;
    const failed = [];

    for (const thread of allThreads) {
      try {
        await api.sendMessage(formSend, thread.threadID);
        sent++;
      } catch (e) {
        failed.push({ id: thread.threadID, err: e.message });
      }
      await new Promise(res => setTimeout(res, delayPerGroup));
    }

    let report = "";
    if (sent > 0) report += getLang("sentNotification", sent) + "\n";
    if (failed.length > 0)
      report += getLang(
        "errorSendingNotification",
        failed.length,
        failed.map(f => `\n - ${f.err} [${f.id}]`).join("")
      );

    message.reply(report || "โœ… All done!");
  }
};

View raw file