Skip to content

Commit

Permalink
feat: expand upon starboard
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklvh committed Jan 1, 2025
1 parent 0c9adf6 commit 87d9473
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const client = new SapphireClient({
scope: BucketScope.User,
},
logger: {
level: LogLevel.Debug,
level: LogLevel.Info,
},
});

Expand Down
34 changes: 31 additions & 3 deletions src/listeners/guild/messageReactionAdd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Events, Listener } from "@sapphire/framework";
import { ApplyOptions } from "@sapphire/decorators";
import { MessageReaction, User } from "discord.js";
import { GuildTextBasedChannel, MessageReaction, User } from "discord.js";

@ApplyOptions<Listener.Options>({
event: Events.MessageReactionAdd,
Expand All @@ -10,8 +10,36 @@ export class MessageReactionAddListener extends Listener {
if (messageReaction.partial) await messageReaction.fetch();
if (user.partial) await user.fetch();

if (user.bot || !messageReaction.message.guild) return;
if (
user.bot ||
!messageReaction.message.guild ||
messageReaction.emoji.name !== "⭐"
)
return;

this.container.utilities;
const starboard = await this.container.utilities.starboard.getStarboard(
messageReaction.message.guild.id,
);

if (
!starboard.enabled ||
messageReaction.count < starboard.starsRequired ||
starboard.starredMessages.includes(messageReaction.message.id) ||
!starboard.channelId
)
return;

await this.container.utilities.starboard.addMessageToDB(
messageReaction.message.guild.id,
messageReaction.message.id,
);

const channel = (await messageReaction.message.guild.channels
.fetch(starboard.channelId)
.catch(() => null)) as GuildTextBasedChannel;

await channel.send(
`${messageReaction.count} ⭐️ ${messageReaction.message.url}`,
);
}
}
8 changes: 1 addition & 7 deletions src/utilities/starboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ export class StarboardUtility extends Utility {
return starboard;
}

public async getStarredMessages(guildId: string) {
const starboard = await this.getStarboard(guildId);

return starboard.starredMessages;
}

public async addMessageToDB(guildId: string, messageId: string) {
return this.container.prisma.starboard.update({
where: {
Expand All @@ -42,7 +36,7 @@ export class StarboardUtility extends Utility {
}

public async removeMessageFromDB(guildId: string, messageId: string) {
const starredMessages = await this.getStarredMessages(guildId);
const { starredMessages } = await this.getStarboard(guildId);

await this.container.prisma.starboard.update({
where: {
Expand Down

0 comments on commit 87d9473

Please sign in to comment.