Files

220 lines
7.8 KiB
JavaScript
Raw Permalink Normal View History

2026-08-28 17:48:09 +01:00
const Command = require("../../Structures/Command.js");
2024-10-10 19:14:45 +01:00
const Discord = require("discord.js");
2025-09-20 23:09:22 +01:00
const db = require("../../Structures/Database.js");
2024-10-10 19:14:45 +01:00
2026-05-16 15:10:27 +01:00
const supportbot = require("../../Structures/ConfigStore").supportbot;
const cmdconfig = require("../../Structures/ConfigStore").commands;
2024-10-10 19:14:45 +01:00
2025-09-20 23:09:22 +01:00
async function loadSettings() {
2026-08-28 17:48:09 +01:00
return typeof db.getSettings === "function" ? db.getSettings() : {};
2024-10-10 19:14:45 +01:00
}
2025-09-20 23:09:22 +01:00
async function saveSettings(settings) {
2026-08-28 17:48:09 +01:00
if (typeof db.saveSettings === "function") {
db.saveSettings(settings);
}
2024-10-10 19:14:45 +01:00
}
module.exports = new Command({
name: cmdconfig.Settings.Command,
description: cmdconfig.Settings.Description,
permissions: cmdconfig.Settings.Permission,
options: [
{
name: 'setstatus',
type: Discord.ApplicationCommandOptionType.Subcommand,
description: 'Set the bot status',
options: [
{
name: 'status',
type: Discord.ApplicationCommandOptionType.String,
description: 'Choose the bot status',
required: true,
choices: [
{ name: 'Online 🟢', value: 'online' },
{ name: 'Idle 🌙', value: 'idle' },
{ name: 'Do Not Disturb ⛔', value: 'dnd' },
{ name: 'Invisible 👻', value: 'invisible' }
],
},
],
},
{
name: 'setactivity',
type: Discord.ApplicationCommandOptionType.Subcommand,
description: 'Set the bot activity',
options: [
{
name: 'type',
type: Discord.ApplicationCommandOptionType.String,
description: 'Choose the activity type',
required: true,
choices: [
{ name: 'Playing 🎮', value: 'PLAYING' },
{ name: 'Watching 👀', value: 'WATCHING' },
{ name: 'Listening 🎧', value: 'LISTENING' },
{ name: 'Competing 🏆', value: 'COMPETING' }
],
},
{
name: 'message',
type: Discord.ApplicationCommandOptionType.String,
description: 'The activity message',
required: true,
},
],
},
{
name: 'streammode',
type: Discord.ApplicationCommandOptionType.Subcommand,
description: 'Set the bot streaming status',
options: [
{
name: 'toggle',
type: Discord.ApplicationCommandOptionType.String,
description: 'Turn streaming mode on or off',
required: true,
choices: [
{ name: 'On', value: 'on' },
{ name: 'Off', value: 'off' }
],
},
{
name: 'twitchurl',
type: Discord.ApplicationCommandOptionType.String,
description: 'Twitch stream URL (Required if turning on)',
required: false,
},
],
},
{
name: 'setnickname',
type: Discord.ApplicationCommandOptionType.Subcommand,
description: 'Set the bot nickname',
options: [
{
name: 'nickname',
type: Discord.ApplicationCommandOptionType.String,
description: 'The new nickname for the bot',
required: true,
},
],
},
],
async run(interaction) {
const subcommand = interaction.options.getSubcommand();
2025-09-20 23:09:22 +01:00
const settings = await loadSettings();
2024-10-10 19:14:45 +01:00
if (subcommand === 'setstatus') {
const status = interaction.options.getString('status');
try {
interaction.client.user.setPresence({
status: status,
activities: interaction.client.user.presence.activities || [],
});
settings.status = status;
2025-09-20 23:09:22 +01:00
await saveSettings(settings);
2024-10-10 19:14:45 +01:00
const embed = new Discord.EmbedBuilder()
.setDescription(`Status set to **${status.charAt(0).toUpperCase() + status.slice(1)}**`)
.setColor(supportbot.Embed.Colours.General);
2025-09-20 23:09:22 +01:00
return interaction.reply({ embeds: [embed], flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
} catch (error) {
2025-09-20 23:09:22 +01:00
return interaction.reply({ content: `Failed to set status: ${error.message}`, flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
}
}
if (subcommand === 'setactivity') {
const activityType = interaction.options.getString('type');
const activityMessage = interaction.options.getString('message');
try {
interaction.client.user.setPresence({
activities: [{ name: activityMessage, type: Discord.ActivityType[activityType] }],
status: interaction.client.user.presence.status || 'online',
});
settings.activity = { type: activityType, message: activityMessage };
2025-09-20 23:09:22 +01:00
await saveSettings(settings);
2024-10-10 19:14:45 +01:00
const embed = new Discord.EmbedBuilder()
.setDescription(`Activity set to **${activityType.toLowerCase()} ${activityMessage}**`)
.setColor(supportbot.Embed.Colours.General);
2025-09-20 23:09:22 +01:00
return interaction.reply({ embeds: [embed], flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
} catch (error) {
2025-09-20 23:09:22 +01:00
return interaction.reply({ content: `Failed to set activity: ${error.message}`, flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
}
} else if (subcommand === 'streammode') {
const toggle = interaction.options.getString('toggle');
const twitchUrl = interaction.options.getString('twitchurl');
if (toggle === 'on') {
if (!twitchUrl) {
2025-09-20 23:09:22 +01:00
return interaction.reply({ content: 'Please provide a Twitch URL to stream.', flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
}
try {
interaction.client.user.setPresence({
activities: [{ name: 'Streaming', type: Discord.ActivityType.Streaming, url: twitchUrl }],
status: 'online',
});
settings.streaming = { active: true, url: twitchUrl };
2025-09-20 23:09:22 +01:00
await saveSettings(settings);
2024-10-10 19:14:45 +01:00
const embed = new Discord.EmbedBuilder()
.setDescription(`**Streaming mode enabled!**\nStreaming: [Twitch](${twitchUrl})`)
.setColor(supportbot.Embed.Colours.General);
2025-09-20 23:09:22 +01:00
return interaction.reply({ embeds: [embed], flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
} catch (error) {
2025-09-20 23:09:22 +01:00
return interaction.reply({ content: `Failed to enable streaming mode: ${error.message}`, flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
}
} else if (toggle === 'off') {
try {
interaction.client.user.setPresence({
activities: interaction.client.user.presence.activities.filter(a => a.type !== Discord.ActivityType.Streaming),
status: settings.status || 'online',
});
settings.streaming = { active: false };
2025-09-20 23:09:22 +01:00
await saveSettings(settings);
2024-10-10 19:14:45 +01:00
const embed = new Discord.EmbedBuilder()
.setDescription(`**Streaming mode disabled!**`)
.setColor(supportbot.Embed.Colours.General);
2025-09-20 23:09:22 +01:00
return interaction.reply({ embeds: [embed], flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
} catch (error) {
2025-09-20 23:09:22 +01:00
return interaction.reply({ content: `Failed to disable streaming mode: ${error.message}`, flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
}
}
} else if (subcommand === 'setnickname') {
const nickname = interaction.options.getString('nickname');
try {
const guild = interaction.guild;
const botMember = guild.members.cache.get(interaction.client.user.id);
await botMember.setNickname(nickname);
settings.nickname = nickname;
2025-09-20 23:09:22 +01:00
await saveSettings(settings);
2024-10-10 19:14:45 +01:00
const embed = new Discord.EmbedBuilder()
.setDescription(`Bot nickname set to **${nickname}**`)
.setColor(supportbot.Embed.Colours.General);
2025-09-20 23:09:22 +01:00
return interaction.reply({ embeds: [embed], flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
} catch (error) {
2025-09-20 23:09:22 +01:00
return interaction.reply({ content: `Failed to set nickname: ${error.message}`, flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
}
} else {
2025-09-20 23:09:22 +01:00
return interaction.reply({ content: 'Invalid command usage.', flags: Discord.MessageFlags.Ephemeral });
2024-10-10 19:14:45 +01:00
}
},
2025-09-20 23:09:22 +01:00
});