nice new update
This commit is contained in:
parent
e136522421
commit
666638c956
136 changed files with 4483 additions and 9190 deletions
140
src/bot/commands/messagemacro/add.ts
Normal file
140
src/bot/commands/messagemacro/add.ts
Normal file
|
@ -0,0 +1,140 @@
|
|||
import { Client, ChatInputCommandInteraction, Role, GuildChannelResolvable, PermissionsBitField, ChannelType } from "discord.js";
|
||||
|
||||
import { schemas } from "../../../database";
|
||||
//@ts-expect-error
|
||||
import YALAS from 'mcstatusbot-logger';
|
||||
|
||||
import { GuildInstance } from "../../../database/schemas/Guild";
|
||||
import { UserInstance } from "../../../database/schemas/User";
|
||||
|
||||
|
||||
export async function chatInputCommand(client: Client, interaction: ChatInputCommandInteraction, guild: GuildInstance, user: UserInstance) {
|
||||
if (!interaction.guild) return interaction.reply("must be done in discord server");
|
||||
|
||||
const botMember = interaction.guild.members.me;
|
||||
if (!botMember) {
|
||||
YALAS.error("messagemacro add: bot in guild null");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//get macro
|
||||
let macroContent = interaction.options.getString('macro');
|
||||
if (!macroContent) return;
|
||||
macroContent = macroContent.replace(/\s+/g, '');
|
||||
|
||||
//get and validate message content
|
||||
const messageContent = interaction.options.getString('message');
|
||||
if (messageContent === null) return;
|
||||
if (messageContent.length < 3 || messageContent.length > 2000) {
|
||||
return interaction.reply({
|
||||
embeds: [{
|
||||
title: "Invalid Message",
|
||||
description: "The set message must be between 3 and 2000 in length."
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//get and validate role
|
||||
const role = interaction.options.getMentionable('trigger-role');
|
||||
if (!(role instanceof Role)) {
|
||||
return interaction.reply({
|
||||
embeds: [{
|
||||
title: "Invalid Role",
|
||||
description: "The selected role is not a valid role"
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
const deleteMsg = interaction.options.getBoolean('deletecmd') ?? false;
|
||||
|
||||
const impersonate = interaction.options.getBoolean('impersonate') ?? false;
|
||||
|
||||
|
||||
|
||||
//get and validate channel
|
||||
let channel = interaction.options.getChannel('channel');
|
||||
console.log("balkkd cjrA")
|
||||
console.log(channel
|
||||
)
|
||||
if (channel === undefined) channel = null;
|
||||
if (channel !== null) {
|
||||
if (channel.type !== ChannelType.GuildText && channel.type !== ChannelType.GuildAnnouncement) {
|
||||
return interaction.reply({
|
||||
embeds: [{
|
||||
title: "That Will Not Work",
|
||||
description: "The selected channel is not a text channel please select a text channel."
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
const botPermSM = botMember.permissionsIn((channel as GuildChannelResolvable)).toArray();
|
||||
if (botPermSM && !botPermSM.includes('SendMessages')) {
|
||||
return interaction.reply({
|
||||
embeds: [{
|
||||
title: "Missing permission",
|
||||
description: "you need to give me the send message permission in the selected channel."
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
await interaction.deferReply();
|
||||
//check msgMacro does net exist for reaction in channel
|
||||
try {
|
||||
const msgMacro = await schemas['MessageMacro'].findOne({
|
||||
where: {
|
||||
guild: guild.id,
|
||||
shortCode: macroContent,
|
||||
}
|
||||
});
|
||||
|
||||
if (msgMacro !== null) {
|
||||
return interaction.editReply({
|
||||
embeds: [{
|
||||
title: "Message Macro Exists",
|
||||
description: "The message macro `" + msgMacro.dataValues.shortCode + "` already exists please edit or remove it"
|
||||
}]
|
||||
});
|
||||
}
|
||||
} catch (err: any) {
|
||||
YALAS.error(err)
|
||||
YALAS.error(err.stack || err);
|
||||
return interaction.editReply("error when checking for existing message macro in database.");
|
||||
}
|
||||
|
||||
try {
|
||||
await schemas['MessageMacro'].create({
|
||||
guild: guild.id,
|
||||
channel: channel ? channel.id : null,
|
||||
shortCode: macroContent,
|
||||
message: messageContent,
|
||||
role: role.id,
|
||||
impersonate: impersonate,
|
||||
deleteShortCode: deleteMsg
|
||||
});
|
||||
} catch (err: any) {
|
||||
YALAS.error(err.stack || err);
|
||||
return interaction.editReply("error when saving reaction role to database.");
|
||||
}
|
||||
|
||||
|
||||
let prefixNote = '';
|
||||
if (macroContent.toLocaleLowerCase().startsWith(guild.prefix)) {
|
||||
prefixNote = "\nNote: it looks like your macro contains the prefix so to activate it you will need to type `" + guild.prefix + macroContent + "`";
|
||||
}
|
||||
try {
|
||||
return interaction.editReply({
|
||||
embeds: [{
|
||||
title: "Success",
|
||||
description: "The message Macro has been created."+macroContent
|
||||
}]
|
||||
});
|
||||
} catch (err: any) {
|
||||
YALAS.error(err.stack || err);
|
||||
}
|
||||
|
||||
}
|
183
src/bot/commands/messagemacro/list.ts
Normal file
183
src/bot/commands/messagemacro/list.ts
Normal file
|
@ -0,0 +1,183 @@
|
|||
import {
|
||||
Client,
|
||||
ChatInputCommandInteraction,
|
||||
EmbedBuilder,
|
||||
ButtonBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonStyle,
|
||||
} from "discord.js";
|
||||
|
||||
import { schemas } from "../../../database";
|
||||
//@ts-expect-error
|
||||
import YALAS from "mcstatusbot-logger";
|
||||
|
||||
import { GuildInstance } from "../../../database/schemas/Guild";
|
||||
import { UserInstance } from "../../../database/schemas/User";
|
||||
import { MessageMacroAttributes } from "../../../database/schemas/MessageMacro";
|
||||
|
||||
export async function chatInputCommand(client: Client, interaction: ChatInputCommandInteraction, guild: GuildInstance, user: UserInstance) {
|
||||
if (!interaction.guild) return interaction.reply("Must be done in a Discord server.");
|
||||
|
||||
const botMember = interaction.guild.members.me;
|
||||
if (!botMember) {
|
||||
YALAS.error("MessageMacro Add: Bot in guild is null");
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
let msgMacros = [];
|
||||
try {
|
||||
const msgMacroDocs = await schemas["MessageMacro"].findAll({
|
||||
where: {
|
||||
guild: guild.id,
|
||||
},
|
||||
});
|
||||
console.log("nuts")
|
||||
msgMacros = msgMacroDocs.map((item: any) => item.dataValues);
|
||||
} catch (err: any) {
|
||||
YALAS.error(err);
|
||||
YALAS.error(err.stack || err);
|
||||
return interaction.editReply("Error when checking for message macros in the database.");
|
||||
}
|
||||
|
||||
if (msgMacros.length === 0) {
|
||||
return interaction.editReply("No message macros found.");
|
||||
}
|
||||
console.log("balks")
|
||||
|
||||
|
||||
const updateEmbed = (index: number) => {
|
||||
const currentMacro: MessageMacroAttributes = msgMacros[index];
|
||||
const embed = new EmbedBuilder()
|
||||
.setAuthor({name: "Message Macro"})
|
||||
.setTitle(currentMacro.shortCode)
|
||||
.setDescription(currentMacro.message + `\n\n-# --\n-# Prefix: ${guild.prefix}\n-# role: <@&${currentMacro.role}>\n-# Channel: ${currentMacro.channel == null ? '' : '<#' + currentMacro.channel + '>'}`)
|
||||
|
||||
const buttons = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId("prev")
|
||||
.setLabel("<")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(index === 0),
|
||||
new ButtonBuilder()
|
||||
.setCustomId("index")
|
||||
.setLabel(`${index + 1}/${msgMacros.length}`)
|
||||
.setStyle(ButtonStyle.Secondary)
|
||||
.setDisabled(true),
|
||||
new ButtonBuilder()
|
||||
.setCustomId("next")
|
||||
.setLabel(">")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(index === msgMacros.length - 1)
|
||||
);
|
||||
|
||||
const actionButtons = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId("delete")
|
||||
.setLabel("Delete")
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
new ButtonBuilder()
|
||||
.setCustomId("edit")
|
||||
.setLabel("Edit")
|
||||
.setStyle(ButtonStyle.Success)
|
||||
);
|
||||
|
||||
return { embed, buttons, actionButtons };
|
||||
};
|
||||
|
||||
|
||||
// Pagination variables
|
||||
let currentIndex = 0;
|
||||
const { embed, buttons, actionButtons } = updateEmbed(currentIndex);
|
||||
|
||||
const message = await interaction.editReply({
|
||||
embeds: [embed],
|
||||
components: [buttons, actionButtons]
|
||||
});
|
||||
|
||||
const collector = message.createMessageComponentCollector({
|
||||
time: 60000, // 1 minute timeout
|
||||
});
|
||||
|
||||
collector.on("collect", async (i) => {
|
||||
if (i.user.id !== interaction.user.id) {
|
||||
return i.reply({ content: "This interaction isn't for you.", ephemeral: true });
|
||||
}
|
||||
|
||||
switch (i.customId) {
|
||||
case "prev":
|
||||
currentIndex = Math.max(0, currentIndex - 1);
|
||||
break;
|
||||
case "next":
|
||||
currentIndex = Math.min(msgMacros.length - 1, currentIndex + 1);
|
||||
break;
|
||||
case "delete":
|
||||
await schemas["MessageMacro"].destroy({
|
||||
where: { id: msgMacros[currentIndex].id },
|
||||
});
|
||||
msgMacros.splice(currentIndex, 1);
|
||||
currentIndex = Math.max(0, currentIndex - 1);
|
||||
break;
|
||||
case "edit":
|
||||
// Handle edit logic here
|
||||
await i.reply({
|
||||
content: "Edit functionality is not implemented yet.",
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (msgMacros.length === 0) {
|
||||
collector.stop();
|
||||
return interaction.editReply({
|
||||
content: "All message macros have been deleted.",
|
||||
embeds: [],
|
||||
components: [],
|
||||
});
|
||||
}
|
||||
|
||||
const { embed, buttons, actionButtons } = updateEmbed(currentIndex);
|
||||
await i.update({ embeds: [embed], components: [buttons, actionButtons] });
|
||||
});
|
||||
|
||||
collector.on("end", () => {
|
||||
const buttons = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId("prev")
|
||||
.setLabel("<")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(true),
|
||||
new ButtonBuilder()
|
||||
.setCustomId("index")
|
||||
.setLabel(`${currentIndex + 1}/${msgMacros.length}`)
|
||||
.setStyle(ButtonStyle.Secondary)
|
||||
.setDisabled(true),
|
||||
new ButtonBuilder()
|
||||
.setCustomId("next")
|
||||
.setLabel(">")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(true)
|
||||
);
|
||||
const actionButtons = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId("delete")
|
||||
.setLabel("Delete")
|
||||
.setStyle(ButtonStyle.Danger)
|
||||
.setDisabled(true),
|
||||
new ButtonBuilder()
|
||||
.setCustomId("edit")
|
||||
.setLabel("Edit")
|
||||
.setStyle(ButtonStyle.Success)
|
||||
.setDisabled(true)
|
||||
);
|
||||
interaction.editReply({
|
||||
components: [buttons, actionButtons],
|
||||
});
|
||||
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue