Skip to content

Commit

Permalink
feat: /profile command to view own or someone else's profile (#246)
Browse files Browse the repository at this point in the history
* feat: basic `/profile` command

* remove LevelingService from custom client props

* add makeshift badge
  • Loading branch information
dev-737 authored Feb 22, 2025
1 parent 4d6383f commit 844670f
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 234 deletions.
7 changes: 2 additions & 5 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,16 @@ model UserData {
banReason String?
mentionOnReply Boolean @default(true)
acceptedRules Boolean @default(false)
updatedAt DateTime @updatedAt
xp Int @default(0)
level Int @default(0)
messageCount Int @default(0)
lastMessageAt DateTime @default(now())
modPositions HubModerator[]
ownedHubs Hub[]
infractions Infraction[] @relation("infractions")
issuedInfractions Infraction[] @relation("issuedInfractions")
inboxLastReadDate DateTime? @default(now())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([xp])
@@index([level])
@@index([messageCount])
}

Expand Down
16 changes: 8 additions & 8 deletions src/commands/Information/rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ export default class RankCommand extends BaseCommand {
await ctx.deferReply();

try {
const targetUser = await ctx.options.getUser('user') ?? ctx.user;
const stats = await ctx.client.userLevels.getStats(
targetUser.id,
targetUser.username,
);
const rankCard = await this.createRankCard(targetUser, stats);

await ctx.editReply({ files: [rankCard] });
// const targetUser = await ctx.options.getUser('user') ?? ctx.user;
// const stats = await ctx.client.userLevels.getStats(
// targetUser.id,
// targetUser.username,
// );
// const rankCard = await this.createRankCard(targetUser, stats);

// await ctx.editReply({ files: [rankCard] });
}
catch (error) {
handleError(error, {
Expand Down
67 changes: 67 additions & 0 deletions src/commands/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import BaseCommand from '#src/core/BaseCommand.js';
import Context from '#src/core/CommandContext/Context.js';
import Constants from '#src/utils/Constants.js';
import db from '#src/utils/Db.js';
import { getUserLeaderboardRank } from '#src/utils/Leaderboard.js';
import { checkIfStaff, fetchUserData } from '#src/utils/Utils.js';
import { ApplicationCommandOptionType, EmbedBuilder, time } from 'discord.js';
export default class ProfileCommand extends BaseCommand {
constructor() {
super({
name: 'profile',
description: 'View your profile or someone else\'s InterChat profile.',
types: { slash: true, prefix: true },
options: [
{
type: ApplicationCommandOptionType.User,
name: 'user',
description: 'The user to view the profile of.',
required: false,
},
],
});
}
async execute(ctx: Context) {
const user = (await ctx.options.getUser('user')) ?? ctx.user;
const userData = await fetchUserData(user.id);

if (!userData) {
await ctx.reply('User not found.');
return;
}

const embed = new EmbedBuilder()
.setDescription(`### @${user.username} ${checkIfStaff(user.id) ? ctx.getEmoji('staff_badge') : ''}`)
.addFields([
{
name: 'Leaderboard Rank',
value: `#${(await getUserLeaderboardRank(user.id)) ?? 'Unranked.'}`,
inline: true,
},
{
name: 'Total Messages',
value: `${userData.messageCount}`,
inline: true,
},
{
name: 'User Since',
value: `${time(Math.round(userData.createdAt.getTime() / 1000), 'D')}`,
inline: true,
},
{
name: 'Hubs Owned',
value: `${(await db.hub.findMany({ where: { ownerId: user.id, private: false } })).map((h) => h.name).join(', ')}`,
inline: true,
},
{
name: 'User ID',
value: user.id,
inline: true,
},
])
.setColor(Constants.Colors.invisible)
.setThumbnail(user.displayAvatarURL());

await ctx.reply({ embeds: [embed] });
}
}
3 changes: 0 additions & 3 deletions src/core/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type { InteractionFunction } from '#src/decorators/RegisterInteractionHan
import AntiSpamManager from '#src/managers/AntiSpamManager.js';
import EventLoader from '#src/modules/Loaders/EventLoader.js';
import CooldownService from '#src/services/CooldownService.js';
import { LevelingService } from '#src/services/LevelingService.js';
import Scheduler from '#src/services/SchedulerService.js';
import { loadInteractions } from '#src/utils/CommandUtils.js';
import { loadCommands } from '#src/utils/Loaders.js';
Expand Down Expand Up @@ -59,8 +58,6 @@ export default class InterChatClient extends Client {
spamCountExpirySecs: 60,
});

public readonly userLevels: LevelingService = new LevelingService();

constructor() {
super({
shards: getInfo().SHARD_LIST, // An array of shards that will get spawned
Expand Down
Loading

0 comments on commit 844670f

Please sign in to comment.