2025-09-20 23:09:22 +01:00
|
|
|
const { Command } = require('../../Structures/Addon.js');
|
2024-10-10 19:14:45 +01:00
|
|
|
const Discord = require("discord.js");
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
const yaml = require("js-yaml");
|
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() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
db.get("SELECT data FROM settings WHERE id = 1", (err, row) => {
|
|
|
|
|
if (err) return reject(err);
|
|
|
|
|
if (!row) return resolve({});
|
|
|
|
|
try {
|
|
|
|
|
resolve(JSON.parse(row.data));
|
|
|
|
|
} catch (e) {
|
|
|
|
|
resolve({});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-10-10 19:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
2025-09-20 23:09:22 +01:00
|
|
|
async function saveSettings(settings) {
|
|
|
|
|
const data = JSON.stringify(settings);
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
db.run(
|
|
|
|
|
"INSERT INTO settings (id, data) VALUES (1, ?) ON CONFLICT(id) DO UPDATE SET data = excluded.data",
|
|
|
|
|
[data],
|
|
|
|
|
(err) => (err ? reject(err) : resolve())
|
|
|
|
|
);
|
|
|
|
|
});
|
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
|
|
|
});
|