testing round 1.

This commit is contained in:
2026-09-13 16:50:53 +08:00
parent e5339b9b14
commit b3521938f5
5 changed files with 10 additions and 8 deletions
+1
View File
@@ -4,3 +4,4 @@ node_modules/
# Files.
.env
.DS_Store
+6 -4
View File
@@ -29,19 +29,19 @@ async function getPoints(id: string, guild_id: string): Promise<number> {
async function addPoints(id: string, guild_id: string, count: number) {
await client`
INSERT INTO points (user_id, guild_id, points)
INSERT INTO points AS p (user_id, guild_id, points)
VALUES (${id}, ${guild_id}, ${count})
ON CONFLICT (user_id, guild_id)
DO UPDATE SET points = user_points.points + ${count}
DO UPDATE SET points = p.points + ${count}
`;
}
async function takePoints(id: string, guild_id: string, count: number) {
await client`
INSERT INTO points (user_id, guild_id, points)
INSERT INTO points AS p (user_id, guild_id, points)
VALUES (${id}, ${guild_id}, 0)
ON CONFLICT (user_id, guild_id)
DO UPDATE SET points = GREATEST(user_points.points - ${count}, 0)
DO UPDATE SET points = GREATEST(p.points - ${count}, 0)
`;
}
@@ -52,6 +52,7 @@ async function getLeaderboard(guild_id: string, limit: number = 10): Promise<{ u
SELECT user_id, points
FROM points
WHERE guild_id = ${guild_id}
AND points > 0
ORDER BY points DESC, user_id ASC
LIMIT ${limit}
`;
@@ -66,6 +67,7 @@ async function getLeaderboardPosition(id: string, guild_id: string): Promise<num
RANK() OVER (ORDER BY points DESC) AS position
FROM points
WHERE guild_id = ${guild_id}
AND points > 0
) leaderboard
WHERE user_id = ${id}
`;
+1 -1
View File
@@ -7,7 +7,7 @@ class ReadyEvent extends Event<CommandClient> {
async handle(context: CommandClient<any, any>) {
await context.deployCommands();
context.setCustomActivity('Petting the Pond!');
context.setCustomActivity('Tracking your petting!');
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ class MessageReactionAddEvent extends Event<CommandClient> {
event: string = 'messageReactionAdd' as const;
async handle(context: CommandClient<any, any>, message: Message, emoji: Constants.APIEmoji, member: Member) {
if (emoji.id !== "448912932340891670") return;
if (!message.guildID || emoji.id != '1547870117080342548' || member.id == message.author.id) return;
await database.points.addPoints(message.author.id, member.guild.id, 1);
}
}
+1 -2
View File
@@ -8,9 +8,8 @@ class MessageReactionRemoveEvent extends Event<CommandClient> {
async handle(context: CommandClient<any, any>, message: { id: string; channel: { id: string } }, emoji: Constants.APIEmoji, userId: string) {
const _message = await context.getMessage(message.channel.id, message.id);
if (!_message.guildID) return;
if (emoji.id !== "448912932340891670") return;
if (!_message.guildID || emoji.id != '1547870117080342548' || userId == _message.author.id) return;
await database.points.takePoints(_message.author.id, _message.guildID, 1);
}
}