← back to browse
goat command

msg

No description

0
views
0
likes
0
installs
raw source
const { getStreamFromURL } = global.utils;

const OWNER_ID = "61594336196895";
const ADMIN_GROUP = "4095426180772827";   // admin group TID

module.exports = {
	config: {
		name: "msg",
		version: "6.2",
		author: "〲MAMUNツ࿐",
		role: 0,
		category: "support system",
		guide: "{pn} <message>  (owner only)"
	},

	onStart: async function ({ api, args, message, threadsData, event }) {

		if (String(event.senderID) !== OWNER_ID)
			return message.reply("⛔ Only owner can use this command.");

		const content = args.join(" ");
		if (!content)
			return message.reply("❌ Write a message.");

		const allThreads = await threadsData.getAll() || [];
		let success = 0;

		for (const thread of allThreads) {
			const tid = thread.threadID || thread.id || thread.threadId;
			if (!tid) continue;

			try {
				api.sendMessage(
					`📢 𝗡𝗢𝗧𝗜𝗙𝗜𝗖𝗔𝗧𝗜𝗢𝗡\n\n${content}\n\n━━━━━━━━━━━━━━\n💬 𝗥𝗘𝗣𝗟𝗬 𝗧𝗢 𝗧𝗛𝗜𝗦 𝗠𝗘𝗦𝗦𝗔𝗚𝗘`,
					tid,
					(err, info) => {
						if (!err && info) {
							global.GoatBot.onReply.set(info.messageID, {
								commandName: "msg",
								type: "userReply",
								threadID: tid
							});
						}
					}
				);
				success++;
			} catch (e) {}
		}

		return message.reply(`✅ Sent to ${success} groups.`);
	},

	onReply: async function ({ api, event, Reply, usersData }) {

		// ===== USER REPLIED =====
		if (Reply.type === "userReply") {

			let userName = "Unknown User";
			let groupName = "Unknown Group";

			try {
				const user = await usersData.get(event.senderID);
				userName = user?.name || userName;
			} catch {}

			try {
				const info = await api.getThreadInfo(event.threadID);
				groupName = info?.threadName || groupName;
			} catch {}

			const attachments = [];
			if (event.attachments?.length) {
				for (const att of event.attachments) {
					try {
						attachments.push(await getStreamFromURL(att.url));
					} catch {}
				}
			}

			return api.sendMessage(
				{
					body: `📩 𝗡𝗘𝗪 𝗥𝗘𝗣𝗟𝗬\n\n👤 𝗡𝗔𝗠𝗘 ➤ ${userName}\n🆔 𝗨𝗜𝗗 ➤ ${event.senderID}\n\n🏘️ 𝗚𝗥𝗢𝗨𝗣 ➤ ${groupName}\n🆔 𝗧𝗜𝗗 ➤ \( {event.threadID}\n\n💬 𝗠𝗘𝗦𝗦𝗔𝗚𝗘:\n \){event.body || "[Attachment]"}`,
					attachment: attachments
				},
				ADMIN_GROUP,
				(err, info) => {
					if (!err && info) {
						global.GoatBot.onReply.set(info.messageID, {
							commandName: "msg",
							type: "adminReply",
							threadID: event.threadID,
							messageID: event.messageID
						});
					}
				}
			);
		}

		// ===== ADMIN REPLIED FROM GROUP =====
		if (Reply.type === "adminReply") {

			if (String(event.senderID) !== OWNER_ID) return;

			const attachments = [];
			if (event.attachments?.length) {
				for (const att of event.attachments) {
					try {
						attachments.push(await getStreamFromURL(att.url));
					} catch {}
				}
			}

			return api.sendMessage(
				{
					body: `📨 𝗔𝗗𝗠𝗜𝗡 𝗥𝗘𝗣𝗟𝗬\n\n${event.body || ""}\n\n━━━━━━━━━━━━━━\n👑 𝗣𝗢𝗪𝗘𝗥𝗘𝗗 𝗕𝗬 𝗠𝗔𝗠𝗨𝗡`,
					attachment: attachments
				},
				Reply.threadID,
				(err, info) => {
					if (!err && info) {
						global.GoatBot.onReply.set(info.messageID, {
							commandName: "msg",
							type: "userReply",
							threadID: Reply.threadID
						});
					}
				},
				Reply.messageID
			);
		}
	}
};

View raw file