fix some syntax and stuff
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { chatClient } from "../core/chat-client.ts";
|
||||
import type { ICommand, ICommandRequirements } from "./interface";
|
||||
import type { ICommand, ICommandRequirements } from "./interface.ts";
|
||||
|
||||
export abstract class BaseCommand implements ICommand {
|
||||
protected get chatClient() {
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
import type { ChatMessage } from "@twurple/chat";
|
||||
import { logSuccess } from "../util/logger.ts";
|
||||
import axios from "axios";
|
||||
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;
|
||||
@@ -19,7 +31,24 @@ export class SongCommand extends BaseCommand {
|
||||
_text: string,
|
||||
_msg: ChatMessage,
|
||||
) => {
|
||||
logSuccess(`${channel} song command triggered`);
|
||||
logSuccess(`${channel} ${user} song command triggered`);
|
||||
logSuccess(await getSongFromTidal());
|
||||
// client.say(channel, "testing");
|
||||
};
|
||||
}
|
||||
|
||||
async function getSongFromTidal() {
|
||||
axios.get<ISong>("http://localhost:47836/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 "";
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ export const Config = {
|
||||
client_secret: process.env.CLIENT_SECRET || "",
|
||||
channels: process.env.CHANNELS?.split(",") || [],
|
||||
developers: process.env.DEVELOPERS?.split(",") || [],
|
||||
};
|
||||
} as const;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ApiClient } from "@twurple/api";
|
||||
import { AppTokenAuthProvider } from "@twurple/auth";
|
||||
import { Config } from "../config/config";
|
||||
import { Config } from "../config/config.ts";
|
||||
|
||||
const authProvider = new AppTokenAuthProvider(
|
||||
Config.client_id,
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { promises as fs } from "node:fs";
|
||||
import * as readline from "node:readline";
|
||||
import type { AccessToken } from "@twurple/auth";
|
||||
|
||||
export class TokenManager {
|
||||
private readonly tokenFilePath: string;
|
||||
|
||||
constructor(userId: string) {
|
||||
this.tokenFilePath = `./tokens/${userId}.json`;
|
||||
this.tokenFilePath = `../db/token.${userId}.json`;
|
||||
}
|
||||
|
||||
async getToken(): Promise<AccessToken | null> {
|
||||
|
||||
16
src/setup.ts
16
src/setup.ts
@@ -1,12 +1,14 @@
|
||||
import { exchangeCode } from "@twurple/auth";
|
||||
import { Config } from "./config/config";
|
||||
import { TokenManager } from "./core/token-manager";
|
||||
import { TwitchAuth } from "./util/auth";
|
||||
import { getUserId } from "./util/general";
|
||||
import { logError, logInfo, logWarning } from "./util/logger";
|
||||
import { Config } from "./config/config.ts";
|
||||
import { TokenManager } from "./core/token-manager.ts";
|
||||
import { TwitchAuth } from "./util/auth.ts";
|
||||
import { getUserId, promptForInput } from "./util/general.ts";
|
||||
import { logError, logInfo, logWarning } from "./util/logger.ts";
|
||||
|
||||
const botname = "";
|
||||
const developers = [""];
|
||||
const botname = await promptForInput("enter bot username: ");
|
||||
const developers = (
|
||||
await promptForInput("enter developer usernames (,separated): ")
|
||||
).split(",");
|
||||
const scopes = ["chat:read", "chat:edit", "channel:moderate"];
|
||||
const port = 3000;
|
||||
const redirectUri = `http://localhost:${port}`;
|
||||
|
||||
@@ -4,14 +4,12 @@ import {
|
||||
type ServerResponse,
|
||||
} from "node:http";
|
||||
import { URL } from "node:url";
|
||||
import { Config } from "../config/config.js";
|
||||
import { Config } from "../config/config.ts";
|
||||
|
||||
export class TwitchAuth {
|
||||
private readonly clientId: string;
|
||||
private readonly redirectUri: string;
|
||||
|
||||
constructor(redirectUri: string = "http://localhost:3000") {
|
||||
this.clientId = Config.client_id;
|
||||
this.redirectUri = redirectUri;
|
||||
}
|
||||
|
||||
@@ -19,7 +17,7 @@ export class TwitchAuth {
|
||||
const baseUrl = "https://id.twitch.tv/oauth2/authorize";
|
||||
const params = new URLSearchParams({
|
||||
response_type: "code",
|
||||
client_id: this.clientId,
|
||||
client_id: Config.client_id,
|
||||
redirect_uri: this.redirectUri,
|
||||
scope: scopes.join(" "),
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { apiClient } from "../core/api-client";
|
||||
import { logError, logInfo } from "./logger";
|
||||
import * as readline from "node:readline";
|
||||
import { apiClient } from "../core/api-client.ts";
|
||||
import { logError, logInfo } from "./logger.ts";
|
||||
|
||||
export async function getUserId(username: string): Promise<string | null> {
|
||||
const user = await apiClient.users.getUserByName(username);
|
||||
@@ -10,3 +11,17 @@ export async function getUserId(username: string): Promise<string | null> {
|
||||
logError(`no user with name ${username} found`);
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function promptForInput(prompt: string): Promise<string> {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
return new Promise<string>((resolve) => {
|
||||
rl.question(prompt, (answer) => {
|
||||
rl.close();
|
||||
resolve(answer.trim());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user