|
| 1 | +import { Message } from "../types/message"; |
| 2 | + |
| 3 | +export const info = { |
| 4 | + command: "echo", |
| 5 | + description: "Echo the user's message.", |
| 6 | + usage: "echo <count> <time> <message>", |
| 7 | + example: "echo 5 10s Hello, world!", |
| 8 | + role: "admin", |
| 9 | + cooldown: 5000, |
| 10 | +}; |
| 11 | + |
| 12 | +export default async function (msg: Message): Promise<void> { |
| 13 | + const args = msg.body.trim().split(" ").slice(1); |
| 14 | + if (args.length < 3) { |
| 15 | + await msg.reply( |
| 16 | + "Usage: echo <count> <time> <message>\nExample: echo 5 10s Hello, world!", |
| 17 | + ); |
| 18 | + return; |
| 19 | + } |
| 20 | + |
| 21 | + const count = parseInt(args[0], 10); |
| 22 | + const timeStr = args[1]; |
| 23 | + const message = args.slice(2).join(" "); |
| 24 | + |
| 25 | + if (isNaN(count) || count <= 0) { |
| 26 | + await msg.reply("Please provide a valid positive number for count."); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + const timeMatch = timeStr.match(/^(\d+)(s|m|h)$/); |
| 31 | + if (!timeMatch) { |
| 32 | + await msg.reply("Please provide a valid time format (e.g., 10s, 5m, 1h)."); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + const timeValue = parseInt(timeMatch[1], 10); |
| 37 | + const timeUnit = timeMatch[2]; |
| 38 | + let delay = 0; |
| 39 | + |
| 40 | + switch (timeUnit) { |
| 41 | + case "s": |
| 42 | + delay = timeValue * 1000; |
| 43 | + break; |
| 44 | + case "m": |
| 45 | + delay = timeValue * 60 * 1000; |
| 46 | + break; |
| 47 | + case "h": |
| 48 | + delay = timeValue * 60 * 60 * 1000; |
| 49 | + break; |
| 50 | + } |
| 51 | + |
| 52 | + for (let i = 0; i < count; i++) { |
| 53 | + setTimeout(async () => { |
| 54 | + await msg.reply(message); |
| 55 | + }, delay * i); |
| 56 | + } |
| 57 | +} |
0 commit comments