Commit 83bf0819 authored by Yashin's avatar Yashin
Browse files

Starting to implement course collections.

parent 8e90be50
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="58" name="JavaScript" />
</Languages>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
const {SlashCommandBuilder} = require('@discordjs/builders');
const locale = require('../util/locale');
module.exports = (loc) => {
const commandLocale = locale.get(loc).slashCommands.create_collection;
return new SlashCommandBuilder()
.setName('add_collection')
.setDescription(commandLocale.description)
.addStringOption((option) =>
option.setName('name')
.setDescription(commandLocale.nameDescription)
.setRequired(true))
.addStringOption((option) =>
option.setName('role_channel_name')
.setDescription(commandLocale.roleChannelNameDescription)
.setRequired(true));
}
\ No newline at end of file
const {SlashCommandBuilder} = require('@discordjs/builders');
const locale = require('../util/locale');
module.exports = (loc) => {
const commandLocale = locale.get(loc).slashCommands.add_course_to_collection;
return new SlashCommandBuilder()
.setName('add_course_to_collection')
.setDescription(commandLocale.description)
.addStringOption((option) =>
option.setName('course')
.setDescription(commandLocale.courseDescription)
.setRequired(true))
.addChannelOption((option) =>
option.setName('collection_category')
.setDescription(commandLocale.categoryCollectionDescription)
.setRequired(true));
}
\ No newline at end of file
......@@ -12,7 +12,8 @@ module.exports = (loc) => {
.setDescription(commandLocale.permissionDescription)
.setRequired(true)
.addChoice(commandLocale.permissionChoices.roleMenus, 'role_menu')
.addChoice(commandLocale.permissionChoices.locale, 'locale'))
.addChoice(commandLocale.permissionChoices.locale, 'locale')
.addChoice(commandLocale.permissionChoices.collection, 'collection'))
.addRoleOption(option =>
option.setName('role')
.setDescription(commandLocale.roleDescription)
......
const {SlashCommandBuilder} = require('@discordjs/builders');
const locale = require('../util/locale');
module.exports = (loc) => {
const commandLocale = locale.get(loc).slashCommands.delete_collection;
return new SlashCommandBuilder()
.setName('delete_collection')
.setDescription(commandLocale.description)
.addChannelOption( (option) =>
option.setName('collection_category')
.setDescription(commandLocale.collectionCategoryDescription)
.setRequired(true));
}
\ No newline at end of file
const {SlashCommandBuilder} = require('@discordjs/builders');
const locale = require('../util/locale');
module.exports = (loc) => {
const commandLocale = locale.get(loc).slashCommands.delete_course_from_collection;
return new SlashCommandBuilder()
.setName('delete_course_from_collection')
.setDescription(commandLocale.description)
.addChannelOption((option) =>
option.setName('course_channel')
.setDescription(commandLocale.courseChannelDescription)
.setRequired(true))
.addBooleanOption((option) =>
option.setName('keep_channel')
.setDescription(commandLocale.keepChannelDescription)
.setRequired(true));
}
\ No newline at end of file
const {SlashCommandBuilder} = require('@discordjs/builders');
const locale = require('../util/locale');
module.exports = (loc) => {
const commandLocale = locale.get(loc).slashCommands.edit_collection;
return new SlashCommandBuilder()
.setName('edit_collection')
.setDescription(commandLocale.description)
.addChannelOption((option) =>
option.setName('collection_category')
.setDescription(commandLocale.collectionCategoryDescription)
.setRequired(true))
.addStringOption((option) =>
option.setName('name')
.setDescription(commandLocale.nameDescription));
}
\ No newline at end of file
......@@ -11,7 +11,9 @@ module.exports = (loc) => {
option.setName('permission')
.setDescription(commandLocale.permissionDescription)
.setRequired(true)
.addChoice(commandLocale.permissionChoices.roleMenus, 'role_menu'))
.addChoice(commandLocale.permissionChoices.roleMenus, 'role_menu')
.addChoice(commandLocale.permissionChoices.locale, 'locale')
.addChoice(commandLocale.permissionChoices.collection, 'collection'))
.addRoleOption(option =>
option.setName('role')
.setDescription(commandLocale.roleDescription)
......
const ServerConfig = require('../models/ServerConfig');
const CourseCollection = require('../models/CourseCollection');
const locales = require("../util/locale");
const checkPerm = require("../util/perm");
async function createCollection(interaction) {
const config = await ServerConfig.findOne({guildID: interaction.guild.id.toString()});
let locale = 'en';
if (config != null) {
locale = config.locale;
}
const functionLocale = locales.get(locale).components.courseCollections;
if (!(await checkPerm(interaction.member, 'collection'))) {
await interaction.reply({content: functionLocale.accessDenied, ephemeral: true})
return;
}
//TODO
}
async function deleteCollection(interaction) {
const config = await ServerConfig.findOne({guildID: interaction.guild.id.toString()});
let locale = 'en';
if (config != null) {
locale = config.locale;
}
const functionLocale = locales.get(locale).components.courseCollections;
if (!(await checkPerm(interaction.member, 'collection'))) {
await interaction.reply({content: functionLocale.accessDenied, ephemeral: true})
return;
}
//TODO
}
async function addCourseToCollection(interaction) {
const config = await ServerConfig.findOne({guildID: interaction.guild.id.toString()});
let locale = 'en';
if (config != null) {
locale = config.locale;
}
const functionLocale = locales.get(locale).components.courseCollections;
if (!(await checkPerm(interaction.member, 'collection'))) {
await interaction.reply({content: functionLocale.accessDenied, ephemeral: true})
return;
}
//TODO
}
async function deleteCourseFromCollection(interaction) {
const config = await ServerConfig.findOne({guildID: interaction.guild.id.toString()});
let locale = 'en';
if (config != null) {
locale = config.locale;
}
const functionLocale = locales.get(locale).components.courseCollections;
if (!(await checkPerm(interaction.member, 'collection'))) {
await interaction.reply({content: functionLocale.accessDenied, ephemeral: true})
return;
}
//TODO
}
async function editCollection(interaction) {
const config = await ServerConfig.findOne({guildID: interaction.guild.id.toString()});
let locale = 'en';
if (config != null) {
locale = config.locale;
}
const functionLocale = locales.get(locale).components.courseCollections;
if (!(await checkPerm(interaction.member, 'collection'))) {
await interaction.reply({content: functionLocale.accessDenied, ephemeral: true})
return;
}
//TODO
}
const slashCommandHandler = async (interaction) => {
if (interaction.commandName === 'create_collection') {
await createCollection(interaction);
} else if (interaction.commandName === 'delete_collection') {
await deleteCollection(interaction);
} else if (interaction.commandName === 'add_course_to_collection') {
await addCourseToCollection(interaction);
} else if (interaction.commandName === 'delete_course_from_collection') {
await deleteCourseFromCollection(interaction);
} else if (interaction.commandName === 'edit_collection') {
await editCollection(interaction);
}
}
const selectMenuHandler = async (interaction) => {
if (interaction.customId === 'selectCourse') {
//TODO
} else if (interaction.customId === 'selectAllCourses') {
//TODO
}
}
module.exports = {
slashCommandHandler,
selectMenuHandler
}
\ No newline at end of file
......@@ -314,20 +314,20 @@ const selectMenuHandler = async (interaction) => {
channelID: channel.id,
messageID: message.id
});
if (menu != null) {
if (interaction.values[0] === 'select_reset') {
const roleIDs = menu.roles.map(role => role.roleID);
roleIDs.forEach(roleID => interaction.member.roles.remove(roleID));
await interaction.reply({content: functionLocale.interactionMessage.roleRemoved, ephemeral: true});
} else {
const roleIDs = menu.roles.map(role => role.roleID);
roleIDs.forEach(roleID => interaction.member.roles.remove(roleID));
interaction.member.roles.add(roleIDs[menu.roles.map(role => role.value).indexOf(interaction.values[0])]);
await interaction.reply({content: functionLocale.interactionMessage.roleAdded, ephemeral: true});
}
if (menu != null) {
if (interaction.values[0] === 'select_reset') {
const roleIDs = menu.roles.map(role => role.roleID);
roleIDs.forEach(roleID => interaction.member.roles.remove(roleID));
await interaction.reply({content: functionLocale.interactionMessage.roleRemoved, ephemeral: true});
} else {
await interaction.reply({content: functionLocale.internalError, ephemeral: true});
const roleIDs = menu.roles.map(role => role.roleID);
roleIDs.forEach(roleID => interaction.member.roles.remove(roleID));
interaction.member.roles.add(roleIDs[menu.roles.map(role => role.value).indexOf(interaction.values[0])]);
await interaction.reply({content: functionLocale.interactionMessage.roleAdded, ephemeral: true});
}
} else {
await interaction.reply({content: functionLocale.internalError, ephemeral: true});
}
}
}
module.exports = {
......
......@@ -8,7 +8,8 @@
"permissionDescription": "Berechtigung, die hinzugefügt werden soll.",
"permissionChoices": {
"roleMenus": "Rollenmenüs",
"locale": "Sprache wechseln"
"locale": "Sprache wechseln",
"collection": "Veranstaltungssammlungen"
},
"roleDescription": "Rolle, der die Berechtigung hinzugefügt werden soll."
},
......@@ -17,7 +18,8 @@
"permissionDescription": "Berechtigung, die entzogen werden soll.",
"permissionChoices": {
"roleMenus": "Rollenmenüs",
"locale": "Sprache wechseln"
"locale": "Sprache wechseln",
"collection": "Veranstaltungssammlungen"
},
"roleDescription": "Rolle, der die Berechtigung entzogen werden soll."
},
......@@ -69,6 +71,30 @@
"change_locale": {
"description": "Die Sprache des Servers wechseln.",
"localeDescription": "Sprache, zu der gewechselt werden soll."
},
"add_collection": {
"description": "Eine neue Sammlung an Veranstaltungen erstellen.",
"nameDescription": "Name der neuen Sammlung.",
"roleChannelNameDescription": "Name des Textkanals mit den Auswahlmenüs."
},
"delete_collection": {
"description": "Eine Veranstaltungssammlung löschen.",
"collectionCategoryDescription": "Kategorie der Veranstaltungssammlung."
},
"add_course_to_collection": {
"description": "Eine Veranstaltung zur Sammlung hinzufügen.",
"courseDescription": "Name der Veranstaltung.",
"collectionCategoryDescription": "Kategorie der Veranstaltungssammlung."
},
"delete_course_from_collection": {
"description": "Eine Veranstaltung aus der Sammlung entfernen.",
"courseChannelDescription": "Veranstaltung die entfernt werden soll.",
"keepChannelDescription": "Kanal der Veranstaltung behalten."
},
"edit_collection": {
"description": "Eine Veranstaltungssammlung bearbeiten.",
"collectionCategoryDescription": "Kategorie der Veranstaltungssammlung.",
"nameDescription": "Neuer Name der Veranstaltungsversammlung."
}
},
"components": {
......@@ -79,9 +105,9 @@
},
"permConfig": {
"replyAssign": "Der Rolle $$ROLE$$ wurde die $$PERM$$ Berechtigung hinzugefügt.",
"replyRevoke": "Der Rolle $ROLE$$ wurde die $$PERM$$ Berechtigung entzogen.",
"replyRevoke": "Der Rolle $$ROLE$$ wurde die $$PERM$$ Berechtigung entzogen.",
"replyList": "Liste der Berechtigungen:\n\nRollenmenüs: $$ROLEMENU$$\nSprache ändern $$LOCALE$$",
"accessDenied": "Nur administratoren dürfen diesen Command nutzen."
"accessDenied": "Nur Administratoren dürfen diesen Command nutzen."
},
"roleMenu": {
"accessDenied": "Du darfst diesen Command nicht nutzen.",
......
......@@ -8,7 +8,8 @@
"permissionDescription": "Permission to assign.",
"permissionChoices": {
"roleMenus": "Role Menus",
"locale": "Change Locales"
"locale": "Change Locales",
"collection": "Course Collection"
},
"roleDescription": "Role to assign permission to."
},
......@@ -17,7 +18,8 @@
"permissionDescription": "Permission to revoke.",
"permissionChoices": {
"roleMenus": "Role Menus",
"locale": "Change Locales"
"locale": "Change Locales",
"collection": "Course Collection"
},
"roleDescription": "Role to revoke permission from."
},
......@@ -69,6 +71,30 @@
"change_locale": {
"description": "Change locale of the bot on this server.",
"localeDescription": "Locale you want to change to bot to."
},
"add_collection": {
"description": "Create a new course collection.",
"nameDescription": "Name of the new collection.",
"roleChannelNameDescription": "Name of the menu channel."
},
"delete_collection": {
"description": "Delete a course collection.",
"collectionCategoryDescription": "Category of the course collection."
},
"add_course_to_collection": {
"description": "Add a course to a course collection.",
"courseDescription": "Name of the course.",
"collectionCategoryDescription": "Category of the course collection."
},
"delete_course_from_collection": {
"description": "Delete a course from a course collection.",
"courseChannelDescription": "Course to be deleted.",
"keepChannelDescription": "Keep the channel of the course?"
},
"edit_collection": {
"description": "Edit a course collection.",
"collectionCategoryDescription": "Category of the course collection.",
"nameDescription": "New name of the course collection."
}
},
"components": {
......
const {Schema, model} = require('mongoose');
const CourseCollectionSchema = new Schema({
guildID: {
type: String,
required: true
},
categoryID: {
type: String,
required: true
},
roleChannelID: {
type: String,
required: true
},
courses: [{
name: {
type: String
},
channelID: {
type: String
},
roleID: {
type: String
},
messageID: {
type: String
},
messageValue: {
type: String
}
}],
roleMessages: [{
messageID: {
type: String
}
}],
selectAllMessage: {
type: String
}
});
CourseCollectionSchema.index({
guildID: 1,
categoryID: 1
}, {
unique: true
});
module.exports = model('coursecollection', CourseCollectionSchema);
\ No newline at end of file
......@@ -17,6 +17,9 @@ const ServerConfigSchema = new Schema({
}],
locale: [{
type: String
}],
collection: [{
type: String
}]
}
});
......
......@@ -11,6 +11,8 @@ module.exports = async (member, permission) => {
return member.roles.cache.some((role) => config.permissions.roleMenu.some((prole) => prole == role.id.toString())) || member.permissions.has(Permissions.FLAGS.ADMINISTRATOR);
} else if (permission === 'locale') {
return member.roles.cache.some((role) => config.permissions.locale.some((prole) => prole == role.id.toString())) || member.permissions.has(Permissions.FLAGS.ADMINISTRATOR);
} else if (permission === 'collection') {
return member.roles.cache.some((role) => config.permissions.collection.some((prole) => prole == role.id.toString())) || member.permissions.has(Permissions.FLAGS.ADMINISTRATOR);
}
return false;
}
\ 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