Skip to content

Commit

Permalink
Merge pull request #12 from imnaiyar/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
imnaiyar authored Jan 18, 2024
2 parents cb999fb + 38b7920 commit 3d1917e
Show file tree
Hide file tree
Showing 63 changed files with 1,396 additions and 1,961 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
34 changes: 29 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ module.exports = class SkyHelper extends Client {
// Datas for Events in Sky
this.skyEvents = {
eventActive: true,
eventName: 'Days of Feast',
eventStarts: moment.tz('2023-12-18T00:00:00', this.timezone),
eventEnds: moment.tz('2024-01-07T23:59:59', this.timezone),
eventDuration: '21 days',
eventName: 'Days of Fortune',
eventStarts: moment.tz('2024-01-29T00:00:00', this.timezone),
eventEnds: moment.tz('2024-02-11T23:59:59', this.timezone),
eventDuration: '13 days',
};

// Checks for how this class is created so it doesnt mess up the process
Expand Down Expand Up @@ -161,7 +161,8 @@ module.exports = class SkyHelper extends Client {
name: cmd.data.name,
description: cmd.data.description,
type: 1,
options: cmd.data.options,
options: cmd.data?.options,
dm_permission: cmd.data?.dm_permission
}))
.forEach((s) => toRegister.push(s));

Expand Down Expand Up @@ -190,4 +191,27 @@ module.exports = class SkyHelper extends Client {
});
return webhook.url;
}

/**
* get commands from client application
*/
async getCommand(value) {
if (!value)
throw new Error('Command "name" or "id" must be passed as an argument');
await this.application.commands.fetch();
const command =
typeof value === 'string' && isNaN(value)
? this.application.commands.cache.find(
(cmd) => cmd.name === value.toLowerCase(),
)
: !isNaN(value)
? this.application.commands.cache.get(value)
: (() => {
throw new Error(
'Provided Value Must Either be a String or a Number',
);
})();
if (!command) throw new Error('No matching command found');
return command;
}
};
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@discordjs/rest": "^2.2.0",
"@fortawesome/fontawesome-free": "^6.4.2",
"aos": "^2.3.4",
"axios": "^1.6.0",
"axios": "^1.6.5",
"body-parser": "^1.20.2",
"chalk": "^4.1.2",
"colors": "^1.4.0",
Expand Down
4 changes: 2 additions & 2 deletions src/cmdDesc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module.exports = {
guides: `Provides guides for seasonal quests, locations of seasonal spirits, and their cosmetic price trees, created by fellow game players and including their credits. Results are ephemeral by default, but you can make them non-ephemeral optionally. The select menus are deleted after 1 minute of inactivity to prevent channel clogging.
\`Usage:\`
/seasonal-guides [ephemeral]
/seasonal-guides [spirit] [ephemeral]
- [spirit] (optional): Directly search for a seasonal spirit's tree/locaction.
- [ephemeral] (optional): Specify this option to receive non-ephemeral results.`,

nextShards: `Provides information about the date and location of the next 5 upcoming shards by default. Optionally, you can request more results.
Expand Down
22 changes: 21 additions & 1 deletion src/commands/guides/seasonal-guides.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
const { ApplicationCommandOptionType } = require('discord.js');
const { Guides } = require('./sub/GuideOption');
const spirits = require('./sub/spiritsIndex.js');
const desc = require('@src/cmdDesc');
module.exports = {
cooldown: 30,
cooldown: 3,
data: {
name: 'seasonal-guides',
description: 'various seasonal guides',
longDesc: desc.guides,
options: [
{
name: 'spirit',
description: 'directly search for a spirit`s tree/location',
type: ApplicationCommandOptionType.String,
required: false,
autocomplete: true,
},
{
name: 'ephemeral',
description:
Expand All @@ -21,4 +29,16 @@ module.exports = {
async execute(interaction) {
await Guides(interaction);
},
async autocomplete(interaction, client) {
const focusedValue = interaction.options.getFocused();
const spiritNames = Object.keys(spirits);
const filtered = spiritNames
.filter((choice) =>
choice.toUpperCase().includes(focusedValue.toUpperCase()),
)
.slice(0, 25);
await interaction.respond(
filtered.map((choice) => ({ name: choice, value: choice })),
);
},
};
127 changes: 103 additions & 24 deletions src/commands/guides/sub/GuideOption.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,111 @@
const { StringSelectMenuBuilder, ActionRowBuilder } = require('discord.js');
const {
StringSelectMenuBuilder,
ActionRowBuilder,
ButtonBuilder,
} = require('discord.js');
const choiceResponses = require('./GuideResponse.js');
const index = require('./spiritsIndex.js');
const messageChoices = new Map();
const CUSTOM_ID = {
FIRST_CHOICE: 'firstChoice',
SECOND_CHOICE: 'secondChoice',
THIRD_CHOICE: 'thirdChoice',
BACK: 'back',
};

async function Guides(interaction) {
if (!interaction.isCommand()) return;
const spirit = interaction.options.getString('spirit');
const ephemeralOption = interaction.options.getString('ephemeral');
const ephemeral = ephemeralOption === 'false' ? false : true;
const filter = (i) => {
if (i.user.id !== interaction.user.id) {
i.reply({
content:
"You can't use the menu generated by others. Run the command </seasonal-guides:1147244751708491897> if you wish to use it.",
ephemeral: true,
});
return false;
}
return i.isStringSelectMenu() || i.isButton();
};
if (spirit) {
const msg = await interaction.deferReply({ ephemeral: ephemeral });
const value = index[spirit.toUpperCase()];
if (!value) {
return interaction.followUp({
content: `\`${spirit}\` does not exist.\n\nMake sure the spirit name is valid and you provide the full name, like, \`Talented Builder\` (without any extra spaces)`,
ephemeral: true,
});
}
let tree;
let location;
if (Array.isArray(value)) {
tree = value[1];
location = value[0];
} else {
tree = value + '_tree';
location = value + '_location';
}
const response = await choiceResponses.getResponse(tree);
const respn = await choiceResponses.getResponse(location);
let disabled;
if (respn) {
disabled = false;
} else {
disabled = true;
}
const lctnBtn = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setEmoji('<:location:1131173266883612722>')
.setLabel('Location')
.setCustomId('sprtLctn')
.setDisabled(disabled)
.setStyle('1'),
);
const treeBtn = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setEmoji('<:tree:1131279758907424870>')
.setLabel('Friendship Tree')
.setCustomId('sprtTree')
.setStyle('1'),
);
await interaction.followUp({
content: `${response.content}\n\n${response.files
.map((file, index) => `[File ${index + 1}](${file})`)
.join('\n')}`,
components: [lctnBtn],
});
const collector = msg.createMessageComponentCollector({
filter,
idle: 3 * 60 * 1000,
});
collector.on('collect', async (interaction) => {
const id = interaction.customId;
if (id === 'sprtTree') {
await interaction.update({
content: `${response.content}\n\n${response.files
.map((file, index) => `[File ${index + 1}](${file})`)
.join('\n')}`,
components: [lctnBtn],
});
} else if (id === 'sprtLctn') {
await interaction.update({
content: `${respn.content}\n\n${respn.files
.map((file, index) => `[File ${index + 1}](${file})`)
.join('\n')}`,
components: [treeBtn],
});
}
});

collector.on('end', async () => {
await msg.edit({
components: [],
});
});
return;
}
const { firstChoices } = require('./SeasonalChoices.js');

const dropdownOptions = firstChoices.map((choice) => ({
Expand All @@ -33,21 +127,9 @@ async function Guides(interaction) {
fetchReply: true,
});

const filter = (i) => {
if (i.user.id !== interaction.user.id) {
i.reply({
content:
"You can't use the menu generated by others. Run the command </seasonal-guides:1147244751708491897> if you wish to use it.",
ephemeral: true,
});
return false;
}
return i.isStringSelectMenu();
};

const collector = reply.createMessageComponentCollector({
filter,
idle: 60 * 1000,
idle: 2 * 60 * 1000,
});

collector.on('collect', async (selectInteraction) => {
Expand Down Expand Up @@ -86,9 +168,7 @@ async function Guides(interaction) {
});

collector.on('end', (collected, reason) => {
if (reply) {
reply.delete();
}
interaction.deleteReply();
});
}

Expand Down Expand Up @@ -144,19 +224,18 @@ async function handleSecond(

if (selectedChoice === CUSTOM_ID.BACK) {
await handleBack(interaction, firstChoices);
} else if (
selectedChoice === 'shattering_q' ||
selectedChoice === 'dreams_q'
) {
const response = choiceResponses.getResponse(selectedChoice);
await respondToInteraction(interaction, response, ephemeral);
} else {
const thirdChoiceOptions = thirdChoices[selectedChoice].map((choice) => ({
const thirdChoiceOptions = thirdChoices[selectedChoice]?.map((choice) => ({
label: choice.label,
value: choice.value,
emoji: choice.emoji,
}));

if (!thirdChoiceOptions) {
const response = choiceResponses.getResponse(selectedChoice);
await respondToInteraction(interaction, response, ephemeral);
return;
}
thirdChoiceOptions.push(backObj);

const row = new ActionRowBuilder().addComponents(
Expand Down
Loading

0 comments on commit 3d1917e

Please sign in to comment.