-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from MozillaReality/error-handling
Add additional error handling and bot join/leave message filtering
- Loading branch information
Showing
8 changed files
with
261 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
# hubs-discord-bot (Beta) | ||
|
||
### [Go here to add the hosted bot to your server!][invite-page] | ||
### [Go here to add the hosted discord bot to your server!][invite-page] | ||
|
||
### [Video introduction](https://www.youtube.com/watch?v=5HtRJolThZ8) | ||
### [Discord Bot Video introduction](https://www.youtube.com/watch?v=5HtRJolThZ8) | ||
|
||
**Note: self-hosting the bot and pointing it at production Hubs servers is currently broken. If you want to run the bot as-is, you'll need to also run your own Hubs server. We're trying to fix this.** | ||
|
||
A Discord bot that interacts with [Mozilla Hubs](https://hubs.mozilla.com). Mostly bridges information (chat, media links, joins/leaves), lets you see who is currently in Hubs from Discord and sets Hubs permissions and abilities based on Discord roles. Check out the bot in action on our own [Hubs community Discord][hubs-discord]! | ||
|
||
* [What it does](#what-it-does) | ||
* [Room/channel permissions linkage](#room-channel-permissions-linkage) | ||
* [Room/channel bridging](#room-channel-bridging) | ||
* [Running the bot](#great-i-want-to-run-this-on-my-discord-server) | ||
* [Permissions](#permissions) | ||
* [Hacking on it](#hacking-on-it) | ||
Discord | ||
- [What it does](#what-it-does) | ||
- [Room/channel permissions linkage](#room-channel-permissions-linkage) | ||
- [Room/channel bridging](#room-channel-bridging) | ||
- [Running the bot](#great-i-want-to-run-this-on-my-discord-server) | ||
- [Permissions](#permissions) | ||
- [Hacking on it](#hacking-on-it) | ||
|
||
## What it does | ||
|
||
|
@@ -36,7 +37,7 @@ Independently of being permission-linked, the bot will detect any Hubs rooms in | |
- A notification will appear in the Discord channel when someone joins or leaves the Hubs room, or if administrative stuff happens in the Hubs room. | ||
- Text chat and images will be bridged from the Discord channel into the Hubs room. | ||
- Text chat and photos will be bridged from the Hubs room into the Discord channel. | ||
- Links to media (images, videos, models) which are *pinned* in the Hubs room will be bridged to Discord. | ||
- Links to media (images, videos, models) which are _pinned_ in the Hubs room will be bridged to Discord. | ||
|
||
Note that you need to set up a webhook for the bot to use in the Discord channel, or it won't be able to post chat from Hubs. | ||
|
||
|
@@ -50,16 +51,24 @@ Once the bot is running on your server: | |
|
||
1. Give the bot [appropriate permissions](#permissions) on the channels you want it to run in. | ||
|
||
2. Create a webhook named "Hubs" in the channels you want it to run in. It will use this webhook to bridge chat and | ||
send Hubs status updates. | ||
2. Create a webhook named "Hubs" in the channels you want it to run in. It will use this webhook to bridge chat and send Hubs status updates. | ||
|
||
3. Try out the bot! Type `!hubs` in a channel the bot is in to see all of the ways you can control the bot. Put your favorite Hubs room into a channel topic to start bridging, or use the `!hubs create` command to create a new room. | ||
|
||
### Permissions | ||
|
||
The bot requires several permissions in order to work: | ||
|
||
- "Send messages," "Read messages," and "Embed links" are necessary in order to bridge between the Hubs room that is linked to a channel and the messages that are sent within the channel on Discord. | ||
General Permissions | ||
- Manage Webhooks | ||
- Manage Channels - Grant locally per channel not in Developer Portal | ||
Text Permissions | ||
- Send Messages | ||
- Manage Messages | ||
- Embed Links | ||
- Read Message History | ||
|
||
- "Send messages" and "Embed links" are necessary in order to bridge between the Hubs room that is linked to a channel and the messages that are sent within the channel on Discord. | ||
- "Manage webhooks" is necessary in order for the bot to find and use a webhook for bridging chat. | ||
- "Manage channels" is necessary in order for the bot to set the channel topic and bridge chat. **Note:** We do not ask for this permission globally when you add the bot to your server, instead we recommend you grant this permission to the bot in specific groups or channels. | ||
- "Manage messages" and "read message history" are necessary in order for the bot to pin notification messages. Like "manage channels", you should probably grant these for specific groups and channels. | ||
|
@@ -80,14 +89,95 @@ To simply run the bot process: | |
|
||
4. [Create a Discord bot on the Discord website.][discord-docs] | ||
|
||
5. Create an `.env` file with your bot's API token. Include `RETICULUM_HOST={your server}` and `HUBS_HOSTS={your server}` to point it at your local backend. You can see the different configuration bits you can override in [`.env.defaults`](./.env.defaults). You can also pass these values as environment variables when you run `npm start`. | ||
5. Add redirect URI in the OAuth page and select the bot permissions | ||
- Redirect URI: `https://hubs.local:4000/api/v1/oauth/discord` | ||
|
||
6. Create an `.env` file with your bot's API token. Include `RETICULUM_HOST={your server}` and `HUBS_HOSTS={your server}` to point it at your local backend. `RETICULUM_HOST={your server}` should point to 'hubs.local:4000'. You can see the different configuration bits you can override in [`.env.defaults`](./.env.defaults). You can also pass these values as environment variables when you run `npm start`/`npm run local`. | ||
|
||
6. Run `npm start` to start the server, connect to Discord and Reticulum, and operate indefinitely. | ||
7. Inside your local reticulum instance in reticulum/config/dev.exs change the configuration for `Ret.DiscordClient` to point to your bot's: `client_id`, `client_secret`, and `bot_token` found inside your discord bot. | ||
|
||
7. [Follow the instructions above](#usage) to set up and use the bot on your Discord guild. | ||
8. Run `npm run local` to start the server, connect to Discord and Reticulum, and operate indefinitely. | ||
|
||
9. [Follow the instructions above](#usage) to set up and use the bot on your Discord guild. | ||
|
||
[npm]: https://nodejs.org/en/ | ||
[discord-docs]: https://discordapp.com/developers/docs/intro | ||
[invite-page]: https://hubs.mozilla.com/discord | ||
[hubs-discord]: https://discord.gg/wHmY4nd | ||
[bot-invite]: mailto:[email protected] | ||
|
||
## Deploying to hubs.mozilla.com | ||
|
||
The Hubs Discord Bot doesn't have a Jenkins job to build it yet. SO we need to build it manually. | ||
|
||
### Prerequisites | ||
You'll need the [Habitat CLI](https://www.habitat.sh/docs/install-habitat/) installed locally. | ||
|
||
You'll also need access to the Habitat Builder Token. Ask someone for help with that. | ||
|
||
|
||
### Import the Habitat Builder Keys | ||
|
||
Ask someone about getting the private key. | ||
|
||
You'll download it and then feed it into Habitat using: | ||
|
||
```bash | ||
hab origin key import path/to/mozillareality.sig.key | ||
``` | ||
|
||
Then for the public key run: | ||
|
||
```bash | ||
hab origin key download mozillareality | ||
``` | ||
|
||
### Building the Habitat Package | ||
In the project directory run: | ||
|
||
```bash | ||
HAB_ORIGIN=mozillareality hab pkg build . | ||
``` | ||
|
||
If everything builds successfully you should see a `/results` folder in the project directory. Take note of the `mozillareality-hubs-discord-bot-0.0.1-<version>-x86_64-linux.hart` file. | ||
|
||
We now need to upload that file to the habitat.sh repository. | ||
|
||
Run the following command in the project directory: | ||
|
||
``` | ||
HAB_AUTH_TOKEN="<habitat builder token>" hab pkg upload ./results/mozillareality-hubs-discord-bot-0.0.1-<version>-x86_64-linux.hart | ||
``` | ||
|
||
You should see a success message. Your uploaded package should be visible at: https://bldr.habitat.sh/#/pkgs/mozillareality/hubs-discord-bot/latest | ||
|
||
### Promoting the Habitat Package | ||
|
||
This step will promote the package to be live on hubs.mozilla.com | ||
|
||
Run this command to promote the package: | ||
|
||
``` | ||
HAB_AUTH_TOKEN="<habitat builder token>" hab pkg promote mozillareality/hubs-discord-bot/0.0.1/<version> stable | ||
``` | ||
|
||
To verify the install you can ssh into the box and tail journalctl. To do so run the following command in the `hubs-ops` directory. | ||
|
||
``` | ||
./bin/ssh.sh discord prod | ||
``` | ||
|
||
Once logged into the box run `journalctl -f` to tail the logs. | ||
|
||
You'll see a bunch of logs saying: | ||
|
||
``` | ||
Connected to Hubs room | ||
``` | ||
|
||
Some errors that are caused by users revoking access to the hubs bot or deleting their guild. These are normal. | ||
|
||
And finally: | ||
``` | ||
Scan finished | ||
``` |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Oops, something went wrong.