-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: global user & server message leaderboards (#245)
- Loading branch information
Showing
13 changed files
with
432 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2025 InterChat | ||
* | ||
* InterChat is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* InterChat is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with InterChat. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import ConfigSetInviteSubcommand from '#src/commands/Main/config/set-invite.js'; | ||
import BaseCommand from '#src/core/BaseCommand.js'; | ||
export default class ConfigCommand extends BaseCommand { | ||
constructor() { | ||
super({ | ||
name: 'config', | ||
description: 'Configure Server settings for InterChat.', | ||
types: { slash: true, prefix: true }, | ||
subcommands: { | ||
'set-invite': new ConfigSetInviteSubcommand(), | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2025 InterChat | ||
* | ||
* InterChat is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* InterChat is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with InterChat. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import BaseCommand from '#src/core/BaseCommand.js'; | ||
import Context from '#src/core/CommandContext/Context.js'; | ||
import db from '#src/utils/Db.js'; | ||
import { ApplicationCommandOptionType, Invite } from 'discord.js'; | ||
|
||
export default class ConfigSetInviteSubcommand extends BaseCommand { | ||
constructor() { | ||
super({ | ||
name: 'set-invite', | ||
description: | ||
'Set the invite link for the server. People can use it to join through InterChat leaderboards.', | ||
types: { slash: true, prefix: true }, | ||
options: [ | ||
{ | ||
type: ApplicationCommandOptionType.String, | ||
name: 'invite', | ||
description: 'The invite link to set for the server. (Leave empty to remove)', | ||
required: false, | ||
}, | ||
], | ||
}); | ||
} | ||
async execute(ctx: Context) { | ||
if (!ctx.inGuild()) return; | ||
await ctx.deferReply(); | ||
|
||
const inviteLink = ctx.options.getString('invite'); | ||
if (!inviteLink?.length) { | ||
await db.serverData.upsert({ | ||
where: { id: ctx.guild.id }, | ||
create: { id: ctx.guildId }, | ||
update: { inviteCode: null }, | ||
}); | ||
|
||
await ctx.replyEmbed('config.setInvite.removed', { | ||
edit: true, | ||
t: { emoji: ctx.getEmoji('tick_icon') }, | ||
}); | ||
return; | ||
} | ||
|
||
const inviteCode = inviteLink.match(Invite.InvitesPattern)?.[1]; | ||
if (!inviteCode) { | ||
await ctx.replyEmbed('config.setInvite.invalid', { | ||
edit: true, | ||
t: { emoji: ctx.getEmoji('x_icon') }, | ||
}); | ||
return; | ||
} | ||
|
||
const inviteInGuild = (await ctx.guild.invites.fetch()).get(inviteCode); | ||
if (!inviteInGuild) { | ||
await ctx.replyEmbed('config.setInvite.notFromServer', { | ||
edit: true, | ||
t: { emoji: ctx.getEmoji('x_icon') }, | ||
}); | ||
return; | ||
} | ||
|
||
await db.serverData.upsert({ | ||
where: { id: ctx.guild.id }, | ||
create: { id: ctx.guildId, inviteCode }, | ||
update: { inviteCode }, | ||
}); | ||
|
||
await ctx.replyEmbed('config.setInvite.success', { | ||
edit: true, | ||
t: { emoji: ctx.getEmoji('tick_icon') }, | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2025 InterChat | ||
* | ||
* InterChat is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* InterChat is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with InterChat. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import ServerLeaderboardCommand from '#src/commands/Main/leaderboard/server.js'; | ||
import UserLeaderboardCommand from '#src/commands/Main/leaderboard/user.js'; | ||
import BaseCommand from '#src/core/BaseCommand.js'; | ||
export default class LeaderboardCommand extends BaseCommand { | ||
constructor() { | ||
super({ | ||
name: 'leaderboard', | ||
description: 'leaderboard rahhh', | ||
types: { slash: true, prefix: true }, | ||
subcommands: { | ||
user: new UserLeaderboardCommand(), | ||
server: new ServerLeaderboardCommand(), | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2025 InterChat | ||
* | ||
* InterChat is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* InterChat is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with InterChat. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import BaseCommand from '#src/core/BaseCommand.js'; | ||
import type Context from '#src/core/CommandContext/Context.js'; | ||
import Constants from '#src/utils/Constants.js'; | ||
import { formatServerLeaderboard, getLeaderboard } from '#src/utils/Leaderboard.js'; | ||
import { resolveColor } from 'discord.js'; | ||
|
||
export default class ServerLeaderboardCommand extends BaseCommand { | ||
constructor() { | ||
super({ | ||
name: 'server', | ||
description: 'Shows the global server leaderboard for InterChat (with invites).', | ||
types: { slash: true, prefix: true }, | ||
}); | ||
} | ||
|
||
async execute(ctx: Context) { | ||
const leaderboard = await getLeaderboard('server', 10); | ||
const leaderboardTable = await formatServerLeaderboard(leaderboard, ctx.client); | ||
|
||
await ctx.reply({ | ||
embeds: [ | ||
{ | ||
title: `${ctx.getEmoji('hash_icon')} Global Server Leaderboard`, | ||
description: leaderboardTable, | ||
color: resolveColor(Constants.Colors.invisible), | ||
footer: { text: 'Resets every month. Send a message in any hub to get on it!' }, | ||
}, | ||
], | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2025 InterChat | ||
* | ||
* InterChat is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* InterChat is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with InterChat. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import BaseCommand from '#src/core/BaseCommand.js'; | ||
import type Context from '#src/core/CommandContext/Context.js'; | ||
import Constants from '#src/utils/Constants.js'; | ||
import { formatUserLeaderboard, getLeaderboard } from '#src/utils/Leaderboard.js'; | ||
import { resolveColor } from 'discord.js'; | ||
|
||
export default class UserLeaderboardCommand extends BaseCommand { | ||
constructor() { | ||
super({ | ||
name: 'user', | ||
description: 'Shows the global user leaderboard for InterChat (with messages).', | ||
types: { slash: true, prefix: true }, | ||
}); | ||
} | ||
|
||
async execute(ctx: Context) { | ||
const leaderboard = await getLeaderboard('user', 10); | ||
const leaderboardTable = await formatUserLeaderboard(leaderboard, ctx.client); | ||
|
||
await ctx.reply({ | ||
embeds: [ | ||
{ | ||
title: `${ctx.getEmoji('hash_icon')} Global User Leaderboard`, | ||
description: leaderboardTable, | ||
color: resolveColor(Constants.Colors.invisible), | ||
footer: { text: 'Resets every month. Send a message in any hub to get on it!' }, | ||
}, | ||
], | ||
}); | ||
} | ||
} |
Oops, something went wrong.