Switch default engine to deezer
This commit is contained in:
parent
21db1896f9
commit
1d865a49b8
14 changed files with 2051 additions and 85 deletions
8
.envrc
8
.envrc
|
|
@ -1,7 +1,3 @@
|
|||
# Automatically sets up your devbox environment whenever you cd into this
|
||||
# directory via our direnv integration:
|
||||
source_url "https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc" "sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0="
|
||||
|
||||
eval "$(devbox generate direnv --print-envrc)"
|
||||
|
||||
# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/
|
||||
# for more details
|
||||
use devenv
|
||||
10
.gitignore
vendored
10
.gitignore
vendored
|
|
@ -130,4 +130,12 @@ dist
|
|||
.pnp.*
|
||||
lavalink/
|
||||
Lavalink.jar
|
||||
settings.json
|
||||
settings.json# Devenv
|
||||
.devenv*
|
||||
devenv.local.nix
|
||||
|
||||
# direnv
|
||||
.direnv
|
||||
|
||||
# pre-commit
|
||||
.pre-commit-config.yaml
|
||||
|
|
|
|||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"deno.enable": true
|
||||
}
|
||||
8
deno.json
Normal file
8
deno.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"tasks": {
|
||||
"dev": "deno run --watch main.ts"
|
||||
},
|
||||
"imports": {
|
||||
"@std/assert": "jsr:@std/assert@1"
|
||||
}
|
||||
}
|
||||
15
devbox.json
15
devbox.json
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"packages": [
|
||||
"nodejs@18",
|
||||
"jdk@17.0.10"
|
||||
],
|
||||
"shell": {
|
||||
"init_hook": [
|
||||
"npm install",
|
||||
"npm run build"
|
||||
],
|
||||
"scripts": {
|
||||
"run_test": "npm run start"
|
||||
}
|
||||
}
|
||||
}
|
||||
39
devbox.lock
39
devbox.lock
|
|
@ -1,39 +0,0 @@
|
|||
{
|
||||
"lockfile_version": "1",
|
||||
"packages": {
|
||||
"jdk@17.0.10": {
|
||||
"last_modified": "2024-02-24T23:06:34Z",
|
||||
"resolved": "github:NixOS/nixpkgs/9a9dae8f6319600fa9aebde37f340975cab4b8c0#jdk17",
|
||||
"source": "devbox-search",
|
||||
"version": "17.0.10",
|
||||
"systems": {
|
||||
"aarch64-darwin": {
|
||||
"store_path": "/nix/store/4p4k1w2q7fz1hwc55wjk44bza0vhh71h-zulu-ca-jdk-17.0.10"
|
||||
},
|
||||
"x86_64-darwin": {
|
||||
"store_path": "/nix/store/kfmkczf4h268yax8bg5nlyapbms6zcav-zulu-ca-jdk-17.0.10"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nodejs@18": {
|
||||
"last_modified": "2024-02-24T23:06:34Z",
|
||||
"resolved": "github:NixOS/nixpkgs/9a9dae8f6319600fa9aebde37f340975cab4b8c0#nodejs_18",
|
||||
"source": "devbox-search",
|
||||
"version": "18.19.1",
|
||||
"systems": {
|
||||
"aarch64-darwin": {
|
||||
"store_path": "/nix/store/fxly5x870ssyw5rbvdi58jbhc4j03mzk-nodejs-18.19.1"
|
||||
},
|
||||
"aarch64-linux": {
|
||||
"store_path": "/nix/store/6iirvvbd99b7dfwk3z8phry2yliwvm99-nodejs-18.19.1"
|
||||
},
|
||||
"x86_64-darwin": {
|
||||
"store_path": "/nix/store/rzsav2ndbzah0vkmyqpnhcwxp4n0zdm6-nodejs-18.19.1"
|
||||
},
|
||||
"x86_64-linux": {
|
||||
"store_path": "/nix/store/c8phnfr1s43123qm3fmyiq5n1hs5csdv-nodejs-18.19.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
116
devenv.lock
Normal file
116
devenv.lock
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
{
|
||||
"nodes": {
|
||||
"devenv": {
|
||||
"locked": {
|
||||
"dir": "src/modules",
|
||||
"lastModified": 1729087493,
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"rev": "d612b77ff73912cd82e58256ab5e84d5904abef7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"dir": "src/modules",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1696426674,
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gitignore": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"pre-commit-hooks",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1709087332,
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1728888510,
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-stable": {
|
||||
"locked": {
|
||||
"lastModified": 1728909085,
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c0b1da36f7c34a7146501f684e9ebdf15d2bebf8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-24.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"pre-commit-hooks": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"gitignore": "gitignore",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"nixpkgs-stable": "nixpkgs-stable"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1729104314,
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"rev": "3c3e88f0f544d6bb54329832616af7eb971b6be6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"devenv": "devenv",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pre-commit-hooks": "pre-commit-hooks"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
51
devenv.nix
Normal file
51
devenv.nix
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
inputs,
|
||||
...
|
||||
}: {
|
||||
# https://devenv.sh/basics/
|
||||
env.GREET = "devenv";
|
||||
|
||||
# https://devenv.sh/packages/
|
||||
packages = [pkgs.git];
|
||||
|
||||
# https://devenv.sh/languages/
|
||||
# languages.rust.enable = true;
|
||||
languages.deno = {
|
||||
enable = true;
|
||||
};
|
||||
# https://devenv.sh/processes/
|
||||
# processes.cargo-watch.exec = "cargo-watch";
|
||||
|
||||
# https://devenv.sh/services/
|
||||
# services.postgres.enable = true;
|
||||
|
||||
# https://devenv.sh/scripts/
|
||||
scripts.hello.exec = ''
|
||||
echo hello from $GREET
|
||||
'';
|
||||
|
||||
enterShell = ''
|
||||
hello
|
||||
git --version
|
||||
'';
|
||||
|
||||
# https://devenv.sh/tasks/
|
||||
# tasks = {
|
||||
# "myproj:setup".exec = "mytool build";
|
||||
# "devenv:enterShell".after = [ "myproj:setup" ];
|
||||
# };
|
||||
|
||||
# https://devenv.sh/tests/
|
||||
enterTest = ''
|
||||
echo "Running tests"
|
||||
git --version | grep --color=auto "${pkgs.git.version}"
|
||||
'';
|
||||
|
||||
# https://devenv.sh/pre-commit-hooks/
|
||||
# pre-commit.hooks.shellcheck.enable = true;
|
||||
|
||||
# See full reference at https://devenv.sh/reference/options/
|
||||
}
|
||||
14
devenv.yaml
Normal file
14
devenv.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
|
||||
inputs:
|
||||
nixpkgs:
|
||||
url: github:NixOS/nixpkgs/nixos-unstable
|
||||
# If you're using non-OSS software, you can set allowUnfree to true.
|
||||
# allowUnfree: true
|
||||
|
||||
# If you're willing to use a package that's vulnerable
|
||||
# permittedInsecurePackages:
|
||||
# - "openssl-1.1.1w"
|
||||
|
||||
# If you have more than one devenv you can merge them
|
||||
#imports:
|
||||
# - ./backend
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "node dist/index.js",
|
||||
"watch": "tsc watch",
|
||||
"watch": "tsc watch src/index.ts",
|
||||
"dev": "nodemon src/index.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
"discord.js": "^14.14.1",
|
||||
"dotenv": "^16.4.5",
|
||||
"kazagumo": "^3.0.1",
|
||||
"kazagumo-deezer": "^2.0.2",
|
||||
"kazagumo-spotify": "^2.0.1",
|
||||
"pretty-ms": "^9.0.0",
|
||||
"shoukaku": "^4.0.1"
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"requestChannels":{"777923126981558282":{"channelId":"1219720332101943296","messageId":"1219745004659015813"}}}
|
||||
{"requestChannels":{"777923126981558282":{"channelId":"1219764003421556816","messageId":"1296249229009752138"}}}
|
||||
533
src/index.js
Normal file
533
src/index.js
Normal file
|
|
@ -0,0 +1,533 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
exports.__esModule = true;
|
||||
var discord_js_1 = require("discord.js");
|
||||
var shoukaku_1 = require("shoukaku");
|
||||
var kazagumo_1 = require("kazagumo");
|
||||
var kazagumo_spotify_1 = require("kazagumo-spotify");
|
||||
var pretty_ms_1 = require("pretty-ms");
|
||||
var Guilds = discord_js_1.GatewayIntentBits.Guilds, GuildVoiceStates = discord_js_1.GatewayIntentBits.GuildVoiceStates, GuildMessages = discord_js_1.GatewayIntentBits.GuildMessages, MessageContent = discord_js_1.GatewayIntentBits.MessageContent;
|
||||
var dotenv = require("dotenv");
|
||||
var fs_1 = require("fs");
|
||||
dotenv.config();
|
||||
if (!process.env.SPOTIFY_ID || !process.env.SPOTIFY_SECRET) {
|
||||
throw "Spotify Credentials missing";
|
||||
}
|
||||
var settings;
|
||||
try {
|
||||
settings = JSON.parse((0, fs_1.readFileSync)("./settings.json", "utf8")); // Load data
|
||||
}
|
||||
catch (e) {
|
||||
settings = { requestChannels: {} }; // Init if no data found
|
||||
}
|
||||
var Nodes = [
|
||||
{
|
||||
name: "lavalink",
|
||||
url: "localhost:2333",
|
||||
auth: "youshallnotpass",
|
||||
secure: false
|
||||
},
|
||||
];
|
||||
var client = new discord_js_1.Client({
|
||||
intents: [Guilds, GuildVoiceStates, GuildMessages, MessageContent]
|
||||
});
|
||||
var kazagumo = new kazagumo_1.Kazagumo({
|
||||
defaultSearchEngine: "youtube",
|
||||
send: function (guildId, payload) {
|
||||
var guild = client.guilds.cache.get(guildId);
|
||||
if (guild)
|
||||
guild.shard.send(payload);
|
||||
},
|
||||
plugins: [
|
||||
new kazagumo_spotify_1["default"]({
|
||||
clientId: process.env.SPOTIFY_ID,
|
||||
clientSecret: process.env.SPOTIFY_SECRET,
|
||||
playlistPageLimit: 1,
|
||||
albumPageLimit: 1,
|
||||
searchLimit: 10,
|
||||
searchMarket: "US"
|
||||
}),
|
||||
]
|
||||
}, new shoukaku_1.Connectors.DiscordJS(client), Nodes);
|
||||
client.on("ready", function () {
|
||||
// console.log(client)
|
||||
console.log("".concat(client.user.tag, "\u00B7Ready!"));
|
||||
});
|
||||
kazagumo.shoukaku.on("ready", function (name) {
|
||||
return console.log("Lavalink ".concat(name, ": Ready!"));
|
||||
});
|
||||
kazagumo.shoukaku.on("error", function (name, error) {
|
||||
return console.error("Lavalink ".concat(name, ": Error Caught,"), error);
|
||||
});
|
||||
kazagumo.shoukaku.on("close", function (name, code, reason) {
|
||||
return console.warn("Lavalink ".concat(name, ": Closed, Code ").concat(code, ", Reason ").concat(reason || "No reason"));
|
||||
});
|
||||
kazagumo.shoukaku.on("debug", function (name, info) {
|
||||
return console.debug("Lavalink ".concat(name, ": Debug,"), info);
|
||||
});
|
||||
kazagumo.shoukaku.on("disconnect", function (name, count) {
|
||||
// if (moved) return;
|
||||
// players.map((player:any) => player.connection.disconnect());
|
||||
console.warn("Lavalink ".concat(name, ": Disconnected"));
|
||||
});
|
||||
kazagumo.on("playerStart", function (player, track) {
|
||||
if (!player.textId)
|
||||
return;
|
||||
var channel = client.channels.cache.get(player.textId);
|
||||
if (!channel)
|
||||
return;
|
||||
if (channel.type === discord_js_1.ChannelType.GuildText) {
|
||||
channel
|
||||
.send({
|
||||
content: "Now playing **".concat(track.title, "** by **").concat(track.author, "**")
|
||||
})
|
||||
.then(function (x) {
|
||||
//TODO: Use embed message instead
|
||||
player.data.set("message", x);
|
||||
setTimeout(function () { return x["delete"](); }, 3000);
|
||||
});
|
||||
}
|
||||
});
|
||||
kazagumo.on("playerEnd", function (player) {
|
||||
var _a;
|
||||
//TODO: Use embed message instead
|
||||
var embed = new discord_js_1.EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: "Moe",
|
||||
iconURL: "https://cdn.m3.fyi/MoeLogo.gif"
|
||||
})
|
||||
.setTitle("Nothing is being played right now")
|
||||
.setDescription("Enter message to search")
|
||||
.addFields({
|
||||
name: "Author",
|
||||
value: "None",
|
||||
inline: true
|
||||
}, {
|
||||
name: "Duration",
|
||||
value: "NaN:NaN",
|
||||
inline: true
|
||||
})
|
||||
.setColor("#ff0047");
|
||||
(_a = player.data.get("message")) === null || _a === void 0 ? void 0 : _a.edit({ embed: [embed] });
|
||||
});
|
||||
kazagumo.on("playerEmpty", function (player) {
|
||||
if (!player.textId)
|
||||
return;
|
||||
var channel = client.channels.cache.get(player.textId);
|
||||
if (!channel)
|
||||
return;
|
||||
if (channel.type === discord_js_1.ChannelType.GuildText) {
|
||||
//TODO: Use embed message instead
|
||||
channel
|
||||
.send({ content: "Destroyed player due to inactivity." })
|
||||
.then(function (x) {
|
||||
player.data.set("message", x);
|
||||
setTimeout(function () { return x["delete"](); }, 3000);
|
||||
});
|
||||
}
|
||||
player.destroy();
|
||||
});
|
||||
client.on("messageCreate", function (msg) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var cmd, _a, play, stop_1, skip, loop, shuffle, seek, previous, row, row2, embed, response, answer_1, controls, answer_2, channelId, messageId, channel_1, query, channel_2, answer_3, player, result, answer_4, _i, _b, track, play, stop_2, skip, loop, shuffle, seek, previous, row, row2, track_author, track_duration, track_thumbnail, embed, response;
|
||||
return __generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0:
|
||||
// console.log(msg.content);
|
||||
if (msg.author.bot)
|
||||
return [2 /*return*/];
|
||||
if (!msg.guild)
|
||||
return [2 /*return*/];
|
||||
if (!msg.member)
|
||||
return [2 /*return*/];
|
||||
if (msg.channel.type !== discord_js_1.ChannelType.GuildText)
|
||||
return [2 /*return*/];
|
||||
if (!msg.content.startsWith(".")) return [3 /*break*/, 9];
|
||||
cmd = msg.content.split(".")[1];
|
||||
_a = cmd;
|
||||
switch (_a) {
|
||||
case "init": return [3 /*break*/, 1];
|
||||
}
|
||||
return [3 /*break*/, 7];
|
||||
case 1:
|
||||
if (!(msg.guildId && msg.channelId)) return [3 /*break*/, 6];
|
||||
if (!!settings.requestChannels[msg.guildId]) return [3 /*break*/, 4];
|
||||
return [4 /*yield*/, msg["delete"]()];
|
||||
case 2:
|
||||
_c.sent();
|
||||
play = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("play")
|
||||
.setLabel("Play/Pause")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("889943073793122355");
|
||||
stop_1 = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("stop")
|
||||
.setLabel("Stop Playing")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("889943074258694184");
|
||||
skip = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("skip")
|
||||
.setLabel("Skip Song")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("889943074233516072");
|
||||
loop = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("loop")
|
||||
.setLabel("Loop Song")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("889943073667289099");
|
||||
shuffle = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("shuffle")
|
||||
.setLabel("Shuffle Queue")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("890325437962678352");
|
||||
seek = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("seek")
|
||||
.setLabel("Seek Forward")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("890325511878889504");
|
||||
previous = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("previous")
|
||||
.setLabel("Previous Song")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("890325512071831562");
|
||||
row = new discord_js_1.ActionRowBuilder().addComponents(play, stop_1, skip, loop);
|
||||
row2 = new discord_js_1.ActionRowBuilder().addComponents(shuffle, seek, previous);
|
||||
embed = new discord_js_1.EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: "Moe",
|
||||
iconURL: "https://cdn.m3.fyi/MoeLogo.gif"
|
||||
})
|
||||
.setTitle("Nothing is being played right now")
|
||||
.setDescription("Enter message to search")
|
||||
.addFields({
|
||||
name: "Author",
|
||||
value: "None",
|
||||
inline: true
|
||||
}, {
|
||||
name: "Duration",
|
||||
value: "NaN:NaN",
|
||||
inline: true
|
||||
})
|
||||
.setColor("#ff0047");
|
||||
return [4 /*yield*/, msg.channel.send({
|
||||
embeds: [embed],
|
||||
components: [row, row2]
|
||||
})];
|
||||
case 3:
|
||||
response = _c.sent();
|
||||
settings.requestChannels[msg.guildId] = {
|
||||
channelId: msg.channelId,
|
||||
messageId: response.id
|
||||
};
|
||||
console.log(settings.requestChannels[msg.guildId]);
|
||||
(0, fs_1.writeFileSync)("./settings.json", JSON.stringify(settings)); // Save count to file
|
||||
return [2 /*return*/];
|
||||
case 4: return [4 /*yield*/, msg.reply("Already initialized")];
|
||||
case 5:
|
||||
answer_1 = _c.sent();
|
||||
console.log(answer_1);
|
||||
setTimeout(function () { return msg["delete"](); }, 3000);
|
||||
setTimeout(function () { return answer_1["delete"](); }, 3000);
|
||||
_c.label = 6;
|
||||
case 6: return [3 /*break*/, 8];
|
||||
case 7: return [3 /*break*/, 8];
|
||||
case 8: return [2 /*return*/];
|
||||
case 9:
|
||||
if (!(msg.channel.name === "moe-song-requests")) return [3 /*break*/, 20];
|
||||
controls = void 0;
|
||||
if (!!settings.requestChannels[msg.guild.id]) return [3 /*break*/, 11];
|
||||
return [4 /*yield*/, msg.reply("Use .init first")];
|
||||
case 10:
|
||||
answer_2 = _c.sent();
|
||||
console.log(answer_2);
|
||||
setTimeout(function () { return msg["delete"](); }, 3000);
|
||||
setTimeout(function () { return answer_2["delete"](); }, 3000);
|
||||
return [2 /*return*/];
|
||||
case 11:
|
||||
channelId = settings.requestChannels[msg.guild.id].channelId;
|
||||
messageId = settings.requestChannels[msg.guild.id].messageId;
|
||||
channel_1 = msg.guild.channels.cache.get(channelId);
|
||||
if (!(channel_1 && channel_1.type === discord_js_1.ChannelType.GuildText)) return [3 /*break*/, 13];
|
||||
return [4 /*yield*/, channel_1.messages.fetch(messageId)];
|
||||
case 12:
|
||||
controls = _c.sent();
|
||||
_c.label = 13;
|
||||
case 13:
|
||||
query = msg.content;
|
||||
channel_2 = msg.member.voice.channel;
|
||||
if (!!channel_2) return [3 /*break*/, 15];
|
||||
return [4 /*yield*/, msg.reply("You need to be in a voice channel to use this command!")];
|
||||
case 14:
|
||||
answer_3 = _c.sent();
|
||||
setTimeout(function () { return answer_3["delete"](); }, 3000);
|
||||
return [2 /*return*/];
|
||||
case 15: return [4 /*yield*/, kazagumo.createPlayer({
|
||||
guildId: msg.guild.id,
|
||||
textId: msg.channel.id,
|
||||
voiceId: channel_2.id,
|
||||
volume: 40
|
||||
})];
|
||||
case 16:
|
||||
player = _c.sent();
|
||||
player.data.set("message", controls);
|
||||
console.log("Player created");
|
||||
return [4 /*yield*/, kazagumo.search(query, { requester: msg.author })];
|
||||
case 17:
|
||||
result = _c.sent();
|
||||
if (!!result.tracks.length) return [3 /*break*/, 19];
|
||||
return [4 /*yield*/, msg.reply("No results found!")];
|
||||
case 18:
|
||||
answer_4 = _c.sent();
|
||||
setTimeout(function () { return answer_4["delete"](); }, 3000);
|
||||
_c.label = 19;
|
||||
case 19:
|
||||
if (result.type === "PLAYLIST")
|
||||
for (_i = 0, _b = result.tracks; _i < _b.length; _i++) {
|
||||
track = _b[_i];
|
||||
player.queue.add(track);
|
||||
}
|
||||
else
|
||||
player.queue.add(result.tracks[0]);
|
||||
play = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("play")
|
||||
.setLabel("Play/Pause")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("889943073793122355");
|
||||
stop_2 = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("stop")
|
||||
.setLabel("Stop Playing")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("889943074258694184");
|
||||
skip = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("skip")
|
||||
.setLabel("Skip Song")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("889943074233516072");
|
||||
loop = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("loop")
|
||||
.setLabel("Loop Song")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("889943073667289099");
|
||||
shuffle = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("shuffle")
|
||||
.setLabel("Shuffle Queue")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("890325437962678352");
|
||||
seek = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("seek")
|
||||
.setLabel("Seek Forward")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("890325511878889504");
|
||||
previous = new discord_js_1.ButtonBuilder()
|
||||
.setCustomId("previous")
|
||||
.setLabel("Previous Song")
|
||||
.setStyle(discord_js_1.ButtonStyle.Secondary)
|
||||
.setEmoji("890325512071831562");
|
||||
row = new discord_js_1.ActionRowBuilder().addComponents(play, stop_2, skip, loop);
|
||||
row2 = new discord_js_1.ActionRowBuilder().addComponents(shuffle, seek, previous);
|
||||
track_author = void 0;
|
||||
if (result.tracks[0].author) {
|
||||
track_author = result.tracks[0].author;
|
||||
}
|
||||
else {
|
||||
track_author = "";
|
||||
}
|
||||
track_duration = void 0;
|
||||
if (result.tracks[0].length) {
|
||||
track_duration = (0, pretty_ms_1["default"])(result.tracks[0].length);
|
||||
}
|
||||
else {
|
||||
track_duration = "NaN:NaN";
|
||||
}
|
||||
track_thumbnail = void 0;
|
||||
if (result.tracks[0].thumbnail) {
|
||||
track_thumbnail = result.tracks[0].thumbnail.toString();
|
||||
}
|
||||
else {
|
||||
track_thumbnail = "NaN:NaN";
|
||||
}
|
||||
embed = new discord_js_1.EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: "Now playing",
|
||||
iconURL: "https://cdn.m3.fyi/MoeLogo.gif"
|
||||
})
|
||||
.setTitle(result.type === "PLAYLIST"
|
||||
? "Playing ".concat(result.tracks.length, " from ").concat(result.playlistName)
|
||||
: "Playing ".concat(result.tracks[0].title))
|
||||
.setDescription("[".concat(result.tracks[0].title, "](").concat(result.tracks[0].uri, ")"))
|
||||
.addFields({
|
||||
name: "Author",
|
||||
value: track_author,
|
||||
inline: true
|
||||
}, {
|
||||
name: "Duration",
|
||||
value: track_duration,
|
||||
inline: true
|
||||
})
|
||||
.setThumbnail(track_thumbnail)
|
||||
.setColor("#ff0047");
|
||||
if (!player.playing && !player.paused)
|
||||
player.play();
|
||||
if (controls) {
|
||||
response = controls.edit({
|
||||
embeds: [embed],
|
||||
components: [row, row2]
|
||||
});
|
||||
}
|
||||
setTimeout(function () { return msg["delete"](); }, 3000);
|
||||
return [2 /*return*/];
|
||||
case 20: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
client.on("interactionCreate", function (interaction) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var guild, member, voiceId, player, _a, track;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
console.log(interaction.id);
|
||||
if (!interaction.isButton()) return [3 /*break*/, 20];
|
||||
guild = client.guilds.cache.get(interaction.guildId);
|
||||
member = guild === null || guild === void 0 ? void 0 : guild.members.cache.get(interaction.member.user.id);
|
||||
voiceId = member === null || member === void 0 ? void 0 : member.voice.channel.id;
|
||||
return [4 /*yield*/, kazagumo.createPlayer({
|
||||
guildId: interaction.guild.id,
|
||||
textId: interaction.channel.id,
|
||||
voiceId: voiceId
|
||||
})];
|
||||
case 1:
|
||||
player = _b.sent();
|
||||
_a = interaction.customId;
|
||||
switch (_a) {
|
||||
case "play": return [3 /*break*/, 2];
|
||||
case "stop": return [3 /*break*/, 4];
|
||||
case "skip": return [3 /*break*/, 6];
|
||||
case "loop": return [3 /*break*/, 8];
|
||||
case "shuffle": return [3 /*break*/, 13];
|
||||
case "seek": return [3 /*break*/, 15];
|
||||
case "previous": return [3 /*break*/, 17];
|
||||
}
|
||||
return [3 /*break*/, 19];
|
||||
case 2:
|
||||
player.pause(!player.paused);
|
||||
return [4 /*yield*/, interaction.reply({
|
||||
ephemeral: true,
|
||||
content: "Toggled Pause"
|
||||
})];
|
||||
case 3:
|
||||
_b.sent();
|
||||
return [3 /*break*/, 20];
|
||||
case 4:
|
||||
// player.disconnect();
|
||||
player.destroy();
|
||||
return [4 /*yield*/, interaction.reply({
|
||||
ephemeral: true,
|
||||
content: "Stopped Playing"
|
||||
})];
|
||||
case 5:
|
||||
_b.sent();
|
||||
return [3 /*break*/, 20];
|
||||
case 6:
|
||||
player.skip();
|
||||
return [4 /*yield*/, interaction.reply({
|
||||
ephemeral: true,
|
||||
content: "Skipped Song"
|
||||
})];
|
||||
case 7:
|
||||
_b.sent();
|
||||
return [3 /*break*/, 20];
|
||||
case 8:
|
||||
if (!(player.loop != "none")) return [3 /*break*/, 10];
|
||||
player.setLoop("none");
|
||||
return [4 /*yield*/, interaction.reply({
|
||||
ephemeral: true,
|
||||
content: "Disabled Looping"
|
||||
})];
|
||||
case 9:
|
||||
_b.sent();
|
||||
return [3 /*break*/, 12];
|
||||
case 10:
|
||||
player.setLoop("track");
|
||||
return [4 /*yield*/, interaction.reply({
|
||||
ephemeral: true,
|
||||
content: "Started Looping"
|
||||
})];
|
||||
case 11:
|
||||
_b.sent();
|
||||
_b.label = 12;
|
||||
case 12: return [3 /*break*/, 20];
|
||||
case 13:
|
||||
player.queue.shuffle();
|
||||
return [4 /*yield*/, interaction.reply({
|
||||
ephemeral: true,
|
||||
content: "Shuffled Queue"
|
||||
})];
|
||||
case 14:
|
||||
_b.sent();
|
||||
return [3 /*break*/, 20];
|
||||
case 15:
|
||||
// let position = player.position / 1000;
|
||||
// position = position | 0;
|
||||
// console.log(position);
|
||||
// player.seek(position + 5);
|
||||
return [4 /*yield*/, interaction.reply({
|
||||
ephemeral: true,
|
||||
content: "Does not work :pensive:"
|
||||
})];
|
||||
case 16:
|
||||
// let position = player.position / 1000;
|
||||
// position = position | 0;
|
||||
// console.log(position);
|
||||
// player.seek(position + 5);
|
||||
_b.sent();
|
||||
return [3 /*break*/, 20];
|
||||
case 17:
|
||||
track = player.getPrevious();
|
||||
return [4 /*yield*/, interaction.reply({
|
||||
ephemeral: true,
|
||||
content: "Queued previous song"
|
||||
})];
|
||||
case 18:
|
||||
_b.sent();
|
||||
player.play(track[0]);
|
||||
return [3 /*break*/, 20];
|
||||
case 19: return [3 /*break*/, 20];
|
||||
case 20: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
client.login(process.env.TOKEN);
|
||||
71
src/index.ts
71
src/index.ts
|
|
@ -10,7 +10,7 @@ import {
|
|||
type Message,
|
||||
SlashCommandBuilder,
|
||||
Interaction,
|
||||
} from "discord.js";
|
||||
} from "npm:discord.js";
|
||||
|
||||
import { Connectors, Track } from "shoukaku";
|
||||
|
||||
|
|
@ -19,18 +19,19 @@ import {
|
|||
type KazagumoPlayer,
|
||||
type KazagumoTrack,
|
||||
type Payload,
|
||||
} from "kazagumo";
|
||||
} from "npm:kazagumo";
|
||||
|
||||
import KazagumoPlugin from "kazagumo-spotify";
|
||||
import prettyMilliseconds from "pretty-ms";
|
||||
import KazagumoPlugin from "npm:kazagumo-spotify";
|
||||
import prettyMilliseconds from "npm:pretty-ms";
|
||||
|
||||
const { Guilds, GuildVoiceStates, GuildMessages, MessageContent } =
|
||||
GatewayIntentBits;
|
||||
|
||||
import * as dotenv from "dotenv";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { channel } from "process";
|
||||
import * as dotenv from "npm:dotenv";
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
|
||||
import process from "node:process";
|
||||
import Deezer from "npm:kazagumo-deezer";
|
||||
dotenv.config();
|
||||
|
||||
if (!process.env.SPOTIFY_ID || !process.env.SPOTIFY_SECRET) {
|
||||
|
|
@ -66,13 +67,14 @@ const kazagumo = new Kazagumo(
|
|||
if (guild) guild.shard.send(payload);
|
||||
},
|
||||
plugins: [
|
||||
new Deezer({playlistLimit:20}),
|
||||
new KazagumoPlugin({
|
||||
clientId: process.env.SPOTIFY_ID,
|
||||
clientSecret: process.env.SPOTIFY_SECRET,
|
||||
playlistPageLimit: 1, // optional ( 100 tracks per page )
|
||||
albumPageLimit: 1, // optional ( 50 tracks per page )
|
||||
searchLimit: 10, // optional ( track search limit. Max 50 )
|
||||
searchMarket: "US", // optional || default: US ( Enter the country you live in. [ Can only be of 2 letters. For eg: US, IN, EN ] )//
|
||||
searchMarket: "DE", // optional || default: US ( Enter the country you live in. [ Can only be of 2 letters. For eg: US, IN, EN ] )//
|
||||
}),
|
||||
],
|
||||
},
|
||||
|
|
@ -135,7 +137,28 @@ kazagumo.on("playerStart", (player: KazagumoPlayer, track: KazagumoTrack) => {
|
|||
|
||||
kazagumo.on("playerEnd", (player: KazagumoPlayer) => {
|
||||
//TODO: Use embed message instead
|
||||
// player.data.get("message")?.edit({ content: "Finished playing" });
|
||||
const embed = new EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: "Moe",
|
||||
iconURL: "https://cdn.m3.fyi/MoeLogo.gif",
|
||||
})
|
||||
.setTitle("Nothing is being played right now")
|
||||
.setDescription("Enter message to search")
|
||||
.addFields(
|
||||
{
|
||||
name: "Author",
|
||||
value: "None",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Duration",
|
||||
value: "NaN:NaN",
|
||||
inline: true,
|
||||
}
|
||||
)
|
||||
.setColor("#ff0047");
|
||||
|
||||
player.data.get("message")?.edit({ embed: [embed] });
|
||||
});
|
||||
|
||||
kazagumo.on("playerEmpty", (player: KazagumoPlayer) => {
|
||||
|
|
@ -155,7 +178,7 @@ kazagumo.on("playerEmpty", (player: KazagumoPlayer) => {
|
|||
});
|
||||
|
||||
client.on("messageCreate", async (msg: Message) => {
|
||||
// console.log(msg.content);
|
||||
console.log(msg.content);
|
||||
if (msg.author.bot) return;
|
||||
if (!msg.guild) return;
|
||||
if (!msg.member) return;
|
||||
|
|
@ -222,11 +245,6 @@ client.on("messageCreate", async (msg: Message) => {
|
|||
previous
|
||||
);
|
||||
|
||||
let track_author: string;
|
||||
track_author = "None";
|
||||
let track_duration;
|
||||
track_duration = "NaN:NaN";
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: "Moe",
|
||||
|
|
@ -237,12 +255,12 @@ client.on("messageCreate", async (msg: Message) => {
|
|||
.addFields(
|
||||
{
|
||||
name: "Author",
|
||||
value: track_author,
|
||||
value: "None",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Duration",
|
||||
value: track_duration,
|
||||
value: "NaN:NaN",
|
||||
inline: true,
|
||||
}
|
||||
)
|
||||
|
|
@ -313,11 +331,20 @@ client.on("messageCreate", async (msg: Message) => {
|
|||
voiceId: channel.id,
|
||||
volume: 40,
|
||||
});
|
||||
console.log("Player created");
|
||||
const result = await kazagumo.search(query, { requester: msg.author });
|
||||
if (!result.tracks.length) {
|
||||
let answer = await msg.reply("No results found!");
|
||||
setTimeout(() => answer.delete(), 3000);
|
||||
player.data.set("message", controls);
|
||||
|
||||
console.log("Player created, Searching with deezer");
|
||||
let result = await kazagumo.search(query, { requester: msg.author, engine: "deezer"})
|
||||
console.log(result.tracks);
|
||||
if (result.tracks.length === 0) {
|
||||
console.log("Searching with youtube");
|
||||
result = await kazagumo.search(query, { requester: msg.author})
|
||||
if (result.tracks.length === 0) {
|
||||
console.log("no yt result found")
|
||||
let answer = await msg.reply("No results found!");
|
||||
setTimeout(() => answer.delete(), 3000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.type === "PLAYLIST")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue