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 induction command #13

Merged
merged 4 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
75 changes: 75 additions & 0 deletions src/commands/induct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");

const wait = require("util").promisify(setTimeout);

module.exports = {
data: new SlashCommandBuilder()
.setDMPermission(false)
.setDefaultMemberPermissions(0x10000000)
.setName("induct")
.setDescription(
"Gives a user the @Guest role, then sends a message in #general saying hello."
)
.addUserOption((option) =>
option
.setName("user")
.setDescription("The user to induct.")
.setRequired(true)
),
async execute(interaction) {
let dt = new Date().toUTCString();
await interaction.deferReply({ ephemeral: true });
await wait(1000);

let user = interaction.options.getUser("user");
await interaction.guild.members.fetch();
await interaction.guild.channels.fetch();
let guildUser = interaction.guild.members.cache.find(
(u) => u.id === user.id
);

let general, roles, role;

try {
general = interaction.guild.channels.cache.find(
(c) => c.name === "general"
);
} catch (error) {
console.log(`${dt} - Error: #general does not exist on this guild.`);
}

try {
roles = interaction.guild.channels.cache.find((c) => c.name === "roles");
} catch (error) {
console.log(`${dt} - Error: #roles does not exist on this guild.`);
}

let message = `Hey everyone! Please welcome ${user} to CSS - remember to grab your roles in ${roles} and say hello to everyone here!`;

try {
role = interaction.guild.roles.cache.find((r) => r.name === "Guest");
} catch (error) {
console.log(`{dt} - Error: @Guest does not exist on this guild.`);
LMBishop marked this conversation as resolved.
Show resolved Hide resolved
}

await guildUser.roles.add(role);

if (general.send(message)) {
console.log(
`${dt} - Warning: ${interaction.user.tag} has inducted ${guildUser.user.tag} into CSS.`
);
await interaction.editReply({
content: "User inducted successfully.",
ephemeral: true,
});
} else {
console.log(
`${dt} - Warning: An error occured during ${interaction.user.tag}'s induction of ${guildUser.user.tag}`
);
await interaction.editReply({
content: "Something has gone wrong.",
ephemeral: true,
});
}
},
};
15 changes: 11 additions & 4 deletions src/commands/makeMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
),
usedIDs: [],
async execute(interaction) {
let dt = new Date().toUTCString();
await interaction.deferReply({ ephemeral: true });
await wait(1000);

Expand All @@ -40,13 +41,15 @@ module.exports = {
const enc = hash.digest("hex");

if (interaction.member.roles.cache.find((r) => r.name === "Member")) {
console.log(`Warning: ${interaction.user.tag} is already a member`);
console.log(
`${dt} - Warning: ${interaction.user.tag} is already a member`
);
return await interaction.editReply({
content: "You're already a member - why are you trying this again?",
});
} else if (this.usedIDs.includes(enc)) {
console.log(
`Warning: ${interaction.user.tag} tried using an ID that has already been used.`
`Warning: $${dt} - {interaction.user.tag} tried using an ID that has already been used.`
LMBishop marked this conversation as resolved.
Show resolved Hide resolved
);
return await interaction.editReply({
content:
Expand All @@ -65,14 +68,18 @@ module.exports = {
);
await interaction.member.roles.add(role).catch(console.error);

console.log(`Warning: ${interaction.user.tag} has been made a member.`);
console.log(
`${dt} - Warning: ${interaction.user.tag} has been made a member.`
);

await interaction.editReply({
content: "Made you a Member!",
ephemeral: true,
});
} else {
console.log(`Warning: ${interaction.user.tag} used an invalid ID.`);
console.log(
`${dt} - Warning: ${interaction.user.tag} used an invalid ID.`
);
await interaction.editReply({
content:
"Invalid Student ID supplied. Please contact a Committee member.",
Expand Down
2 changes: 2 additions & 0 deletions src/commands/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module.exports = {
.setName("ping")
.setDescription("Replies with Pong!"),
async execute(interaction) {
let dt = new Date().toUTCString();
console.log(`${dt} - Warning: ${interaction.user.tag} made me pong!!s`);
await interaction.reply("Pong!");
},
};
8 changes: 2 additions & 6 deletions src/events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
module.exports = {
name: "interactionCreate",
execute(interaction) {
console.log(
`${interaction.user.tag} in #${interaction.channel.name} triggered an interaction.`
);

if (!interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);
Expand All @@ -14,8 +10,8 @@ module.exports = {
try {
command.execute(interaction);
} catch (err) {
console.error(err);
interaction.reply({
console.error(`${dt} - ${err}`);
interaction.replsy({
content: "There was an errour while executing this command.",
LMBishop marked this conversation as resolved.
Show resolved Hide resolved
ephemeral: true,
});
Expand Down