From 7f20247a477e0a7d2ddca14ca9353bed34fbaa3b Mon Sep 17 00:00:00 2001 From: Darius Date: Mon, 6 Oct 2025 01:41:59 +0200 Subject: [PATCH] volume permissions --- src/commands/impl/volume.ts | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/commands/impl/volume.ts b/src/commands/impl/volume.ts index e7ceef2..719e806 100644 --- a/src/commands/impl/volume.ts +++ b/src/commands/impl/volume.ts @@ -1,8 +1,9 @@ -import type { ChatMessage } from "@twurple/chat"; +import type { ChatMessage, ChatUser } from "@twurple/chat"; +import { Config } from "../../config/config.ts"; import { getVolumeFromTidal, setVolumeToTidal } from "../../util/api-tidal.ts"; import { logSuccess } from "../../util/logger.ts"; import { BaseCommand } from "../base-command.ts"; -import type { ICommandRequirements } from "../interface.ts"; +import type { ICommand, ICommandRequirements } from "../interface.ts"; export class VolumeCommand extends BaseCommand { name = "vol"; @@ -22,20 +23,33 @@ export class VolumeCommand extends BaseCommand { ) => { logSuccess(`${channel} ${user} volume command triggered`); - const volumeText = await parseCommand(text); + const volumeText = await parseCommand(text, msg.userInfo, this); if (volumeText) { this.chatClient.say(channel, volumeText, { replyTo: msg }); } else { this.chatClient.say(channel, "tidal not running..", { replyTo: msg }); } }; + + checkPerms = (_user: ChatUser): boolean => { + if (!this.enabled) { + return false; + } + + return true; + }; } -async function parseCommand(message: string): Promise { +async function parseCommand( + message: string, + user: ChatUser, + command: ICommand, +): Promise { const args = message.slice(4).trim(); // Remove '!volume' + const hasPerms = _hasPermsForSetting(user, command); // Case 1: no args - if (args === "") { + if (args === "" || !hasPerms) { const volume = await getVolumeFromTidal(); if (volume) { return `volume is at ${volume.volume} right now`; @@ -70,3 +84,14 @@ async function parseCommand(message: string): Promise { function clamp(value: number): number { return Math.min(Math.max(value, 0), 100); } + +function _hasPermsForSetting(user: ChatUser, command: ICommand): boolean { + if ( + (command.requirements.developer && + Config.developers.includes(user.userId)) || + (command.requirements.mod && user.isMod) + ) { + return true; + } + return false; +}