Skip to content

Commit

Permalink
all: idk
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcarreon123 committed Feb 20, 2024
1 parent 8f2f38e commit 83bc69b
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 21 deletions.
33 changes: 33 additions & 0 deletions src/bot/commands/misc/button-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

const {
SlashCommandBuilder,
EmbedBuilder,
Interaction,
ActionRowBuilder,
} = require("discord.js");
const { config } = require("../../config");
const logger = require("../../../utils/logger");
const { data } = require("../../components/buttons/test-button.ts")

module.exports = {
data: new SlashCommandBuilder()
.setName("button-test")
.setDescription(`temp command`),
async execute(interaction: typeof Interaction) {
// Grab client latency
const latency = Math.abs(Date.now() - interaction.createdAt);

// Row
const row = new ActionRowBuilder().addComponents(data)

// Reply
await interaction.reply({ content: "test", components: [row] });

logger.info(`Res ping -> latency of ${latency}ms`);
},
};
28 changes: 23 additions & 5 deletions src/bot/commands/misc/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { GuildConfig } = require('../../database/schema');
module.exports = {
data: new SlashCommandBuilder()
.setName("configure")
.setDescription(`Database test`)
.setDescription("Configure Liberation")
.addChannelOption(option =>
option.setName('channel')
.setDescription('The channel for the temp vc thing')
Expand All @@ -27,9 +27,10 @@ module.exports = {
.addChannelOption(option =>
option.setName('category')
.setDescription('The category for the temp vc thing')
.setRequired(true)
.addChannelTypes(ChannelType.GuildCategory))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild),
.addChannelTypes(ChannelType.GuildCategory)
.setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.setDMPermission(false),
async execute(interaction: typeof Interaction) {
const channel = interaction.options.getChannel('channel')
const category = interaction.options.getChannel('category')
Expand All @@ -42,6 +43,23 @@ module.exports = {

guildConfig.save();

await interaction.reply('done');
const configureReply = new EmbedBuilder()
.setColor(config.colors.primary)
.setTitle("Liberation configured!")
.addFields([
{
name: "Create a Temp VC channel",
value: `${channel}`,
inline: true
},
{
name: "Temp VC category",
value: `${category}`,
inline: true
}
]);


await interaction.reply({ embeds: [ configureReply ], ephemeral: true });
},
};
6 changes: 3 additions & 3 deletions src/bot/components/buttons/test-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const { ButtonBuilder, ButtonStyle, Interaction } = require("discord.js");
const config = require("../../config.ts");

module.exports = {
button: new ButtonBuilder()
data: new ButtonBuilder()
.setLabel("Poke")
.setCustomId("test-button")
.setStyle(ButtonStyle),
.setStyle(ButtonStyle.Primary),
async execute(interaction: typeof Interaction) {
await interaction.reply("hello");
await interaction.update("hello");
},
};
7 changes: 4 additions & 3 deletions src/bot/database/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as mongoose from "mongoose";
const guildConfigSchema = new mongoose.Schema(
{
guildId: {type: String, required: true},
tempVoiceEnabled: {type: Boolean, required: true},
// tempVoiceEnabled: {type: Boolean, required: true},
tempVoiceChannelId: {type: String},
tempVoiceCategoryId: {type: String},
tempTextEnabled: {type: Boolean, required: true},
// tempTextEnabled: {type: Boolean, required: true},
tempTextChannelId: {type: String},
tempTextCategoryId: {type: String},
ticketsEnabled: {type: Boolean, required: true},
// ticketsEnabled: {type: Boolean, required: true},
ticketsMessageId: {type: String},
ticketsCategoryId: {type: String},
}
Expand All @@ -36,6 +36,7 @@ const tempTextSchema = new mongoose.Schema(
const ticketSchema = new mongoose.Schema(
{
ticketId: {type: String},
isClosed: {type: Boolean, required: true},
guildId: {type: String, required: true},
ticketChannelId: {type: String, required: true},
ownerId: {type: String, required: true}
Expand Down
19 changes: 19 additions & 0 deletions src/bot/events/channelDelete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

const { Events, VoiceChannel } = require("discord.js");
const { config } = require("../config");
const { GuildConfig, TempVoice } = require("../database/schema")
const logger = require("../../utils/logger");

module.exports = {
name: Events.ChannelDelete,
async execute(channel: typeof VoiceChannel) {
await TempVoice.deleteMany({ voiceChannelId: channel.id });

logger.info(`Voice channel deleted. ID: ${channel.id}`);
},
};
26 changes: 19 additions & 7 deletions src/bot/events/voiceStateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ module.exports = {
`${member.user.username} joined ${newState.channel.name}`
);

// TODO: add party creation logic
GuildConfig.find({ guildId: guild.id })
.then(async res => {
if (res) {
if (res) {
const pGuild = res[0]

if (pGuild.tempVoiceChannelId == newState.channelId) {
if (pGuild && pGuild.tempVoiceChannelId == newState.channelId) {
const channel = await guild.channels.create({ name: `${member.user.username}'s party`, type: ChannelType.GuildVoice })
await channel.setParent(pGuild.tempVoiceCategoryId)

Expand All @@ -35,19 +34,32 @@ module.exports = {

tempVoice.save()

member.voice.setChannel(channel, 'Created party VC')
await member.voice.setChannel(channel, 'Created party VC')
.catch(error => {
logger.warn(`Error occured while switching user to party VC: ${error}`)
});
}
}
}
})
}

// Left
if (oldState.channelId && !newState.channelId) {
// Left & Switched
if (oldState.channelId) {
logger.info(
`${member.user.username} left ${oldState.channel.name}`
);

// TODO: add party deletion logic
TempVoice.find({ voiceChannelId: oldState.channelId })
.then(async res => {
if (res) {
if (res[0] && res[0].voiceChannelId === oldState.channelId) {
if (oldState.channel.members.size < 1) {
await oldState.channel.delete();
}
}
}
})
}
},
};
6 changes: 3 additions & 3 deletions src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ for (const file of buttonFiles) {

// Load select menus
logger.info("Loading select menus");
client.buttons = new Map();
client.selectMenus = new Map();
const selectMenusPath = path.join(import.meta.dir, "./components/selectmenus");
const selectMenuFiles = fs
.readdirSync(buttonsPath)
.readdirSync(selectMenusPath)
.filter((file: string) => file.endsWith(".ts"));

for (const file of buttonFiles) {
for (const file of selectMenuFiles) {
const selectMenu = require(`${selectMenusPath}/${file}`);
client.selectMenus.set(selectMenu.data.customId, selectMenu);
}
Expand Down
25 changes: 25 additions & 0 deletions src/templates/selectmenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { EmbedBuilder, Interaction, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } = require("discord.js");
const config = require("../../config.ts");

module.exports = {
selectMenu: () => {
const select = new StringSelectMenuBuilder()
.setCustomId('')
.setPlaceholder('')
.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel('')
.setDescription('')
.setValue(''),
new StringSelectMenuOptionBuilder()
.setLabel('')
.setDescription('')
.setValue(''),
);

return select
},
async execute(interaction: typeof Interaction) {
// Logic
},
};

0 comments on commit 83bc69b

Please sign in to comment.