mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
test
This commit is contained in:
1 parent
b50e0bac83
commit
33ff2632f9
10 files changed
+222
-166
No files matched your search
@@ -1,29 +0,0 @@
|
|||||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
|
||||||
import { EmbedBuilder } from "@fluxerjs/core";
|
|
||||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
|
||||||
|
|
||||||
export const command = new CommandBuilder()
|
|
||||||
.setName("login")
|
|
||||||
.setDescription("Confirm a login of your account on the website", "commands.login")
|
|
||||||
.setCategory("util")
|
|
||||||
.addStringOption(o =>
|
|
||||||
o.setName("id")
|
|
||||||
.setDescription("The id you got from logging in at the dashboard.", "options.login.id")
|
|
||||||
.setRequired(true));
|
|
||||||
|
|
||||||
export async function run(msg, data) {
|
|
||||||
const code = data.get("id").value;
|
|
||||||
|
|
||||||
if (!this.dashboard?.enabled) {
|
|
||||||
const embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(msg, "responses.login.dashboardDisabled"));
|
|
||||||
return msg.reply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
const error = await this.dashboard.confirmLogin(msg.author.id, code);
|
|
||||||
const desc = (error === null)
|
|
||||||
? this.t(msg, "responses.login.success")
|
|
||||||
: this.t(msg, "responses.login.failed", { error });
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc);
|
|
||||||
msg.reply({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
@@ -65,6 +65,12 @@
|
|||||||
"enabled": false,
|
"enabled": false,
|
||||||
"redis": {
|
"redis": {
|
||||||
"url": "redis://localhost:6379"
|
"url": "redis://localhost:6379"
|
||||||
|
},
|
||||||
|
"Comment": "Fluxer OAuth2 credentials for dashboard login. Create an OAuth2 app at https://fluxer.app/developers/applications",
|
||||||
|
"fluxer": {
|
||||||
|
"id": "your fluxer oauth2 application id",
|
||||||
|
"secret": "your fluxer oauth2 client secret",
|
||||||
|
"redirectUri": "https://your-backend.com/auth/fluxer"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dashboardUrl": "The url the dashboard is accessible with.",
|
"dashboardUrl": "The url the dashboard is accessible with.",
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ export class Remix {
|
|||||||
this.locale.load();
|
this.locale.load();
|
||||||
|
|
||||||
this.dashboard = new Dashboard(this, {
|
this.dashboard = new Dashboard(this, {
|
||||||
mysql: config.mysql,
|
|
||||||
...config.dashboard,
|
...config.dashboard,
|
||||||
|
fluxer: config.dashboard?.fluxer,
|
||||||
});
|
});
|
||||||
|
|
||||||
const presenceContents = config.presenceContents ?? [];
|
const presenceContents = config.presenceContents ?? [];
|
||||||
|
|||||||
+11
-33
@@ -516,22 +516,25 @@ export class PlayerManager {
|
|||||||
*/
|
*/
|
||||||
async leave(msg, cid) {
|
async leave(msg, cid) {
|
||||||
if (!cid) {
|
if (!cid) {
|
||||||
const serverId = msg.channel?.server_id ?? msg.channel?.serverId ??
|
const guildId = getMessageGuildId(msg);
|
||||||
msg.message?.server_id ?? msg.message?.serverId;
|
if (guildId) {
|
||||||
if (serverId) {
|
|
||||||
const matchedEntry = [...this.playerMap.entries()].find(([, player]) =>
|
const matchedEntry = [...this.playerMap.entries()].find(([, player]) =>
|
||||||
String(player?._guildId ?? "").replace(/\D/g, "") === String(serverId).replace(/\D/g, "")
|
getPlayerGuildId(player) === cleanId(guildId)
|
||||||
);
|
);
|
||||||
cid = matchedEntry?.[0] ?? null;
|
cid = getPlayerChannelId(matchedEntry?.[1], matchedEntry?.[0]) || matchedEntry?.[0] || null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const player = cid ? this.playerMap.get(cid) : null;
|
const cleanChannelId = cleanId(cid);
|
||||||
|
const player = cleanChannelId
|
||||||
|
? this.playerMap.get(cleanChannelId) ??
|
||||||
|
[...this.playerMap.values()].find((entry) => getPlayerChannelId(entry) === cleanChannelId)
|
||||||
|
: null;
|
||||||
if (!player) return msg.reply(mkEmbed(this._t(msg, "responses._common.notInVoice")));
|
if (!player) return msg.reply(mkEmbed(this._t(msg, "responses._common.notInVoice")));
|
||||||
|
|
||||||
const activeChannelId = String(player._channelId ?? cid).replace(/\D/g, "") || cid;
|
const activeChannelId = getPlayerChannelId(player, cleanChannelId) || cleanChannelId;
|
||||||
this.playerMap.delete(activeChannelId);
|
this.playerMap.delete(activeChannelId);
|
||||||
if (activeChannelId !== cid) this.playerMap.delete(cid);
|
if (activeChannelId !== cleanChannelId) this.playerMap.delete(cleanChannelId);
|
||||||
await msg.reply(mkEmbed(this._t(msg, "responses._common.successfullyLeft")));
|
await msg.reply(mkEmbed(this._t(msg, "responses._common.successfullyLeft")));
|
||||||
await player.leave();
|
await player.leave();
|
||||||
player.destroy();
|
player.destroy();
|
||||||
@@ -652,29 +655,4 @@ export class PlayerManager {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
async leave(msg, cid) {
|
|
||||||
if (!cid) {
|
|
||||||
const guildId = getMessageGuildId(msg);
|
|
||||||
if (guildId) {
|
|
||||||
const matchedEntry = [...this.playerMap.entries()].find(([, player]) =>
|
|
||||||
getPlayerGuildId(player) === cleanId(guildId)
|
|
||||||
);
|
|
||||||
cid = getPlayerChannelId(matchedEntry?.[1], matchedEntry?.[0]) || matchedEntry?.[0] || null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const cleanChannelId = cleanId(cid);
|
|
||||||
const player = cleanChannelId
|
|
||||||
? this.playerMap.get(cleanChannelId) ??
|
|
||||||
[...this.playerMap.values()].find((entry) => getPlayerChannelId(entry) === cleanChannelId)
|
|
||||||
: null;
|
|
||||||
if (!player) return msg.reply(mkEmbed(this._t(msg, "responses._common.notInVoice")));
|
|
||||||
|
|
||||||
const activeChannelId = getPlayerChannelId(player, cleanChannelId) || cleanChannelId;
|
|
||||||
this.playerMap.delete(activeChannelId);
|
|
||||||
if (activeChannelId !== cleanChannelId) this.playerMap.delete(cleanChannelId);
|
|
||||||
await msg.reply(mkEmbed(this._t(msg, "responses._common.successfullyLeft")));
|
|
||||||
await player.leave();
|
|
||||||
player.destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+204
-58
@@ -2,30 +2,58 @@ import { Remix } from "../../index.mjs";
|
|||||||
import { CommandBuilder, CommandHandler, Option } from "../CommandHandler.mjs";
|
import { CommandBuilder, CommandHandler, Option } from "../CommandHandler.mjs";
|
||||||
import Player from "../Player.mjs";
|
import Player from "../Player.mjs";
|
||||||
import { Utils } from "../Utils.mjs";
|
import { Utils } from "../Utils.mjs";
|
||||||
import { DatabaseManager } from "./DatabaseManager.mjs";
|
|
||||||
import { RedisHandler } from "./RedisHandler.mjs";
|
import { RedisHandler } from "./RedisHandler.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fluxer OAuth2 configuration (standard OAuth2 authorization code flow).
|
||||||
|
* @typedef {Object} FluxerOAuth2Config
|
||||||
|
* @property {string} id OAuth2 client ID
|
||||||
|
* @property {string} secret OAuth2 client secret
|
||||||
|
* @property {string} redirectUri Redirect URI registered on the Fluxer app
|
||||||
|
* @property {string} [apiBase] Fluxer API base URL (default: https://api.fluxer.app)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Default Fluxer API endpoints derived from the Fluxer platform docs */
|
||||||
|
const FLUXER_API_DEFAULTS = {
|
||||||
|
apiBase: "https://api.fluxer.app/v1",
|
||||||
|
tokenEndpoint: "https://api.fluxer.app/v1/oauth2/token",
|
||||||
|
authorizeEndpoint: "https://fluxer.app/oauth2/authorize",
|
||||||
|
userinfoEndpoint: "https://api.fluxer.app/v1/users/@me",
|
||||||
|
};
|
||||||
|
|
||||||
export class Dashboard {
|
export class Dashboard {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
expiryTime = 1000 * 60 * 60 * 6;
|
|
||||||
/**
|
/**
|
||||||
* @param {Remix} remix
|
* @param {Remix} remix
|
||||||
* @param {Object} opts
|
* @param {Object} opts
|
||||||
* @param {boolean} opts.enabled Whether the Dashboard is enabled and connections should be attempted
|
* @param {boolean} opts.enabled Whether the Dashboard is enabled and connections should be attempted
|
||||||
* @param {Object} opts.redis Connection options passed directly to redis createClient
|
* @param {Object} opts.redis Connection options passed directly to redis createClient
|
||||||
* @param {Object} opts.mysql mysql2 pool options
|
* @param {FluxerOAuth2Config} [opts.fluxer] Fluxer OAuth2 credentials
|
||||||
*/
|
*/
|
||||||
constructor(remix, opts) {
|
constructor(remix, opts) {
|
||||||
this.enabled = opts?.enabled;
|
this.enabled = opts?.enabled;
|
||||||
this.remix = remix;
|
this.remix = remix;
|
||||||
|
|
||||||
if (!this.enabled) return this;
|
// Fluxer OAuth2 config
|
||||||
|
const fluxer = opts?.fluxer ?? {};
|
||||||
|
this.fluxer = {
|
||||||
|
clientId: fluxer.id,
|
||||||
|
clientSecret: fluxer.secret,
|
||||||
|
redirectUri: fluxer.redirectUri,
|
||||||
|
apiBase: fluxer.apiBase ?? FLUXER_API_DEFAULTS.apiBase,
|
||||||
|
tokenEndpoint: fluxer.tokenEndpoint ?? FLUXER_API_DEFAULTS.tokenEndpoint,
|
||||||
|
authorizeEndpoint: fluxer.authorizeEndpoint ?? FLUXER_API_DEFAULTS.authorizeEndpoint,
|
||||||
|
userinfoEndpoint: fluxer.userinfoEndpoint ?? FLUXER_API_DEFAULTS.userinfoEndpoint,
|
||||||
|
};
|
||||||
|
|
||||||
this.db = new DatabaseManager(opts.mysql);
|
if (!this.enabled) return this;
|
||||||
|
|
||||||
this.redis = new RedisHandler(opts.redis);
|
this.redis = new RedisHandler(opts.redis);
|
||||||
this.redis.setRequestHandler(async (data) => {
|
this.redis.setRequestHandler(async (data) => {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
|
// ── Existing request types ─────────────────────────────────────────────
|
||||||
|
|
||||||
case "fetchPlayers":
|
case "fetchPlayers":
|
||||||
return [...this.remix.players.playerMap.values()].map(p => Dashboard.convertPlayer(p));
|
return [...this.remix.players.playerMap.values()].map(p => Dashboard.convertPlayer(p));
|
||||||
|
|
||||||
@@ -36,7 +64,9 @@ export class Dashboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "sharedServers":
|
case "sharedServers":
|
||||||
return await this.remix.getSharedServers(await this.remix.client.users.fetch(data.key).catch(() => null));
|
return await this.remix.getSharedServers(
|
||||||
|
await this.remix.client.users.fetch(data.key).catch(() => null)
|
||||||
|
);
|
||||||
|
|
||||||
case "server": {
|
case "server": {
|
||||||
try {
|
try {
|
||||||
@@ -53,20 +83,161 @@ export class Dashboard {
|
|||||||
return server;
|
return server;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const id = Utils.uid();
|
const id = Utils.uid();
|
||||||
console.log(e, id);
|
console.log("[Dashboard] Server error:", id, e);
|
||||||
return { error: "An error occurred. Id: " + id };
|
return { error: "An error occurred. Id: " + id };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case "commands":
|
case "commands":
|
||||||
return this.remix.handler.commands.map(c => Dashboard.convertCommand(c, this.remix.handler));
|
return this.remix.handler.commands.map(c =>
|
||||||
|
Dashboard.convertCommand(c, this.remix.handler)
|
||||||
|
);
|
||||||
|
|
||||||
case "function":
|
case "function":
|
||||||
return await this.runFunction(data.params);
|
return await this.runFunction(data.params);
|
||||||
|
|
||||||
|
// ── Fluxer OAuth2 request types ─────────────────────────────────────────
|
||||||
|
|
||||||
|
case "fluxerAuthorizeUrl": {
|
||||||
|
// Returns the full OAuth2 authorize URL for the dashboard frontend to redirect to
|
||||||
|
const scopes = (data.scopes ?? ["identify"]).join(" ");
|
||||||
|
const state = data.state ?? Utils.uid();
|
||||||
|
const url = new URL(this.fluxer.authorizeEndpoint);
|
||||||
|
url.searchParams.set("client_id", this.fluxer.clientId);
|
||||||
|
url.searchParams.set("redirect_uri", this.fluxer.redirectUri);
|
||||||
|
url.searchParams.set("response_type", "code");
|
||||||
|
url.searchParams.set("scope", scopes);
|
||||||
|
url.searchParams.set("state", state);
|
||||||
|
return { url: url.toString(), state };
|
||||||
|
}
|
||||||
|
|
||||||
|
case "fluxerVerify": {
|
||||||
|
// Backend sends a Fluxer access token — bot verifies it and returns user info.
|
||||||
|
// The bot calls the Fluxer API's /users/@me with the access token to
|
||||||
|
// confirm the user's identity, then cross-references with the bot's
|
||||||
|
// internal user cache to confirm the user is known.
|
||||||
|
const accessToken = data.accessToken;
|
||||||
|
if (!accessToken) return { error: "Missing access token" };
|
||||||
|
return await this.verifyFluxerToken(accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "fluxerToken": {
|
||||||
|
// Backend sends an authorization code — bot exchanges it for tokens.
|
||||||
|
// This is useful if the bot wants to perform the code→token exchange
|
||||||
|
// itself rather than relying on the backend to do it.
|
||||||
|
const code = data.code;
|
||||||
|
if (!code) return { error: "Missing authorization code" };
|
||||||
|
return await this.exchangeFluxerCode(code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
// Fluxer OAuth2 Methods
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify a Fluxer OAuth2 access token by calling the Fluxer /users/@me endpoint.
|
||||||
|
* Returns the user object from the Fluxer API, plus a `knownToBot` flag
|
||||||
|
* indicating whether this user is cached in the bot's client.
|
||||||
|
*
|
||||||
|
* @param {string} accessToken
|
||||||
|
* @returns {Promise<Object>} User data or error
|
||||||
|
*/
|
||||||
|
async verifyFluxerToken(accessToken) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(this.fluxer.userinfoEndpoint, {
|
||||||
|
headers: { Authorization: `Bearer ${accessToken}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
const body = await res.text().catch(() => "");
|
||||||
|
console.log("[Dashboard] Fluxer token verification failed:", res.status, body);
|
||||||
|
return { error: "Invalid or expired access token", status: res.status };
|
||||||
|
}
|
||||||
|
|
||||||
|
const fluxerUser = await res.json();
|
||||||
|
if (!fluxerUser?.id) {
|
||||||
|
return { error: "Fluxer API returned no user ID" };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cross-reference with the bot's cached users to check if this user
|
||||||
|
// shares any servers with the bot (i.e. is a potential dashboard user).
|
||||||
|
let botUser = null;
|
||||||
|
try {
|
||||||
|
botUser = await this.remix.client.users.fetch(fluxerUser.id).catch(() => null);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: fluxerUser.id,
|
||||||
|
username: fluxerUser.username,
|
||||||
|
displayName: fluxerUser.displayName ?? fluxerUser.globalName ?? fluxerUser.username,
|
||||||
|
avatar: {
|
||||||
|
url: fluxerUser.avatar
|
||||||
|
? `https://cdn.fluxer.app/avatars/${fluxerUser.id}/${fluxerUser.avatar}.webp`
|
||||||
|
: null,
|
||||||
|
},
|
||||||
|
knownToBot: !!botUser,
|
||||||
|
botUser: botUser ? Dashboard.convertUser(botUser) : null,
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
console.log("[Dashboard] Fluxer verify error:", e.message);
|
||||||
|
return { error: "Failed to verify with Fluxer API: " + e.message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exchange an OAuth2 authorization code for access/refresh tokens.
|
||||||
|
* This calls the Fluxer token endpoint directly.
|
||||||
|
*
|
||||||
|
* @param {string} code Authorization code from the OAuth2 redirect
|
||||||
|
* @returns {Promise<Object>} Token data or error
|
||||||
|
*/
|
||||||
|
async exchangeFluxerCode(code) {
|
||||||
|
try {
|
||||||
|
const body = new URLSearchParams({
|
||||||
|
grant_type: "authorization_code",
|
||||||
|
code,
|
||||||
|
redirect_uri: this.fluxer.redirectUri,
|
||||||
|
client_id: this.fluxer.clientId,
|
||||||
|
client_secret: this.fluxer.clientSecret,
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await fetch(this.fluxer.tokenEndpoint, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||||
|
body,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
const errorBody = await res.text().catch(() => "");
|
||||||
|
console.log("[Dashboard] Fluxer token exchange failed:", res.status, errorBody);
|
||||||
|
return { error: "Token exchange failed", status: res.status };
|
||||||
|
}
|
||||||
|
|
||||||
|
const tokens = await res.json();
|
||||||
|
if (!tokens.access_token) {
|
||||||
|
return { error: "No access_token in response" };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
accessToken: tokens.access_token,
|
||||||
|
tokenType: tokens.token_type ?? "Bearer",
|
||||||
|
expiresIn: tokens.expires_in ?? null,
|
||||||
|
refreshToken: tokens.refresh_token ?? null,
|
||||||
|
scope: tokens.scope ?? null,
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
console.log("[Dashboard] Fluxer token exchange error:", e.message);
|
||||||
|
return { error: "Failed to exchange code: " + e.message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
// Dashboard Function Dispatch
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} params
|
* @param {Object} params
|
||||||
* @param {string} params.func
|
* @param {string} params.func
|
||||||
@@ -74,7 +245,7 @@ export class Dashboard {
|
|||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
async runFunction(params) {
|
async runFunction(params) {
|
||||||
var user;
|
let user;
|
||||||
if (!!params.data.user) {
|
if (!!params.data.user) {
|
||||||
try {
|
try {
|
||||||
user = await this.remix.client.users.fetch(params.data.user);
|
user = await this.remix.client.users.fetch(params.data.user);
|
||||||
@@ -85,7 +256,7 @@ export class Dashboard {
|
|||||||
}
|
}
|
||||||
switch (params.func) {
|
switch (params.func) {
|
||||||
case "join": {
|
case "join": {
|
||||||
var voiceChannel, textChannel;
|
let voiceChannel, textChannel;
|
||||||
try {
|
try {
|
||||||
voiceChannel = await this.remix.client.channels.fetch(params.data.channel);
|
voiceChannel = await this.remix.client.channels.fetch(params.data.channel);
|
||||||
textChannel = await this.remix.client.channels.fetch(params.data.text);
|
textChannel = await this.remix.client.channels.fetch(params.data.text);
|
||||||
@@ -101,39 +272,39 @@ export class Dashboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "pausePlayback": {
|
case "pausePlayback": {
|
||||||
var player = this._getPlayerById(params.data.player);
|
let player = this._getPlayerById(params.data.player);
|
||||||
if (!player) return { error: "Player not found" };
|
if (!player) return { error: "Player not found" };
|
||||||
var msg = player.pause() || "Paused successfully";
|
let msg = player.pause() || "Paused successfully";
|
||||||
return { message: msg };
|
return { message: msg };
|
||||||
}
|
}
|
||||||
|
|
||||||
case "resumePlayback": {
|
case "resumePlayback": {
|
||||||
var player = this._getPlayerById(params.data.player);
|
let player = this._getPlayerById(params.data.player);
|
||||||
if (!player) return { error: "Player not found" };
|
if (!player) return { error: "Player not found" };
|
||||||
var msg = player.resume() || "Resumed successfully";
|
let msg = player.resume() || "Resumed successfully";
|
||||||
return { message: msg };
|
return { message: msg };
|
||||||
}
|
}
|
||||||
|
|
||||||
case "skip": {
|
case "skip": {
|
||||||
var player = this._getPlayerById(params.data.player);
|
let player = this._getPlayerById(params.data.player);
|
||||||
if (!player) return { error: "Player not found" };
|
if (!player) return { error: "Player not found" };
|
||||||
var msg = player.skip() || "Skipped song";
|
let msg = player.skip() || "Skipped song";
|
||||||
return { message: msg };
|
return { message: msg };
|
||||||
}
|
}
|
||||||
|
|
||||||
case "volume": {
|
case "volume": {
|
||||||
var player = this._getPlayerById(params.data.player);
|
let player = this._getPlayerById(params.data.player);
|
||||||
if (!player) return { error: "Player not found" };
|
if (!player) return { error: "Player not found" };
|
||||||
var msg = player.setVolume(params.data.volume);
|
let msg = player.setVolume(params.data.volume);
|
||||||
return { message: msg };
|
return { message: msg };
|
||||||
}
|
}
|
||||||
|
|
||||||
case "addToQueue": {
|
case "addToQueue": {
|
||||||
var player = this._getPlayerById(params.data.player);
|
let player = this._getPlayerById(params.data.player);
|
||||||
if (!player) return { error: "Player not found" };
|
if (!player) return { error: "Player not found" };
|
||||||
if (!user) return { error: "Invalid user" };
|
if (!user) return { error: "Invalid user" };
|
||||||
var type = params.data.type;
|
const type = params.data.type;
|
||||||
var query = params.data.query;
|
const query = params.data.query;
|
||||||
if (type === "radio") {
|
if (type === "radio") {
|
||||||
const radio = this.remix.config.radio.find(e => e.name === query);
|
const radio = this.remix.config.radio.find(e => e.name === query);
|
||||||
if (!radio) return { error: "Invalid radio station" };
|
if (!radio) return { error: "Invalid radio station" };
|
||||||
@@ -157,7 +328,9 @@ export class Dashboard {
|
|||||||
*/
|
*/
|
||||||
_getPlayerById(id) {
|
_getPlayerById(id) {
|
||||||
return this.remix.players.playerMap.get(id)
|
return this.remix.players.playerMap.get(id)
|
||||||
?? [...this.remix.players.playerMap.values()].find(p => p._channelId === id || p._guildId === id)
|
?? [...this.remix.players.playerMap.values()].find(
|
||||||
|
p => p._channelId === id || p._guildId === id
|
||||||
|
)
|
||||||
?? null;
|
?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +354,7 @@ export class Dashboard {
|
|||||||
username: user.username,
|
username: user.username,
|
||||||
displayName: user.displayName ?? user.globalName ?? user.username,
|
displayName: user.displayName ?? user.globalName ?? user.username,
|
||||||
avatar: {
|
avatar: {
|
||||||
url: user.displayAvatarURL() ?? user.defaultAvatarURL
|
url: user.displayAvatarURL() ?? user.defaultAvatarURL,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -204,9 +377,9 @@ export class Dashboard {
|
|||||||
description: vid.description,
|
description: vid.description,
|
||||||
artist: {
|
artist: {
|
||||||
name: vid.author?.name ?? vid.artist,
|
name: vid.author?.name ?? vid.artist,
|
||||||
url: vid.author?.url
|
url: vid.author?.url,
|
||||||
},
|
},
|
||||||
thumbnail: vid.thumbnail
|
thumbnail: vid.thumbnail,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +415,7 @@ export class Dashboard {
|
|||||||
isVoice,
|
isVoice,
|
||||||
voiceParticipants,
|
voiceParticipants,
|
||||||
mature: channel.nsfw ?? false,
|
mature: channel.nsfw ?? false,
|
||||||
serverId: channel.guildId
|
serverId: channel.guildId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,7 +456,7 @@ export class Dashboard {
|
|||||||
volume: (player.preferredVolume ?? 1) * 100,
|
volume: (player.preferredVolume ?? 1) * 100,
|
||||||
queue: {
|
queue: {
|
||||||
current: Dashboard.convertVideo(player.queue.current),
|
current: Dashboard.convertVideo(player.queue.current),
|
||||||
data: (player.queue.data ?? []).map(v => Dashboard.convertVideo(v))
|
data: (player.queue.data ?? []).map(v => Dashboard.convertVideo(v)),
|
||||||
},
|
},
|
||||||
users: (() => {
|
users: (() => {
|
||||||
if (!channel) return [];
|
if (!channel) return [];
|
||||||
@@ -319,7 +492,7 @@ export class Dashboard {
|
|||||||
required: opt.required,
|
required: opt.required,
|
||||||
uid: opt.uid,
|
uid: opt.uid,
|
||||||
defaultValue: opt.defaultValue,
|
defaultValue: opt.defaultValue,
|
||||||
dynamicDefaultPresent: !!opt.dynamicDefault
|
dynamicDefaultPresent: !!opt.dynamicDefault,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +510,7 @@ export class Dashboard {
|
|||||||
category: com.category,
|
category: com.category,
|
||||||
examples: com.examples,
|
examples: com.examples,
|
||||||
usage: commands.helpHandler?.commandUsage?.(com, {
|
usage: commands.helpHandler?.commandUsage?.(com, {
|
||||||
message: { guildId: null }
|
message: { guildId: null },
|
||||||
}) ?? null,
|
}) ?? null,
|
||||||
options: com.options.map(o => Dashboard.convertOption(o)),
|
options: com.options.map(o => Dashboard.convertOption(o)),
|
||||||
};
|
};
|
||||||
@@ -355,7 +528,7 @@ export class Dashboard {
|
|||||||
const serialised = Dashboard.convertPlayer(player);
|
const serialised = Dashboard.convertPlayer(player);
|
||||||
this.redis.send(this.redis.platform + ":players", JSON.stringify({
|
this.redis.send(this.redis.platform + ":players", JSON.stringify({
|
||||||
...details,
|
...details,
|
||||||
player: serialised
|
player: serialised,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +553,7 @@ export class Dashboard {
|
|||||||
const channel = this.redis.platform + ":users";
|
const channel = this.redis.platform + ":users";
|
||||||
this.redis.send(channel, JSON.stringify({
|
this.redis.send(channel, JSON.stringify({
|
||||||
...details,
|
...details,
|
||||||
user: Dashboard.convertUser(user)
|
user: Dashboard.convertUser(user),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,31 +562,4 @@ export class Dashboard {
|
|||||||
const channel = this.redis.platform + ":user_" + user.id;
|
const channel = this.redis.platform + ":user_" + user.id;
|
||||||
this.redis.send(channel, JSON.stringify(details));
|
this.redis.send(channel, JSON.stringify(details));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify a dashboard login code for a user
|
|
||||||
* @param {string} user User ID
|
|
||||||
* @param {string} code Plaintext code to check
|
|
||||||
* @returns {Promise<string|null>} null on success, error string on failure
|
|
||||||
*/
|
|
||||||
async confirmLogin(user, code) {
|
|
||||||
if (!this.enabled) return "Dashboard not enabled.";
|
|
||||||
var res;
|
|
||||||
try {
|
|
||||||
res = await this.db.execute("SELECT * FROM login_codes WHERE user=?", [user]);
|
|
||||||
} catch (e) {
|
|
||||||
const id = Utils.uid();
|
|
||||||
console.log("[Dashboard] MySQL error, id: ", id, e);
|
|
||||||
return "An error occurred, please contact an administrator. Error id: `" + id + "`";
|
|
||||||
}
|
|
||||||
if (res.length === 0) return "If this is a valid code, it was not created for your account.";
|
|
||||||
for (let i = 0; i < res.length; i++) {
|
|
||||||
if ((await this.db.compareHash(code, res[i].token))) {
|
|
||||||
if (Date.now() - this.expiryTime > (new Date(res[i].createdAt)).getTime()) return "Login token expired";
|
|
||||||
await this.db.execute("UPDATE login_codes SET verified=true WHERE id=?", [res[i].id]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "Invalid code.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,6 @@
|
|||||||
"join": "اجعل البوت ينضم إلى قناتك الصوتية، أو حدد قناة معينة.",
|
"join": "اجعل البوت ينضم إلى قناتك الصوتية، أو حدد قناة معينة.",
|
||||||
"leave": "اجعل البوت يغادر قناتك الصوتية الحالية.",
|
"leave": "اجعل البوت يغادر قناتك الصوتية الحالية.",
|
||||||
"list": "اعرض قائمة الأغاني في قائمة انتظار قناتك الصوتية الحالية.",
|
"list": "اعرض قائمة الأغاني في قائمة انتظار قناتك الصوتية الحالية.",
|
||||||
"login": "تأكيد تسجيل دخول حسابك على الموقع.",
|
|
||||||
"loop": "تفعيل/تعطيل تكرار قائمة الانتظار/الأغنية.",
|
"loop": "تفعيل/تعطيل تكرار قائمة الانتظار/الأغنية.",
|
||||||
"lyrics": "عرض كلمات الأغنية المتزامنة من NodeLink.",
|
"lyrics": "عرض كلمات الأغنية المتزامنة من NodeLink.",
|
||||||
"np": "اطلب اسم ورابط الأغنية التي تعمل حالياً.",
|
"np": "اطلب اسم ورابط الأغنية التي تعمل حالياً.",
|
||||||
@@ -74,9 +73,6 @@
|
|||||||
"join": {
|
"join": {
|
||||||
"channel": "إشارة أو معرف أو اسم قناة صوتية للانضمام. الافتراضي: قناتك الحالية."
|
"channel": "إشارة أو معرف أو اسم قناة صوتية للانضمام. الافتراضي: قناتك الحالية."
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"id": "المعرف الذي حصلت عليه من تسجيل الدخول في لوحة التحكم."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"type": "يحدد ما يجب تبديل تكراره."
|
"type": "يحدد ما يجب تبديل تكراره."
|
||||||
},
|
},
|
||||||
@@ -255,11 +251,6 @@
|
|||||||
"upNext": " ▶",
|
"upNext": " ▶",
|
||||||
"queueTitle": "🎧 قائمة الانتظار"
|
"queueTitle": "🎧 قائمة الانتظار"
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"dashboardDisabled": "❌ لوحة التحكم غير مفعّلة في هذا البوت.",
|
|
||||||
"success": "✅ نجح تسجيل الدخول! يمكنك الآن المتابعة إلى صفحة الويب.",
|
|
||||||
"failed": "❌ فشل تسجيل الدخول! السبب: `{{error}}`. إذا كان هذا خطأ والمشكلة مستمرة، يرجى التواصل مع عضو فريق الدعم من خلال الخادم في وصفي."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"invalidChoice": "'{{choice}}' غير صالح. استخدم `song` أو `queue`",
|
"invalidChoice": "'{{choice}}' غير صالح. استخدم `song` أو `queue`",
|
||||||
"songActivated": "🔂 تم تفعيل تكرار الأغنية",
|
"songActivated": "🔂 تم تفعيل تكرار الأغنية",
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
"join": "بۆتەکە بکە بچێتە کەناڵی دەنگی خۆت، یان یەکێک دیاریبکە.",
|
"join": "بۆتەکە بکە بچێتە کەناڵی دەنگی خۆت، یان یەکێک دیاریبکە.",
|
||||||
"leave": "بۆتەکە بکە کەناڵی دەنگی ئێستات بەجێبهێڵێت.",
|
"leave": "بۆتەکە بکە کەناڵی دەنگی ئێستات بەجێبهێڵێت.",
|
||||||
"list": "لیستی گۆرانییەکانی ڕیزبەندیی کەناڵی دەنگی ئێستات نیشان بدە.",
|
"list": "لیستی گۆرانییەکانی ڕیزبەندیی کەناڵی دەنگی ئێستات نیشان بدە.",
|
||||||
"login": "پشتڕاستکردنەوەی چوونەژوورەوەی ئەکاونتەکەت لە ماڵپەڕەکە.",
|
|
||||||
"loop": "کردنەوە/داخستنی دووبارەکردنەوەی ڕیزبەندی/گۆرانی.",
|
"loop": "کردنەوە/داخستنی دووبارەکردنەوەی ڕیزبەندی/گۆرانی.",
|
||||||
"lyrics": "دەقی گۆرانیی هاوئاهەنگ لە NodeLink نیشان بدە.",
|
"lyrics": "دەقی گۆرانیی هاوئاهەنگ لە NodeLink نیشان بدە.",
|
||||||
"np": "ناو و بەستەری گۆرانیی ئێستا داوا بکە.",
|
"np": "ناو و بەستەری گۆرانیی ئێستا داوا بکە.",
|
||||||
@@ -74,9 +73,6 @@
|
|||||||
"join": {
|
"join": {
|
||||||
"channel": "مەنتشن، ID، یان ناوی کەناڵێکی دەنگی بۆ پەیوەستبوون. بنەڕەتی: کەناڵی ئێستای تۆ."
|
"channel": "مەنتشن، ID، یان ناوی کەناڵێکی دەنگی بۆ پەیوەستبوون. بنەڕەتی: کەناڵی ئێستای تۆ."
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"id": "IDیەکەی لە کاتی چوونەژوورەوە لە داشبۆردەکە وەرگرتووە."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"type": "دیاری دەکات کام لووپ بکرێتەوە."
|
"type": "دیاری دەکات کام لووپ بکرێتەوە."
|
||||||
},
|
},
|
||||||
@@ -255,11 +251,6 @@
|
|||||||
"upNext": " ▶",
|
"upNext": " ▶",
|
||||||
"queueTitle": "🎧 ڕیزبەندی"
|
"queueTitle": "🎧 ڕیزبەندی"
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"dashboardDisabled": "❌ داشبۆردەکە لەم بۆتەکەدا چالاک نەکراوە.",
|
|
||||||
"success": "✅ چوونەژوورەوە سەرکەوتوو بوو! دەتوانیت بەردەوامبیت بۆ ماڵپەڕەکە.",
|
|
||||||
"failed": "❌ چوونەژوورەوە سەرکەوتوو نەبوو! هۆکار: `{{error}}`. ئەگەر ئەمە هەڵەیەکە و کێشەکە بەردەوامە، تکایە پەیوەندی بە ئەندامێکی تیمەوە بکە لە ڕێگەی سێرڤەرەکە لە وەسفەکەمدا."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"invalidChoice": "'{{choice}}' دروست نییە. `song` یان `queue` بەکاربهێنە",
|
"invalidChoice": "'{{choice}}' دروست نییە. `song` یان `queue` بەکاربهێنە",
|
||||||
"songActivated": "🔂 لووپی گۆرانی چالاک کرا",
|
"songActivated": "🔂 لووپی گۆرانی چالاک کرا",
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
"join": "Lass den Bot deinem Sprachkanal beitreten oder gib einen bestimmten an.",
|
"join": "Lass den Bot deinem Sprachkanal beitreten oder gib einen bestimmten an.",
|
||||||
"leave": "Lass den Bot deinen aktuellen Sprachkanal verlassen.",
|
"leave": "Lass den Bot deinen aktuellen Sprachkanal verlassen.",
|
||||||
"list": "Liste die Songs in der Warteschlange deines aktuellen Sprachkanals auf.",
|
"list": "Liste die Songs in der Warteschlange deines aktuellen Sprachkanals auf.",
|
||||||
"login": "Bestätige die Anmeldung deines Kontos auf der Website.",
|
|
||||||
"loop": "Aktiviere/Deaktiviere die Schleife deiner Warteschlange/des Songs.",
|
"loop": "Aktiviere/Deaktiviere die Schleife deiner Warteschlange/des Songs.",
|
||||||
"lyrics": "Zeige synchronisierte Songtexte von NodeLink an.",
|
"lyrics": "Zeige synchronisierte Songtexte von NodeLink an.",
|
||||||
"np": "Frage den Namen und die URL des aktuell spielenden Songs ab.",
|
"np": "Frage den Namen und die URL des aktuell spielenden Songs ab.",
|
||||||
@@ -74,9 +73,6 @@
|
|||||||
"join": {
|
"join": {
|
||||||
"channel": "Eine Sprachkanal-Erwähnung, ID oder Name zum Beitreten. Standard: dein aktueller Kanal."
|
"channel": "Eine Sprachkanal-Erwähnung, ID oder Name zum Beitreten. Standard: dein aktueller Kanal."
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"id": "Die ID, die du beim Login im Dashboard erhalten hast."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"type": "Bestimmt, welche Schleife umgeschaltet werden soll."
|
"type": "Bestimmt, welche Schleife umgeschaltet werden soll."
|
||||||
},
|
},
|
||||||
@@ -255,11 +251,6 @@
|
|||||||
"upNext": " ▶",
|
"upNext": " ▶",
|
||||||
"queueTitle": "🎧 Warteschlange"
|
"queueTitle": "🎧 Warteschlange"
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"dashboardDisabled": "❌ Das Dashboard ist auf diesem Bot nicht aktiviert.",
|
|
||||||
"success": "✅ Login erfolgreich! Du kannst jetzt auf der Webseite fortfahren.",
|
|
||||||
"failed": "❌ Login fehlgeschlagen! Grund: `{{error}}`. Wenn dies ein Fehler ist und das Problem besteht, wende dich an ein Teammitglied über den Server in meiner Beschreibung."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"invalidChoice": "'{{choice}}' ist ungültig. Nutze `song` oder `queue`",
|
"invalidChoice": "'{{choice}}' ist ungültig. Nutze `song` oder `queue`",
|
||||||
"songActivated": "🔂 Song-Schleife aktiviert",
|
"songActivated": "🔂 Song-Schleife aktiviert",
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
"join": "Make the bot join your voice channel, or specify one.",
|
"join": "Make the bot join your voice channel, or specify one.",
|
||||||
"leave": "Make the bot leave your current voice channel.",
|
"leave": "Make the bot leave your current voice channel.",
|
||||||
"list": "List the songs in the queue of your current voice channel.",
|
"list": "List the songs in the queue of your current voice channel.",
|
||||||
"login": "Confirm a login of your account on the website.",
|
|
||||||
"loop": "Toggle the looping of your queue/song.",
|
"loop": "Toggle the looping of your queue/song.",
|
||||||
"lyrics": "Display synced lyrics from NodeLink.",
|
"lyrics": "Display synced lyrics from NodeLink.",
|
||||||
"np": "Request the name and url of the currently playing song.",
|
"np": "Request the name and url of the currently playing song.",
|
||||||
@@ -74,9 +73,6 @@
|
|||||||
"join": {
|
"join": {
|
||||||
"channel": "A voice channel mention, ID, or name to join. Defaults to your current channel."
|
"channel": "A voice channel mention, ID, or name to join. Defaults to your current channel."
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"id": "The id you got from logging in at the dashboard."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"type": "Specifies what loop should be toggled."
|
"type": "Specifies what loop should be toggled."
|
||||||
},
|
},
|
||||||
@@ -255,11 +251,6 @@
|
|||||||
"upNext": " ▶",
|
"upNext": " ▶",
|
||||||
"queueTitle": "🎧 Queue"
|
"queueTitle": "🎧 Queue"
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"dashboardDisabled": "❌ The dashboard is not enabled on this bot.",
|
|
||||||
"success": "✅ Login succeeded! You can continue to the webpage now.",
|
|
||||||
"failed": "❌ Login failed! Reason: `{{error}}`. If this is an error and the issue persists, please contact a team member through the server in my description."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"invalidChoice": "'{{choice}}' is not valid. Use `song` or `queue`",
|
"invalidChoice": "'{{choice}}' is not valid. Use `song` or `queue`",
|
||||||
"songActivated": "🔂 Song loop activated",
|
"songActivated": "🔂 Song loop activated",
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
"join": "Faça o bot entrar no seu canal de voz ou especifique um.",
|
"join": "Faça o bot entrar no seu canal de voz ou especifique um.",
|
||||||
"leave": "Faça o bot sair do seu canal de voz atual.",
|
"leave": "Faça o bot sair do seu canal de voz atual.",
|
||||||
"list": "Liste as músicas na fila do seu canal de voz atual.",
|
"list": "Liste as músicas na fila do seu canal de voz atual.",
|
||||||
"login": "Confirme o login da sua conta no site.",
|
|
||||||
"loop": "Ative/desative o loop da fila/música.",
|
"loop": "Ative/desative o loop da fila/música.",
|
||||||
"lyrics": "Exiba letras sincronizadas do NodeLink.",
|
"lyrics": "Exiba letras sincronizadas do NodeLink.",
|
||||||
"np": "Solicite o nome e a URL da música que está tocando atualmente.",
|
"np": "Solicite o nome e a URL da música que está tocando atualmente.",
|
||||||
@@ -74,9 +73,6 @@
|
|||||||
"join": {
|
"join": {
|
||||||
"channel": "Menção, ID ou nome de um canal de voz para entrar. Padrão: seu canal atual."
|
"channel": "Menção, ID ou nome de um canal de voz para entrar. Padrão: seu canal atual."
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"id": "O ID que você obteve ao fazer login no painel."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"type": "Especifica qual loop deve ser alternado."
|
"type": "Especifica qual loop deve ser alternado."
|
||||||
},
|
},
|
||||||
@@ -255,11 +251,6 @@
|
|||||||
"upNext": " ▶",
|
"upNext": " ▶",
|
||||||
"queueTitle": "🎧 Fila"
|
"queueTitle": "🎧 Fila"
|
||||||
},
|
},
|
||||||
"login": {
|
|
||||||
"dashboardDisabled": "❌ O painel não está habilitado neste bot.",
|
|
||||||
"success": "✅ Login bem-sucedido! Você pode continuar para a página web agora.",
|
|
||||||
"failed": "❌ Falha no login! Motivo: `{{error}}`. Se isso for um erro e o problema persistir, entre em contato com um membro da equipe através do servidor na minha descrição."
|
|
||||||
},
|
|
||||||
"loop": {
|
"loop": {
|
||||||
"invalidChoice": "'{{choice}}' é inválido. Use `song` ou `queue`",
|
"invalidChoice": "'{{choice}}' é inválido. Use `song` ou `queue`",
|
||||||
"songActivated": "🔂 Loop de música ativado",
|
"songActivated": "🔂 Loop de música ativado",
|
||||||
|
|||||||
Reference in new issue
Block a user