1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
import { PermissionFlagsBits, SlashCommandBuilder, MessageFlags, EmbedBuilder } from 'discord.js';
import { guildSettings } from '../models/guild-settings.js';
import { abEmbedColour } from '../storage/consts.js';
export default {
data: new SlashCommandBuilder()
.setName('settings')
.setDescription('Settings for AleeBot.')
.setContexts(0)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.addSubcommand(subcommand =>
subcommand
.setName('set')
.setDescription('Sets the settings for this guild.')
.addChannelOption(option =>
option
.setName('log')
.setDescription('Log channel.'))
.addChannelOption(option =>
option
.setName('suggestion')
.setDescription('Suggestion channel.'))
.addChannelOption(option =>
option
.setName('qotd')
.setDescription('Quote of the Day channel.'))
.addBooleanOption(option =>
option
.setName('qotdtoggle')
.setDescription('Toggle Quote of the Day.'))
.addBooleanOption(option =>
option
.setName('llmtoggle')
.setDescription('Toggle LLM Chatbot.')))
.addSubcommand(subcommand =>
subcommand
.setName('clear')
.setDescription('Clears all settings for this guild.')),
async execute(interaction) {
if (!interaction.member.permissions.has(PermissionFlagsBits.ManageGuild) &&
!interaction.member.permissions.has(PermissionFlagsBits.Administrator) &&
interaction.user.id !== interaction.guild.ownerId) return await interaction.reply({ content: 'You do not have the permission to manage this guild.', flags: MessageFlags.Ephemeral });
const guildSetting = await guildSettings.findOne({ where: { guildID: interaction.guild.id } });
if (!guildSetting) await guildSettings.create({ guildID: interaction.guild.id });
if (interaction.options.getSubcommand() === 'clear') {
await guildSettings.update({
logChannelID: null,
suggestionsChannelID: null,
qotdChannelID: null,
qotdToggle: null,
ollamaEnabled: null
}, { where: { guildID: interaction.guild.id } });
return await interaction.reply({ content: 'Cleared all settings for this guild.', flags: MessageFlags.Ephemeral });
}
const guildEmbed = new EmbedBuilder()
.setAuthor({ name: 'AleeBot Guild Settings', iconURL: interaction.client.user.avatarURL() })
.setDescription('Settings for this guild.')
.setColor(abEmbedColour);
// Handle clearing settings
if (areAllSettingsEmpty(interaction)) {
guildEmbed.addFields(
{ name: 'Logging', value: guildSetting?.logChannelID ? `<#${guildSetting.logChannelID}>` : 'N/A', inline: true },
{ name: 'Suggestions', value: guildSetting?.suggestionsChannelID ? `<#${guildSetting.suggestionsChannelID}>` : 'N/A', inline: true },
{ name: 'QOTD Channel', value: guildSetting?.qotdChannelID ? `<#${guildSetting.qotdChannelID}>` : 'N/A', inline: true },
{ name: 'LLM Chatbot', value: guildSetting?.ollamaEnabled ? 'Enabled' : 'Disabled', inline: true },
{ name: 'Quote of the Day', value: guildSetting?.qotdToggle ? 'Enabled' : 'Disabled', inline: true }
);
return await interaction.reply({ embeds: [guildEmbed], flags: MessageFlags.Ephemeral });
}
// Process each setting type
guildEmbed.setDescription('Updated this setting.');
await updateChannelSetting(interaction, guildEmbed, 'log', 'logChannelID', 'Logging');
await updateChannelSetting(interaction, guildEmbed, 'suggestion', 'suggestionsChannelID', 'Suggestions');
await updateChannelSetting(interaction, guildEmbed, 'qotd', 'qotdChannelID', 'QOTD Channel');
await updateBooleanSetting(interaction, guildEmbed, 'qotdtoggle', 'qotdToggle', 'Quote of the Day');
await updateBooleanSetting(interaction, guildEmbed, 'llmtoggle', 'ollamaEnabled', 'LLM Chatbot');
return await interaction.reply({ embeds: [guildEmbed], flags: MessageFlags.Ephemeral });
}
};
// Helper functions
function areAllSettingsEmpty(interaction) {
return !interaction.options.getChannel('log') &&
!interaction.options.getChannel('suggestion') &&
!interaction.options.getChannel('qotd') &&
interaction.options.getBoolean('qotdtoggle') === null &&
interaction.options.getBoolean('llmtoggle') === null;
}
async function updateChannelSetting(interaction, embed, optionName, dbField, displayName) {
const channel = interaction.options.getChannel(optionName);
if (channel) {
embed.addFields({ name: displayName, value: `${channel}`, inline: true });
await guildSettings.update({ [dbField]: channel.id }, { where: { guildID: interaction.guild.id } });
}
}
async function updateBooleanSetting(interaction, embed, optionName, dbField, displayName) {
const value = interaction.options.getBoolean(optionName);
if (value !== null) {
embed.addFields({ name: displayName, value: value ? 'Enabled' : 'Disabled', inline: true });
await guildSettings.update({ [dbField]: value }, { where: { guildID: interaction.guild.id } });
}
}
|