Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
This Repository has moved from AS1100K/aether to it's own repository.

For previous commits see AS1100K/aether#17
  • Loading branch information
AS1100K committed Jul 27, 2024
1 parent a017fbb commit d2748ef
Show file tree
Hide file tree
Showing 8 changed files with 623 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
# Run cargo test
test:
name: Test Suite
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.toml') }}
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install Dependencies
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: Run cargo test
run: cargo test

# Run cargo clippy -- -D warnings
clippy_check:
name: Clippy
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.toml') }}
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Install Dependencies
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: Run clippy
run: cargo clippy -- -D warnings

# Run cargo fmt --all -- --check
format:
name: Format
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Run cargo fmt
run: cargo fmt --all -- --check
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
# Pattern matched against refs/tags
tags:
- 'v*'

jobs:
publish:
name: Publish
# Specify OS
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@stable

- name: Publish Crate
run: cargo publish --token ${CRATES_TOKEN}
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
24 changes: 24 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "bevy-discord"
description = "A bevy plugin that can send messages to discord."
version = "0.2.0-alpha.1"
edition = "2021"
authors = ["Aditya Kumar <[email protected]>"]
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]
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"
tokio = { version = "1.38.0", features = ["rt-multi-thread", "rt"] }
serde_json = { version = "1.0.117" }

[dev-dependencies]
anyhow = "1.0.86"
azalea = "0.9.1"
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Bevy Discord Plugin

![GitHub License](https://img.shields.io/github/license/AS1100K/bevy-discord)
![Crates.io Version](https://img.shields.io/crates/v/bevy-discord)
![CI](https://github.com/as1100k/bevy-discord/actions/workflows/ci.yml/badge.svg?event=push)


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::prelude::*;
use azalea::Vec3;
use bevy_discord::common::DiscordMessage;
use bevy_discord::webhook::{DiscordWebhookPlugin, DiscordWebhookRes, SendMessageEvent};
#[tokio::main]
async fn main() {
let account = Account::offline("_aether");
let discord_webhook = DiscordWebhookRes::new()
.add_channel(
"channel_name",
"webhook_url",
"",
""
);
ClientBuilder::new()
.set_handler(handle)
.add_plugins(DiscordWebhookPlugin::new(discord_webhook))
.start(account, "localhost")
.await
.unwrap();
}
#[derive(Default, Clone, Component)]
pub struct State {}
async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
match event {
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(())
}
```
Loading

0 comments on commit d2748ef

Please sign in to comment.