added welcome-leave commands and updated activitytypes

This commit is contained in:
2025-10-03 18:00:47 -04:00
parent 9bc7a5e6b8
commit 524a6cc633
11 changed files with 258 additions and 30 deletions

View File

@@ -0,0 +1,63 @@
const { SlashCommandBuilder } = require('discord.js');
const { readDb, writeDb } = require('../../backend/db.js');
module.exports = {
name: 'config-leave',
description: 'Configure the leave message for this server.',
enabled: true,
builder: new SlashCommandBuilder()
.setName('config-leave')
.setDescription('Configure the leave message for this server.')
.addSubcommand(subcommand =>
subcommand
.setName('set-channel')
.setDescription('Set the channel for leave messages.')
.addChannelOption(option =>
option.setName('channel')
.setDescription('The channel to send leave messages to.')
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('set-message')
.setDescription('Set the leave message.')
.addStringOption(option =>
option.setName('message')
.setDescription('The leave message. Use {user} for username and {server} for server name.')
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('disable')
.setDescription('Disable leave messages.')
),
async execute(interaction) {
const db = readDb();
const guildId = interaction.guildId;
const subcommand = interaction.options.getSubcommand();
if (!db[guildId]) {
db[guildId] = {};
}
if (subcommand === 'set-channel') {
const channel = interaction.options.getChannel('channel');
db[guildId].leaveChannel = channel.id;
db[guildId].leaveEnabled = true;
writeDb(db);
await interaction.reply(`Leave channel set to ${channel}.`);
} else if (subcommand === 'set-message') {
const message = interaction.options.getString('message');
db[guildId].leaveMessage = message;
db[guildId].leaveEnabled = true;
writeDb(db);
await interaction.reply(`Leave message set to: "${message}"`);
} else if (subcommand === 'disable') {
db[guildId].leaveEnabled = false;
writeDb(db);
await interaction.reply('Leave messages disabled.');
}
},
};

View File

@@ -3,6 +3,7 @@ const { readDb } = require('../../backend/db.js');
module.exports = {
name: 'ping',
description: 'Replies with Pong!',
enabled: true,
execute(interaction) {
const db = readDb();
const settings = db[interaction.guildId] || { pingCommand: false };

View File

@@ -0,0 +1,63 @@
const { SlashCommandBuilder } = require('discord.js');
const { readDb, writeDb } = require('../../backend/db.js');
module.exports = {
name: 'config-welcome',
description: 'Configure the welcome message for this server.',
enabled: true,
builder: new SlashCommandBuilder()
.setName('config-welcome')
.setDescription('Configure the welcome message for this server.')
.addSubcommand(subcommand =>
subcommand
.setName('set-channel')
.setDescription('Set the channel for welcome messages.')
.addChannelOption(option =>
option.setName('channel')
.setDescription('The channel to send welcome messages to.')
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('set-message')
.setDescription('Set the welcome message.')
.addStringOption(option =>
option.setName('message')
.setDescription('The welcome message. Use {user} for username mention and {server} for server name.')
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('disable')
.setDescription('Disable welcome messages.')
),
async execute(interaction) {
const db = readDb();
const guildId = interaction.guildId;
const subcommand = interaction.options.getSubcommand();
if (!db[guildId]) {
db[guildId] = {};
}
if (subcommand === 'set-channel') {
const channel = interaction.options.getChannel('channel');
db[guildId].welcomeChannel = channel.id;
db[guildId].welcomeEnabled = true;
writeDb(db);
await interaction.reply(`Welcome channel set to ${channel}.`);
} else if (subcommand === 'set-message') {
const message = interaction.options.getString('message');
db[guildId].welcomeMessage = message;
db[guildId].welcomeEnabled = true;
writeDb(db);
await interaction.reply(`Welcome message set to: "${message}"`);
} else if (subcommand === 'disable') {
db[guildId].welcomeEnabled = false;
writeDb(db);
await interaction.reply('Welcome messages disabled.');
}
},
};

View File

@@ -0,0 +1,34 @@
const { SlashCommandBuilder } = require('discord.js');
const { readDb } = require('../../backend/db.js');
module.exports = {
name: 'view-welcome-leave',
description: 'View the current welcome and leave message configuration.',
enabled: true,
builder: new SlashCommandBuilder()
.setName('view-welcome-leave')
.setDescription('View the current welcome and leave message configuration.'),
async execute(interaction) {
const db = readDb();
const guildId = interaction.guildId;
const settings = db[guildId] || {};
const welcomeChannel = settings.welcomeChannel ? `<#${settings.welcomeChannel}>` : 'Not set';
const welcomeMessage = settings.welcomeMessage || 'Not set';
const welcomeEnabled = settings.welcomeEnabled ? 'Enabled' : 'Disabled';
const leaveChannel = settings.leaveChannel ? `<#${settings.leaveChannel}>` : 'Not set';
const leaveMessage = settings.leaveMessage || 'Not set';
const leaveEnabled = settings.leaveEnabled ? 'Enabled' : 'Disabled';
await interaction.reply(
`**Welcome Messages: ${welcomeEnabled}**
Channel: ${welcomeChannel}
Message: "${welcomeMessage}"
**Leave Messages: ${leaveEnabled}**
Channel: ${leaveChannel}
Message: "${leaveMessage}"`
);
},
};

View File

@@ -1,10 +1,23 @@
require('dotenv').config({ path: '../backend/.env' });
const { REST, Routes } = require('discord.js');
const fs = require('fs');
const path = require('path');
const commands = [{
name: 'ping',
description: 'Replies with Pong!',
}];
const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if (command.enabled === false) continue;
if (command.builder) {
commands.push(command.builder.toJSON());
} else {
commands.push({ name: command.name, description: command.description });
}
}
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN);

View File

@@ -6,16 +6,16 @@ module.exports = {
async execute(member) {
try {
const db = readDb();
const settings = db[`${member.guild.id}_welcome_leave`];
const settings = db[member.guild.id];
if (settings && settings.welcome && settings.welcome.enabled && settings.welcome.channel) {
const channel = member.guild.channels.cache.get(settings.welcome.channel);
if (settings && settings.welcomeEnabled && settings.welcomeChannel) {
const channel = member.guild.channels.cache.get(settings.welcomeChannel);
if (channel) {
try {
const message = settings.welcome.message.replace('{user}', member.user.toString());
const message = (settings.welcomeMessage || 'Welcome {user} to {server}!').replace('{user}', member.user.toString()).replace('{server}', member.guild.name);
await channel.send(message);
} catch (error) {
console.error(`Could not send welcome message to channel ${settings.welcome.channel} in guild ${member.guild.id}:`, error);
console.error(`Could not send welcome message to channel ${settings.welcomeChannel} in guild ${member.guild.id}:`, error);
}
}
}

View File

@@ -6,16 +6,16 @@ module.exports = {
async execute(member) {
try {
const db = readDb();
const settings = db[`${member.guild.id}_welcome_leave`];
const settings = db[member.guild.id];
if (settings && settings.leave && settings.leave.enabled && settings.leave.channel) {
const channel = member.guild.channels.cache.get(settings.leave.channel);
if (settings && settings.leaveEnabled && settings.leaveChannel) {
const channel = member.guild.channels.cache.get(settings.leaveChannel);
if (channel) {
try {
const message = settings.leave.message.replace('{user}', member.user.tag);
const message = (settings.leaveMessage || '{user} has left the server.').replace('{user}', member.user.tag).replace('{server}', member.guild.name);
await channel.send(message);
} catch (error) {
console.error(`Could not send leave message to channel ${settings.leave.channel} in guild ${member.guild.id}:`, error);
console.error(`Could not send leave message to channel ${settings.leaveChannel} in guild ${member.guild.id}:`, error);
}
}
}

View File

@@ -1,14 +1,30 @@
const { ActivityType } = require('discord.js');
const deployCommands = require('../deploy-commands');
module.exports = {
name: 'clientReady',
once: true,
execute(client) {
async execute(client) {
console.log('ECS - Full Stack Bot Online!');
client.user.setActivity('ehchad', {
type: ActivityType.Streaming,
url: 'https://twitch.tv/ehchad'
});
const guilds = client.guilds.cache.map(guild => guild.id);
for (const guildId of guilds) {
await deployCommands(guildId);
}
const activities = [
{ name: 'Watch EhChad Live!', type: ActivityType.Streaming, url: 'https://twitch.tv/ehchad' },
{ name: 'Follow EhChad!', type: ActivityType.Streaming, url: 'https://twitch.tv/ehchad' },
{ name: '/help', type: ActivityType.Streaming, url: 'https://twitch.tv/ehchad' },
{ name: 'EhChadServices', type: ActivityType.Streaming, url: 'https://twitch.tv/ehchad' },
];
let activityIndex = 0;
setInterval(() => {
const activity = activities[activityIndex];
client.user.setActivity(activity.name, { type: activity.type, url: activity.url });
activityIndex = (activityIndex + 1) % activities.length;
}, 3000);
},
};

View File

@@ -8,6 +8,8 @@ module.exports = (client) => {
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if (command.enabled === false) continue;
if (command.name) {
client.commands.set(command.name, command);
}