This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from MCUxDaredevil/main
Add config.json file and loa slash command
- Loading branch information
Showing
3 changed files
with
197 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,90 @@ | ||
const { MessageEmbed } = require('discord.js'); | ||
const getFiles = require('../utils/getFiles'); | ||
const config = require('../config.json'); | ||
require('dotenv').config(); | ||
|
||
module.exports = (client) => { | ||
const path = '\\commands'; | ||
const commands = []; | ||
const commandFiles = getFiles(`${path}\\normal`, '.js'); | ||
|
||
for (const command of commandFiles) { | ||
const split = command.replace(/\\/g, '/').split('/'); | ||
const commandName = split[split.length - 1].replace('.js', ''); | ||
commands[commandName.toLowerCase()] = require(command); | ||
} | ||
client.on('messageCreate', (message) => { | ||
const extCommands = [ | ||
['bread', () => { for (const i of '🍞🇧 🇷 🇪 🇦 🇩👍') { if (i != ' ') message.react(i) }}], | ||
['pineapple', () => message.react('🍍')], | ||
['cheese', () => message.react('🧀')], | ||
['forgor', () => message.react('💀')] | ||
] | ||
if (!message.author.bot) { | ||
if (!message.content.startsWith(process.env.PREFIX)) { | ||
for (const msg of extCommands) { | ||
if (message.content.toLowerCase().includes(msg[0])) { | ||
if (typeof(msg[1]) != 'string') return msg[1](); | ||
else return message.channel.send(msg[1]); | ||
}; | ||
}; | ||
return; | ||
} else { | ||
const args = message.content.slice(process.env.PREFIX.length).trim().split(/ +/); | ||
const commandName = args.shift().toLowerCase(); | ||
try { | ||
commands[commandName].callback(message, args); | ||
} catch (error) { | ||
console.error(error); | ||
const path = '\\commands'; | ||
const commands = []; | ||
const commandFiles = getFiles(`${path}\\normal`, '.js'); | ||
|
||
const embed = new MessageEmbed() | ||
.setTitle('An error occured while executing that command.') | ||
.setColor('RED'); | ||
for (const command of commandFiles) { | ||
const split = command.replace(/\\/g, '/').split('/'); | ||
const commandName = split[split.length - 1].replace('.js', ''); | ||
commands[commandName.toLowerCase()] = require(command); | ||
} | ||
client.on('messageCreate', (message) => { | ||
const extCommands = [ | ||
[ | ||
'bread', | ||
() => { | ||
for (const i of '🍞🇧 🇷 🇪 🇦 🇩👍') { | ||
if (i != ' ') message.react(i); | ||
} | ||
}, | ||
], | ||
['pineapple', () => message.react('🍍')], | ||
['cheese', () => message.react('🧀')], | ||
['forgor', () => message.react('💀')], | ||
]; | ||
if (!message.author.bot) { | ||
if (!message.content.startsWith(process.env.PREFIX)) { | ||
for (const msg of extCommands) { | ||
if (message.content.toLowerCase().includes(msg[0])) { | ||
if (typeof msg[1] != 'string') return msg[1](); | ||
else return message.channel.send(msg[1]); | ||
} | ||
} | ||
return; | ||
} else { | ||
const args = message.content.slice(process.env.PREFIX.length).trim().split(/ +/); | ||
const commandName = args.shift().toLowerCase(); | ||
try { | ||
commands[commandName].callback(message, args); | ||
} catch (error) { | ||
console.error(error); | ||
|
||
message.channel.send({ embeds: [embed] }); | ||
} | ||
} | ||
} else return; | ||
}); | ||
const embed = new MessageEmbed().setTitle('An error occured while executing that command.').setColor('RED'); | ||
|
||
const slashCommands = []; | ||
const slashCommandFiles = getFiles(`${path}\\slash`, '.js'); | ||
const guild = client.guilds.cache.get('986268144446341142'); | ||
for (const slashCommand of slashCommandFiles) { | ||
let slashCommandFile = require(slashCommand); | ||
slashCommands[slashCommandFile.name.toLowerCase()] = slashCommandFile; | ||
slashCommands.push(slashCommandFile); | ||
}; | ||
guild.commands.set(slashCommands); | ||
global.pollsList = {}; | ||
client.on('interactionCreate', (interaction) => { | ||
if (!interaction.isCommand()) { | ||
if (interaction.isButton()) { | ||
if (interaction.customId.substring(0,4) == 'poll') { | ||
const pollId = interaction.customId.substring(5, 10); | ||
let embed = new MessageEmbed() | ||
if (global.pollsList[pollId][interaction.user.id]) embed.setTitle('You have already voted for this poll').setColor('RED'); | ||
else { | ||
global.pollsList[pollId][interaction.user.id] = interaction.customId; | ||
embed.setTitle(`You successfully voted for **${getLabel(pollId, interaction.customId.substring(11,13))}**`).setColor('GREEN'); | ||
} | ||
return interaction.reply({embeds: [embed], ephemeral: true }); | ||
} else return; | ||
} else return; | ||
} else { | ||
try { | ||
slashCommands[interaction.commandName].callback(interaction); | ||
} catch (error) { | ||
console.error(error); | ||
message.channel.send({ embeds: [embed] }); | ||
} | ||
} | ||
} else return; | ||
}); | ||
|
||
const embed = new MessageEmbed() | ||
.setTitle('An error occured while executing that command.') | ||
.setColor('RED') | ||
interaction.reply({ embeds: [embed], ephemeral: true }); | ||
} | ||
} | ||
}); | ||
const slashCommands = []; | ||
const slashCommandFiles = getFiles(`${path}\\slash`, '.js'); | ||
const guild = client.guilds.cache.get(config.server); | ||
for (const slashCommand of slashCommandFiles) { | ||
let slashCommandFile = require(slashCommand); | ||
slashCommands[slashCommandFile.name.toLowerCase()] = slashCommandFile; | ||
slashCommands.push(slashCommandFile); | ||
} | ||
guild.commands.set(slashCommands); | ||
global.pollsList = {}; | ||
client.on('interactionCreate', (interaction) => { | ||
if (!interaction.isCommand()) { | ||
if (interaction.isButton()) { | ||
if (interaction.customId.substring(0, 4) == 'poll') { | ||
const pollId = interaction.customId.substring(5, 10); | ||
let embed = new MessageEmbed(); | ||
if (global.pollsList[pollId][interaction.user.id]) embed.setTitle('You have already voted for this poll').setColor('RED'); | ||
else { | ||
global.pollsList[pollId][interaction.user.id] = interaction.customId; | ||
embed.setTitle(`You successfully voted for **${getLabel(pollId, interaction.customId.substring(11, 13))}**`).setColor('GREEN'); | ||
} | ||
return interaction.reply({ embeds: [embed], ephemeral: true }); | ||
} else return; | ||
} else return; | ||
} else { | ||
try { | ||
slashCommands[interaction.commandName].callback(interaction); | ||
} catch (error) { | ||
console.error(error); | ||
|
||
const embed = new MessageEmbed().setTitle('An error occured while executing that command.').setColor('RED'); | ||
interaction.reply({ embeds: [embed], ephemeral: true }); | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const config = require('../../config.json'); | ||
const { MessageEmbed } = require('discord.js'); | ||
|
||
module.exports = { | ||
name: 'loa', | ||
description: 'Apply or Return LOA', | ||
options: [ | ||
{ | ||
type: 'SUB_COMMAND', | ||
name: 'apply', | ||
description: 'Apply for LOA', | ||
options: [ | ||
{ | ||
name: 'reason', | ||
description: 'The reason for your leave', | ||
type: 'STRING', | ||
required: true, | ||
}, | ||
{ | ||
name: 'return', | ||
description: 'Time of return from leave', | ||
type: 'STRING', | ||
required: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'SUB_COMMAND', | ||
name: 'return', | ||
description: 'Return from LOA', | ||
}, | ||
], | ||
callback: async (interaction) => { | ||
const options = interaction.options; | ||
if (options._subcommand === 'apply') { | ||
if (!interaction.member.roles.cache.some((r) => r.id === config.devRole)) { | ||
return interaction.reply({ content: 'You need the Developer role to apply for LOA', ephemeral: true }); | ||
} | ||
|
||
if (interaction.member.roles.cache.some((r) => r.id === config.loaRole)) { | ||
return interaction.reply({ content: 'You are already set to LOA', ephemeral: true }); | ||
} | ||
|
||
const dev = interaction.member; | ||
const loaRole = interaction.guild.roles.cache.find((r) => r.id === config.loaRole); | ||
const loaChannel = interaction.guild.channels.cache.find((c) => c.id === config.loaReports); | ||
|
||
const embed = new MessageEmbed({ | ||
title: `\`${dev.user.tag}\` has set their status to LOA`, | ||
color: '#0099ff', | ||
fields: [ | ||
{ | ||
name: 'Reason', | ||
value: options.getString('reason'), | ||
inline: true, | ||
}, | ||
{ | ||
name: 'Return', | ||
value: options.getString('return'), | ||
inline: true, | ||
}, | ||
], | ||
}); | ||
|
||
try { | ||
await dev.setNickname(`[LOA] ${dev.displayName}`); | ||
await dev.roles.add(loaRole); | ||
await loaChannel.send({ embeds: [embed] }); | ||
interaction.reply({ content: 'LOA applied successfully', ephemeral: true }); | ||
} catch (err) { | ||
console.log(err); | ||
interaction.reply({ content: 'Something went wrong', ephemeral: true }); | ||
} | ||
} else if (options._subcommand === 'return') { | ||
if (!interaction.member.roles.cache.some((r) => r.id === config.devRole)) { | ||
return interaction.reply({ content: 'You need the Developer role to return from LOA', ephemeral: true }); | ||
} | ||
|
||
if (!interaction.member.roles.cache.some((r) => r.id === config.loaRole)) { | ||
return interaction.reply({ content: 'You are not set to LOA', ephemeral: true }); | ||
} | ||
|
||
const dev = interaction.member; | ||
const loaRole = interaction.guild.roles.cache.find((r) => r.id === config.loaRole); | ||
const loaChannel = interaction.guild.channels.cache.find((c) => c.id === config.loaReports); | ||
|
||
const embed = new MessageEmbed({ | ||
title: `\`${dev.user.tag}\` has returned from their LOA`, | ||
color: '#0099ff', | ||
}); | ||
|
||
if (dev.displayName.slice(0, 6) !== '[LOA] ') { | ||
await dev.roles.remove(loaRole); | ||
await loaChannel.send({ embeds: [embed] }); | ||
|
||
return interaction.reply({ content: 'It seems that your nickname was altered during your LOA\nNo actions will executed on your nickname', ephemeral: true }); | ||
} | ||
|
||
try { | ||
await dev.setNickname(dev.displayName.slice(6)); | ||
await dev.roles.remove(loaRole); | ||
await loaChannel.send({ embeds: [embed] }); | ||
|
||
interaction.reply({ content: 'LOA returned successfully', ephemeral: true }); | ||
} catch (err) { | ||
console.log(err); | ||
interaction.reply({ content: 'Something went wrong', ephemeral: true }); | ||
} | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"server": "759539934557110272", | ||
"loaReports": "828554084058923038", | ||
"devRole": "988646299039580201", | ||
"loaRole": "988653144365994084" | ||
} |