From 22681129206a946cd10f8c01206abe8516e514f1 Mon Sep 17 00:00:00 2001 From: qwerinope Date: Mon, 7 Apr 2025 13:24:08 +0200 Subject: [PATCH] move !modme and !getloot options to env variables --- .example.env | 2 ++ README.md | 20 +++++++++++--------- src/bot.ts | 6 ++++-- src/commands/modme.ts | 3 ++- src/lib/lootboxes.ts | 4 ++-- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.example.env b/.example.env index 6315c96..f2b90f8 100644 --- a/.example.env +++ b/.example.env @@ -1,5 +1,7 @@ BOT_NAME= CHANNEL= +MODS= +COOLDOWN= CLIENT_ID= CLIENT_SECRET= REDIRECT_URI=https://qweri0p.github.io/url-params/ diff --git a/README.md b/README.md index d7ff13e..9f27c99 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,17 @@ Here is the list of commands. COMMAND|FUNCTION|USER|ALIASES -|-|-|- -`!balance [target]`|List write the amount of money the user or the target user has.|anyone|`!bal, !qbucks, !qweribucks` -`!inventory [target]`|Show inventory contents of user or the target user.|anyone|`!inv` -`!getloot`|Give user a lootbox. This command has a cooldown that can be changed in `lootbox.ts`.|anyone|`None` -`!stats [target]`|Show the stats of user or target user including users shot, TNT used and grenades lobbed of the current month.|anyone|`None` -`!alltime [target]`|Show the stats of user or target user including users shot, TNT used and grenades lobbed of all time.|anyone|`None` -`!timeout {target}`|Give the target user a timeout of 60 seconds. This requires 100 qbucks.|anyone|`None` +`!balance [target]`|List write the amount of money the user or the target user has|anyone|`!bal, !qbucks, !qweribucks` +`!inventory [target]`|Show inventory contents of user or the target user|anyone|`!inv` +`!getloot`|Give user a lootbox. This command has a cooldown that can be changed with the `COOLDOWN` environment variable|anyone|`None` +`!stats [target]`|Show the stats of user or target user including users shot, TNT used and grenades lobbed of the current month|anyone|`None` +`!alltime [target]`|Show the stats of user or target user including users shot, TNT used and grenades lobbed of all time|anyone|`None` +`!timeout {target}`|Give the target user a timeout of 60 seconds. This requires 100 qbucks|anyone|`None` `!use {item}`|Use a specific item. The user needs the specific item in their inventory. For items please look at the table below|anyone|`None` `!iteminfo {item}`|Gives a description of the requested item. Identical to [the item descriptions in this document](#items)|anyone|`!item` -`!modme`|Gives the user moderator status. Only gives users moderator status if their name is in `modme.ts`|anyone|`None` +`!modme`|Gives the user moderator status. Only gives users moderator status if their name is in the `MODS` environment variable|anyone|`None` `!give {target} {item} {count}`|Give a specific user a specific amount of an item. Negative amounts can be used to remove items|streamer|`None` -`!vulnchatters`|Print how many users are vulnerable to TNT and grenade explosions.|streamer|`None` +`!vulnchatters`|Print how many users are vulnerable to TNT and grenade explosions|streamer|`None` ### Items @@ -98,7 +98,9 @@ Options with :bangbang: in the Required column need to be present for setup, and VARIABLE|DEFAULT|FUNCTION|REQUIRED -|-|-|- `BOT_NAME`|None|Set the name of the bot user for Authentification|:white_check_mark: -`CHANNEL`|None| Set the name of the twitch channel to join|:white_check_mark: +`CHANNEL`|None|Set the name of the twitch channel to join|:white_check_mark: +`MODS`|None|List of users that can use `!modme` to give themselves moderator status|:white_check_mark: +`COOLDOWN`|24 Hours|Cooldown between letting users get a lootbox with `!getloot` in seconds|:x: `CLIENT_ID`|None|Set the CLIENT_ID to authenticate the bot|:bangbang: `CLIENT_SECRET`|None|Set the CLIENT_SECRET to authenticate the bot|:bangbang: `REDIRECT_URI`|`https://qweri0p.github.io/url-params/`|The REDIRECT_URI set in the twitch dev console|:bangbang: diff --git a/src/bot.ts b/src/bot.ts index 7b82d39..a86e226 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -6,8 +6,10 @@ import api, { broadcasterAuthProvider } from './lib/api'; import { removeVulnChatter, vulnerableUsers } from './lib/timeoutHelper'; -const channel = process.env.CHANNEL ?? '' -const user = process.env.BOT_NAME ?? '' +const user = process.env.BOT_NAME +if (!user) { console.error("Please set the BOT_NAME environment variable."); process.exit(1) } +const channel = process.env.CHANNEL +if (!channel) { console.error("Please set the CHANNEL environment variable."); process.exit(1) } const bot = new Bot({ authProvider, diff --git a/src/commands/modme.ts b/src/commands/modme.ts index 9a585ae..6f1a94d 100644 --- a/src/commands/modme.ts +++ b/src/commands/modme.ts @@ -1,7 +1,8 @@ import { createBotCommand } from "@twurple/easy-bot"; import api, { broadcasterApi } from "../lib/api"; -const MODS = ['qwerinope'] +const MODS = process.env.MODS +if (!MODS) { console.error("Please set the MODS environment variable."); process.exit(1) } export default createBotCommand('modme', async (_params, { userName, broadcasterId }) => { if (!MODS.includes(userName)) return diff --git a/src/lib/lootboxes.ts b/src/lib/lootboxes.ts index 5a14c49..4f5807f 100644 --- a/src/lib/lootboxes.ts +++ b/src/lib/lootboxes.ts @@ -1,8 +1,8 @@ import { HelixUser } from "@twurple/api" import pb, { User } from "./pocketbase" -// const COOLDOWN = 1000 * 60 * 60 * 24 * 30 // 1000 milliseconds * 60 seconds * 60 minutes * 24 hours * 30 days -export const COOLDOWN = 1000 * 60 * 15 + +export const COOLDOWN = !process.env.COOLDOWN ? 60 * 60 * 24 : Number(process.env.COOLDOWN) interface lootboxReadyResult { result: boolean,