volume permissions

This commit is contained in:
Darius
2025-10-06 01:41:59 +02:00
parent b7287f19f3
commit 7f20247a47

View File

@@ -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 { getVolumeFromTidal, setVolumeToTidal } from "../../util/api-tidal.ts";
import { logSuccess } from "../../util/logger.ts"; import { logSuccess } from "../../util/logger.ts";
import { BaseCommand } from "../base-command.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 { export class VolumeCommand extends BaseCommand {
name = "vol"; name = "vol";
@@ -22,20 +23,33 @@ export class VolumeCommand extends BaseCommand {
) => { ) => {
logSuccess(`${channel} ${user} volume command triggered`); logSuccess(`${channel} ${user} volume command triggered`);
const volumeText = await parseCommand(text); const volumeText = await parseCommand(text, msg.userInfo, this);
if (volumeText) { if (volumeText) {
this.chatClient.say(channel, volumeText, { replyTo: msg }); this.chatClient.say(channel, volumeText, { replyTo: msg });
} else { } else {
this.chatClient.say(channel, "tidal not running..", { replyTo: msg }); 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<string | null> { async function parseCommand(
message: string,
user: ChatUser,
command: ICommand,
): Promise<string | null> {
const args = message.slice(4).trim(); // Remove '!volume' const args = message.slice(4).trim(); // Remove '!volume'
const hasPerms = _hasPermsForSetting(user, command);
// Case 1: no args // Case 1: no args
if (args === "") { if (args === "" || !hasPerms) {
const volume = await getVolumeFromTidal(); const volume = await getVolumeFromTidal();
if (volume) { if (volume) {
return `volume is at ${volume.volume} right now`; return `volume is at ${volume.volume} right now`;
@@ -70,3 +84,14 @@ async function parseCommand(message: string): Promise<string | null> {
function clamp(value: number): number { function clamp(value: number): number {
return Math.min(Math.max(value, 0), 100); 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;
}