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 };

View File

@@ -7,6 +7,7 @@ import { ChatClient } from "@twurple/chat";
import { ChatCommands } from "../../enums/ChatCommands";
import { TwitchPrivateMessage } from "@twurple/chat/lib/commands/TwitchPrivateMessage";
import { broadcast } from "../helpers/webServer";
import { createReward } from "./commands/createReward";
import { start } from "../helpers/miniDb";
let chatClient: ChatClient;
@@ -105,6 +106,9 @@ async function onMessage(
`Comandos disponibles: "${Object.values(ChatCommands).join('", "')}"`
);
break;
case ChatCommands.CreateReward:
await createReward(channel, user, args.join(" "), msg);
break;
default:
console.log(
`${LOG_PREFIX}Command ${commandPrefix}${commandName} not handled`