✨ Add command to create channel point rewards
This commit is contained in:
42
src/backend/chatClient/commands/createReward.ts
Normal file
42
src/backend/chatClient/commands/createReward.ts
Normal 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 };
|
@@ -7,6 +7,7 @@ import { ChatClient } from "@twurple/chat";
|
|||||||
import { ChatCommands } from "../../enums/ChatCommands";
|
import { ChatCommands } from "../../enums/ChatCommands";
|
||||||
import { TwitchPrivateMessage } from "@twurple/chat/lib/commands/TwitchPrivateMessage";
|
import { TwitchPrivateMessage } from "@twurple/chat/lib/commands/TwitchPrivateMessage";
|
||||||
import { broadcast } from "../helpers/webServer";
|
import { broadcast } from "../helpers/webServer";
|
||||||
|
import { createReward } from "./commands/createReward";
|
||||||
import { start } from "../helpers/miniDb";
|
import { start } from "../helpers/miniDb";
|
||||||
|
|
||||||
let chatClient: ChatClient;
|
let chatClient: ChatClient;
|
||||||
@@ -105,6 +106,9 @@ async function onMessage(
|
|||||||
`Comandos disponibles: "${Object.values(ChatCommands).join('", "')}"`
|
`Comandos disponibles: "${Object.values(ChatCommands).join('", "')}"`
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case ChatCommands.CreateReward:
|
||||||
|
await createReward(channel, user, args.join(" "), msg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.log(
|
console.log(
|
||||||
`${LOG_PREFIX}Command ${commandPrefix}${commandName} not handled`
|
`${LOG_PREFIX}Command ${commandPrefix}${commandName} not handled`
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
export enum ChatCommands {
|
export enum ChatCommands {
|
||||||
Commands = "commands",
|
Commands = "commands",
|
||||||
|
CreateReward = "createreward"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user