Skip to content

Commit

Permalink
Fixes #5 - makes all commands ephemeral
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandyn committed Jan 7, 2024
1 parent 7bdd2ac commit 6b08636
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 195 deletions.
146 changes: 71 additions & 75 deletions src/actions/discordComamnds/createRoleRequestMessage.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,80 @@
const db = require('../../database')
const synchroniseUser = require('../synchronizeUser')
const ts = require('../../teamspeak');
const { SlashCommandBuilder, PermissionsBitField, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const db = require("../../database");
const synchroniseUser = require("../synchronizeUser");
const ts = require("../../teamspeak");
const {
SlashCommandBuilder,
PermissionsBitField,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
} = require("discord.js");

class CreateRoleRequestMessageCommand {
constructor() {
this.public = false;
this.data = new SlashCommandBuilder()
.setName("createrolerequestmessage")
.setDescription("Create a message for role requests")
.addMentionableOption(option =>
option.setName("role1")
.setDescription("Selectable Role")
)
.addMentionableOption(option =>
option.setName("role2")
.setDescription("Selectable Role")
)
.addMentionableOption(option =>
option.setName("role3")
.setDescription("Selectable Role")
)
.addMentionableOption(option =>
option.setName("role4")
.setDescription("Selectable Role")
)
.addMentionableOption(option =>
option.setName("role5")
.setDescription("Selectable Role")
)
.addMentionableOption(option =>
option.setName("role6")
.setDescription("Selectable Role")
)
.addMentionableOption(option =>
option.setName("role7")
.setDescription("Selectable Role")
)
}
constructor() {
this.public = false;
this.data = new SlashCommandBuilder()
.setName("createrolerequestmessage")
.setDescription("Create a message for role requests")
.addMentionableOption((option) =>
option.setName("role1").setDescription("Selectable Role")
)
.addMentionableOption((option) =>
option.setName("role2").setDescription("Selectable Role")
)
.addMentionableOption((option) =>
option.setName("role3").setDescription("Selectable Role")
)
.addMentionableOption((option) =>
option.setName("role4").setDescription("Selectable Role")
)
.addMentionableOption((option) =>
option.setName("role5").setDescription("Selectable Role")
)
.addMentionableOption((option) =>
option.setName("role6").setDescription("Selectable Role")
)
.addMentionableOption((option) =>
option.setName("role7").setDescription("Selectable Role")
);
}

// TODO: Implement a rate limit

async execute(interaction) {
const roles = interaction.options._hoistedOptions;

const row1 = new ActionRowBuilder()
.addComponents(new ButtonBuilder()
.setCustomId(roles[0].role.name)
.setLabel(roles[0].role.name)
.setStyle(ButtonStyle.Primary)
)
interaction.reply({content: "I Think You Sould", components: [row1]})
// TODO: Implement a rate limit

async execute(interaction) {
const roles = interaction.options._hoistedOptions;

const row1 = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId(roles[0].role.name)
.setLabel(roles[0].role.name)
.setStyle(ButtonStyle.Primary)
);
interaction.reply({ content: "I Think You Sould", components: [row1] });

// let member;
// let member;

// if (interaction.options.getMentionable('user'))
// if (interaction.member.permissions.has(PermissionsBitField.Flags.ManageRoles))
// member = interaction.options.getMentionable('user');
// else
// interaction.reply("Sorry you don't have have permission to sync another user's roles")
// else
// member = interaction.member;

// const tsid = await db.getTeamspeakIDByDiscordId(member.user.id)

// let client;
// try {
// client = await ts.client.clientGetDbidFromUid(tsid)
// } catch (ex) { console.log(ex) }

// if (client) {
// await synchroniseUser(interaction.member, tsid)
// interaction.reply(`Roles of ${member.user.username} synchronized!`)
// } else {
// interaction.reply("Sorry I can't find that ID in teamspeak, please make sure you have connected to the server before and that you have used the ID for the correct identity. If you need help contact a member of high command.")
// }

}
// if (interaction.options.getMentionable('user'))
// if (interaction.member.permissions.has(PermissionsBitField.Flags.ManageRoles))
// member = interaction.options.getMentionable('user');
// else
// interaction.reply("Sorry you don't have have permission to sync another user's roles")
// else
// member = interaction.member;

// const tsid = await db.getTeamspeakIDByDiscordId(member.user.id)

// let client;
// try {
// client = await ts.client.clientGetDbidFromUid(tsid)
// } catch (ex) { console.log(ex) }

// if (client) {
// await synchroniseUser(interaction.member, tsid)
// interaction.reply(`Roles of ${member.user.username} synchronized!`)
// } else {
// interaction.reply("Sorry I can't find that ID in teamspeak, please make sure you have connected to the server before and that you have used the ID for the correct identity. If you need help contact a member of high command.")
// }
}
}

module.exports = new CreateRoleRequestMessageCommand();
module.exports = new CreateRoleRequestMessageCommand();
13 changes: 9 additions & 4 deletions src/actions/discordComamnds/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ class RegisterCommand {
if (client) {
await db.updateTeamspeakID(user.user.id, tsid);
await synchroniseUser(user, tsid);
interaction.reply(`Teamspeak ID of ${user.user.username} updated!`);
interaction.reply({
content: `Teamspeak ID of ${user.user.username} updated!`,
ephemeral: true,
});
} else {
interaction.reply(
"Sorry I can't find that ID in teamspeak, please make sure you have connected to the server before and that you have used the ID for the correct identity. If you need help contact a member of high command."
);
interaction.reply({
content:
"Sorry I can't find that ID in teamspeak, please make sure you have connected to the server before and that you have used the ID for the correct identity. If you need help contact a member of high command.",
ephemeral: true,
});
}
}

Expand Down
94 changes: 53 additions & 41 deletions src/actions/discordComamnds/sync.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,60 @@
const db = require('../../database')
const synchroniseUser = require('../synchronizeUser')
const ts = require('../../teamspeak');
const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
const db = require("../../database");
const synchroniseUser = require("../synchronizeUser");
const ts = require("../../teamspeak");
const { SlashCommandBuilder, PermissionsBitField } = require("discord.js");

class SyncCommand {
constructor() {
this.public = true;
this.data = new SlashCommandBuilder()
.setName("sync")
.setDescription("Forces the user to resynchronize.")
.addMentionableOption(option =>
option.setName("user")
.setDescription("The user to be synchronized")
)
constructor() {
this.public = true;
this.data = new SlashCommandBuilder()
.setName("sync")
.setDescription("Forces the user to resynchronize.")
.addMentionableOption((option) =>
option.setName("user").setDescription("The user to be synchronized")
);
}

// TODO: Implement a rate limit

async execute(interaction) {
let member;

if (interaction.options.getMentionable("user"))
if (
interaction.member.permissions.has(
PermissionsBitField.Flags.ManageRoles
)
)
member = interaction.options.getMentionable("user");
else
interaction.reply(
"Sorry you don't have have permission to sync another user's roles"
);
else member = interaction.member;

const tsid = await db.getTeamspeakIDByDiscordId(member.user.id);

let client;
try {
client = await ts.client.clientGetDbidFromUid(tsid);
} catch (ex) {
console.log(ex);
}

// TODO: Implement a rate limit

async execute(interaction) {
let member;

if (interaction.options.getMentionable('user'))
if (interaction.member.permissions.has(PermissionsBitField.Flags.ManageRoles))
member = interaction.options.getMentionable('user');
else
interaction.reply("Sorry you don't have have permission to sync another user's roles")
else
member = interaction.member;

const tsid = await db.getTeamspeakIDByDiscordId(member.user.id)

let client;
try {
client = await ts.client.clientGetDbidFromUid(tsid)
} catch (ex) { console.log(ex) }

if (client) {
await synchroniseUser(interaction.member, tsid)
interaction.reply(`Roles of ${member.user.username} synchronized!`)
} else {
interaction.reply("Sorry I can't find that ID in teamspeak, please make sure you have connected to the server before and that you have used the ID for the correct identity. If you need help contact a member of high command.")
}

if (client) {
await synchroniseUser(interaction.member, tsid);
interaction.reply({
content: `Roles of ${member.user.username} synchronized!`,
ephemeral: true,
});
} else {
interaction.reply({
content:
"Sorry I can't find that ID in teamspeak, please make sure you have connected to the server before and that you have used the ID for the correct identity. If you need help contact a member of high command.",
ephemeral: true,
});
}
}
}

module.exports = new SyncCommand();
module.exports = new SyncCommand();
72 changes: 35 additions & 37 deletions src/actions/discordComamnds/syncRole.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
const db = require('../../database')
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const db = require("../../database");
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");

class SyncRoleCommand {
constructor() {
this.public = true;
this.data = new SlashCommandBuilder()
.setName("syncrole")
.setDescription("Configures a role to by synchronized.")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.addMentionableOption(option =>
option.setName("role")
.setDescription("The role to be synchronized")
.setRequired(true)
)

}
async execute(interaction) {
constructor() {
this.public = true;
this.data = new SlashCommandBuilder()
.setName("syncrole")
.setDescription("Configures a role to by synchronized.")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.addMentionableOption((option) =>
option
.setName("role")
.setDescription("The role to be synchronized")
.setRequired(true)
);
}
async execute(interaction) {
const role = interaction.options.getMentionable("role");

const role = interaction.options.getMentionable('role');

let synced = await db.getSynchronizedRoles();
console.log(synced)
if (synced === undefined) {
synced = []
}

synced.push(role.name);
await db.addSynchronizedRoles(role.name);

synced = await db.getSynchronizedRoles();
console.log(synced)
let syncedString = "Syncing: "
synced.forEach((r, index) => {
syncedString += r
if (index < synced.length - 1)
syncedString += ", "
})
interaction.reply(syncedString)
let synced = await db.getSynchronizedRoles();
console.log(synced);
if (synced === undefined) {
synced = [];
}

synced.push(role.name);
await db.addSynchronizedRoles(role.name);

synced = await db.getSynchronizedRoles();
console.log(synced);
let syncedString = "Syncing: ";
synced.forEach((r, index) => {
syncedString += r;
if (index < synced.length - 1) syncedString += ", ";
});
interaction.reply({ content: syncedString, ephemeral: true });
}
}

module.exports = new SyncRoleCommand();
module.exports = new SyncRoleCommand();
13 changes: 9 additions & 4 deletions src/actions/discordComamnds/tsid.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ class TSIDCommand {
if (client) {
await db.updateTeamspeakID(user.user.id, tsid);
await synchroniseUser(user, tsid);
interaction.reply(`Teamspeak ID of ${user.user.username} updated!`);
interaction.reply({
content: `Teamspeak ID of ${user.user.username} updated!`,
ephemeral: true,
});
} else {
interaction.reply(
"Sorry I can't find that ID in teamspeak, please make sure you have connected to the server before and that you have used the ID for the correct identity. If you need help contact a member of high command."
);
interaction.reply({
content:
"Sorry I can't find that ID in teamspeak, please make sure you have connected to the server before and that you have used the ID for the correct identity. If you need help contact a member of high command.",
ephemeral: true,
});
}
}

Expand Down
Loading

0 comments on commit 6b08636

Please sign in to comment.