Skip to content

Commit

Permalink
Massively update commands
Browse files Browse the repository at this point in the history
  • Loading branch information
SherRao committed May 13, 2022
1 parent 31c822f commit dbd1dbb
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 168 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
config.js

# Logs
logs
*.log
Expand Down
92 changes: 0 additions & 92 deletions src/authoriseGoogleSheets.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/commands/minecraft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { getVerifiedUser } = require("../util/users");

const data = new SlashCommandBuilder()
.setName("minecraft")
.setDescription("Links your Discord account to the (Java) Minecraft server and whitelists you.")
.addStringOption(option =>
option.setName("minecraftUsername")
.setDescription("Your Minecraft username to login to the server with..")
.setRequired(true)
);

const execute = async (interaction) => {
const userId = interaction.author.id;
const verifiedUser = await getVerifiedUser(userId);
if(!verifiedUser)
return await interaction.reply("This command can only be used by users who are verified!");

//get user from firestore table.
//check if user already has a minecraft user in the table.
//if not, add user to table AND send their username to the whitelist.
//if so, delete old username from the whitelist, send their new username to the whitelist, and add username to table.
};

module.exports = { data: data, execute: execute, enabled: true, roleRequired: "" };
88 changes: 70 additions & 18 deletions src/commands/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ const data = new SlashCommandBuilder()
.setDescription("The name of the team.")
.setRequired(true)
)
)

.addSubcommand(subCommand =>
subCommand.setName("invite")
.setDescription("Add a user to your team.")
.addUserOption(option =>
option.setName("target")
.setDescription("The user to invite.")
.setRequired(true)
)
)

.addSubcommand(subCommand =>
subCommand.setName("delete")
.setDescription("Delete your team (only if you created the team).")
)

.addSubcommand(subCommand =>
subCommand.setName("leave")
.setDescription("Leave your team.")
)

.addSubcommand(subCommand =>
subCommand.setName("DELETECONFIRM")
)

.addSubcommand(subCommand =>
subCommand.setName("LEAVECONFIRM")
);

const execute = async (interaction) => {
Expand All @@ -27,59 +55,83 @@ const execute = async (interaction) => {

const subCommand = interaction.options.getSubcommand();
switch(subCommand) {
case "create":{
case "create": {
if(team)
return await interaction.reply("You are already in a team!");
return await interaction.reply("You are already in a team!");

createTeam(verifiedUser);
const name = interaction.options.getStringOption("name");
createTeam(verifiedUser, name);
break;
}

case "invite":{
case "invite": {
if(!team)
return await interaction.reply("You are not in a team!");
return await interaction.reply("You are not in a team!");

if(!captainId)
return await interaction.reply("You are not the captain of your team!");
return await interaction.reply("You are not the captain of your team!");

const targetId = interaction.options.getStringOption("target");
const targetId = interaction.options.getUserOption("target").id;
if(targetId == userId)
return await interaction.reply("You cannot invite yourself!");
return await interaction.reply("You cannot invite yourself!");

const verifiedTarget = getVerifiedUser(targetId);
if(!verifiedTarget)
return await interaction.reply("This user is not verified!");
return await interaction.reply("This user is not verified!");

const targetTeamId = verifiedTarget.teamId;
if(targetTeamId)
return await interaction.reply("This user is already in a team!");
return await interaction.reply("This user is already in a team!");

inviteUserToTeam(team, verifiedUser, verifiedTarget);
break;
}

case "delete":{
case "delete": {
if(!team)
return await interaction.reply("You are not in a team!");
return await interaction.reply("You are not in a team!");

if(!captainId)
return await interaction.reply("You are not the captain of your team!");
return await interaction.reply("❌ You are not the captain of your team!");

await interaction.reply("⚠️ If you're sure, please type `/tean DELETECONFIRM`");
break;
}

case "DELETECONFIRM": {
if(!team)
return await interaction.reply("❌ You are not in a team!");

if(!captainId)
return await interaction.reply("❌ You are not the captain of your team!");

//TODO: ask if sure.
deleteTeam(team);
break;
}

case "leave":{
case "leave": {
if(!team)
return await interaction.reply("❌ You are not in a team!");

if(team.captainId == userId)
return await interaction.reply("❌ You can't leave a team you're the captain of! You have to delete your team first!");

await interaction.reply("⚠️ If you're sure, please type `/tean LEAVECONFIRM`");
break;
}

case "LEAVECONFIRM": {
if(!team)
return await interaction.reply("You are not in a team!");
return await interaction.reply("❌ You are not in a team!");

if(team.captainId == userId)
return await interaction.reply("❌ You can't leave a team you're the captain of! You have to delete your team first!");

//TODO: ask if sure.
leaveTeam(team, verifiedUser);
break;
}

default: { await interaction.reply("You're using this command incorrectly!"); }
default: { await interaction.reply("You're using this command incorrectly!"); }
}
};

Expand Down
29 changes: 29 additions & 0 deletions src/commands/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { getVerifiedUser, getSheetsUser } = require("../util/users");
const { addVerifiedUser } = require("../util/users");

const data = new SlashCommandBuilder()
.setName("verify")
.setDescription("Command used to verify that you're a registered user.")
.addStringOption(option =>
option.setName("email")
.setDescription("The email address you used on your application.")
.setRequired(true)
);

const execute = async (interaction) => {
const userId = interaction.author.id;
const verifiedUser = await getVerifiedUser(userId);
if(verifiedUser)
return await interaction.reply("❌ This command can only be used by users who are NOT verified!");

const email = interaction.options.getStringOption("email");
const sheetsUser = await getSheetsUser(email);
if(!sheetsUser.isAccepted)
return await interaction.reply("❌ This command can only be used by users who have been officially accepted!");

await addVerifiedUser(userId, interaction.author);
await interaction.reply("✔️ You are now verified!");
};

module.exports = { data: data, execute: execute, enabled: true, roleRequired: "" };
24 changes: 24 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
config: {
gsheets: {
spreadsheetId: "18l2IrquSjLyyu0LqOt_s92J-B3Nj4vpPRMqa-7CLgxI",
},

firebaseConfig: {
apiKey: "AIzaSyCF4gclwE2tXz_Fh3tkZyel5ZBV0iak1yU",
authDomain: "hawkhacks-2022.firebaseapp.com",
databaseURL: "https://hawkhacks-2022-default-rtdb.firebaseio.com",
projectId: "hawkhacks-2022",
storageBucket: "hawkhacks-2022.appspot.com",
messagingSenderId: "13981651926",
appId: "1:13981651926:web:7d63e321884c166d830a77",
measurementId: "G-W9RSGE33FK"
},

discord: {
teamCategoryId: "970876620648882186",
verifiedRoleId: "962115254018527372"

}
}
};
12 changes: 12 additions & 0 deletions src/google_jwt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "hawkhacks-2022",
"private_key_id": "5937c9a037c08251096ef1ee5129316442ea9ef3",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDpIjTIod43TsRP\ngv1xfqSSU69AGQFKMznGwymA/n1jE8dX7uQLlWxELWImKL58KhuMuH9Cu303oMgZ\n70ZiA8MnCyWIbn57X6hBOKJSaYjiNjAlNN1IEyla9c8SqJ4W8jGG5gxEa1ulTfby\n8TXi36sJEAOcmwS6jdGukb1nwg55FriE8GxE1wf1NEyfefRFJLJz/ekXmvLM08S/\nSIJiobDTjtBsyTbn7C8QVVHMtsU3ZEtNksSK9uIr8W/ESgYH/ciXWwtwn/Jd9DW/\n/JhsiTzHedbbLwCTFgwySzAHCZMsfp+RvCtgnPOYkKbE5OZ+zgegHX6ul8KYwpUN\nCq/VkDx1AgMBAAECggEAT8+qClV/4adRhXbulQAqDv4fLO5ihqhqyyTc/JAjFNwc\njnn2EBEjc2OmCjJAo/k2XUJ8LrhI8dZVKqvDiKKJGMC0JLTPECV7UHi2+Uev2OF8\nMgCbEKWerskgDt8y3+AiHHB9Gp82TK0YMatqKzUvNHcLBX38bHFIq16xXOgOVF1P\negS01Y8FDWJcYbv9zUYEJ0MGFMddmJQCowNj0VPxGdC0apuGtPq2DXFuwLSzbodV\nGib4Y3z8SzvvJS/MekjhhQXX8/jh/LQigFJxC5giHp7pIL9SttmetMhVz87cazdz\nBe+uCbfJTRiUFcpBiYsZd3UVPFn2L2ZSEWrheEYwMQKBgQD+8Z/LsZ4FgUqzwuTD\nNTflG/HssIswQZ1KeMk5TOh8TO4WhxBjHxRHVoTFsqjJs+8Vyby7v/TK78tiKaQS\nwKlnxx+BtOJdoTXfnt8A9CA5fShmModk8EdCBOz1uHBIKRczkmvPOKMFk7yIfdMI\nuKg+75EOwpxOyouTlVron9ZOewKBgQDqGXOZ7mo58pKhiEebe4C1Rs3Ow48pjlf8\nrsN8g5V8e0nM5E7J1DzIXmbXM81mI7ee7bji7bmpPOBVEKRhKIGn/dXLEgm7vf9K\n5X9uJF8uNP33NlGsFmmWByHFAhjPqvQPyW1AQOvK0dOC7zrcCr0YTcxTm6nRQzuB\n53NRDh0lzwKBgGiXqo4/3Wu2wnYDZCTuBXN6RoNrXn86vBQcf7mBYvPz/83ANank\ny0YFKc2N4Y92wYS30jVYqE5FmLQ6DzUeU6He4H8vPZtaEyceH7Fddob/YP6khkWU\nCjf8m1aoB3CjYwBmdtJ6Eu+rz7JTpKu0TloboPBkSQpOMHso0DYVtS9XAoGBAJfc\nXuOSiBKDS5/CGkHAwmPWRJhGwE5C6s0eSe4yJf0UtXFXAc1oAu4wXyJnlm0V6n4M\n1I1Rjck9loFYRGpKrqFdxxzu3KWPwVbCvgGjUqNU+RMvh5fNCj2q7rswewvsaFr9\nXgP6mXt+1mjv7AzmYnirr0rlhiocJTRGAsaoEzx9AoGASo2mCCbAxlyE2/UOPe6d\nSOAz0vU2cwa92ma7uz9DfJWOzigUMXVZ0p3JD9WEj69wrO8EcXs1uqsRcy5b37zk\nI2wB4D84pVPB7fgMfesJsNhjyGY8NM5jKJpcJ3xNH1s9ftiNPuHRfypS3RmOa+Tu\neuuD5dFFc4Yl6IVkIKYCCZQ=\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "105002544491941745608",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/google-sheets%40hawkhacks-2022.iam.gserviceaccount.com"
}
6 changes: 2 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { Client, Collection, Intents } = require("discord.js");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const { NoPermissionEmbed } = require("./embeds/noPermission");

require("dotenv").config();

const TOKEN = process.env.DISCORD_TOKEN;
Expand All @@ -22,8 +21,7 @@ const client = new Client({
partials: ["MESSAGE", "CHANNEL", "REACTION"]
});

function main() {

async function main() {
process.on("exit", () => {
client.emit("shutdown");

Expand Down Expand Up @@ -114,7 +112,7 @@ function handleCommands() {
await interaction.reply({
embeds: [NoPermissionEmbed],
ephemeral: true,
});
});
});

}
Expand Down
9 changes: 9 additions & 0 deletions src/util/firestore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { config } = require("../config");
const firebase = require("firebase");
require("firebase/firestore");

const firebaseConfig = config.firebaseConfig;
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();

module.exports = { firebase, db };
Loading

0 comments on commit dbd1dbb

Please sign in to comment.