diff --git a/README.md b/README.md index bd1729f..420c6e1 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,14 @@ The enable and disable redeem commands have a way to enable/disable all sound al When running the development database and twitch api application, the redeems will not get created. This is because twitch only allows editing or deleting rewards when the same application created the reward. (fucking stupid) +### Welcome message + +Welcome message in the context of this project means 2 things: +- The message the bot says when it's the first time you're chatting in the channel. +- The personalized message the bot says when you chat for the first time during a stream. + +The personalized message can be set by using the channel point redemption. The message cannot be longer than 200 characters. + ### Chatterbot/streamerbot This depends on if the `CHATTER_IS_STREAMER` environment variable is set. @@ -224,6 +232,7 @@ NAME|AMOUNT|USAGE|FUNCTION NAME|COST|DESCRIPTION|INTERNALNAME -|-|-|- +`Set welcome message`|15000|Set the message the bot will say when you first chat during a stream (character limit is 200)|`setwelcomemsg` `FREE MONEY`|1000|Get 100 qbucks|`qbucksredeem` `RIPBOZO`|500|Sound: Coffeezilla calls me a conman [(source)](https://www.youtube.com/watch?v=QRvEGn7i-wM)|`sfxripbozo` `Welcome to the Madhouse`|100|Sound: mrockstar20 says: "Welcome to the Madhouse"|`sfxmrockmadhouse` diff --git a/src/events/message.ts b/src/events/message.ts index 1fe7c5f..01605bc 100644 --- a/src/events/message.ts +++ b/src/events/message.ts @@ -48,6 +48,18 @@ async function parseChatMessage(msg: EventSubChannelChatMessageEvent) { if (!(await isInvuln(user?.id!))) user?.setVulnerable(); // Make the user vulnerable to explosions if not marked as invuln + // Custom welcome messages + const wcmessage = await redis.get(`user:${user?.id}:welcomemessagetext`); + if ( + process.env.NODE_ENV === "production" && // when running prod DB + wcmessage && // when chatter has a welcome message set + (await redis.exists(`streamIsLive`)) && // when the stream is active + !(await redis.exists(`user:${user?.id}:haschattedthisstream`)) // when the user hasn't chatted this stream + ) + await sendMessage(wcmessage); + + await redis.set(`user:${user?.id}:haschattedthisstream`, "1"); + if (!msg.isCheer && !msg.isRedemption) await handleChatMessage(msg, user!); else if (msg.isCheer && !msg.isRedemption) await handleCheer(msg, msg.bits, user!); diff --git a/src/events/streamState.ts b/src/events/streamState.ts index 5eff1ed..516fc33 100644 --- a/src/events/streamState.ts +++ b/src/events/streamState.ts @@ -5,16 +5,23 @@ import { streamerId } from "main"; import { sendDiscordMessage } from "web/discordConnection"; eventSub.onStreamOnline(streamerId, async (msg) => { - await redis.set("streamIsLive", "1"); - await sendMessage( - `${msg.broadcasterDisplayName.toUpperCase()} IS LIVE! START DIGGING!`, - ); - await sendDiscordMessage({ message: "live" }); + await Promise.all([ + redis.set("streamIsLive", "1"), + sendMessage( + `${msg.broadcasterDisplayName.toUpperCase()} IS LIVE! START DIGGING!`, + ), + sendDiscordMessage({ message: "live" }), + redis + .keys("user:*:haschattedthisstream") + .then((a) => a.map(async (b) => await redis.del(b))), + ]); }); eventSub.onStreamOffline(streamerId, async (msg) => { - await redis.del("streamIsLive"); - await sendMessage( - `${msg.broadcasterDisplayName.toUpperCase()} IS OFFLINE! NO MORE FREE LOOT!`, - ); + await Promise.all([ + redis.del("streamIsLive"), + sendMessage( + `${msg.broadcasterDisplayName.toUpperCase()} IS OFFLINE! NO MORE FREE LOOT!`, + ), + ]); }); diff --git a/src/pointRedeems/welcomemessageset.ts b/src/pointRedeems/welcomemessageset.ts new file mode 100644 index 0000000..49d6742 --- /dev/null +++ b/src/pointRedeems/welcomemessageset.ts @@ -0,0 +1,26 @@ +import PointRedeem from "pointRedeems"; +import { sendMessage } from "lib/commandUtils"; +import { redis } from "lib/redis"; + +export default new PointRedeem({ + name: "setwelcomemsg", + cost: 15000, + title: "Set welcome message", + input: true, + color: "#0099FF", + prompt: + "Set your welcome message (echoed once per stream). Character limit is 200", + async execution(msg) { + if (msg.input.length > 200) { + await sendMessage(`Your desired welcome message is too long`); + if (process.env.NODE_ENV === "production") + await msg.updateStatus("CANCELED"); + } + await Promise.all([ + sendMessage( + `${msg.userDisplayName} successfully set their new welcome message`, + ), + redis.set(`user:${msg.userId}:welcomemessagetext`, "1"), + ]); + }, +});