change list + list directory

This commit is contained in:
ChomeNS 2022-11-18 17:10:34 +07:00
parent a0e6c90ef3
commit fbece8a406
2 changed files with 46 additions and 45 deletions

View file

@ -11,18 +11,13 @@ module.exports = {
if (args[0]==='list') {
const listed = Object.keys(cows);
let color = 'gold';
let primary = true;
const message = [];
listed.forEach((value) => {
if (color === 'gold') {
color = 'yellow';
} else if (color === 'yellow') {
color = 'gold';
};
message.push({
text: value + ' ',
color,
color: (!((primary = !primary)) ? 'gold' : 'yellow'),
clickEvent: {
action: 'suggest_command',
value: `${prefix}cowsay ${value} `,

View file

@ -86,8 +86,14 @@ async function resolve(filepath) {
return filepath;
}
async function list(bot, discord, channeldc, prefix, selector) {
const absolutePath = await resolve(SONGS_PATH);
async function list(bot, discord, channeldc, prefix, selector, args) {
try {
let absolutePath;
if (args[1]) absolutePath = await resolve(path.join(SONGS_PATH, args.slice(1).join(' ')));
else absolutePath = await resolve(SONGS_PATH);
if (!absolutePath.includes('midis')) throw new Error('bro trying to hack my server?!/1?!');
const listed = await fileList(absolutePath);
if (discord) {
@ -99,21 +105,17 @@ async function list(bot, discord, channeldc, prefix, selector) {
return;
}
let color = 'gold';
let primary = true;
const message = [];
listed.forEach((value) => {
if (color === 'gold') {
color = 'yellow';
} else if (color === 'yellow') {
color = 'gold';
};
for (const value of listed) {
const isFile = (await fs.lstat(path.join(absolutePath, value))).isFile();
message.push({
text: value + ' ',
color,
color: (!((primary = !primary)) ? 'gold' : 'yellow'),
clickEvent: {
action: 'suggest_command',
value: `${prefix}music play ${value}`,
value: `${prefix}music ${isFile ? 'play' : 'list'} ${path.join(args.slice(1).join(' '), value)}`,
},
hoverEvent: {
action: 'show_text',
@ -123,10 +125,14 @@ async function list(bot, discord, channeldc, prefix, selector) {
'\n',
{text: 'Click here to suggest the command!', color: 'green'},
],
}});
},
});
};
bot.tellraw(selector, message);
} catch (e) {
bot.tellraw(selector, {text: e.toString(), color: 'red'});
}
};
module.exports = {
@ -139,7 +145,7 @@ module.exports = {
'<playurl> <url>',
'<stop>',
'<loop> <all|current|off>',
'<list>',
'<list> [directory]',
'<skip>',
'<nowplaying>',
'<queue>',
@ -205,7 +211,7 @@ module.exports = {
}
break;
case 'list':
list(bot, false, null, prefix, selector);
list(bot, false, null, prefix, selector, args);
break;
case 'nowplaying':
bot.tellraw(selector, [