Skip to content

Commit

Permalink
feat(commands): improve remove-previous system in autoreport comm…
Browse files Browse the repository at this point in the history
…and (#1)
  • Loading branch information
dmyna committed Aug 20, 2024
1 parent 4cb7ad4 commit a9b2fed
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ model AutoReportPresetInfo {
emoji String
emojiID String?
customEmoji Boolean
reactNewMessages Boolean
info AutoReportPresetData? @relation
}
Expand Down
79 changes: 38 additions & 41 deletions src/commands/mod/autoreport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ export const data: types.data = () => {
remove: {
subc: "Remove o preset que você criou para eu reagir nos chats!",
preset: "Qual preset você deseja remover?",
removePrevious:
"Você deseja que eu faça com que as mensagens já reagidas " +
"parem de ser reportadas?",
preservePrevious:
"Você deseja que eu continue lidando com as mensagens já reagidas? " +
"(remoção parcial)",
},
list: {
subc: "Lista todos os presets que você criou para eu reagir nos chats!",
Expand Down Expand Up @@ -246,10 +246,10 @@ export const data: types.data = () => {
.setAutocomplete(true)
.setRequired(true)
)
.addBooleanOption((removePrevious) =>
removePrevious
.setName("remove-previous")
.setDescription(description.remove.removePrevious)
.addBooleanOption((preservePrevious) =>
preservePrevious
.setName("preserve-previous")
.setDescription(description.remove.preservePrevious)
)
.addBooleanOption((ephemeral) =>
ephemeral
Expand All @@ -262,11 +262,6 @@ export const data: types.data = () => {
list
.setName("list")
.setDescription(description.list.subc)
.addBooleanOption((withOlds) =>
withOlds
.setName("with-olds")
.setDescription(description.list.withOlds)
)
.addBooleanOption((ephemeral) =>
ephemeral
.setName("ephemeral")
Expand Down Expand Up @@ -356,9 +351,7 @@ export const action: types.actionFunction = async (params) => {
};
}

const middleActionOnFirstReaction: reactTypes.ActionBeforeReact = async (
message
) => {
const actionBeforeReact: reactTypes.ActionBeforeReact = async (message) => {
const dataTable = await prisma.autoReportPresetData.findUnique({
where: { name: params.name },
});
Expand Down Expand Up @@ -399,7 +392,7 @@ export const action: types.actionFunction = async (params) => {
{
action: actionOnUserReaction,
actionParams: executionParams,
middleAction: middleActionOnFirstReaction,
middleAction: actionBeforeReact,
}
);

Expand Down Expand Up @@ -453,7 +446,7 @@ export const action: types.actionFunction = async (params) => {
{
const actionOnFirstReaction = await react.reactOnNewMessage(
executionParams,
middleActionOnFirstReaction
actionBeforeReact
);

// React to new messages
Expand Down Expand Up @@ -552,22 +545,20 @@ const subCommands: Factory<types.SubCommands> = () => {
customEmoji,
};

const initialData = {
alreadyReported: [],
messages: [],
};

await prisma.autoReportPresetInfo.create({
const presetInfo = await prisma.autoReportPresetInfo.create({
data: {
name: presetName,
reactNewMessages: true,
...presetParams,
},
});

await prisma.autoReportPresetData.create({
data: {
name: presetName,
...initialData,
alreadyReported: [],
noReported: [],
infoUUID: presetInfo.uuid
},
});

Expand Down Expand Up @@ -748,29 +739,35 @@ const subCommands: Factory<types.SubCommands> = () => {
"preset-name",
true
);
const removePrevious =
interaction.options.getBoolean("remove-previous");
const preservePrevious =
interaction.options.getBoolean("preserve-previous");

await prisma.autoReportPresetInfo.delete({
where: { name: presetName },
});
if (preservePrevious) {
await prisma.autoReportPresetInfo.update({
where: { name: presetName },
data: { reactNewMessages: false },
});
} else {
await prisma.autoReportPresetData.delete({
where: { name: presetName },
});

await prisma.autoReportPresetData.delete({
where: { name: presetName },
});
await prisma.autoReportPresetInfo.delete({
where: { name: presetName },
});

new ListenerHandler(
Events.MessageReactionAdd,
`${Events.MessageReactionAdd}-${presetName}`
).Remove();
}

new ListenerHandler(
Events.MessageCreate,
`${Events.MessageCreate}-${presetName}`
).Remove();
new ListenerHandler(
Events.MessageReactionAdd,
`${Events.MessageReactionAdd}-${presetName}`
).Remove();


return Ok(`O preset **${presetName}** foi removido`);

},
list: async (interaction) => {
const messageEmbed = await messagesLib.embed.sendListMessage(
Expand All @@ -793,9 +790,9 @@ export const execute: types.execute = async (interaction) => {
var response: Ok<string | APIEmbed>;
const getEphemeral = interaction.options.getBoolean("ephemeral");

// await interaction.deferReply({
// ephemeral: getEphemeral !== null ? getEphemeral : true,
// });
await interaction.deferReply({
ephemeral: getEphemeral !== null ? getEphemeral : true,
});

switch (subcommand) {
case "new":
Expand Down
23 changes: 15 additions & 8 deletions src/lib/external/factories/preseted.f.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,24 @@ const Default: Factory<types.PresetedFuns> = () => {
"Não existem presets disponíveis!\n" +
`*Você pode criar um usando \`/${params.commandName} new\`!*`;
} else {
for (const obj of dataTables) {
embed.description += `· **${obj.name}** - `;
if (obj.customEmoji) {
embed.description += `<:${obj.emoji}:${obj.emojiID}> - `;
for (const preset of dataTables) {
embed.description += `· **${preset.name}** - `;

if (preset.customEmoji) {
embed.description += `<:${preset.emoji}:${preset.emojiID}> - `;
} else {
embed.description += `${obj.emoji} - `;
embed.description += `${preset.emoji} - `;
}

embed.description +=
`<#${obj.chatID}> -> ` + `<#${obj.logChatID}>\n`;
`<#${preset.chatID}> -> ` +
`<#${preset.logChatID}>`;

if (!preset.reactNewMessages) {
embed.description += " (not reacting to new messages :x:)";
}

embed.description += "\n";
}
}

Expand Down

0 comments on commit a9b2fed

Please sign in to comment.