Skip to content

Commit

Permalink
0.11.1 - Update Azalea
Browse files Browse the repository at this point in the history
  • Loading branch information
ShayBox committed Jan 20, 2025
1 parent fbd659e commit 8f9898f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 41 deletions.
45 changes: 23 additions & 22 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shaysbot"
version = "0.11.0"
version = "0.11.1"
authors = ["Shayne Hartford <shaybox@shaybox.com>"]
edition = "2021"
description = "My personal Minecraft bot using Azalea"
Expand Down
10 changes: 7 additions & 3 deletions src/chat/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ impl Plugin for ApiServerPlugin {
.add_systems(Startup, Self::handle_startup)
.add_systems(
Update,
(Self::handle_api_requests, Self::handle_send_whisper_events),
(
Self::handle_api_requests
.before(MinecraftChatPlugin::handle_chat_received_events),
Self::handle_send_whisper_events,
),
);
}
}

impl ApiServerPlugin {
pub fn handle_startup(mut api_server: ResMut<ApiServer>, settings: Res<GlobalSettings>) {
match Server::http(settings.api_server.bind_addr.clone()) {
match Server::http(settings.api.bind_addr.clone()) {
Ok(server) => {
info!("API Server @ {}", server.server_addr());
api_server.0 = Some(server);
Expand Down Expand Up @@ -87,7 +91,7 @@ impl ApiServerPlugin {
return;
};

if username != settings.api_server.username || password != settings.api_server.password {
if username != settings.api.username || password != settings.api.password {
send_text(request, "Invalid Credentials", 406);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ pub mod api;
pub mod discord;
pub mod minecraft;

#[cfg(feature = "api")]
use std::sync::Mutex;
use std::{
collections::{HashMap, VecDeque},
sync::Mutex,
time::{Duration, Instant},
};

Expand Down
1 change: 1 addition & 0 deletions src/commands/pearl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl Plugin for PearlCommandPlugin {

impl PearlCommandPlugin {
#[allow(clippy::too_many_lines)]
#[cfg_attr(not(feature = "discord"), allow(unused_variables))]
pub fn handle_pearl_command_events(
mut command_events: EventReader<CommandEvent>,
mut pearl_events: EventWriter<PearlGotoEvent>,
Expand Down
2 changes: 2 additions & 0 deletions src/commands/whitelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use azalea::{
PlayerInfo,
TabList,
};
#[cfg(feature = "discord")]
use serde::Deserialize;
use uuid::Uuid;

Expand Down Expand Up @@ -184,6 +185,7 @@ fn try_find_player<'a>(tab_list: &'a TabList, name: &str) -> Option<(&'a Uuid, &
tab_list.iter().find(|(_, info)| info.profile.name == name)
}

#[cfg(feature = "discord")]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct Json {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use smart_default::SmartDefault;
use terminal_link::Link;
use url::Url;

use crate::{chat::api::ApiServerPlugin, prelude::*};
use crate::prelude::*;

pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const CARGO_PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
Expand Down Expand Up @@ -98,16 +98,16 @@ pub async fn start() -> Result<()> {
}

#[cfg(feature = "api")] /* Enable the ApiServer plugin if it's enabled */
if global_settings.api_server.enabled {
if global_settings.api.enabled {
client = client.add_plugins(ApiServerPlugin);
}

#[cfg(feature = "discord")] /* Enable the Discord plugin if a token was provided */
if !global_settings.discord_token.is_empty() {
if !global_settings.discord.token.is_empty() {
let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT;
let config = DiscordBotConfig::default()
.gateway_intents(intents)
.token(global_settings.discord_token.clone());
.token(global_settings.discord.token.clone());

client = client.add_plugins((
DiscordBotPlugin::new(config),
Expand Down
4 changes: 3 additions & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#[cfg(feature = "api")]
pub use super::chat::api::*;
#[cfg(feature = "discord")]
pub use super::{chat::discord::*, modules::discord_logger::*};
pub use super::{
chat::{api::*, minecraft::*, *},
chat::{minecraft::*, *},
commands::{join::*, leave::*, pearl::*, playtime::*, seen::*, whitelist::*, *},
modules::{
anti_afk::*,
Expand Down
32 changes: 23 additions & 9 deletions src/settings/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ pub struct GlobalSettings {
#[serde_as(as = "DurationSeconds")]
pub command_cooldown: Duration,

/// Discord client token for commands and events. (Optional)
#[default("")]
#[cfg(feature = "discord")]
pub discord_token: String,

/// Minecraft server ender pearl view distance in blocks.
/// It is better to under-estimate than to over-estimate.
#[default(64)]
pub pearl_view_distance: i32,

/// Minecraft server address.
#[default(ServerAddress {
#[default(ServerAddress{
host: str!("play.vengeancecraft.net"),
port: 25565
})]
})]
pub server_address: ServerAddress,

/// ViaProxy server version. (Optional)
Expand All @@ -55,10 +50,18 @@ pub struct GlobalSettings {
#[default(false)]
pub whitelist: bool,

/// API Server for local integrations. (SECURITY: USE A REVERSE PROXY FOR PUBLIC ACCESS!)
pub api_server: ApiServer,
/// API Server for local integrations.
#[cfg(feature = "api")]
#[serde(rename = "api_server")]
pub api: ApiServer,

/// Discord bot for commands and events.
#[cfg(feature = "discord")]
#[serde(rename = "discord_bot")]
pub discord: DiscordBot,

/// Chat encryption using the NCR (No Chat Reports) mod.
#[serde(rename = "chat_encryption")]
pub encryption: ChatEncryption,

/// Whitelisted Minecraft accounts and their linked Discord accounts.
Expand Down Expand Up @@ -97,6 +100,17 @@ pub struct ChatEncryption {
pub mode: EncryptionMode,
}

#[cfg(feature = "discord")]
#[derive(Clone, Eq, PartialEq, Deserialize, Serialize, SmartDefault)]
#[serde(default)]
pub struct DiscordBot {
#[default(false)]
pub enabled: bool,

/// Discord client token.
pub token: String,
}

#[derive(Clone, Default, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum EncryptionMode {
Expand Down

0 comments on commit 8f9898f

Please sign in to comment.