Files
matrix-sob/src/commands/repeat.ts
T
2025-06-08 16:16:37 +08:00

35 lines
1.2 KiB
TypeScript

import { MatrixClient } from "matrix-bot-sdk";
import { CommandData } from "../types/Command";
import Logger from "../util/Logger";
import { cd } from "..";
export const Command: CommandData = {
name: 'repeat',
description: 'Echoes text.',
usage: 'sob!repeat <text>(;;;@;;;(times to repeat)) [ex. sob!repeat sob;;;@;;;3]',
execute: async (client: MatrixClient, roomId: string, event: any, userInput: any) => {
//await client.replyNotice(roomId, event, "😭");
userInput = userInput.replace('sob!repeat ', '')
var initial: string[] = userInput.split(';;;') // initial[0]: text to spam
try {
if (initial[1] === "@") {
var times = parseInt(initial[2])
cd.quiet(`Times: ${times.toString()}`)
for (let i = 0; i < times; i++) {
if (i != (times - 1))
await client.sendMessage(roomId, {
msgtype: "m.text",
body: initial[0],
})
}
return initial[0]
}
return initial[0]
} catch (err) {
return err.toString()
}
}
}
export default Command