added welcome-leave commands and updated activitytypes
This commit is contained in:
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 = {
|
||||
name: 'ping',
|
||||
description: 'Replies with Pong!',
|
||||
enabled: true,
|
||||
execute(interaction) {
|
||||
const db = readDb();
|
||||
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' });
|
||||
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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user