Skip to content

Commit

Permalink
chore(README.md): remove DISCORD_PLACE_API_KEY from environment varia…
Browse files Browse the repository at this point in the history
…bles list

refactor(client.js): update logic to fetch and update bot stats using Bot model
  • Loading branch information
chimpdev committed Sep 15, 2024
1 parent 1e70031 commit 17a272d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ CLOUDFLARE_API_KEY=
CLOUDFLARE_EMAIL=
CLOUDFLARE_ACCOUNT_ID=
CLOUDFLARE_BLOCK_IP_LIST_ID=
DISCORD_PLACE_API_KEY=
LOGTAIL_SOURCE_TOKEN=
LEMON_SQUEEZY_WEBHOOK_SECRET=
LEMON_SQUEEZY_API_KEY=
Expand Down Expand Up @@ -160,7 +159,6 @@ DISCORD_BOT_GET_APPROXIMATE_GUILD_COUNT_API_SECRET=
| `CLOUDFLARE_EMAIL` | Cloudflare email. |
| `CLOUDFLARE_ACCOUNT_ID` | Cloudflare account ID. |
| `CLOUDFLARE_BLOCK_IP_LIST_ID` | Cloudflare block IP list ID. |
| `DISCORD_PLACE_API_KEY` | discord.place API key. (not required) |
| `DISCORD_PLACE_INSTATUS_API_KEY` | discord.place Instatus API key. (not required) |
| `LOGTAIL_SOURCE_TOKEN` | Logtail source token. (not required) |
| `LEMON_SQUEEZY_WEBHOOK_SECRET` | Lemon Squeezy webhook secret. (not required) |
Expand All @@ -177,7 +175,6 @@ DISCORD_BOT_GET_APPROXIMATE_GUILD_COUNT_API_SECRET=
> - The `CLOUDFLARE_TURNSTILE_SECRET_KEY` is used for verifying the Turnstile token. We use Cloudflare Turnstile for ensuring that the user is a human and not a bot on the website. Refer to the [Cloudflare Turnstile documentation](https://developers.cloudflare.com/turnstile/get-started/#get-a-sitekey-and-secret-key) to get your Turnstile secret key.
> - The `CLOUDFLARE_API_KEY`, `CLOUDFLARE_EMAIL`, and `CLOUDFLARE_ACCOUNT_ID` values are required for interacting with the Cloudflare API. You can get the API key from the Cloudflare dashboard.
> - The `CLOUDFLARE_BLOCK_IP_LIST_ID` is used for blocking IP addresses within the Cloudflare firewall. Refer to the [Cloudflare WAF documentation](https://developers.cloudflare.com/waf/tools/lists/create-dashboard/) to create a list. After creating the list, you can get the list ID from the URL. (usually should be in the end of the URL)
> - The `DISCORD_PLACE_API_KEY` is used for authenticating requests to the discord.place API endpoints. This is not required for self-hosting. We use this for update our bot's command count every day on the website.
> - The `DISCORD_PLACE_INSTATUS_API_KEY` is used for authenticating requests to the discord.place Instatus API endpoints. This is not required for self-hosting. We use this for displaying the current status of the discord.place on the homepage. You can get this from the Instatus dashboard. Refer to the [Instatus API documentation](https://instatus.com/help/api) for more information.
> - The `LOGTAIL_SOURCE_TOKEN` is used for sending logs to Logtail. This is not required for self-hosting. We actually not use this in our production environment. But we wanted to keep this in the repository for future use.
> - The `LEMON_SQUEEZY_WEBHOOK_SECRET` is used for verifying the Lemon Squeezy webhook. This is not required for self-hosting. We use Lemon Squeezy for our payment system. Refer to the [Lemon Squeezy documentation](https://docs.lemonsqueezy.com/help/webhooks) for more information.
Expand Down
1 change: 0 additions & 1 deletion server/.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ CLOUDFLARE_BLOCK_IP_LIST_ID=

# Discord Place

DISCORD_PLACE_API_KEY=
DISCORD_PLACE_INSTATUS_API_KEY=

# Logtail
Expand Down
28 changes: 11 additions & 17 deletions server/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,25 +253,19 @@ module.exports = class Client {
}

async updateBotStats() {
if (!process.env.DISCORD_PLACE_API_KEY) return logger.warn('API key is not defined. Please define DISCORD_PLACE_API_KEY in your environment variables.');

const url = `https://api.discord.place/bots/${client.user.id}/stats`;
const data = {
command_count: client.commands.size
};

try {
const response = await axios.patch(url, data, {
headers: {
authorization: process.env.DISCORD_PLACE_API_KEY
const bot = await Bot.findOne({ id: client.user.id });
if (!bot) return logger.error(`${client.user.id} bot not found in the Bot collection. Skipping update bot stats.`);

await Bot.updateOne({ id: client.user.id }, {
$set: {
command_count: {
value: client.commands.size,
updatedAt: new Date()
}
});
}
});

if (response.status === 200) logger.info('Bot stats updated on Discord Place.');
else logger.error(`Failed to update bot stats: ${response.data}`);
} catch (error) {
logger.error('Failed to update bot stats:', error);
}
logger.info('Updated bot stats.');
}

async checkExpiredBlockedIPs() {
Expand Down

0 comments on commit 17a272d

Please sign in to comment.