Browse Source
* Updated feature-preferences * Create settings.ts * Update to settings.ts * Update settings.ts * still trying to debug 💀 * Revert "still trying to debug 💀" This reverts commitdevelopment45aac13ddf
. * Revert "Update settings.ts" This reverts commit446f253844
. * Revert "Update to settings.ts" This reverts commit8faac8d2bf
. * created stable parsing version * Update settings.ts * Update settings.ts * Made subcommands do actual stuff * Update settings.ts * Revert "Update settings.ts" This reverts commita0743960dd
. * Update settings.ts * fixed gradelevels case * fixed case * Updated level subcommand * Update settings.ts * Canary 04-12-22 All menus are done...only thing left is to hook it up to the database * Update settings.ts fixes majority of linting issues * intellij idea configs * more IntelliJ configs * Implemented multi-select menus semi-stable - major bugs need fixing * Worked out level selection * Fixed display and subject commands * Update settings.ts Fixed linting * deleted js files in helper directory * Fixed display subcommand Co-authored-by: Eric Yang <64386991+xlq902@users.noreply.github.com> Co-authored-by: Eric Yang <tetrgda@gmail.com>
Abheek Dhawan
3 years ago
committed by
GitHub
9 changed files with 361 additions and 5 deletions
@ -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 |
@ -0,0 +1,8 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="SwUserDefinedSpecifications"> |
|||
<option name="specTypeByUrl"> |
|||
<map /> |
|||
</option> |
|||
</component> |
|||
</project> |
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="VcsDirectoryMappings"> |
|||
<mapping directory="" vcs="Git" /> |
|||
</component> |
|||
</project> |
@ -0,0 +1 @@ |
|||
browser=Chrome.INTEGRATED |
@ -0,0 +1,4 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> |
|||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> |
|||
</project-private> |
@ -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; |
|||
} |
|||
} |
|||
} |
@ -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'; |
|||
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'; |
|||
|
@ -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; |
Loading…
Reference in new issue