mirror of
https://github.com/nx-bat/pet-the-pond.git
synced 2026-09-22 10:29:11 -04:00
testing round 1.
This commit is contained in:
@@ -4,3 +4,4 @@ node_modules/
|
|||||||
|
|
||||||
# Files.
|
# Files.
|
||||||
.env
|
.env
|
||||||
|
.DS_Store
|
||||||
|
|||||||
+6
-4
@@ -29,19 +29,19 @@ async function getPoints(id: string, guild_id: string): Promise<number> {
|
|||||||
|
|
||||||
async function addPoints(id: string, guild_id: string, count: number) {
|
async function addPoints(id: string, guild_id: string, count: number) {
|
||||||
await client`
|
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})
|
VALUES (${id}, ${guild_id}, ${count})
|
||||||
ON CONFLICT (user_id, guild_id)
|
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) {
|
async function takePoints(id: string, guild_id: string, count: number) {
|
||||||
await client`
|
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)
|
VALUES (${id}, ${guild_id}, 0)
|
||||||
ON CONFLICT (user_id, guild_id)
|
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
|
SELECT user_id, points
|
||||||
FROM points
|
FROM points
|
||||||
WHERE guild_id = ${guild_id}
|
WHERE guild_id = ${guild_id}
|
||||||
|
AND points > 0
|
||||||
ORDER BY points DESC, user_id ASC
|
ORDER BY points DESC, user_id ASC
|
||||||
LIMIT ${limit}
|
LIMIT ${limit}
|
||||||
`;
|
`;
|
||||||
@@ -66,6 +67,7 @@ async function getLeaderboardPosition(id: string, guild_id: string): Promise<num
|
|||||||
RANK() OVER (ORDER BY points DESC) AS position
|
RANK() OVER (ORDER BY points DESC) AS position
|
||||||
FROM points
|
FROM points
|
||||||
WHERE guild_id = ${guild_id}
|
WHERE guild_id = ${guild_id}
|
||||||
|
AND points > 0
|
||||||
) leaderboard
|
) leaderboard
|
||||||
WHERE user_id = ${id}
|
WHERE user_id = ${id}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class ReadyEvent extends Event<CommandClient> {
|
|||||||
|
|
||||||
async handle(context: CommandClient<any, any>) {
|
async handle(context: CommandClient<any, any>) {
|
||||||
await context.deployCommands();
|
await context.deployCommands();
|
||||||
context.setCustomActivity('Petting the Pond!');
|
context.setCustomActivity('Tracking your petting!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class MessageReactionAddEvent extends Event<CommandClient> {
|
|||||||
event: string = 'messageReactionAdd' as const;
|
event: string = 'messageReactionAdd' as const;
|
||||||
|
|
||||||
async handle(context: CommandClient<any, any>, message: Message, emoji: Constants.APIEmoji, member: Member) {
|
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);
|
await database.points.addPoints(message.author.id, member.guild.id, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
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);
|
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);
|
await database.points.takePoints(_message.author.id, _message.guildID, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user