Commit 6c99db38 authored by Yashin's avatar Yashin
Browse files

Implementing course collections feature. Bulk add works, but is still a bit wonky.

parent 7ee0d711
......@@ -7,8 +7,12 @@ module.exports = (loc) => {
return new SlashCommandBuilder()
.setName('delete_collection')
.setDescription(commandLocale.description)
.addChannelOption( (option) =>
option.setName('collection_category')
.setDescription(commandLocale.collectionCategoryDescription)
.setRequired(true));
.addChannelOption((option) =>
option.setName('collection_category')
.setDescription(commandLocale.collectionCategoryDescription)
.setRequired(true))
.addBooleanOption((option) =>
option.setName('delete_channels')
.setDescription(commandLocale.deleteChannelDescription)
.setRequired(true));
}
\ No newline at end of file
This diff is collapsed.
......@@ -44,7 +44,7 @@ async function changeLocale(interaction) {
}
}
const slashCommandHandler = async (interaction) => {
const slashCommandHandler = async (interaction, client) => {
if (interaction.commandName === 'change_locale') {
await changeLocale(interaction);
}
......
......@@ -153,7 +153,7 @@ async function deleteMemberChannel(interaction) {
}
async function slashCommandHandler (interaction) {
async function slashCommandHandler (interaction, client) {
if (interaction.commandName === 'assign_member_role') {
assignMemberStatus(interaction);
} else if (interaction.commandName === 'revoke_member_role') {
......
......@@ -105,10 +105,18 @@ async function listPermissions(interaction) {
config.guildID = interaction.guild.id.toString();
config.permissions.roleMenu = [];
}
const roles = await Promise.all(config.permissions.roleMenu.map(async (roleID) => (await interaction.guild.roles.fetch(roleID)).name));
const roles = await Promise.all([
config.permissions.roleMenu,
config.permissions.locale,
config.permissions.collection,
config.permissions.memberManagement
].map(async (IDs) => await Promise.all(IDs.map(async (roleID) => (await interaction.guild.roles.fetch(roleID)).name))));
await interaction.reply({
content: functionLocale.replyList.replaceAll('$$ROLEMENU$$', `${roles.join(',')}`),
content: functionLocale.replyList
.replaceAll('$$ROLEMENU$$', `${roles[0].join(',')}`)
.replaceAll('$$LOCALE$$', `${roles[1].join(',')}`)
.replaceAll('$$COLLECTION$$', `${roles[2].join(',')}`)
.replaceAll('$$MEMBERMANAGEMENT$$', `${roles[3].join(',')}`),
ephemeral: true
});
} else {
......@@ -116,7 +124,7 @@ async function listPermissions(interaction) {
}
}
const slashCommandHandler = async (interaction) => {
const slashCommandHandler = async (interaction, client) => {
if (interaction.commandName === 'assign_permission') {
await assignPermission(interaction);
} else if (interaction.commandName === 'revoke_permission') {
......
......@@ -280,7 +280,7 @@ async function editRoleMenu(interaction) {
}
}
const slashCommandHandler = async (interaction) => {
const slashCommandHandler = async (interaction, client) => {
if (interaction.commandName === 'add_role_menu') {
await addRoleMenu(interaction);
} else if (interaction.commandName === 'delete_role_menu') {
......@@ -294,11 +294,11 @@ const slashCommandHandler = async (interaction) => {
}
}
/*const buttonHandler = async (interaction) => {
/*const buttonHandler = async (interaction, client) => {
}*/
const selectMenuHandler = async (interaction) => {
const selectMenuHandler = async (interaction, client) => {
if (interaction.customId === 'selectRole') {
const config = await ServerConfig.findOne({guildID: interaction.guild.id.toString()});
let locale = 'en';
......
......@@ -27,7 +27,7 @@ for (const file of componentFiles) {
// Creating the discord client.
const client = new Client({intents: [Intents.FLAGS.GUILDS]});
const client = new Client({intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.DIRECT_MESSAGES]});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
......@@ -37,22 +37,36 @@ client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
components.forEach(component => {
if (component.slashCommandHandler !== undefined) {
component.slashCommandHandler(interaction);
component.slashCommandHandler(interaction, client);
}
});
} else if (interaction.isButton()) {
components.forEach(component => {
if (component.buttonHandler !== undefined) {
component.buttonHandler(interaction);
component.buttonHandler(interaction, client);
}
});
} else if (interaction.isSelectMenu()) {
components.forEach(component => {
if (component.selectMenuHandler !== undefined) {
component.selectMenuHandler(interaction);
component.selectMenuHandler(interaction, client);
}
});
}
});
client.on('messageCreate', async (message) => {
console.log('asd')
if (message.author.id != client.user.id) {
if (message.guild == null) {
console.log('asd');
components.forEach(component => {
if (component.dmMessageHandler !== undefined) {
component.dmMessageHandler(message, client);
}
})
}
}
});
client.login(botConfig.token);
\ No newline at end of file
......@@ -81,7 +81,8 @@
},
"delete_collection": {
"description": "Eine Veranstaltungssammlung löschen.",
"collectionCategoryDescription": "Kategorie der Veranstaltungssammlung."
"collectionCategoryDescription": "Kategorie der Veranstaltungssammlung.",
"deleteChannelDescription": "Sollen die Textkanäle gelöscht werden?"
},
"add_course_to_collection": {
"description": "Eine Veranstaltung zur Sammlung hinzufügen.",
......@@ -128,7 +129,7 @@
"permConfig": {
"replyAssign": "Der Rolle $$ROLE$$ wurde die $$PERM$$ Berechtigung hinzugefügt.",
"replyRevoke": "Der Rolle $$ROLE$$ wurde die $$PERM$$ Berechtigung entzogen.",
"replyList": "Liste der Berechtigungen:\n\nRollenmenüs: $$ROLEMENU$$\nSprache ändern $$LOCALE$$",
"replyList": "Liste der Berechtigungen:\n\nRollenmenüs: $$ROLEMENU$$\nSprache ändern: $$LOCALE$$\nVeranstaltungssammlungen: $$COLLECTION$$\nMemberstatus von Rollen bearbeiten: $$MEMBERMANAGEMENT$$",
"accessDenied": "Nur Administratoren dürfen diesen Command nutzen."
},
"roleMenu": {
......@@ -152,22 +153,36 @@
"internalError": "Interner Fehler. Bitte kontaktier einen Admin."
},
"memberManagement": {
"accessDenied": "You are not authorized to do this.",
"roleAlreadyMember": "This role is already a member role.",
"roleAdded": "Role $$ROLE$$ has been turned into a member role and all member channels are updated.",
"roleNotMember": "This role is not a member role.",
"roleRevoked": "Role $$ROLE$$ has it's member status revoked.",
"channelAlreadyMember": "This channel is already a member channel.",
"channelAdded": "Channel $$CHANNEL$$ has been turned into a member channel.",
"channelNotMember": "This channel is not a member channel.",
"channelRemoved": "Channel $$CHANNEL$$ has it's member status removed."
"accessDenied": "Du darfst diesen Command nicht nutzen.",
"roleAlreadyMember": "Diese Rolle ist bereits eine Member Rolle.",
"roleAdded": "Die Rolle $$ROLE$$ wurde zu einer Member Rolle gemacht und alle Memberkanäle wurden geupdated.",
"roleNotMember": "Diese Rolle ist keine Member Rolle.",
"roleRevoked": "Der Rolle $$ROLE$$ wurde der Member Status entzogen.",
"channelAlreadyMember": "Dieser Kanal war bereits ein Member Kanal.",
"channelAdded": "Der Kanal $$CHANNEL$$ wurde zu einem Memberkanal gemacht.",
"channelNotMember": "Dieser Kanal ist kein Memberkanal.",
"channelRemoved": "Dem Kanal $$CHANNEL$$ wurde der Memberstatus entzogen."
},
"courseCollections": {
"accessDenied": "You are not authorized to do this.",
"collectionAdded": "The collection has been successfully added.",
"collectionNotAdded": "There was an error adding the collection.",
"collectionDeleted": "The collection has been successfully deleted.",
"collectionNotDeleted": "There was an error deleting the collection."
"accessDenied": "Du darfst diesen Command nicht nutzen.",
"collectionAdded": "Die Kurssammlung wurde hinzugefügt. Bitte bewege die Sammlungsrolle dort hin, wo sie bleiben soll, damit neue Rollen an der richtigen Position erstellt werden.",
"collectionNotAdded": "Es gab einen Fehler beim Hinzufügen der Sammlung.",
"collectionDeleted": "Die Sammlung wurde gelöscht.",
"collectionNotDeleted": "Es gab einen Fehler beim löschen der Sammlung.",
"courseAdded": "Der Kurs wurde erfolgreich hinzugefügt.",
"courseNotAdded": "Es gab einen Fehler beim Hinzufügen des Kurses.",
"selectCourseChannel": "Bitte wähle einen Kurskanal aus.",
"courseDeleted": "Der Kurs wurde erfolgreich gelöscht.",
"courseNotDeleted": "Es gab einen Fehler beim Hinzufügen des Kurses.",
"coursesAdded": "Du wurdest diesen Kursen hinzugefügt: $$COURSES$$.",
"coursesAddedEmpty": "Du wurdest aus allen Kursen in diesem Menü entfernt.",
"enableAllCourses": "Du kannst alle Kurse in dieser Sammlung sehen.",
"disableAllCourses": "Du kannst nur noch alle Kurse, die du ausgewählt hast, sehen.",
"bulkInteractionStarted": "Geh zu den Direktnachrichten mit mir und folge dort meinen Anweisungen um mehrere Kurse hinzuzufügen.",
"internalError": "Interner Fehler. Bitte kontaktier einen Administrator.",
"bulkInteractionSuccess": "Du hast diese Kurse erfolgreich hinzugefügt.",
"bulkInteractionCancel": "Du hast diese Interaktion abgebrochen.",
"bulkInteractionInteractiveAck": "$$COURSE$$ wurde der Liste der hinzuzufügenden Kurse hinzugefügt."
}
},
"misc": {
......@@ -177,11 +192,38 @@
"selectResetText": "Auswahl zurücksetzen."
},
"collectionAllRoleMessage": {
"message": "In this dropdown you can enable seeing all the courses.",
"message": "In diesem Menü kannst du auswählen, ob du alle Kurse sehen möchtest, oder nur die, die du unten auswählst.",
"dropdown": {
"placeholder": "Make a selection.",
"enable": "See all the courses.",
"disable": "See only selected courses."
"placeholder": "Bitte wähle eine Option aus.",
"enable": "Siehe alle Kurse.",
"disable": "Nur die ausgewählten Kurse sehen."
}
},
"collectionRoleMessage": {
"message": "In diesem Menü kannst du die (alphabetisch sortierten) Kurse von $$COURSE1$$ bis $$COURSE2$$ auswählen.",
"underConstruction": "Diese Nachricht wird gerade befüllt, bitte warte kurz.",
"placeholder": "Wähle hier deine Kurse aus".
},
"bulkAddMessage": {
"messages": {
"interactiveOrFileQuery": "Wähl aus, ob du Kurse interaktiv über den Chat oder als Datei hochladen möchtest.",
"interactiveMessage": "Schreibe die Namen der Kurse, die du hinzufügen möchtest, in einzelnen Nachrichten in diesen Chat. Die Maximallänge der Kursnamen ist 99 Zeichen. Wenn ich deine Eingabe erkannt habe, schreibe ich dir eine kurze Antwort.",
"interactiveEnd": "Bitte bestätige, dass du alle Kurse, die ich mit ACK bestätigt habe, hinzufügen möchtest. Wenn irgendwas falsch ist, kannst du hier abbrechen."
},
"interactiveButton": {
"label": "Interaktiv"
},
"fileButton": {
"label": "NOT YET IMPLEMENTED Datei"
},
"endButton": {
"label": "Beenden"
},
"confirmButton": {
"label": "Bestätigen"
},
"cancelButton": {
"label": "Abbrechen"
}
}
}
......
......@@ -81,7 +81,8 @@
},
"delete_collection": {
"description": "Delete a course collection.",
"collectionCategoryDescription": "Category of the course collection."
"collectionCategoryDescription": "Category of the course collection.",
"deleteChannelDescription": "Should the text channels be deleted?"
},
"add_course_to_collection": {
"description": "Add a course to a course collection.",
......@@ -128,7 +129,7 @@
"permConfig": {
"replyAssign": "Role $$ROLE$$ has been aded to $$PERM$$ permission.",
"replyRevoke": "Role $$ROLE$$ has been removed from $$PERM$$ permission.",
"replyList": "List of Permissions:\n\nRole Menu: $$ROLEMENU$$\nLocale: $$LOCALE$$",
"replyList": "List of Permissions:\n\nRole Menu: $$ROLEMENU$$\nLocale: $$LOCALE$$\nCourse Collection: $$COLLECTION$$\nManage member status of roles: $$MEMBERMANAGEMENT",
"accessDenied": "Only administrators can access this command."
},
"roleMenu": {
......@@ -164,10 +165,24 @@
},
"courseCollections": {
"accessDenied": "You are not authorized to do this.",
"collectionAdded": "The collection has been successfully added.",
"collectionAdded": "The collection has been successfully added. Please move the collection role to the appropriate position.",
"collectionNotAdded": "There was an error adding the collection.",
"collectionDeleted": "The collection has been successfully deleted.",
"collectionNotDeleted": "There was an error deleting the collection."
"collectionNotDeleted": "There was an error deleting the collection.",
"courseAdded": "The course has been successfully added.",
"courseNotAdded": "There was an error adding the course.",
"selectCourseChannel": "Please select a course channel.",
"courseDeleted": "The course has been successfully deleted.",
"courseNotDeleted": "There was an error deleting the course.",
"coursesAdded": "You have been added to these courses: $$COURSES$$.",
"coursesAddedEmpty": "You have been removed from all courses in this menu.",
"enableAllCourses": "You can now see all courses for this collection.",
"disableAllCourses": "You can now only see the courses you select.",
"bulkInteractionStarted": "Go to your DM with me and follow my instructions to bulk add courses.",
"internalError": "Internal error encountered, please contact an administrator.",
"bulkInteractionSuccess": "You have successfully added these courses to the collection.",
"bulkInteractionCancel": "You have canceled this bulk add interaction.",
"bulkInteractionInteractiveAck": "$$COURSE$$ has been added to the list of courses to be added."
}
},
"misc": {
......@@ -183,6 +198,33 @@
"enable": "See all the courses.",
"disable": "See only selected courses."
}
},
"collectionRoleMessage": {
"message": "You can select courses between $$COURSE1$$ and $$COURSE2$$ here.",
"underConstruction": "This message is under construction. Please wait.",
"placeholder": "Select your courses here"
},
"bulkAddMessage": {
"messages": {
"interactiveOrFileQuery": "Select whether you want to enter courses interactively in this chat or upload a file.",
"interactiveMessage": "Please write the names of the courses you want to add one by one as messages into this DM channel. Only Lengths of less than 100 characters are allowed.",
"interactiveEnd": "Please confirm the courses to be added or cancel this interaction if something is wrong."
},
"interactiveButton": {
"label": "Interactive"
},
"fileButton": {
"label": "NOT YET IMPLEMENTED File"
},
"endButton": {
"label": "End"
},
"confirmButton": {
"label": "Confirm"
},
"cancelButton": {
"label": "Cancel"
}
}
}
}
......
......@@ -10,10 +10,24 @@ const CollectionBulkAddInteractionSchema = new Schema({
type: String,
required: true
},
collection: {
dmMessage: {
type: String
},
col: {
type: Schema.Types.ObjectId,
ref: 'coursecollection'
}
ref: 'coursecol',
required: true
},
state: {
type: String,
required: true
},
trashMessages: [{
type: String
}],
courses: [{
type: String
}]
});
module.exports = model('collectionbulkaddinteraction', CollectionBulkAddInteractionSchema);
\ No newline at end of file
module.exports = model('colbulkaddinteraction', CollectionBulkAddInteractionSchema);
\ No newline at end of file
......@@ -23,17 +23,12 @@ const CourseCollectionSchema = new Schema({
roleID: {
type: String
},
messageID: {
type: String
},
messageValue: {
type: String
}
}],
roleMessages: [{
messageID: {
type: String
}
type: String
}],
selectAllMessage: {
type: String
......@@ -44,7 +39,6 @@ const CourseCollectionSchema = new Schema({
});
CourseCollectionSchema.index({
guildID: 1,
categoryID: 1
......@@ -52,4 +46,4 @@ CourseCollectionSchema.index({
unique: true
});
module.exports = model('coursecollection', CourseCollectionSchema);
\ No newline at end of file
module.exports = model('coursecol', CourseCollectionSchema);
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment