commit
This commit is contained in:
parent
f6e5d49159
commit
bc3c3f4cf1
3 changed files with 90 additions and 0 deletions
47
src/commands/guilds/enablefeature.ts
Normal file
47
src/commands/guilds/enablefeature.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { SlashCommandBuilder, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js";
|
||||
import { connectToDb, getGuild, setFeature } from "../../libs/mysql.js";
|
||||
import { errorEmbed, successEmbed } from "../../libs/discord.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("enablefeature")
|
||||
.setDescription("Enable a feature of the bot.")
|
||||
.setDMPermission(false)
|
||||
.addStringOption(option =>
|
||||
option.setName("feature")
|
||||
.setDescription("The feature to be enabled.")
|
||||
.setRequired(true)
|
||||
.addChoices([
|
||||
{name: "Welcome message", value: "welcome_message"},
|
||||
{name: "Goodbye message", value: "bye_message"},
|
||||
])),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
const connection = await connectToDb();
|
||||
|
||||
const guild_id = interaction.guild?.id ? interaction.guild?.id : ""
|
||||
|
||||
const guild = await getGuild(connection, guild_id)
|
||||
|
||||
if (!guild[0]) {
|
||||
const embed = errorEmbed("Your server must be registered to the bot, use /register to do so.", interaction.client.user.displayAvatarURL());
|
||||
|
||||
return interaction.reply({embeds: [embed]});
|
||||
}
|
||||
|
||||
const member = interaction.guild?.members.cache.get(interaction.user.id)
|
||||
|
||||
if (!member?.permissions.has(PermissionFlagsBits.Administrator) && !member?.roles.cache.has(guild[0].admin_role_id)) {
|
||||
const embed = errorEmbed("You are not allowed to use that command.", interaction.client.user.displayAvatarURL());
|
||||
|
||||
return await interaction.reply({embeds: [embed]});
|
||||
}
|
||||
|
||||
const feature: string | null = interaction.options.getString("feature")
|
||||
|
||||
setFeature(connection, guild_id, feature ? feature : "", "true");
|
||||
|
||||
const embed = successEmbed("The feature has been successfully activated.", interaction.client.user.displayAvatarURL())
|
||||
|
||||
interaction.reply({embeds: [embed]})
|
||||
},
|
||||
};
|
31
src/commands/guilds/setupwelcomemessage.ts
Normal file
31
src/commands/guilds/setupwelcomemessage.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { SlashCommandBuilder, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js";
|
||||
import { connectToDb, getGuild } from "../../libs/mysql.js";
|
||||
import { errorEmbed, successEmbed } from "../../libs/discord.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("setupwelcomemessage")
|
||||
.setDescription("Enable a feature of the bot.")
|
||||
.setDMPermission(false),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
const connection = await connectToDb();
|
||||
|
||||
const guild_id = interaction.guild?.id ? interaction.guild?.id : ""
|
||||
|
||||
const guild = await getGuild(connection, guild_id)
|
||||
|
||||
if (!guild[0]) {
|
||||
const embed = errorEmbed("Your server must be registered to the bot, use /register to do so.", interaction.client.user.displayAvatarURL());
|
||||
|
||||
return interaction.reply({embeds: [embed]});
|
||||
}
|
||||
|
||||
const member = interaction.guild?.members.cache.get(interaction.user.id)
|
||||
|
||||
if (!member?.permissions.has(PermissionFlagsBits.Administrator) && !member?.roles.cache.has(guild[0].admin_role_id)) {
|
||||
const embed = errorEmbed("You are not allowed to use that command.", interaction.client.user.displayAvatarURL());
|
||||
|
||||
return await interaction.reply({embeds: [embed]});
|
||||
}
|
||||
},
|
||||
};
|
|
@ -109,3 +109,15 @@ export function setAdminRole(connection: mysql.Connection, guild_id: string, rol
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function setFeature(connection: mysql.Connection, guild_id: string, feature: string, code: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(`UPDATE guilds SET ${feature} = ${code} WHERE guild_id = "${guild_id}"`, (error, result) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue