-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bot): added hourly leaderboard updates
also tried messing around with eslint - never again
- Loading branch information
1 parent
a07319b
commit e2ffaf4
Showing
16 changed files
with
188 additions
and
182 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"extends": "eslint:recommended", | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
}, | ||
"parserOptions": { | ||
"sourceType": "module", | ||
"ecmaVersion": "latest" | ||
}, | ||
"rules": { | ||
"arrow-spacing": ["warn", { "before": true, "after": true }], | ||
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }], | ||
"comma-dangle": ["error", "always-multiline"], | ||
"comma-spacing": "error", | ||
"comma-style": "error", | ||
"curly": ["error", "multi-line", "consistent"], | ||
"dot-location": ["error", "property"], | ||
"handle-callback-err": "off", | ||
"indent": ["error", "tab"], | ||
"keyword-spacing": "error", | ||
"max-nested-callbacks": ["error", { "max": 4 }], | ||
"max-statements-per-line": ["error", { "max": 2 }], | ||
"no-console": "off", | ||
"no-empty-function": "error", | ||
"no-floating-decimal": "error", | ||
"no-inline-comments": "error", | ||
"no-lonely-if": "error", | ||
"no-multi-spaces": "error", | ||
"no-multiple-empty-lines": [ | ||
"error", | ||
{ "max": 2, "maxEOF": 1, "maxBOF": 0 } | ||
], | ||
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }], | ||
"no-trailing-spaces": ["error"], | ||
"no-var": "error", | ||
"object-curly-spacing": ["error", "always"], | ||
"prefer-const": "error", | ||
"quotes": ["error", "single"], | ||
"semi": ["error", "always"], | ||
"space-before-blocks": "error", | ||
"space-before-function-paren": [ | ||
"error", | ||
{ | ||
"anonymous": "never", | ||
"named": "never", | ||
"asyncArrow": "always" | ||
} | ||
], | ||
"space-in-parens": "error", | ||
"space-infix-ops": "error", | ||
"space-unary-ops": "error", | ||
"spaced-comment": "error", | ||
"yoda": "error" | ||
} | ||
} |
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
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,41 @@ | ||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js"; | ||
import quickEmbed from "./quickEmbed"; | ||
import { getGuildLeaderboard } from "./requestAPI"; | ||
import client from ".."; | ||
|
||
export default async function (guild: string, interaction?: any) { | ||
const leaderboard = await getGuildLeaderboard(guild); | ||
|
||
if (leaderboard.length === 0) { | ||
await interaction.reply('No leaderboard data available.'); | ||
return; | ||
} | ||
|
||
// Create a new embed using the custom embed function | ||
const leaderboardEmbed = quickEmbed({ | ||
color: 'Blurple', | ||
title: `Leaderboard for ${interaction ? interaction.guild?.name : (await client.guilds.fetch(guild)).name}`, | ||
description: 'Top 10 Users' | ||
}, interaction); | ||
|
||
// Add a field for each user with a mention | ||
leaderboard.leaderboard.slice(0, 10).forEach((entry: { id: string; xp: number; }, index: number) => { | ||
leaderboardEmbed.addFields([ | ||
{ | ||
name: `${index + 1}.`, | ||
value: `<@${entry.id}>: ${entry.xp.toLocaleString("en-US")} XP`, | ||
inline: false | ||
} | ||
]); | ||
}); | ||
|
||
const button = new ButtonBuilder() | ||
.setLabel('Leaderboard') | ||
.setURL(`https://chatr.fun/leaderboard/${guild}`) | ||
.setStyle(ButtonStyle.Link); | ||
|
||
const row = new ActionRowBuilder<ButtonBuilder>() | ||
.addComponents(button); | ||
|
||
return [leaderboardEmbed, row]; | ||
} |
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,15 @@ | ||
import type { TextChannel } from "discord.js"; | ||
import client from ".."; | ||
import leaderboardEmbed from "./leaderboardEmbed"; | ||
import { getAllGuildsWithUpdatesEnabled } from "./requestAPI"; | ||
|
||
export default async function () { | ||
const allGuildsData = await getAllGuildsWithUpdatesEnabled() | ||
|
||
// TODO: Type guild | ||
allGuildsData.forEach(async (guild: any) => { | ||
const [embed, row] = await leaderboardEmbed(guild.id) | ||
const channel = await client.channels.fetch(guild.updates_channel_id) as TextChannel; | ||
await channel?.send({ embeds: [embed], components: [row] }); | ||
}) | ||
} |
Oops, something went wrong.