Skip to content

Commit

Permalink
Recode utils to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorKowalczyk committed Nov 30, 2024
1 parent b52d155 commit 1aca32f
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 278 deletions.
6 changes: 3 additions & 3 deletions apps/bot/commands/Moderation/warn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clearWarns, listWarnings, warnUser, removeWarning } from "@majoexe/util/database";
import { clearWarns, listWarns, warnUser, removeWarn } from "@majoexe/util/database";
import { ApplicationCommandType, ApplicationCommandOptionType, PermissionsBitField, EmbedBuilder, codeBlock, PermissionFlagsBits, InteractionContextType, ApplicationIntegrationType } from "discord.js";
import type { SlashCommand } from "@/util/types/Command";

Expand Down Expand Up @@ -135,7 +135,7 @@ export default {
return client.errorMessages.createSlashError(interaction, "❌ You need to provide the ID of the warning to remove!");
}

const removedWarning = await removeWarning(interaction.guild.id, user.id, id);
const removedWarning = await removeWarn(interaction.guild.id, user.id, id);

if (!removedWarning) {
return client.errorMessages.createSlashError(interaction, "❌ I couldn't find a warning with that ID!");
Expand All @@ -161,7 +161,7 @@ export default {
return client.errorMessages.createSlashError(interaction, "❌ You need to provide a user to list the warnings of!");
}

const warnings = await listWarnings(interaction.guild.id, user.id);
const warnings = await listWarns(interaction.guild.id, user.id);

if (!warnings || warnings.length === 0) {
return client.errorMessages.createSlashError(interaction, "❌ I couldn't find any warnings for that user!");
Expand Down
16 changes: 8 additions & 8 deletions packages/utils/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export * from "./settings/XPSettings.js";

// Logs
export * from "./logs/fetchLogs.js";
export * from "./logs/fetchLogs";

// AutoMod
export * from "./moderation/automod/createDatabaseAutoModRule";
Expand All @@ -12,17 +12,17 @@ export * from "./moderation/automod/syncDatabaseAutoModRule";
export * from "./moderation/automod/updateDatabaseAutoModRule";

// Warnings
export * from "./moderation/warn/add.js";
export * from "./moderation/warn/clear.js";
export * from "./moderation/warn/list.js";
export * from "./moderation/warn/remove.js";
export * from "./moderation/warn/warnUser.js";
export * from "./moderation/warn/clearWarns";
export * from "./moderation/warn/listWarns";
export * from "./moderation/warn/removeWarn";

// XP
export * from "./xp/check.js";
export * from "./xp/reset.js";
export * from "./xp/checkXP";
export * from "./xp/resetXP";

// Reputation
export * from "./reputation/check.js";
export * from "./reputation/checkReputation";
export * from "./reputation/give.js";
export * from "./reputation/take.js";
export * from "./reputation/set";
Expand Down
55 changes: 0 additions & 55 deletions packages/utils/database/logs/fetchLogs.js

This file was deleted.

27 changes: 0 additions & 27 deletions packages/utils/database/moderation/warn/clear.js

This file was deleted.

20 changes: 20 additions & 0 deletions packages/utils/database/moderation/warn/clearWarns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import prismaClient from "@majoexe/database";
import { Snowflake } from "discord-api-types/globals";

export async function clearWarns(userId: Snowflake, guildId: Snowflake) {
try {
const allWarnings = await prismaClient.guildWarns.deleteMany({
where: {
guildId,
user: {
discordId: userId,
},
},
});

return allWarnings?.count || 0;
} catch (error) {
console.error("Failed to clear warns:", error);
throw error;
}
}
27 changes: 0 additions & 27 deletions packages/utils/database/moderation/warn/list.js

This file was deleted.

20 changes: 20 additions & 0 deletions packages/utils/database/moderation/warn/listWarns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import prismaClient from "@majoexe/database";
import { Snowflake } from "discord-api-types/globals";

export async function listWarns(guildId: Snowflake, userId: Snowflake) {
try {
const warnings = await prismaClient.guildWarns.findMany({
where: {
guildId,
user: {
discordId: userId,
},
},
});

return warnings;
} catch (error) {
console.error("Failed to list warnings:", error);
throw error;
}
}
37 changes: 0 additions & 37 deletions packages/utils/database/moderation/warn/remove.js

This file was deleted.

29 changes: 29 additions & 0 deletions packages/utils/database/moderation/warn/removeWarn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import prismaClient, { GuildWarns } from "@majoexe/database";
import { Snowflake } from "discord-api-types/globals";

export async function removeWarn(guildId: Snowflake, userId: Snowflake, warnId: GuildWarns["warnId"]) {
try {
const warning = await prismaClient.guildWarns.findFirst({
where: {
guildId,
user: {
discordId: userId,
},
warnId,
},
});

if (!warning) return false;

await prismaClient.guildWarns.delete({
where: {
id: warning.id,
},
});

return warning;
} catch (error) {
console.error("Failed to remove warning: ", error);
throw error;
}
}
26 changes: 0 additions & 26 deletions packages/utils/database/reputation/check.js

This file was deleted.

19 changes: 19 additions & 0 deletions packages/utils/database/reputation/checkReputation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import prismaClient from "@majoexe/database";
import { Snowflake } from "discord-api-types/globals";

export async function checkReputation(userId: Snowflake, guildId: Snowflake) {
try {
const rep = await prismaClient.reputation.findFirst({
where: {
guildId,
userId,
},
});

if (!rep) return 0;
return rep.reputation || 0;
} catch (error) {
console.error("Failed to check reputation:", error);
throw error;
}
}
26 changes: 0 additions & 26 deletions packages/utils/database/xp/check.js

This file was deleted.

19 changes: 19 additions & 0 deletions packages/utils/database/xp/checkXP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import prismaClient from "@majoexe/database";
import { Snowflake } from "discord-api-types/globals";

export async function checkXP(userId: Snowflake, guildId: Snowflake) {
try {
const xp = await prismaClient.guildXp.findFirst({
where: {
guildId,
userId,
},
});

if (!xp) return 0;
return xp.xp || 0;
} catch (error) {
console.error("Failed to check XP:", error);
throw error;
}
}
25 changes: 0 additions & 25 deletions packages/utils/database/xp/reset.js

This file was deleted.

Loading

0 comments on commit 1aca32f

Please sign in to comment.