added welcome-leave commands and updated activitytypes
This commit is contained in:
@@ -143,28 +143,45 @@ app.get('/api/servers/:guildId/channels', async (req, res) => {
|
|||||||
app.get('/api/servers/:guildId/welcome-leave-settings', (req, res) => {
|
app.get('/api/servers/:guildId/welcome-leave-settings', (req, res) => {
|
||||||
const { guildId } = req.params;
|
const { guildId } = req.params;
|
||||||
const db = readDb();
|
const db = readDb();
|
||||||
const settings = db[`${guildId}_welcome_leave`] || {
|
const settings = db[guildId] || {};
|
||||||
|
|
||||||
|
const welcomeLeaveSettings = {
|
||||||
welcome: {
|
welcome: {
|
||||||
enabled: false,
|
enabled: settings.welcomeEnabled || false,
|
||||||
channel: '',
|
channel: settings.welcomeChannel || '',
|
||||||
message: 'Welcome to the server, {user}!',
|
message: settings.welcomeMessage || 'Welcome to the server, {user}!',
|
||||||
customMessage: '',
|
customMessage: settings.welcomeCustomMessage || '',
|
||||||
},
|
},
|
||||||
leave: {
|
leave: {
|
||||||
enabled: false,
|
enabled: settings.leaveEnabled || false,
|
||||||
channel: '',
|
channel: settings.leaveChannel || '',
|
||||||
message: '{user} has left the server.',
|
message: settings.leaveMessage || '{user} has left the server.',
|
||||||
customMessage: '',
|
customMessage: settings.leaveCustomMessage || '',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
res.json(settings);
|
|
||||||
|
res.json(welcomeLeaveSettings);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/api/servers/:guildId/welcome-leave-settings', (req, res) => {
|
app.post('/api/servers/:guildId/welcome-leave-settings', (req, res) => {
|
||||||
const { guildId } = req.params;
|
const { guildId } = req.params;
|
||||||
const newSettings = req.body;
|
const newSettings = req.body;
|
||||||
const db = readDb();
|
const db = readDb();
|
||||||
db[`${guildId}_welcome_leave`] = newSettings;
|
|
||||||
|
if (!db[guildId]) {
|
||||||
|
db[guildId] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
db[guildId].welcomeEnabled = newSettings.welcome.enabled;
|
||||||
|
db[guildId].welcomeChannel = newSettings.welcome.channel;
|
||||||
|
db[guildId].welcomeMessage = newSettings.welcome.message;
|
||||||
|
db[guildId].welcomeCustomMessage = newSettings.welcome.customMessage;
|
||||||
|
|
||||||
|
db[guildId].leaveEnabled = newSettings.leave.enabled;
|
||||||
|
db[guildId].leaveChannel = newSettings.leave.channel;
|
||||||
|
db[guildId].leaveMessage = newSettings.leave.message;
|
||||||
|
db[guildId].leaveCustomMessage = newSettings.leave.customMessage;
|
||||||
|
|
||||||
writeDb(db);
|
writeDb(db);
|
||||||
res.json({ success: true });
|
res.json({ success: true });
|
||||||
});
|
});
|
||||||
|
|||||||
19
checklist.md
19
checklist.md
@@ -62,6 +62,9 @@
|
|||||||
- [x] Implement event handler
|
- [x] Implement event handler
|
||||||
- [x] Set bot status on ready event
|
- [x] Set bot status on ready event
|
||||||
- [x] Automatically register slash commands on server join.
|
- [x] Automatically register slash commands on server join.
|
||||||
|
- [x] On startup, automatically register all slash commands and remove any obsolete commands.
|
||||||
|
- [x] Add a mechanism to enable or disable commands from being registered and displayed.
|
||||||
|
- [x] In `ready.js`, set the bot's activity to change every 3 seconds with the following streaming activities: "Watch EhChad Live!", "Follow EhChad!", "/help", and "EhChadServices", all pointing to `https://twitch.tv/ehchad`.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- [x] **Welcome/Leave Messages**
|
- [x] **Welcome/Leave Messages**
|
||||||
@@ -79,3 +82,19 @@
|
|||||||
- [x] **Bot Integration:**
|
- [x] **Bot Integration:**
|
||||||
- [x] Connect frontend settings to the backend.
|
- [x] Connect frontend settings to the backend.
|
||||||
- [x] Implement bot logic to send welcome/leave messages based on server settings.
|
- [x] Implement bot logic to send welcome/leave messages based on server settings.
|
||||||
|
- [x] **Slash Command Integration:**
|
||||||
|
- [x] ~~Create a `/config-welcome` slash command.~~
|
||||||
|
- [x] ~~Add a subcommand to `set-channel` for welcome messages.~~
|
||||||
|
- [x] ~~Add a subcommand to `set-message` with options for default and custom messages.~~
|
||||||
|
- [x] ~~Add a subcommand to `disable` welcome messages.~~
|
||||||
|
- [x] ~~Create a `/config-leave` slash command.~~
|
||||||
|
- [x] ~~Add a subcommand to `set-channel` for leave messages.~~
|
||||||
|
- [x] ~~Add a subcommand to `set-message` with options for default and custom messages.~~
|
||||||
|
- [x] ~~Add a subcommand to `disable` leave messages.~~
|
||||||
|
- [x] ~~Create a `/view-config` slash command to display the current welcome and leave channels.~~
|
||||||
|
- [ ] Refactor `/config-welcome` to `/setup-welcome` with interactive setup for channel and message.
|
||||||
|
- [ ] Refactor `/config-leave` to `/setup-leave` with interactive setup for channel and message.
|
||||||
|
- [ ] Rename `/view-config` to `/view-welcome-leave`.
|
||||||
|
- [x] Ensure settings updated via slash commands are reflected on the frontend.
|
||||||
|
- [x] Ensure settings updated via the frontend are reflected in the bot's behavior.
|
||||||
|
- [x] Persist the selected message option (default or custom) for welcome and leave messages.
|
||||||
63
discord-bot/commands/config-leave.js
Normal file
63
discord-bot/commands/config-leave.js
Normal 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.');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -3,6 +3,7 @@ const { readDb } = require('../../backend/db.js');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'ping',
|
name: 'ping',
|
||||||
description: 'Replies with Pong!',
|
description: 'Replies with Pong!',
|
||||||
|
enabled: true,
|
||||||
execute(interaction) {
|
execute(interaction) {
|
||||||
const db = readDb();
|
const db = readDb();
|
||||||
const settings = db[interaction.guildId] || { pingCommand: false };
|
const settings = db[interaction.guildId] || { pingCommand: false };
|
||||||
|
|||||||
63
discord-bot/commands/setup-welcome.js
Normal file
63
discord-bot/commands/setup-welcome.js
Normal 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.');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
34
discord-bot/commands/view-welcome-leave.js
Normal file
34
discord-bot/commands/view-welcome-leave.js
Normal 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}"`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,10 +1,23 @@
|
|||||||
require('dotenv').config({ path: '../backend/.env' });
|
require('dotenv').config({ path: '../backend/.env' });
|
||||||
const { REST, Routes } = require('discord.js');
|
const { REST, Routes } = require('discord.js');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const commands = [{
|
const commands = [];
|
||||||
name: 'ping',
|
const commandsPath = path.join(__dirname, 'commands');
|
||||||
description: 'Replies with Pong!',
|
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);
|
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN);
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ module.exports = {
|
|||||||
async execute(member) {
|
async execute(member) {
|
||||||
try {
|
try {
|
||||||
const db = readDb();
|
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) {
|
if (settings && settings.welcomeEnabled && settings.welcomeChannel) {
|
||||||
const channel = member.guild.channels.cache.get(settings.welcome.channel);
|
const channel = member.guild.channels.cache.get(settings.welcomeChannel);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
try {
|
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);
|
await channel.send(message);
|
||||||
} catch (error) {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ module.exports = {
|
|||||||
async execute(member) {
|
async execute(member) {
|
||||||
try {
|
try {
|
||||||
const db = readDb();
|
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) {
|
if (settings && settings.leaveEnabled && settings.leaveChannel) {
|
||||||
const channel = member.guild.channels.cache.get(settings.leave.channel);
|
const channel = member.guild.channels.cache.get(settings.leaveChannel);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
try {
|
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);
|
await channel.send(message);
|
||||||
} catch (error) {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,30 @@
|
|||||||
const { ActivityType } = require('discord.js');
|
const { ActivityType } = require('discord.js');
|
||||||
|
const deployCommands = require('../deploy-commands');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'clientReady',
|
name: 'clientReady',
|
||||||
once: true,
|
once: true,
|
||||||
execute(client) {
|
async execute(client) {
|
||||||
console.log('ECS - Full Stack Bot Online!');
|
console.log('ECS - Full Stack Bot Online!');
|
||||||
|
|
||||||
client.user.setActivity('ehchad', {
|
const guilds = client.guilds.cache.map(guild => guild.id);
|
||||||
type: ActivityType.Streaming,
|
for (const guildId of guilds) {
|
||||||
url: 'https://twitch.tv/ehchad'
|
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);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ module.exports = (client) => {
|
|||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const filePath = path.join(commandsPath, file);
|
const filePath = path.join(commandsPath, file);
|
||||||
const command = require(filePath);
|
const command = require(filePath);
|
||||||
|
if (command.enabled === false) continue;
|
||||||
|
|
||||||
if (command.name) {
|
if (command.name) {
|
||||||
client.commands.set(command.name, command);
|
client.commands.set(command.name, command);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user