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

Commit

Permalink
Added Discord to take commands
Browse files Browse the repository at this point in the history
  • Loading branch information
AS1100K committed Aug 24, 2024
1 parent aaad339 commit 6b494dc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
8 changes: 8 additions & 0 deletions aether-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] 0.3.0-rc.1

### Added

- Added Discord Chat Relay
- Added Discord Notifications for important events
- Added Discord to take command

### Changed

- Upgrade dependency `serde_json`
- Changed bot joining mechanism to retry forever

### Removed

- Removed azalea patch i.e. [`better-1.20.6`](https://github.com/as1100k-forks/azalea.git)

### Fixed

- Removed Auto Eat [Issue #24](https://github.com/AS1100K/aether/issues/24)

## [0.3.0-beta.1] 07-08-2024

### Added

- Added `InWorld`, and `ExecutingTask` Component [#22](https://github.com/AS1100K/aether/pull/22)
- Added `PearlLoad` Event [#22](https://github.com/AS1100K/aether/pull/22)
- Added Auto Eat
- Added Auto Totem

### Changed

- Migrated from Tokio to Bevy ECS [#22](https://github.com/AS1100K/aether/pull/22)

### Removed

- Removed Integration with `azalea_discord` [#22](https://github.com/AS1100K/aether/pull/22)

_For previous Changelog, you need to do `git blame`_
1 change: 0 additions & 1 deletion aether-core/src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use azalea::entity::LocalEntity;
use azalea::prelude::*;
use azalea_anti_afk::config::AntiAFKConfig;
use azalea_anti_afk::AntiAFK;
use azalea_utility::auto_eat::{StartAutoEat, StopAutoEat};
use azalea_utility::auto_totem::AutoTotem;
use bevy_discord::bot::serenity::all::ChannelId;
use bevy_discord::bot::DiscordBotRes;
Expand Down
5 changes: 1 addition & 4 deletions aether-core/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use azalea::{
app::Plugin,
prelude::*,
};
use azalea::{app::Plugin, prelude::*};
use pearl::load::{handle_executing_task, handle_load_peral, LoadPearl};

pub mod pearl;
Expand Down
4 changes: 2 additions & 2 deletions aether-core/src/commands/pearl/load.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::time::Duration;

use azalea::chat::SendChatEvent;
use azalea::ecs::prelude::*;
use azalea::prelude::*;
use azalea_anti_afk::config::AntiAFKConfig;
use azalea_task_manager::{task_manager_queue::Task, AddTaskEvent};
use azalea::prelude::*;
use azalea::ecs::prelude::*;

use crate::{commands::ExecutingTask, config::Bot};

Expand Down
48 changes: 46 additions & 2 deletions aether-core/src/discord.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use azalea::app::{Plugin, Update};
use azalea::chat::{ChatPacketKind, ChatReceivedEvent, SendChatKindEvent};
use azalea::chat::{ChatPacket, ChatPacketKind, ChatReceivedEvent, SendChatKindEvent};
use azalea::ecs::prelude::*;
use azalea::entity::metadata::Player;
use azalea::entity::LocalEntity;
use azalea::prelude::*;
use azalea::protocol::packets::game::clientbound_system_chat_packet::ClientboundSystemChatPacket;
use bevy_discord::bot::events::BMessage;
use bevy_discord::bot::serenity::all::ChannelId;
use bevy_discord::bot::DiscordBotRes;
use bevy_discord::runtime::tokio_runtime;
use serde_json::json;
use std::sync::Arc;
use tracing::error;

use crate::chat::handle_chat;
Expand All @@ -32,7 +34,11 @@ impl Plugin for AetherDiscordPlugin {
fn build(&self, app: &mut azalea::app::App) {
app.add_systems(
Update,
(handle_chat_relay, handle_discord_bridge)
(
handle_chat_relay,
handle_discord_bridge,
handle_disocrd_channel_id,
)
.chain()
.after(handle_chat),
);
Expand Down Expand Up @@ -74,6 +80,7 @@ fn handle_chat_relay(
}
}

#[allow(clippy::complexity)]
fn handle_discord_bridge(
mut events: EventReader<BMessage>,
query: Query<(&DiscordChatRelay, Entity), (With<Player>, With<LocalEntity>)>,
Expand All @@ -95,3 +102,40 @@ fn handle_discord_bridge(
}
}
}

#[allow(clippy::complexity)]
fn handle_disocrd_channel_id(
mut events: EventReader<BMessage>,
query: Query<(&DiscordChannelId, Entity), (With<Player>, With<LocalEntity>)>,
mut chat_received_event: EventWriter<ChatReceivedEvent>,
) {
for BMessage {
ctx: _,
new_message,
} in events.read()
{
for (DiscordChannelId { channel_id }, entity) in query.iter() {
if !new_message.author.bot && &new_message.channel_id == channel_id {
match new_message
.content
.split_whitespace()
.collect::<Vec<&str>>()
.as_slice()
{
["!pearl", "load", username] => {
chat_received_event.send(ChatReceivedEvent {
entity,
packet: ChatPacket::System(Arc::new(ClientboundSystemChatPacket {
overlay: true,
content: format!("{} whispers: !pearl load", username).into(),
})),
});
}
_ => {
error!("Invalid Discord Command")
}
}
}
}
}
}

0 comments on commit 6b494dc

Please sign in to comment.