Merge pull request #425 from VermiumSifell/dev

🧑‍💻 Fixed more code smells
This commit is contained in:
Axel Olausson Holtenäs 2022-10-14 13:35:46 +02:00 committed by GitHub
commit 82cee377f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 23 deletions

View file

@ -1,6 +1,6 @@
import { ChannelType, Message } from "discord.js";
import * as cooldown from "../../../../../helpers/cooldown";
import fetchGuild from "../../../../../helpers/fetchGuild";
import { message as CooldownMessage } from "../../../../../helpers/cooldown";
import fetchGuild from "../../../../../helpers/guildData";
import fetchUser from "../../../../../helpers/userData";
import logger from "../../../../../middlewares/logger";
@ -20,7 +20,7 @@ export default {
if (content.length < guildData.credits.minimumLength) return;
const isOnCooldown = await cooldown.message(
const isOnCooldown = await CooldownMessage(
message,
guildData.credits.timeout,
"messageCreate-credits"
@ -31,15 +31,13 @@ export default {
await userData
.save()
.then(async () => {
.then(() => {
logger.silly(
`User ${userId} in guild ${guildId} has ${userData.credits} credits`
);
})
.catch(async (err) => {
logger.error(
`Error saving credits for user ${userId} in guild ${guildId} - ${err}`
);
.catch(() => {
throw new Error(`Error saving credits to database.`);
});
},
};

View file

@ -1,6 +1,6 @@
import { ChannelType, Message } from "discord.js";
import * as cooldown from "../../../../../helpers/cooldown";
import fetchGuild from "../../../../../helpers/fetchGuild";
import { message as CooldownMessage } from "../../../../../helpers/cooldown";
import fetchGuild from "../../../../../helpers/guildData";
import fetchUser from "../../../../../helpers/userData";
import logger from "../../../../../middlewares/logger";
@ -17,7 +17,7 @@ export default {
if (content.length < guildData.credits.minimumLength) return;
const isOnCooldown = await cooldown.message(
const isOnCooldown = await CooldownMessage(
message,
guildData.credits.timeout,
"messageCreate-points"
@ -28,16 +28,13 @@ export default {
await userData
.save()
.then(async () => {
.then(() => {
logger.silly(
`Successfully saved user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`
);
})
.catch(async (err) => {
logger.error(
`Error saving points for user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`,
err
);
.catch(() => {
throw new Error("Error saving points to database.");
});
logger.silly(

View file

@ -1,4 +1,4 @@
import { EmbedBuilder, Message, TextChannel } from "discord.js";
import { ChannelType, EmbedBuilder, Message } from "discord.js";
import getEmbedConfig from "../../../helpers/getEmbedData";
import logger from "../../../middlewares/logger";
import guildSchema from "../../../models/guild";
@ -26,9 +26,10 @@ export default {
const channel = client.channels.cache.get(`${guildData.audits.channelId}`);
if (channel === null) return;
if (!channel) return;
if (channel.type !== ChannelType.GuildText) return;
(channel as TextChannel)
channel
.send({
embeds: [
new EmbedBuilder()
@ -50,13 +51,13 @@ export default {
}),
],
})
.then(async () => {
.then(() => {
logger.info(
`Audit log sent for event messageDelete in guild ${message?.guild?.name} (${message?.guild?.id})`
);
})
.catch(async () => {
logger.error(
.catch(() => {
throw new Error(
`Audit log failed to send for event messageDelete in guild ${message?.guild?.name} (${message?.guild?.id})`
);
});