diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..283b9b4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..3b1a22e --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1 @@ +browser=Chrome.INTEGRATED diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..4750962 --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/commands/settings.ts b/src/commands/settings.ts new file mode 100644 index 0000000..8a52b5e --- /dev/null +++ b/src/commands/settings.ts @@ -0,0 +1,245 @@ +import { SlashCommandBuilder } from '@discordjs/builders'; +import { Message, MessageActionRow, MessageSelectMenu } from 'discord.js'; +import { CommandInteraction, MessageEmbed } from 'discord.js'; +import log from '../helpers/log.js'; + +export const data = new SlashCommandBuilder() + .setName('settings') + .setDescription('BETA - settings configuration') + .addSubcommand(subcommand => { + subcommand + .setName('subject') + .setDescription('Changes subject of problems'); + return subcommand; + }) + .addSubcommand(subcommand => { + subcommand + .setName('display') + .setDescription('Displays current settings'); + return subcommand; + }) + .addSubcommand(subcommand => { + subcommand + .setName('gradelevels') + .setDescription('Changes grade level of problems'); + return subcommand; + }) +; + +export async function execute(interaction : CommandInteraction) { + const action = interaction.options.getSubcommand(); + switch (action) { + case 'display': { + await interaction.deferReply(); + const settingsEmbed = new MessageEmbed() + .setColor('#ffffff'); + + const user = interaction.options.getUser('user') || interaction.user; + + settingsEmbed + .setAuthor({ name: user.tag, iconURL: user.displayAvatarURL() }) + .setDescription('Current selections: '); + const menu = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId('selectdisp') + .setPlaceholder('Nothing selected') + .addOptions([ + { + label: 'subjects', + description: 'subjects', + value: 'subjects', + }, + { + label: 'gradelevels', + description: 'grade levels', + value: 'gradelevels', + }, + ]), + ); + + interaction.followUp({ + embeds: [settingsEmbed], + components: [menu], + }) + .then((dispMsg => { + const w = dispMsg as Message; + let h; + const dispFilter = i => ['selectdisp'].includes(i.customId) && i.user.id == interaction.user.id; // <== ATTENTION! First argument... + w.awaitMessageComponent({ filter: dispFilter, componentType: 'SELECT_MENU' }) + .then(dispChoice => { + h = dispChoice.values; + if (h == 'subjects') { + interaction.editReply({ content: 'Current subjects setting:', components: [] }); + } + else if (h == 'gradelevels') { + interaction.editReply({ content: 'Current grade level setting: ', components: [] }); + } + else { + err => log({ logger: '\'Error occurred: /settings:display did not equal subjects or gradelevels.\'', content: `${err}`, level: 'error' }); + } + }); + })); + break; + } + case 'gradelevels': { + await interaction.deferReply(); + + const settingsEmbed = new MessageEmbed() + .setColor('#ffffff'); + + const user = interaction.options.getUser('user') || interaction.user; + + settingsEmbed + .setAuthor({ name: user.tag, iconURL: user.displayAvatarURL() }) + .setDescription('Current level settings: '); + const menu = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId('selectlvl') + .setPlaceholder('Nothing selected') + .setMinValues(1) + .setMaxValues(2) + .addOptions([ + { + label: 'Middle School', + description: 'Middle school level problems', + value: 'ms', + }, + { + label: 'High School', + description: 'High school level problems', + value: 'hs', + }, + ]), + ); + + interaction.followUp({ + embeds: [settingsEmbed], + components: [menu], + }) + .then((lvlMsg => { + const w = lvlMsg as Message; + let h; + const lvlFilter = i => ['selectlvl'].includes(i.customId) && i.user.id == interaction.user.id; // <== ATTENTION! First argument... + w.awaitMessageComponent({ filter: lvlFilter, componentType: 'SELECT_MENU' }) + .then(lvlChoice => { + h = lvlChoice.values; + if (h == 'ms') { + interaction.editReply({ content: 'Level set to: Middle School', components: [] }); + } + else if (h == 'hs') { + interaction.editReply({ content: 'Level set to: High School', components: [] }); + } + else { + interaction.editReply({ content: 'Level set to: All', components: [] }); + } + }); + })); + break; + } + case 'subject': { + await interaction.deferReply(); + + const settingsEmbed = new MessageEmbed() + .setColor('#ffffff'); + + const user = interaction.options.getUser('user') || interaction.user; + + settingsEmbed + .setAuthor({ name: user.tag, iconURL: user.displayAvatarURL() }) + .setDescription('Current subject settings: '); + const menu = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId('selectsubject') + .setPlaceholder('Nothing selected') + .setMinValues(1) + .setMaxValues(7) + .addOptions([ + { + label: 'Astronomy', + description: 'Astronomy', + value: 'astro', + }, + { + label: 'Biology', + description: 'Biology', + value: 'bio', + }, + { + label: 'Earth Science', + description: 'Earth Science', + value: 'es', + }, + { + label: 'Chemistry', + description: 'Chemistry', + value: 'chem', + }, + { + label: 'Physics', + description: 'Physics', + value: 'phy', + }, + { + label: 'Mathematics', + description: 'Mathematics', + value: 'math', + }, + { + label: 'Energy', + description: 'Energy', + value: 'energy', + }, + ]), + ); + + interaction.followUp({ + embeds: [settingsEmbed], + components: [menu], + }) + .then((subjectMsg => { + const w = subjectMsg as Message; + let h; + const subjectFilter = i => ['selectsubject'].includes(i.customId) && i.user.id == interaction.user.id; // <== ATTENTION! First argument... + w.awaitMessageComponent({ filter: subjectFilter, componentType: 'SELECT_MENU' }) + .then(subjectChoice => { + let sendstring = 'Subjects set to: '; + h = subjectChoice.values; + if (h.includes('astro')) { + // astro processing code here + sendstring = sendstring + 'Astronomy, '; + } + if (h.includes('bio')) { + // bio processing code here + sendstring = sendstring + 'Biology, '; + } + if (h.includes('es')) { + // earth science processing code here + sendstring = sendstring + 'Earth Science, '; + } + if (h.includes('chem')) { + // chemistry processing code here + sendstring = sendstring + 'Chemistry, '; + } + if (h.includes('phy')) { + // physics processing code here + sendstring = sendstring + 'Physics, '; + } + if (h.includes('math')) { + // math processing code here + sendstring = sendstring + 'Math, '; + } + if (h.includes('energy')) { + // energy processing code here + sendstring = sendstring + 'Energy, '; + } + sendstring = sendstring.slice(0, -2); + interaction.editReply({ content: sendstring, components: [] }); + }); + })); + break; + } + } +} \ No newline at end of file diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 8cdd4b0..9c4f7c7 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -6,10 +6,12 @@ export const once = false; export async function execute(interaction) { const client = interaction.client; + if (!interaction.isCommand()) return; const command = client.commands.get(interaction.commandName); - if (!command) return; + + if (!command) return; //h try { await command.execute(interaction); diff --git a/src/helpers/env.ts b/src/helpers/env.ts index c339592..25d4f8e 100644 --- a/src/helpers/env.ts +++ b/src/helpers/env.ts @@ -1,6 +1,6 @@ import 'dotenv/config'; -export const clientId : string = process.env.CLIENT_ID || ''; -export const testingGuild : string = process.env.TESTING_GUILD || ''; -export const token : string = process.env.TOKEN || ''; -export const mongoUri : string = process.env.MONGO_URI || 'mongodb://mongo:27017/awesome'; \ No newline at end of file +export const clientId = process.env.CLIENT_ID || ''; +export const testingGuild = process.env.TESTING_GUILD || ''; +export const token = process.env.TOKEN || ''; +export const mongoUri = process.env.MONGO_URI = 'mongodb://localhost:27017'; diff --git a/src/helpers/util/pagination.js b/src/helpers/util/pagination.js new file mode 100644 index 0000000..a4576cd --- /dev/null +++ b/src/helpers/util/pagination.js @@ -0,0 +1,82 @@ +"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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.paginateInteraction = exports.paginateMessage = void 0; +const discord_js_1 = require("discord.js"); +function paginateMessage(message, embeds) { + return __awaiter(this, void 0, void 0, function* () { + let index = 0; + const row = new discord_js_1.MessageActionRow; + row.addComponents(new discord_js_1.MessageButton() + .setCustomId('paginator-left') + .setEmoji('868552005977788466') + .setStyle('SECONDARY'), new discord_js_1.MessageButton() + .setCustomId('paginator-right') + .setEmoji('868551772887711754') + .setStyle('SECONDARY')); + yield message.reply({ content: `Page 1 of ${embeds.length}:`, embeds: [embeds[index]], components: [row] }) + .then((paginatorMessage) => __awaiter(this, void 0, void 0, function* () { + const filter = m => m.author.id === message.author.id; + const paginatorCollector = paginatorMessage.createMessageComponentCollector({ componentType: 'BUTTON', filter: filter }); + paginatorCollector.on('collect', (i) => __awaiter(this, void 0, void 0, function* () { + switch (i.customId) { + case 'paginator-left': + index--; + if (index < 0) + index = embeds.length - 1; + break; + case 'paginator-right': + index++; + if (index > embeds.length - 1) + index = 0; + break; + } + paginatorMessage.edit({ content: `Page ${index + 1} of ${embeds.length}:`, embeds: [embeds[index]] }); + })); + })); + }); +} +exports.paginateMessage = paginateMessage; +function paginateInteraction(interaction, embeds) { + return __awaiter(this, void 0, void 0, function* () { + let index = 0; + const row = new discord_js_1.MessageActionRow; + row.addComponents(new discord_js_1.MessageButton() + .setCustomId('paginator-left') + .setEmoji('868552005977788466') + .setStyle('SECONDARY'), new discord_js_1.MessageButton() + .setCustomId('paginator-right') + .setEmoji('868551772887711754') + .setStyle('SECONDARY')); + yield interaction.followUp({ content: `Page 1 of ${embeds.length}:`, embeds: [embeds[index]], components: [row], fetchReply: true }) + .then((p) => __awaiter(this, void 0, void 0, function* () { + const paginatorMessage = p; + const filter = i => i.user.id === interaction.user.id; + const paginatorCollector = paginatorMessage.createMessageComponentCollector({ componentType: 'BUTTON', filter: filter }); + paginatorCollector.on('collect', (i) => __awaiter(this, void 0, void 0, function* () { + switch (i.customId) { + case 'paginator-left': + index--; + if (index < 0) + index = embeds.length - 1; + break; + case 'paginator-right': + index++; + if (index > embeds.length - 1) + index = 0; + break; + } + yield i.update({ content: `Page ${index + 1} of ${embeds.length}:`, embeds: [embeds[index]] }); + })); + })); + }); +} +exports.paginateInteraction = paginateInteraction;