Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
Universal Bevy Discord Plugin (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
AS1100K authored Jul 13, 2024
1 parent c0d6784 commit 6ab418e
Show file tree
Hide file tree
Showing 15 changed files with 488 additions and 358 deletions.
3 changes: 2 additions & 1 deletion aether-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "aether-core"
version = "0.3.0-alpha.7"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.dev]
Expand All @@ -21,7 +22,7 @@ anyhow = "1.0.83"
azalea = { git = "https://github.com/as1100k-forks/azalea.git", branch = "better-1.20.6" }
azalea-task-manager = { path = "../plugins/task-manager", features = ["anti-afk"] }
azalea-anti-afk = { path = "../plugins/anti-afk" }
azalea-discord = { path = "../plugins/discord", features = ["chat-bridge", "log-bridge"] }
azalea-discord = { git = "https://github.com/as1100k/aether", tag = "azalea-discord@v0.1.0", features = ["chat-bridge", "log-bridge"] }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
tokio = { version = "1.37.0", features = ["macros"] }
Expand Down
1 change: 1 addition & 0 deletions examples/anti-afk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "anti-afk"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
azalea = { git = "https://github.com/as1100k-forks/azalea.git", branch = "better-1.20.6" }
Expand Down
1 change: 1 addition & 0 deletions examples/stone-miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "stone-miner"
version = "0.2.0"
edition = "2021"
publish = false

[profile.dev]
opt-level = 1
Expand Down
5 changes: 2 additions & 3 deletions plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ This directory contains small plugins that can be added to any of our bots.
* [Anti-AFK](./anti-afk/README.md) This Plugin Attempts to make the bot not get AFK Kicked.
* [Auto-Mine](./auto-mine/README.md) This plugins is the implementation of holding left-click in minecraft.
* [Task-Manager](./task-manager/README.md) This plugin acts as the task manger and executes tasks one by one.
* [Discord](./discord/README.md) This plugin is the bridge between minecraft and discord. _(Currently it can only send
messages and can't receive them)_
* [Utility](./utility/README.md) A small collection of necessary plugins for a bot like auto-eat, kill aura (WIP).
* [Bevy Discord](./discord/README.md) ![Crates.io Version](https://img.shields.io/crates/v/bevy-discord) A bevy plugin that can send messages to discord _(currently, only webhooks are supported)_.
* [Utility](./utility/README.md) A small collection of necessary plugins for a bot like auto-eat, kill aura (WIP).
1 change: 1 addition & 0 deletions plugins/anti-afk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "azalea-anti-afk"
version = "0.1.0"
edition = "2021"
authors = ["Aditya Kumar <117935160+AS1100K@users.noreply.github.com>"]
publish = false

[dependencies]
azalea = { git = "https://github.com/as1100k-forks/azalea.git", branch = "better-1.20.6" }
Expand Down
1 change: 1 addition & 0 deletions plugins/auto-mine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "azalea-auto-mine"
version = "0.1.0"
edition = "2021"
authors = ["Aditya Kumar <117935160+AS1100K@users.noreply.github.com>"]
publish = false

[dependencies]
azalea = { git = "https://github.com/as1100k-forks/azalea.git", branch = "better-1.20.6" }
Expand Down
27 changes: 14 additions & 13 deletions plugins/discord/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
[package]
name = "azalea-discord"
version = "0.1.0"
name = "bevy-discord"
description = "A bevy plugin that can send messages to discord."
version = "0.2.0-alpha.1"
edition = "2021"
authors = ["Aditya Kumar <117935160+AS1100K@users.noreply.github.com>"]

[features]
chat-bridge = ["dep:uuid", "dep:tokio"]
log-bridge = ["dep:tracing-subscriber", "dep:serde_json"]
readme = "README.md"
repository = "https://github.com/AS1100K/aether/tree/main/plugins/discord"
publish = true
license = "GPL-3.0-only"
keywords = ["bevy", "plugin", "discord"]

[dependencies]
azalea = { git = "https://github.com/as1100k-forks/azalea.git", branch = "better-1.20.6"}
reqwest = { version = "0.12.5", features = ["json"]}
bevy_app = "0.13.2"
bevy_ecs = "0.13.2"
reqwest = { version = "0.12.5", features = ["json", "rustls-tls"]}
serde = { version = "1.0.203", features = ["derive"] }
tracing = "0.1.40"
uuid = { version = "1.8.0", features = ["v4"], optional = true }
tokio = { version = "1.38.0", optional = true }
tracing-subscriber = { version = "0.3.18", optional = true }
serde_json = { version = "1.0.117", optional = true }
tokio = { version = "1.38.0", features = ["rt-multi-thread", "rt"] }
serde_json = { version = "1.0.117" }

[dev-dependencies]
anyhow = "1.0.86"
tokio = "1.38.0"
azalea = "0.9.1"
51 changes: 28 additions & 23 deletions plugins/discord/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
# Azalea Discord Plugin
# Bevy Discord Plugin

A very simple, discord plugin that let you send messages through discord webhooks. _In Future releases, this plugin will support
![GitHub License](https://img.shields.io/github/license/AS1100K/aether)
![Crates.io Version](https://img.shields.io/crates/v/bevy-discord)


A very simple, bevy plugin that let you send messages through discord webhooks. _In Future releases, this plugin will support
discord applications & bots and can send & receive messages by them._

## Example
This example is shown inside azalea, but this plugin can be used with any bevy app.

```rust,no_run
use azalea_discord::DiscordPlugin;
use azalea_discord::DiscordExt;
use azalea_discord::SendDiscordMessage;
use azalea::prelude::*;
use azalea::Vec3;
use bevy_discord::common::DiscordMessage;
use bevy_discord::webhook::{DiscordWebhookPlugin, DiscordWebhookRes, SendMessageEvent};
#[tokio::main]
async fn main() {
let account = azalea::Account::offline("_aether");
let account = Account::offline("_aether");
let discord_webhook = DiscordWebhookRes::new()
.add_channel(
"channel_name",
"webhook_url",
"",
""
);
ClientBuilder::new()
.set_handler(handle)
.add_plugins(DiscordPlugin)
.start(account, "10.9.12.3")
.add_plugins(DiscordWebhookPlugin::new(discord_webhook))
.start(account, "localhost")
.await
.unwrap();
}
Expand All @@ -28,24 +40,17 @@ pub struct State {}
async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
match event {
Event::Login => {
bot.send_discord_message(SendDiscordMessage {
webhook: "https://discord.com".to_string(),
contents: "Logged into the server".to_string(),
username: None,
avatar_url: None
});
Event::Chat(m) => {
let content = m.message();
println!("{}", &content.to_ansi());
let message = DiscordMessage::new()
.content(content.to_string());
bot.ecs.lock().send_event(SendMessageEvent::new("channel_name", message));
}
_ => {}
}
Ok(())
}
```

## Modules Available

1. Chat Bridge -> _only on feature `chat-bridge`_
Stream all the chats in minecraft to discord. Check this [example](./src/chat_bridge.rs) to learn how to use it.
2. Logs Bridge -> _only on feature `log-bridge`_
Stream all the logs _only supports `tracing`_ to discord. Check this [example](./src/log_bridge.rs) to learn how to use it.
138 changes: 0 additions & 138 deletions plugins/discord/src/chat_bridge.rs

This file was deleted.

Loading

0 comments on commit 6ab418e

Please sign in to comment.