Skip to content

Commit

Permalink
Merge pull request #47 from destruc7i0n/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
destruc7i0n authored Feb 11, 2020
2 parents 1a4acf2 + b174e69 commit d2cff4c
Show file tree
Hide file tree
Showing 17 changed files with 1,648 additions and 1,059 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
package-lock.json

yarn-error.log
.idea
build
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, destruc7i0n
Copyright (c) 2020, destruc7i0n

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
## In Action
![discord-mc](http://i.thedestruc7i0n.ca/I5anbg.gif)

## Features
- Sends message to and from Vanilla Minecraft servers
- Can send messages regarding advancements, when players join and leave, and player deaths
- Allows admins to send commands to Minecraft through Discord

## Installation and usage

Create a Discord bot here: https://discordapp.com/developers/applications/me
Expand All @@ -21,18 +26,20 @@ rcon.password=<your password>
rcon.port=<1-65535>
```

Clone repository onto a server, edit ```config.json``` (see below for more info) and change any options, and then, in the repository folder:
Clone repository onto a server, edit ```config.json``` (see below for more info) and change any options.
Then, in the repository folder:
```sh
$ yarn
$ yarn start
$ yarn build && yarn start
```

If you are running this locally, check the `IS_LOCAL_FILE` flag and related options below. Otherwise, perform the following command:
On your server hosting (in a screen/tmux session or background process, make sure to replace your `YOUR_URL` with whatever URL you're using (`localhost:8000` if running on the same server and default config) and `PATH_TO_MINECRAFT_SERVER_INSTALL` with the path to the Minecraft server installation, such as `/usr/home/minecraft_server/`):
If you are running this on the same server as the MC server, enable the `IS_LOCAL_FILE` flag and update related options below.
Otherwise, perform the following command on the server hosting (in a screen/tmux session or background process, make sure to replace your `YOUR_URL` with whatever URL you're using (`localhost:8000` if running on the same server and default config) and `PATH_TO_MINECRAFT_SERVER_INSTALL` with the path to the Minecraft server installation, such as `/usr/home/minecraft_server/`):

``` sh
tail -F /PATH_TO_MINECRAFT_SERVER_INSTALL/logs/latest.log | grep --line-buffered ": <" | while read x ; do echo -ne $x | curl -X POST -d @- http://YOUR_URL/minecraft/hook ; done
```
(The above command will also be given to you if you are not using a local file when you start up Shulker)

You can also easily Deploy to Heroku and the like, just be sure to edit `YOUR_URL` in the command to match accordingly.

Expand All @@ -48,6 +55,7 @@ You can also easily Deploy to Heroku and the like, just be sure to edit `YOUR_UR
"WEBHOOK_URL": "DISCORD_WEBHOOK_URL_HERE", /* Be sure to create a webhook in the channel settings and place it here! */
"DISCORD_TOKEN": "<12345>", /* Discord bot token. [Click here](https://discordapp.com/developers/applications/me) to create you application and add a bot to it. */
"DISCORD_CHANNEL_ID": "<channel>", /* Discord channel ID for for the discord bot. Enable developer mode in your Discord client, then right click channel and select "Copy ID". */
"DISCORD_CHANNEL_NAME": "#<channel name>" /* The Discord channel name. It is recommended to use the ID if the bot is in multiple servers. The ID will take precedence. */
"DISCORD_MESSAGE_TEMPLATE": "`%username%`:%message%", /* Message template to display in Discord */

"MINECRAFT_SERVER_RCON_IP": "127.0.0.1", /* Minecraft server IP (make sure you have enabled rcon) */
Expand All @@ -57,25 +65,49 @@ You can also easily Deploy to Heroku and the like, just be sure to edit `YOUR_UR

"IS_LOCAL_FILE": false, /* should tail the local file, may be a little buggy. please report any you find */
"LOCAL_FILE_PATH": "/usr/home/minecraft_server/logs/latest.log", /* the path to the local file if specified */
"ALLOW_USER_MENTIONS": false, /* should replace @mentions with the mention in discord */

"SHOW_INIT_MESSAGE": true, /* Sends the message on boot if not a local file of what command to run */

"ALLOW_USER_MENTIONS": false, /* should replace @mentions with the mention in discord (format: @username#discriminator) */
"ALLOW_HERE_EVERYONE_MENTIONS": false, /* replaces @everyone and @here with "@ everyone" and "@ here" respectively */
"ALLOW_SLASH_COMMANDS": false, /* whether to allow users to run slash commands from discord */
"SLASH_COMMAND_ROLES": [], /* if the above is enabled, the names of the roles which can run slash commands */

"WEBHOOK": "/minecraft/hook", /* Web hook, where to send the log to */
"REGEX_MATCH_CHAT_MC": "\\[Server thread/INFO\\]: <(.*)> (.*)", /* What to match for chat (best to leave as default) */
"REGEX_SERVER_PREFIX": "\\[Server thread/INFO\\]:", /* What the lines of the log should start with */
"REGEX_MATCH_CHAT_MC": "^<([^>]*)> (.*)", /* What to match for chat (best to leave as default) */
"REGEX_IGNORED_CHAT": "packets too frequently", /* What to ignore, you can put any regex for swear words for example and it will be ignored */
"DEBUG": false /* Dev debugging */
"DEBUG": false, /* Dev debugging */

"SERVER_NAME": "Shulker", /* The username used when displaying any server information in chat, e.g., Server - Shulker : Server message here*/
"SERVER_IMAGE": "", /* Image for the server when sending such messages (if enabled below). Only for WebHooks. */
"SHOW_PLAYER_CONN_STAT": false, /* Shows player connection status in chat, e.g., Server - Shulker : TheMachine joined the game */
"SHOW_PLAYER_ADVANCEMENT": false, /* Shows when players earn advancements in chat, e.g., Server - Shulker : TheMachine has made the advacement [MEME - Machine] */
"SHOW_PLAYER_DEATH": false, /* Shows when players die in chat, e.g., Server - Shulker : TheMachine was blown up by creeper */
"SHOW_PLAYER_ME": false, /* Shows when players use the /me command, e.g. **destruc7i0n** says hello */
"DEATH_KEY_WORDS": ["shot", "fell", "etc".] /* Key words to look for when trying to identify a death message. (As of 3/11/2019 this list is up to date) */
}
```

## FAQ
* How do I make this work on a modded server?
- Try replacing `REGEX_SERVER_PREFIX` with `"\\[Server thread/INFO\\] \\[.*\\]:"`

* Why can't I send commands even if I have the option enabled?
- Make sure that you have a role on the server which is put in the array `SLASH_COMMAND_ROLES` case-sensitive.
- e.g. `"SLASH_COMMAND_ROLES": ["Admin"]`

## Upcoming
None

## Suggestions
If you have any suggestions or feature requests, feel free to add an issue and I will take a look and possibly add it to the "Upcoming" section!
If you have any suggestions or feature requests, feel free to add an issue and I will take a look.

## Thanks
* [hydrabolt](https://github.com/hydrabolt) for discord.js
* [qrush](https://github.com/qrush) for the idea of this ([wither](https://github.com/qrush/wither))
* [SecretOnline](https://github.com/secretonline) for Rcon reconnecting and for making it only send messages in specified channel
* [TheZackCodec](https://github.com/TheZackCodec/) for the updates in server based messages

## License

Expand Down
23 changes: 19 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"USE_WEBHOOKS": true,
"WEBHOOK_URL": "DISCORD_WEBHOOK_URL_HERE",
"DISCORD_TOKEN": "TOKEN_HERE",
"DISCORD_CHANNEL_ID": "1234",
"DISCORD_CHANNEL_ID": "",
"DISCORD_CHANNEL_NAME": "#bot",
"DISCORD_MESSAGE_TEMPLATE": "`%username%`: %message%",

"MINECRAFT_SERVER_RCON_IP": "127.0.0.1",
Expand All @@ -15,11 +16,25 @@
"IS_LOCAL_FILE": false,
"LOCAL_FILE_PATH": "/usr/home/minecraft_server/logs/latest.log",

"SHOW_INIT_MESSAGE": true,

"ALLOW_USER_MENTIONS": false,
"ALLOW_HERE_EVERYONE_MENTIONS": false,
"ALLOW_SLASH_COMMANDS": false,
"SLASH_COMMAND_ROLES": [],

"WEBHOOK": "/minecraft/hook",
"REGEX_MATCH_CHAT_MC": "\\[Server thread/INFO\\]: <([^>]*)> (.*)",
"REGEX_SERVER_PREFIX": "\\[Server thread/INFO\\]:",
"REGEX_MATCH_CHAT_MC": "^<([^>]*)> (.*)",
"REGEX_IGNORED_CHAT": "packets too frequently",
"RCON_RECONNECT_DELAY": 10,
"DEBUG": false
"DEBUG": false,

"SERVER_NAME": "Shulker",
"SERVER_IMAGE": "",
"SHOW_PLAYER_CONN_STAT": false,
"SHOW_PLAYER_ADVANCEMENT": false,
"SHOW_PLAYER_DEATH": false,
"SHOW_PLAYER_ME": false,
"DEATH_KEY_WORDS": ["shot", "fell", "death", "died", "doomed", "pummeled", "removed", "didn't want", "withered", "squashed", "flames", "burnt", "walked into", "bang", "roasted", "squished", "drowned", "killed", "slain", "blown", "blew", "suffocated", "struck", "lava", "impaled", "speared", "fireballed", "finished", "kinetic"]
}

184 changes: 0 additions & 184 deletions index.js

This file was deleted.

Loading

0 comments on commit d2cff4c

Please sign in to comment.