Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #226

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/rankBg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"dependencies": {
"@prisma/client": "^6.1.0",
"@sentry/bun": "^8.47.0",
"canvas": "^3.0.1",
"common-tags": "^1.8.2",
"discord-hybrid-sharding": "^2.2.3",
"discord.js": "^14.17.2",
Expand All @@ -51,7 +52,7 @@
"nodemon": "^3.1.9",
"prettier": "^3.4.2",
"prisma": "^6.1.0",
"release-it": "^17.11.0",
"release-it": "18",
"typescript": "^5.7.2",
"typescript-eslint": "^8.19.0"
},
Expand Down
9 changes: 5 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
}

datasource db {
Expand Down Expand Up @@ -173,7 +173,7 @@ model UserData {
modPositions HubModerator[]
updatedAt DateTime @updatedAt
xp Int @default(0)
level Int @default(1)
level Int @default(0)
messageCount Int @default(0)
lastMessageAt DateTime @default(now())
ownedHubs Hub[]
Expand All @@ -184,9 +184,10 @@ model UserData {
}

model ServerData {
id String @id @default(auto()) @map("_id") @db.ObjectId
serverId String @unique
id String @id @map("_id") @db.String
premiumStatus Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
messageCount Int @default(0)
lastMessageAt DateTime @default(now())
}
7 changes: 3 additions & 4 deletions src/commands/context-menu/deleteMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { t } from '#utils/Locale.js';
import { logMsgDelete } from '#utils/hub/logger/ModLogs.js';
import { isStaffOrHubMod } from '#utils/hub/utils.js';
import { deleteMessageFromHub, isDeleteInProgress } from '#utils/moderation/deleteMessage.js';
import { fetchUserLocale } from '#main/utils/Utils.js';

export default class DeleteMessage extends BaseCommand {
readonly data: RESTPostAPIContextMenuApplicationCommandsJSONBody = {
Expand Down Expand Up @@ -53,8 +54,7 @@ export default class DeleteMessage extends BaseCommand {
originalMsg: OriginalMessage,
hub: HubManager,
): Promise<void> {
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);

await interaction.editReply(
`${this.getEmoji('tick_icon')} Your request has been queued. Messages will be deleted shortly...`,
Expand Down Expand Up @@ -87,8 +87,7 @@ export default class DeleteMessage extends BaseCommand {
originalMsg: OriginalMessage | null,
hub: HubManager | null,
) {
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);

if (!originalMsg || !hub) {
await interaction.editReply(
Expand Down
13 changes: 4 additions & 9 deletions src/commands/context-menu/editMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import db from '#utils/Db.js';
import { getAttachmentURL } from '#utils/ImageUtils.js';
import { t } from '#utils/Locale.js';
import { censor } from '#utils/ProfanityUtils.js';
import { containsInviteLinks, handleError, replaceLinks } from '#utils/Utils.js';
import { containsInviteLinks, fetchUserLocale, handleError, replaceLinks } from '#utils/Utils.js';

interface ImageUrls {
oldURL?: string | null;
Expand All @@ -51,10 +51,9 @@ export default class EditMessage extends BaseCommand {
const isOnCooldown = await this.checkOrSetCooldown(interaction);
if (isOnCooldown) return;

const { userManager } = interaction.client;
const target = interaction.targetMessage;
const locale = await userManager.getUserLocale(interaction.user.id);
const voteLimiter = new VoteBasedLimiter('editMsg', interaction.user.id, userManager);
const locale = await fetchUserLocale(interaction.user.id);
const voteLimiter = new VoteBasedLimiter('editMsg', interaction.user.id);

if (await voteLimiter.hasExceededLimit()) {
await interaction.reply({
Expand Down Expand Up @@ -226,11 +225,7 @@ export default class EditMessage extends BaseCommand {
.catch(handleError);

// Decrement the vote limiter
const voteLimiter = new VoteBasedLimiter(
'editMsg',
interaction.user.id,
interaction.client.userManager,
);
const voteLimiter = new VoteBasedLimiter('editMsg', interaction.user.id);
await voteLimiter.decrementUses();
}

Expand Down
7 changes: 3 additions & 4 deletions src/commands/context-menu/messageInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { InfoEmbed } from '#utils/EmbedUtils.js';
import { type supportedLocaleCodes, t } from '#utils/Locale.js';
import { sendHubReport } from '#utils/hub/logger/Report.js';
import { isStaffOrHubMod } from '#utils/hub/utils.js';
import { fetchUserLocale } from '#main/utils/Utils.js';

type LocaleInfo = { locale: supportedLocaleCodes };
type AuthorInfo = { author: User };
Expand Down Expand Up @@ -388,8 +389,7 @@ export default class MessageInfo extends BaseCommand {
}

private async getMessageInfo(interaction: MessageContextMenuCommandInteraction) {
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id) ?? 'en';
const target = interaction.targetMessage;
const originalMsg =
(await getOriginalMessage(target.id)) ?? (await findOriginalMessage(target.id));
Expand All @@ -404,8 +404,7 @@ export default class MessageInfo extends BaseCommand {
const originalMsg =
(await getOriginalMessage(messageId)) ?? (await findOriginalMessage(messageId));

const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id) ?? 'en';

return { originalMsg, locale, messageId };
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/context-menu/modActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '#main/utils/network/messageUtils.js';
import { t } from '#utils/Locale.js';
import { isStaffOrHubMod } from '#utils/hub/utils.js';
import { fetchUserData, fetchUserLocale } from '#main/utils/Utils.js';

export default class BlacklistCtxMenu extends BaseCommand {
readonly data: RESTPostAPIContextMenuApplicationCommandsJSONBody = {
Expand All @@ -27,9 +28,9 @@ export default class BlacklistCtxMenu extends BaseCommand {
async execute(interaction: MessageContextMenuCommandInteraction) {
await interaction.deferReply({ flags: ['Ephemeral'] });

const { userManager } = interaction.client;
const dbUser = await userManager.getUser(interaction.user.id);
const locale = await userManager.getUserLocale(dbUser);

const dbUser = await fetchUserData(interaction.user.id);
const locale = dbUser ? await fetchUserLocale(dbUser) : 'en';

const originalMsg =
(await getOriginalMessage(interaction.targetId)) ??
Expand Down
4 changes: 2 additions & 2 deletions src/commands/slash/Information/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import type { ChatInputCommandInteraction } from 'discord.js';
import BaseCommand from '#main/core/BaseCommand.js';
import Constants from '#utils/Constants.js';
import { t } from '#utils/Locale.js';
import { fetchUserLocale } from '#main/utils/Utils.js';

export default class Invite extends BaseCommand {
readonly data = {
name: 'invite',
description: '👋 Invite me to your server!',
};
async execute(interaction: ChatInputCommandInteraction) {
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);
await interaction.reply({
content: t('invite', locale, {
support: Constants.Links.SupportInvite,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/slash/Information/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { type ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
import BaseCommand from '#main/core/BaseCommand.js';
import Constants from '#utils/Constants.js';
import { t } from '#utils/Locale.js';
import { fetchUserLocale } from '#main/utils/Utils.js';

export default class Rules extends BaseCommand {
readonly data = {
name: 'rules',
description: '📋 Sends the network rules for InterChat.',
};
async execute(interaction: ChatInputCommandInteraction) {
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);
const rulesEmbed = new EmbedBuilder()
.setDescription(t('rules.rules', locale, { rules_emoji: this.getEmoji('rules_icon') }))
.setImage(Constants.Links.RulesBanner)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/slash/Information/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import BaseCommand from '#main/core/BaseCommand.js';
import Constants from '#utils/Constants.js';
import { t } from '#utils/Locale.js';
import { fetchUserData, fetchUserLocale } from '#main/utils/Utils.js';

export default class Vote extends BaseCommand {
readonly data = {
Expand All @@ -18,10 +19,9 @@ export default class Vote extends BaseCommand {
};
async execute(interaction: ChatInputCommandInteraction) {
const { id } = interaction.user;
const userData = await interaction.client.userManager.getUser(id);
const userData = await fetchUserData(id);
const voteCount = String(userData?.voteCount ?? 0);
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = userData ? await fetchUserLocale(userData) : 'en';

const embed = new EmbedBuilder()
.setDescription(t('vote.description', locale))
Expand Down
5 changes: 2 additions & 3 deletions src/commands/slash/Main/blacklist/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Pagination } from '#main/modules/Pagination.js';
import Constants from '#utils/Constants.js';
import db from '#utils/Db.js';
import { type supportedLocaleCodes, t } from '#utils/Locale.js';
import { toTitleCase } from '#utils/Utils.js';
import { fetchUserLocale, toTitleCase } from '#utils/Utils.js';
import BlacklistCommand from './index.js';

// Type guard
Expand All @@ -17,8 +17,7 @@ export default class ListBlacklists extends BlacklistCommand {
const hubName = interaction.options.getString('hub', true);
const hub = await this.findHubsByName(hubName, interaction.user.id, 1);

const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);
if (!hub) {
await this.replyEmbed(
interaction,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/slash/Main/blacklist/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { t } from '#utils/Locale.js';
import { logServerUnblacklist } from '#utils/hub/logger/ModLogs.js';
import { sendBlacklistNotif } from '#utils/moderation/blacklistUtils.js';
import BlacklistCommand from './index.js';
import { fetchUserLocale } from '#main/utils/Utils.js';

export default class extends BlacklistCommand {
async execute(interaction: ChatInputCommandInteraction) {
await interaction.deferReply();

const { id: moderatorId } = interaction.user;
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);

const hubName = interaction.options.getString('hub');
const hub = await this.getHub({ name: hubName, userId: moderatorId });
Expand Down
9 changes: 5 additions & 4 deletions src/commands/slash/Main/blacklist/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { logUserUnblacklist } from '#utils/hub/logger/ModLogs.js';
import { sendBlacklistNotif } from '#utils/moderation/blacklistUtils.js';
import BlacklistCommand from './index.js';
import { Infraction } from '@prisma/client';
import { fetchUserLocale } from '#main/utils/Utils.js';

interface BlacklistOptions {
expiresAt: Date | null;
Expand Down Expand Up @@ -39,7 +40,7 @@ export default class extends BlacklistCommand {

private async extractCommandData(interaction: ChatInputCommandInteraction) {
const moderatorId = interaction.user.id;
const locale = await interaction.client.userManager.getUserLocale(moderatorId);
const locale = await fetchUserLocale(moderatorId);

const hubName = interaction.options.getString('hub');
const hub = await this.getHub({ name: hubName, userId: moderatorId });
Expand Down Expand Up @@ -88,7 +89,7 @@ export default class extends BlacklistCommand {
) {
const userId = interaction.options.getString('user', true);
const blacklistManager = new BlacklistManager('user', userId);
const locale = await interaction.client.userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);

const wasRemoved = await this.removeUserBlacklist(interaction, blacklistManager, userId, {
hubId,
Expand All @@ -110,7 +111,7 @@ export default class extends BlacklistCommand {
blacklistManager: BlacklistManager,
hubId: string,
) {
const locale = await interaction.client.userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);
const { reason, expiresAt: expires } = blacklist;

await this.sendSuccessResponse(
Expand Down Expand Up @@ -202,7 +203,7 @@ export default class extends BlacklistCommand {
blacklistManager: BlacklistManager,
{ userId, hubId, duration }: UserCheckOptions,
) {
const locale = await interaction.client.userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);
const hiddenOpt = { flags: ['Ephemeral'] } as const;

if (await this.hasBlockingCondition(interaction, userId, duration, locale)) {
Expand Down
9 changes: 4 additions & 5 deletions src/commands/slash/Main/connection/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CustomID } from '#utils/CustomID.js';
import db from '#utils/Db.js';
import { InfoEmbed } from '#utils/EmbedUtils.js';
import { t } from '#utils/Locale.js';
import { getOrCreateWebhook } from '#utils/Utils.js';
import { fetchUserLocale, getOrCreateWebhook } from '#utils/Utils.js';
import {
buildChannelSelect,
buildEditEmbed,
Expand Down Expand Up @@ -164,8 +164,8 @@ export default class ConnectionEditCommand extends Connection {
const customId = CustomID.parseCustomId(interaction.customId);
const channelId = customId.args.at(0);
const userIdFilter = customId.args.at(1);
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);

const locale = await fetchUserLocale(interaction.user.id);

if (userIdFilter !== interaction.user.id) {
const embed = new InfoEmbed().setDescription(
Expand Down Expand Up @@ -270,8 +270,7 @@ export default class ConnectionEditCommand extends Connection {
if (!interaction.isChannelSelectMenu()) return;
await interaction.deferUpdate();

const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);

const emoji = this.getEmoji('x_icon');
const customId = CustomID.parseCustomId(interaction.customId);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/slash/Main/connection/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Constants from '#utils/Constants.js';
import db from '#utils/Db.js';
import { t } from '#utils/Locale.js';
import ConnectionCommand from './index.js';
import { fetchUserLocale } from '#main/utils/Utils.js';

export default class List extends ConnectionCommand {
async execute(interaction: ChatInputCommandInteraction): Promise<void> {
Expand All @@ -13,8 +14,7 @@ export default class List extends ConnectionCommand {
include: { hub: true },
});

const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);
const locale = await fetchUserLocale(interaction.user.id);
if (connections.length === 0) {
await interaction.reply(
t('hub.joined.noJoinedHubs', locale, {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/slash/Main/connection/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import db from '#utils/Db.js';
import { InfoEmbed } from '#utils/EmbedUtils.js';
import { t } from '#utils/Locale.js';
import Connection from './index.js';
import { fetchUserLocale } from '#main/utils/Utils.js';

export default class Pause extends Connection {
override async execute(interaction: ChatInputCommandInteraction): Promise<void> {
const channelId = interaction.options.getString('channel') ?? interaction.channelId;
const connected = await db.connection.findFirst({ where: { channelId } });
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);

const locale = await fetchUserLocale(interaction.user.id);

if (!connected) {
await interaction.reply({
Expand Down
6 changes: 3 additions & 3 deletions src/commands/slash/Main/connection/unpause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { fetchCommands, findCommand } from '#utils/CommandUtils.js';
import { updateConnection } from '#utils/ConnectedListUtils.js';
import db from '#utils/Db.js';
import { t } from '#utils/Locale.js';
import { getOrCreateWebhook } from '#utils/Utils.js';
import { fetchUserLocale, getOrCreateWebhook } from '#utils/Utils.js';
import Connection from './index.js';

export default class Unpause extends Connection {
override async execute(interaction: ChatInputCommandInteraction): Promise<void> {
const channelId = interaction.options.getString('channel') ?? interaction.channelId;
const connected = await db.connection.findFirst({ where: { channelId } });
const { userManager } = interaction.client;
const locale = await userManager.getUserLocale(interaction.user.id);

const locale = await fetchUserLocale(interaction.user.id);

if (!connected) {
await this.replyEmbed(
Expand Down
3 changes: 2 additions & 1 deletion src/commands/slash/Main/hub/appeal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ms from 'ms';
import { ErrorEmbed } from '#utils/EmbedUtils.js';
import { t } from '#utils/Locale.js';
import HubCommand from './index.js';
import { fetchUserLocale } from '#main/utils/Utils.js';

export default class AppealCommand extends HubCommand {
async execute(interaction: ChatInputCommandInteraction) {
Expand Down Expand Up @@ -53,7 +54,7 @@ export default class AppealCommand extends HubCommand {
interaction,
t(
'hub.notFound_mod',
await interaction.client.userManager.getUserLocale(interaction.user.id),
await fetchUserLocale(interaction.user.id),
{ emoji: this.getEmoji('x_icon') },
),
{ flags: ['Ephemeral'] },
Expand Down
Loading
Loading