Skip to content

Commit

Permalink
🚸 Make MAX_PLAYERS optional, accept interactions from all channels
Browse files Browse the repository at this point in the history
  • Loading branch information
GiyoMoon committed Sep 10, 2022
1 parent 2aedf89 commit bfe537e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 84 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ DISCORD_TOKEN=
CONSOLE_CHANNEL_ID=
SERVER_JAR_PATH=./server/server.jar
SERVER_MEMORY=6144
# Optional
MAX_PLAYERS=5
# Optional
JVM_FLAGS=

# Only for development
DEV=1
GUILD_ID=
59 changes: 25 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eve"
version = "0.1.0"
version = "0.1.1"
authors = ["GiyoMoon <giyomoon@gmail.com>"]
edition = "2021"
publish = false
Expand All @@ -13,14 +13,14 @@ codegen-units = 1
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.63"
anyhow = "1.0.64"
dotenvy = "0.15.3"
env_logger = "0.9.0"
futures = "0.3.24"
log = "0.4.17"
thiserror = "1.0.34"
tokio = { version = "1.21.0", features = ["rt-multi-thread", "macros", "process"] }
twilight-gateway = "0.13.0"
twilight-gateway = "0.13.1"
twilight-http = "0.13.0"
twilight-model = "0.13.2"
twilight-model = "0.13.3"
twilight-util = { version = "0.13.1", features = ["builder"] }
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ EVE lets you control a Minecraft server through Discord. It routes everything fr

![Example](./assets/example.png)
## Configuration
To run Eve, you need to set up a few environment variables:
To run EVE, you need to set up a few environment variables:

- `DISCORD_TOKEN`: The token of you Discord bot
- `CONSOLE_CHANNEL_ID`: The the ID of the Discord channel which should be used as the console. EVE will pass every output from the server into this channel
- `SERVER_JAR_PATH`: Path to the server executable. E.g. `/srv/server/server.jar`
- `SERVER_MEMORY`: Memory in megabytes to assign to the minecraft server. E.g `6144`
- `MAX_PLAYERS`: Max players of your minecraft server. (This is only used for the bot presence)
- `MAX_PLAYERS`: (Optional) Max players of your minecraft server. This is only used for the bot presence and if not provided, it won't show the player count there.
- `JVM_FLAGS`: (Optional) Additional jvm flags to pass to the server instance
- `RUST_LOG`: (Optional) Rust log level (Does not affect the server output). Set it to `info` to recieve all information or to `warn` if you just want to receive warnings/errors.

Expand Down Expand Up @@ -43,7 +43,7 @@ sudo touch /etc/systemd/system/eve.service
Insert this content:
```
[Unit]
Description=Eve
Description=EVE
Wants=network-online.target
After=network-online.target
Expand Down
24 changes: 9 additions & 15 deletions src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub async fn init() -> Result<(), anyhow::Error> {
let token = env::var("DISCORD_TOKEN").unwrap();
let channel_id: Id<ChannelMarker> =
Id::new(env::var("CONSOLE_CHANNEL_ID").unwrap().parse().unwrap());
let max_players: u8 = env::var("MAX_PLAYERS").unwrap().parse().unwrap();
let max_players: Option<u8> = env::var("MAX_PLAYERS").ok().map(|max| max.parse().unwrap());

let scheme = ShardScheme::Range {
from: 0,
Expand Down Expand Up @@ -100,20 +100,14 @@ pub async fn init() -> Result<(), anyhow::Error> {
while let Some((_, event)) = events.next().await {
match event {
Event::InteractionCreate(interaction) => {
match interaction.0.channel_id {
// check if interaction comes from configured channel
Some(c_id) if c_id == channel_id => {
handle_interaction(
application_id,
Arc::clone(&http),
Arc::clone(&server),
sender.clone(),
interaction,
)
.await?;
}
_ => {}
}
handle_interaction(
application_id,
Arc::clone(&http),
Arc::clone(&server),
sender.clone(),
interaction,
)
.await?;
}
Event::Ready(_) => {
info!("Bot started!");
Expand Down
Loading

0 comments on commit bfe537e

Please sign in to comment.