1
0

Add command to create channel point rewards

This commit is contained in:
2022-01-06 02:49:46 +01:00
parent ab8786b68b
commit 2076089bb6
3 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import { LOG_PREFIX, say } from "..";
import { TwitchPrivateMessage } from "@twurple/chat/lib/commands/TwitchPrivateMessage";
import { createReward as createChannelPointsReward } from "../../helpers/twitch";
async function createReward(
channel: string,
user: string,
message: string,
msg: TwitchPrivateMessage
): Promise<void> {
const args = message.split(" ");
const title = args.shift();
const cost = Math.max(1, parseInt(args.shift() ?? "0"));
if (!title || !cost) {
await say(
channel,
"No se ha especificado el nombre de la recompensa o costo"
);
return;
}
try {
await createChannelPointsReward(msg.channelId as string, {
title,
cost
});
say(
channel,
`✅ Creada recompensa de canal "${title}" con un costo de ${cost}`
);
} catch (e) {
if (e instanceof Error) {
console.log(`${LOG_PREFIX}${e.message}`);
}
}
}
export { createReward };