Skip to content
This repository was archived by the owner on Sep 28, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion commands/Music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const { convertToHHMMSS, msToSec } = require("../../utils/time");
const { isYouTubeUrl, isHStudioPlayUrl } = require("../../utils/youtube");
const AdsSchema = require("../../schemas/Ad");
const YoutubeDirectSchema = require("../../schemas/YoutubeDirect");
const DefaultSourceSchema = require("../../schemas/DefaultSource");

const sources = require("../../configs/sources.json");

module.exports = {
data: new SlashCommandBuilder()
Expand Down Expand Up @@ -32,6 +35,10 @@ module.exports = {

let query = interaction.options.getString("query");

const user_source = await DefaultSourceSchema.findOne({
userId: interaction.user.id
});

let player = client.moon.createPlayer({
guildId: interaction.guild.id,
voiceChannelId: interaction.member.voice.channel.id,
Expand Down Expand Up @@ -68,7 +75,7 @@ module.exports = {

let res = await client.moon.search({
query,
source: "spsearch",
source: user_source ? sources[user_source.source] : "spsearch",
requester: interaction.user.id
});

Expand Down
90 changes: 90 additions & 0 deletions commands/Utils/setting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const { SlashCommandBuilder, EmbedBuilder, Colors } = require("discord.js");
const DefaultSourceSchema = require("../../schemas/DefaultSource");

module.exports = {
data: new SlashCommandBuilder()
.setName("setting")
.setDescription("Setting")
.setDescriptionLocalizations({
th: "การตั้งค่า"
})
.addSubcommand((sub) =>
sub.setName("search")
.setDescription("Change default search source")
.setDescriptionLocalizations({
th: "การตั้งค่าการค้นหาเริ่มต้น"
})
.addStringOption((option) =>
option
.setName("source")
.setDescription("Source")
.setDescriptionLocalizations({
th: "แหล่งที่มา"
})
.setRequired(true)
.setChoices(
{
name: "Spotify",
value: "spotify"
},
{
name: "Youtube",
value: "youtube"
},
{
name: "Youtube Music",
value: "youtube_music"
}
))
),

/**
*
* @param {import("discord.js").CommandInteraction} interaction
* @param {import("discord.js").Client} client
* @param {import("../../class/Locale")} locale
*/
async execute(interaction, client, locale) {
const sub = interaction.options.getSubcommand();

switch (sub) {
case "search": {
await interaction.deferReply();
const source = interaction.options.getString("source");

if (!source) return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(Colors.Red)
.setDescription(locale.replacePlaceholders(locale.getLocaleString("command.setting.search.save.fail"), [source]))
]
});

const oldConfig = await DefaultSourceSchema.findOne({
userId: interaction.user.id
});

if (oldConfig) {
await DefaultSourceSchema.updateOne({
userId: interaction.user.id
}, {
source: source
});
} else {
await DefaultSourceSchema.create({
userId: interaction.user.id,
source: source
});
}

await interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(Colors.Blue)
.setDescription(locale.replacePlaceholders(locale.getLocaleString("command.setting.search.saved"), [source]))
]
});
}
}
}
};
5 changes: 5 additions & 0 deletions configs/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"spotify": "spsearch",
"youtube": "ytsearch",
"youtube_music": "ytmsearch"
}
4 changes: 3 additions & 1 deletion locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,7 @@
"moonlink.trackStart.withoutUrl": "{0} Start playing **{1}**",
"moonlink.trackEnd": "There are no more tracks",
"command.clear.success": "🗑️ Clear Queue Success",
"command.clear.fail": "❌ Can't clear queue"
"command.clear.fail": "❌ Can't clear queue",
"command.setting.search.saved": "💾 Saved default source with `{0}`",
"command.setting.search.save.fail": "❌ Fail to save default source with `{0}`"
}
8 changes: 8 additions & 0 deletions schemas/DefaultSource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { model, Schema } = require("mongoose");

module.exports = model("default_source", new Schema({
userId: String,
source: String
}, {
timestamps: true
}));