Skip to content
Merged
1 change: 1 addition & 0 deletions src/Config.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const config: Config = {
commands: {
daily: "1059214166075912225",
},

roles: {
tiers: [
"821743100203368458", // @everyone (tier 0)
Expand Down
1 change: 1 addition & 0 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const config: Config = {
auditLog: "994623474557538415",
modLog: "994623474557538415",
general: "904478147351806015",
leaderboard: "904478147351806015",
},
starboard: {
emojiId: "⭐",
Expand Down
1 change: 1 addition & 0 deletions src/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Config {
modLog: string;
introductions?: string;
general: string;
leaderboard?: string;
};
starboard: {
emojiId: string;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ImageForwarderModule from "./modules/imageForwarder.module.js";
import { InformationModule } from "./modules/information/information.module.js";
import JoinLeaveMessageModule from "./modules/joinLeaveMessage.module.js";
import { LanguageStatusModule } from "./modules/languageStatus.module.js";
import LeaderboardModule from "./modules/leaderboard/leaderboard.module.js";
import { LearningModule } from "./modules/learning/learning.module.js";
import { ModerationModule } from "./modules/moderation/moderation.module.js";
import { ModmailModule } from "./modules/modmail/modmail.module.js";
Expand Down Expand Up @@ -65,6 +66,7 @@ export const moduleManager = new ModuleManager(
ModerationModule,
StarboardModule,
ModmailModule,
LeaderboardModule,
],
);

Expand Down
17 changes: 11 additions & 6 deletions src/modules/core/bump.listener.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
Client,
Message,
MessageInteraction,
MessageInteractionMetadata,
PartialTextBasedChannelFields,
User,
} from "discord.js";
Expand Down Expand Up @@ -67,7 +68,7 @@ test("simple bump", async () => {
const { ddUser, fakeUser, mockReact, mockChannel } = await setupMocks();
await handleBumpStreak(
ddUser,
{ user: fakeUser } as unknown as MessageInteraction,
{ user: fakeUser } as unknown as MessageInteractionMetadata,
{ channel: mockChannel, react: mockReact } as unknown as Message & {
channel: PartialTextBasedChannelFields;
},
Expand All @@ -88,7 +89,7 @@ test("simple bump with streak", async () => {

await handleBumpStreak(
ddUser,
{ user: fakeUser } as unknown as MessageInteraction,
{ user: fakeUser } as unknown as MessageInteractionMetadata,
{ channel: mockChannel, react: mockReact } as unknown as Message & {
channel: PartialTextBasedChannelFields;
},
Expand All @@ -113,7 +114,7 @@ test("simple bump with big streak", async () => {
}
await handleBumpStreak(
ddUser,
{ user: fakeUser } as unknown as MessageInteraction,
{ user: fakeUser } as unknown as MessageInteractionMetadata,
{ channel: mockChannel, react: mockReact } as unknown as Message & {
channel: PartialTextBasedChannelFields;
},
Expand All @@ -137,7 +138,7 @@ test("speedy bump ", async () => {
setLastBumpNotificationTime(new Date(Date.now() - 1000));
await handleBumpStreak(
ddUser,
{ user: fakeUser } as unknown as MessageInteraction,
{ user: fakeUser } as unknown as MessageInteractionMetadata,
{ channel: mockChannel, react: mockReact } as unknown as Message & {
channel: PartialTextBasedChannelFields;
},
Expand Down Expand Up @@ -170,7 +171,9 @@ test("End other user's streak", async () => {
});
await handleBumpStreak(
otherUser,
{ user: createFakeUser(otherUserId) } as unknown as MessageInteraction,
{
user: createFakeUser(otherUserId),
} as unknown as MessageInteractionMetadata,
{ channel: mockChannel, react: mockReact } as unknown as Message & {
channel: PartialTextBasedChannelFields;
},
Expand Down Expand Up @@ -243,7 +246,9 @@ test("End other user's streak with real data", async () => {

await handleBumpStreak(
otherUser,
{ user: createFakeUser(otherUserId) } as unknown as MessageInteraction,
{
user: createFakeUser(otherUserId),
} as unknown as MessageInteractionMetadata,
{ channel: mockChannel, react: mockReact } as unknown as Message & {
channel: PartialTextBasedChannelFields;
},
Expand Down
49 changes: 23 additions & 26 deletions src/modules/core/bump.listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type EmojiIdentifierResolvable,
InteractionType,
type Message,
type MessageInteraction,
type MessageInteractionMetadata,
type PartialTextBasedChannelFields,
} from "discord.js";
import { config } from "../../Config.js";
Expand All @@ -16,6 +16,7 @@ import {
getAllBumps,
getBumpStreak,
getStreaks,
type Streak,
} from "../../store/models/bumps.js";
import { type DDUser, getOrCreateUserById } from "../../store/models/DDUser.js";
import { fakeMention, mentionIfPingable } from "../../util/users.js";
Expand All @@ -42,10 +43,9 @@ export function setLastBumpNotificationTime(date: Date) {
lastBumpNotificationTime = date;
}

// noinspection JSDeprecatedSymbols
export async function handleBumpStreak(
bumper: DDUser,
interactionOld: MessageInteraction,
interactionOld: MessageInteractionMetadata,
message: Message & {
channel: PartialTextBasedChannelFields;
},
Expand All @@ -69,15 +69,14 @@ export async function handleBumpStreak(
streak.current === 1 // just started a new streak
) {
// allStreaks[-1] will be the current streak
const mostRecent = allStreaks[allStreaks.length - 2]; // so check the one before that
const mostRecent = allStreaks.at(-2) as {
Comment thread
Pdzly marked this conversation as resolved.
userId: bigint;
} & Streak; // so check the one before that
logger.debug(`Most recent streak:`, mostRecent);
logger.debug(
"Most recent streaks:",
allStreaks.slice(allStreaks.length - 5),
);
logger.debug("Most recent streaks:", allStreaks.slice(-5));
if (mostRecent.userId !== bumper.id && mostRecent.current > 2) {
const user = await client.users.fetch(mostRecent.userId.toString());
message.channel.send(
await message.channel.send(
`☠️ ${mentionIfPingable(interactionOld.user)} ended ${fakeMention(user)}'s bump streak of ${mostRecent.current}!`,
);
}
Expand All @@ -88,7 +87,7 @@ export async function handleBumpStreak(
const timeSinceLastBump = Date.now() - lastBumpNotificationTime.getTime();
if (timeSinceLastBump < 30000) {
// this might seem generous, but in reality when you factor in the discord delay, even if you react instantaneously on your screen you can still be too slow
message.channel.send(
await message.channel.send(
`⚡⚡⚡ ${fakeMention(interactionOld.user)} bumped in just **${timeSinceLastBump / 1000}s**!`,
);
} else {
Expand All @@ -104,12 +103,14 @@ export async function handleBumpStreak(

if (streak.current === streak.highest) {
// new high score!
message.channel.send(
await message.channel.send(
`${mentionIfPingable(interactionOld.user)}, you beat your max bump streak and are now on a streak of ${streak.current}! Keep it up!`,
);
}

const highestStreakEver = allStreaks.sort((a, b) => b.highest - a.highest)[0];
const highestStreakEver = allStreaks.toSorted(
(a, b) => b.highest - a.highest,
)[0];
logger.debug("Highest streak ever: %O", highestStreakEver);
logger.debug("This streak: %O", streak);
if (
Expand All @@ -121,17 +122,16 @@ export async function handleBumpStreak(
) {
// if they currently have the highest streak
logger.debug("User has the highest streak");
message.channel.send(
await message.channel.send(
`🔥🔥🔥🔥🔥 ${mentionIfPingable(interactionOld.user)}, you have the highest EVER bump streak in the server of ${highestStreakEver.highest}! Keep it up!`,
);
}
}

// noinspection JSDeprecatedSymbols
export async function handleBump(
client: Client,
bumper: DDUser,
interactionOld: MessageInteraction,
interactionOld: MessageInteractionMetadata,
message: Message & {
channel: PartialTextBasedChannelFields;
},
Expand All @@ -144,37 +144,34 @@ export async function handleBump(
}

export const BumpListener: EventListener = {
ready: async (client) => {
clientReady: async (client) => {
scheduleBumpReminder(client);
},
messageCreate: async (client, message) => {
const interaction = message.interactionMetadata;

if (
!interaction ||
!(interaction.type === InteractionType.ApplicationCommand)
)
if (!interaction || interaction.type !== InteractionType.ApplicationCommand)
return;
if (message.author.id !== "302050872383242240") return; // /disboard user id
// noinspection JSDeprecatedSymbols don't think there's another way of doing this

// noinspection JSDeprecatedSymbols don't think there's another way of doing this ( yes there is )
const interactionOld = message.interaction;
if (interactionOld?.commandName !== "bump") return;

// since the bump failed message is ephemeral, we know if we can see the message then the bump succeeded!
const ddUser = await getOrCreateUserById(BigInt(interactionOld.user.id));
const ddUser = await getOrCreateUserById(BigInt(interaction.user.id));

// Bump
await Bump.create({
messageId: BigInt(message.id),
userId: BigInt(interactionOld.user.id),
userId: BigInt(interaction.user.id),
timestamp: new Date(),
});
logger.info(
`User ${interactionOld.user.id} bumped! Total bumps: ${await ddUser.countBumps()}`,
`User ${interaction.user.id} bumped! Total bumps: ${await ddUser.countBumps()}`,
);
clearBumpsCache();
await ddUser.save();
await handleBump(client, ddUser, interactionOld, message);
await handleBump(client, ddUser, interaction, message);
},
};
const streakReacts: EmojiIdentifierResolvable[] = [
Expand Down
Loading