tested & working basic bot

This commit is contained in:
Darius
2025-09-27 16:12:50 +02:00
parent 44f3f7af0b
commit 10eee0c0fd
16 changed files with 161 additions and 127 deletions

View File

@@ -1,3 +1,4 @@
import type { ChatUser } from "@twurple/chat";
import { chatClient } from "../core/chat-client.ts";
import type { ICommand, ICommandRequirements } from "./interface.ts";
@@ -9,6 +10,7 @@ export abstract class BaseCommand implements ICommand {
abstract name: string;
abstract cooldown: number;
abstract enabled: boolean;
abstract checkPerms(user: ChatUser): boolean;
abstract triggered(...args: unknown[]): Promise<unknown>;
abstract requirements: ICommandRequirements;
}

View File

@@ -1,7 +1,9 @@
import { Collection } from "@discordjs/collection";
import { SongCommand } from "./command-song.ts";
import { SongCommand } from "./impl/song.ts";
import type { ICommand } from "./interface.ts";
export const commands = new Collection<string, ICommand>();
commands.set(SongCommand.name, new SongCommand());
const songCommand = new SongCommand();
commands.set(songCommand.name, songCommand);

View File

@@ -1,55 +0,0 @@
import type { ChatMessage } from "@twurple/chat";
import axios from "axios";
import { Config } from "../config/config.ts";
import { logError, logSuccess } from "../util/logger.ts";
import { BaseCommand } from "./base-command.ts";
import type { ICommandRequirements } from "./interface.ts";
interface ISong {
title: string;
artists: string;
album: string;
playingFrom: string;
status: "playing" | "paused";
url: string;
current: string;
duration: string;
}
export class SongCommand extends BaseCommand {
name = "song";
cooldown = 0;
enabled = true;
requirements: ICommandRequirements = {
developer: true,
mod: false,
};
triggered = async (
channel: string,
user: string,
_text: string,
_msg: ChatMessage,
) => {
logSuccess(`${channel} ${user} song command triggered`);
logSuccess(await getSongFromTidal());
// client.say(channel, "testing");
};
}
async function getSongFromTidal() {
axios.get<ISong>(`${Config.tidal.host}:${Config.tidal.port}/current`).then(
(response) => {
const currentSong = response.data;
const status = currentSong.status === "playing" ? "▶️" : "⏸️";
return `listening to ${currentSong.title} by ${currentSong.artists}. ${status} ${currentSong.current}/${currentSong.duration}. link: ${currentSong.url}`;
},
() => {
logError("error getting song from tidal");
return "";
},
);
}

78
src/commands/impl/song.ts Normal file
View File

@@ -0,0 +1,78 @@
import type { ChatMessage, ChatUser } from "@twurple/chat";
import axios from "axios";
import { Config } from "../../config/config.ts";
import { chatClient } from "../../core/chat-client.ts";
import { logSuccess, logWarning } from "../../util/logger.ts";
import { BaseCommand } from "../base-command.ts";
import type { ICommandRequirements } from "../interface.ts";
interface ISong {
title: string;
artists: string;
album: string;
playingFrom: string;
status: "playing" | "paused";
url: string;
current: string;
duration: string;
}
export class SongCommand extends BaseCommand {
name = "song";
cooldown = 0;
enabled = true;
requirements: ICommandRequirements = {
developer: true,
mod: false,
};
triggered = async (
channel: string,
user: string,
_text: string,
msg: ChatMessage,
) => {
logSuccess(`${channel} ${user} song command triggered`);
const song = await getSongFromTidal();
if (song) {
logSuccess(song);
chatClient.say(channel, song, { replyTo: msg });
} else {
chatClient.say(channel, "tidal not running..", { replyTo: msg });
}
};
checkPerms = (user: ChatUser): boolean => {
if (!this.enabled) {
return false;
}
if (
(this.requirements.developer &&
!Config.developers.includes(user.userId)) ||
(this.requirements.mod && !user.isMod)
) {
return false;
}
return true;
};
}
async function getSongFromTidal(): Promise<string> {
try {
const response = await axios.get<ISong>(
`${Config.tidal.host}:${Config.tidal.port}/current`,
);
const currentSong = response.data;
const status = currentSong.status === "playing" ? "▶️" : "⏸️";
return `listening to ${currentSong.title} by ${currentSong.artists}. ${status} ${currentSong.current}/${currentSong.duration}. link: ${currentSong.url}`;
} catch {
logWarning("error getting song from tidal");
return "";
}
}

View File

@@ -1,7 +1,10 @@
import type { ChatUser } from "@twurple/chat";
export interface ICommand {
name: string;
cooldown: number;
enabled: boolean;
checkPerms(user: ChatUser): boolean;
triggered(...args: unknown[]): Promise<unknown>;
requirements: ICommandRequirements;
}