Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rewrite instructions for hypixel api keys #229

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ MINECRAFT_PASSWORD=""
MINECRAFT_CHAT_SEPARATOR=">"
# The character that separates the author name from their message in game

HYPIXEL_API_KEY=""
# Do `/api new` on Hypixel for this
HYPIXEL_API_KEY=
# Some features will not work if left unset

USE_PROFANITY_FILTER=true
# Profanity filter is designed to only block words disallowed by Hypixel, but may have false positives
Expand All @@ -30,4 +30,4 @@ MEMBER_CHANNEL_ID=
OFFICER_CHANNEL_ID=
BLACKLIST_CHANNEL_ID=
BOT_OWNER_ID=
STAFF_ROLE_ID=
STAFF_ROLE_ID=
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Setup](#setup)
- [Process Management](#process-management)
- [Hypixel API keys](#hypixel-api-keys)
- [Process management](#process-management)
- [Contributing](#contributing)
- [Issues and Bug Reports](#issues-and-bug-reports)
- [Issues and bug reports](#issues-and-bug-reports)
- [Acknowledgements](#acknowledgements)
- [License](#license)

Expand All @@ -52,50 +53,57 @@

### Setup

1. ⭐ Star this repository!
2. Install [pnpm](https://pnpm.io/) via one of their [installation methods](https://pnpm.io/installation), or the following command:
1. Install [pnpm](https://pnpm.io/) via one of their [installation methods](https://pnpm.io/installation), or the following command:

```bash
$ npm install -g pnpm
```

3. Clone the repository into a directory of your choice.
2. Clone the repository into a directory of your choice.

```bash
$ git clone https://github.com/MiscGuild/bridge.git
```

4. Enter the new directory and install packages.
3. Enter the new directory and install packages.

```bash
$ cd bridge
$ pnpm install
```

5. Make a new Discord bot account on the [Discord Developer Portal](https://discord.com/developers/applications) and retrieve the bot token.
4. Make a new Discord bot account on the [Discord Developer Portal](https://discord.com/developers/applications) and retrieve the bot token.

6. Under the `Bot` tab, grant the bot the `Message Content` Intent.
5. Under the `Bot` tab, grant the bot the `Message Content` Intent.

7. Generate an invite URL by going to the OAuth2 tab and clicking on the URL Generator. Add the `bot` and `application.commands` scopes, before opening the link to invite the bot to your server.
6. Generate an invite URL by going to the OAuth2 tab and clicking on the URL Generator. Add the `bot` and `application.commands` scopes, before opening the link to invite the bot to your server.

8. Setup the project config files.
7. Setup the project config files.

```bash
$ pnpm run setup-files
```

9. Fill out the `.env` file with your credentials.
8. Fill out the `.env` file with your credentials.

10. Promote the Minecraft account used by the bot to Officer in-game in order for it to view the Officer chat and run privileged commands.
9. Promote the Minecraft account used by the bot to Officer in-game in order for it to view the Officer chat and run privileged commands.

11. Build and run the bot.
10. Build and run the bot.

```bash
$ pnpm run build
$ pnpm start
```

### Process Management
### Hypixel API keys

After the June 2023 [Hypixel Public API update](https://hypixel.net/threads/hypixel-developer-dashboard-public-api-changes-june-2023.5364455/), Development API Keys now expire after three days but can be easily renewed.

To acquire a permanent key, first generate a Development Key [here](https://developer.hypixel.net/dashboard). Then, fill out the form under `Apps > Create app > Personal API Key`. Please note that applications concerning bridge bots may be denied.

Alternatively, you may omit the `HYPIXEL_API_KEY` field of the `.env` file, but some features such as minimum network level enforcement will be disabled.

### Process management

If you are self-hosting or your process manager does not automatically restart the bot in the event of a crash, you may use [PM2](https://pm2.keymetrics.io/), a process manager for Node.js applications.

Expand All @@ -110,14 +118,17 @@ Please refer to the [PM2 documentation](https://pm2.keymetrics.io/docs/usage/qui

## Contributing

Pull requests are welcome. If you would like to chat with other developers please join our [Discord](https://discord.gg/bHFWukp) and go to `#programming-talk`.
Pull requests are welcome. If you would like to chat with other developers please join our [Discord](https://discord.gg/bHFWukp).

Before submitting your changes for review, please ensure:

- The application is fully functional, and all your code has been thoroughly tested to avoid potential bugs or security vulnerabilities.
- Your commit messages adhere to the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/).
- the application is fully functional
- your code has been thoroughly tested
- your commit messages adhere to the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/).

Give this repository a ⭐ if it helped you!

### Issues and Bug Reports
### Issues and bug reports

To raise an issue or bug report, please contact a developer or [open an issue](https://github.com/MiscGuild/bridge/issues).

Expand Down
2 changes: 1 addition & 1 deletion src/events/mineflayer/chat/whisper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
runOnce: false,
run: async (bot, playerName: string, message: string) => {
const errorMessage = `/w ${playerName} There was an error attempting your request! (Check spelling and/or try again later)`;
const target = message.startsWith('weeklygexp' || 'weeklygxp')
const target = message.startsWith('weeklygexp')
? playerName
: (message.split(' ')[0] as string);

Expand Down
2 changes: 1 addition & 1 deletion src/requests/fetch-error-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export default (requestError: FetchError) =>
.setColor('Red')
.setTitle('Error')
.setDescription(
`There was an error while attempting your request, a detailed log is below.\n\`\`\`Error: ${requestError.status}\nReason: ${requestError.statusText}\`\`\``
`There was an error while attempting your request.\n\`\`\`Error: ${requestError.status}\nReason: ${requestError.statusText}\`\`\``
);
3 changes: 3 additions & 0 deletions src/requests/fetch-hypixel-guild.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import env from '@util/env';

export default async (uuid: string) => {
if (!env.HYPIXEL_API_KEY)
return { status: 400, statusText: 'Missing Hypixel API key' } as FetchError;

const response = await fetch(
`https://api.hypixel.net/guild?key=${env.HYPIXEL_API_KEY}&player=${uuid}`
);
Expand Down
3 changes: 3 additions & 0 deletions src/requests/fetch-hypixel-player-profile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import env from '@util/env';

export default async (username: string) => {
if (!env.HYPIXEL_API_KEY)
return { status: 400, statusText: 'Missing Hypixel API key' } as FetchError;

const response = await fetch(
`https://api.hypixel.net/player?key=${env.HYPIXEL_API_KEY}&name=${username}`
);
Expand Down
2 changes: 1 addition & 1 deletion src/util/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const envSchema = z
.object({
MINECRAFT_EMAIL: z.string().email(),
MINECRAFT_PASSWORD: z.string(), // no minimum length allows for manual authorization - dotenv populates an empty string by default
HYPIXEL_API_KEY: z.string().min(1),
HYPIXEL_API_KEY: z.string().min(1).optional(),
MINECRAFT_CHAT_SEPARATOR: z.string().trim().min(1),
USE_PROFANITY_FILTER: BOOLEAN_SCHEMA,
USE_FIRST_WORD_OF_AUTHOR_NAME: BOOLEAN_SCHEMA,
Expand Down
Loading