Merge pull request #33 from MinazukiAmane/Development

aad ability to change source
This commit is contained in:
Amane Serenetia 2024-12-10 08:05:44 +07:00 committed by GitHub
commit 419c5abc4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 92 additions and 16 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
node_modules
docs
.env.asli
config.js
# Logs
logs

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "TinashaBot",
"version": "5.7.0",
"version": "5.7.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "TinashaBot",
"version": "5.7.0",
"version": "5.7.1",
"license": "ISC",
"dependencies": {
"@google/generative-ai": "^0.14.0",

View File

@ -1,6 +1,6 @@
{
"name": "TinashaBot",
"version": "5.7.0",
"version": "5.7.1",
"description": "multipurpose discord bot built using discord-js",
"main": "bot.js",
"author": "Amane",

View File

@ -12,12 +12,40 @@ module.exports = {
command: {
enabled: true,
aliases: ["p"],
usage: "<song-name>",
usage: "[source:Default/Youtube Music/Soundcloud/Spotify/Deezer] <song-name>",
minArgsCount: 1,
},
slashCommand: {
enabled: true,
options: [
{
name: "source",
description: "select the source to search from",
type: ApplicationCommandOptionType.String,
required: true,
choices: [
{
name: "Default",
value: "ytsearch",
},
{
name: "Youtube Music",
value: "ytmsearch",
},
{
name: "Soundcloud",
value: "scsearch",
},
{
name: "Spotify",
value: "spsearch",
},
{
name: "Deezer",
value: "dzsearch",
},
],
},
{
name: "query",
description: "song name or url",
@ -28,14 +56,23 @@ module.exports = {
},
async messageRun(message, args) {
let source = MUSIC.DEFAULT_SOURCE;
// Check if the first argument is a valid source
const validSources = ["ytsearch", "ytmsearch", "scsearch", "spsearch", "dzsearch"];
if (validSources.includes(args[0].toLowerCase())) {
source = args.shift().toLowerCase();
}
const searchQuery = args.join(" ");
const response = await play(message, searchQuery);
const response = await play(message, searchQuery, source);
await message.safeReply(response);
},
async interactionRun(interaction) {
const source = interaction.options.getString("source") || MUSIC.DEFAULT_SOURCE;
const searchQuery = interaction.options.getString("query");
const response = await play(interaction, searchQuery);
const response = await play(interaction, searchQuery, source);
await interaction.followUp(response);
},
};
@ -44,7 +81,7 @@ module.exports = {
* @param {import("discord.js").CommandInteraction|import("discord.js").Message} arg0
* @param {string} query
*/
async function play({ member, guild, channel }, searchQuery) {
async function play({ member, guild, channel }, searchQuery, source) {
if (!member.voice.channel) return "🚫 You need to join a voice channel first";
let player = guild.client.musicManager.getPlayer(guild.id);
@ -67,7 +104,7 @@ async function play({ member, guild, channel }, searchQuery) {
if (!player.connected) await player.connect();
try {
const res = await player.search({ query: searchQuery }, member.user);
const res = await player.search({ query: searchQuery, source: source }, member.user);
if (!res || res.loadType === "empty") {
return `🚫 No results found for "${searchQuery}"`;

View File

@ -12,18 +12,46 @@ const { EMBED_COLORS, MUSIC } = require("@root/config");
*/
module.exports = {
name: "search",
description: "search for matching songs on YouTube",
description: "search for matching songs",
category: "MUSIC",
botPermissions: ["EmbedLinks"],
command: {
enabled: true,
aliases: ["sc"],
usage: "<song-name>",
usage: "[source:Default/Youtube Muisc/SoundCloud/Spotify/Deezer] <song-name>",
minArgsCount: 1,
},
slashCommand: {
enabled: true,
options: [
{
name: "source",
description: "select the source to search from",
type: ApplicationCommandOptionType.String,
required: true,
choices: [
{
name: "Default",
value: "ytsearch",
},
{
name: "Youtube Music",
value: "ytmsearch",
},
{
name: "Soundcloud",
value: "scsearch",
},
{
name: "Spotify",
value: "spsearch",
},
{
name: "Deezer",
value: "dzsearch",
},
],
},
{
name: "query",
description: "song to search",
@ -34,14 +62,23 @@ module.exports = {
},
async messageRun(message, args) {
let source = MUSIC.DEFAULT_SOURCE;
// Check if the first argument is a valid source
const validSources = ["ytsearch", "ytmsearch", "scsearch", "spsearch", "dzsearch"];
if (validSources.includes(args[0].toLowerCase())) {
source = args.shift().toLowerCase();
}
const query = args.join(" ");
const response = await search(message, query);
const response = await search(message, query, source);
if (response) await message.safeReply(response);
},
async interactionRun(interaction) {
const source = interaction.options.getString("source") || MUSIC.DEFAULT_SOURCE;
const query = interaction.options.getString("query");
const response = await search(interaction, query);
const response = await search(interaction, query, source);
if (response) await interaction.followUp(response);
else interaction.deleteReply();
},
@ -50,14 +87,15 @@ module.exports = {
/**
* @param {import("discord.js").CommandInteraction|import("discord.js").Message} interaction
* @param {string} query
* @param {string} source
*/
async function search({ member, guild, channel }, query) {
if (!member.voice.channel) return "🚫 You need to join a voice channel first";
async function search({ member, guild, channel }, query, source) {
if (!member.voice.channel) return "🚫 You need to join a voice channel first";
let player = guild.client.musicManager.getPlayer(guild.id);
if (player && member.voice.channel !== guild.members.me.voice.channel) {
return "🚫 You must be in the same voice channel as me.";
return "🚫 You must be in the same voice channel as me.";
}
if (!player) {
@ -73,7 +111,7 @@ async function search({ member, guild, channel }, query) {
if (!player.connected) await player.connect();
const res = await player.search({ query }, member.user);
const res = await player.search({ query, source }, member.user);
if (!res || !res.tracks?.length) {
return {