Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add moderator types #36

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/commands/mod-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const { modal: modApplicationModal } = require('../modals/mod-application');
* @param {Discord.CommandInteraction} interaction
*/
async function modApplicationHandler(interaction) {
modApplicationModal.setCustomId("mod-application-" + interaction.options.get('role').value);

interaction.showModal(modApplicationModal, {
client: interaction.client,
interaction: interaction
Expand All @@ -16,11 +18,22 @@ async function modApplicationHandler(interaction) {
const command = new SlashCommandBuilder()
.setDefaultMemberPermissions(Discord.PermissionFlagsBits.SendMessages)
.setName('mod-application')
.setDescription('Apply for a position as a moderator');
.setDescription('Apply for a position as a moderator.')
.addStringOption(option =>
option.setName('role')
.setDescription('Moderator type to apply to.')
.setRequired(true)
.addChoices(
{ name: 'Discord Moderator', value: 'discord' },
{ name: 'Discord VC Moderator', value: 'vc' },
{ name: 'Forum Moderator', value: 'forum' },
{ name: 'Network Moderator', value: 'network' },
{ name: 'Juxtaposition Moderator', value: 'juxt' }
));

module.exports = {
name: command.name,
help: 'Displays a popup modal to apply for a moderator position.\n```\nUsage: /mod-application\n```',
help: 'Displays a popup modal to apply for a moderator position.\n```\nUsage: /mod-application role\n```',
handler: modApplicationHandler,
deploy: command.toJSON()
};
4 changes: 4 additions & 0 deletions src/commands/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const editableOptions = [
'unverified_role_id',
'developer_role_id',
'mod_applications_channel_id',
'vc_mod_apps_channel_id',
'forum_mod_apps_channel_id',
'network_mod_apps_channel_id',
'juxt_mod_apps_channel_id',
'reports_channel_id',
'readme_channel_id',
'rules_channel_id',
Expand Down
40 changes: 38 additions & 2 deletions src/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ async function connect() {
unverified_role_id TEXT,
developer_role_id TEXT,
mod_applications_channel_id TEXT,
vc_mod_apps_channel_id TEXT,
forum_mod_apps_channel_id TEXT,
network_mod_apps_channel_id TEXT,
juxt_mod_apps_channel_id TEXT,
reports_channel_id TEXT,
readme_channel_id TEXT,
rules_channel_id TEXT,
Expand All @@ -34,15 +38,47 @@ async function connect() {
UNIQUE(guild_id)
)`);

// This adds an ay_lmao_disabled column to the server settings table, if missing.
// This adds items to the server settings table, if missing.
let hasAyLmaoColumn = false;
let hasVCModApps = false;
let hasForumModApps = false;
let hasNetworkModApps = false;
let hasJuxtModApps = false;
await database.each('SELECT * FROM pragma_table_info(\'server_settings\')', (_err, row) => {
if (row.name === 'ay_lmao_disabled') hasAyLmaoColumn = true;
switch(row.name) {
case 'ay_lmao_disabled':
hasAyLmaoColumn = true;
break;
case 'vc_mod_apps_channel_id':
hasVCModApps = true;
break;
case 'forum_mod_apps_channel_id':
hasForumModApps = true;
break;
case 'network_mod_apps_channel_id':
hasNetworkModApps = true;
break;
case 'juxt_mod_apps_channel_id':
hasJuxtModApps = true;
break;
}
});

if (!hasAyLmaoColumn) {
await database.run('ALTER TABLE server_settings ADD ay_lmao_disabled INTEGER DEFAULT 0 NOT NULL;');
}
if (!hasVCModApps) {
await database.run('ALTER TABLE server_settings ADD vc_mod_apps_channel_id TEXT;');
}
if (!hasForumModApps) {
await database.run('ALTER TABLE server_settings ADD forum_mod_apps_channel_id TEXT;');
}
if (!hasNetworkModApps) {
await database.run('ALTER TABLE server_settings ADD network_mod_apps_channel_id TEXT;');
}
if (!hasJuxtModApps) {
await database.run('ALTER TABLE server_settings ADD juxt_mod_apps_channel_id TEXT;');
}

await database.run(`CREATE TABLE IF NOT EXISTS nlp_disabled (
guild_id TEXT,
Expand Down
43 changes: 40 additions & 3 deletions src/modals/mod-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async function modApplicationHandler(interaction) {
ephemeral: true
});

const modType = interaction.customId.split('-').pop();
const experience = interaction.fields.getTextInputValue('experience');
const timezone = interaction.fields.getTextInputValue('timezone');
const availablity = interaction.fields.getTextInputValue('availablity');
Expand All @@ -72,7 +73,26 @@ async function modApplicationHandler(interaction) {
const applyingMember = await interaction.member.fetch();
const guild = await interaction.guild.fetch();

const channelId = await database.getGuildSetting(interaction.guildId, 'mod_applications_channel_id');
var selectedDBItem = '';
switch(modType) {
case 'discord':
selectedDBItem = 'mod_applications_channel_id';
break;
case 'vc':
selectedDBItem = 'vc_mod_apps_channel_id';
break;
case 'forum':
selectedDBItem = 'forum_mod_apps_channel_id';
break;
case 'network':
selectedDBItem = 'network_mod_apps_channel_id';
break;
case 'juxt':
selectedDBItem = 'juxt_mod_apps_channel_id';
break;
}

const channelId = await database.getGuildSetting(interaction.guildId, selectedDBItem);
const channel = channelId && await guild.channels.fetch(channelId);

if (!channel) {
Expand All @@ -82,8 +102,25 @@ async function modApplicationHandler(interaction) {
const modApplicationEmbed = new Discord.EmbedBuilder();

modApplicationEmbed.setColor(0x9D6FF3);
modApplicationEmbed.setTitle('Mod Application');
modApplicationEmbed.setDescription(`<@${applyingMember.user.id}> has submitted a moderator application`);

switch(modType) {
case 'discord':
modApplicationEmbed.setTitle('Discord Mod Application');
break;
case 'vc':
modApplicationEmbed.setTitle('VC Mod Application');
break;
case 'forum':
modApplicationEmbed.setTitle('Forum Mod Application');
break;
case 'network':
modApplicationEmbed.setTitle('Network Mod Application');
break;
case 'juxt':
modApplicationEmbed.setTitle('Juxt Mod Application');
break;
}
modApplicationEmbed.setDescription(`<@${applyingMember.user.id}> has submitted a ${modType} moderator application`);
modApplicationEmbed.setImage('attachment://pending-banner.png');
modApplicationEmbed.setThumbnail('attachment://pending-icon.png');
modApplicationEmbed.setAuthor({
Expand Down
Loading