diff --git a/CHANGELOG.md b/CHANGELOG.md index e820c2b..8107442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ Notable `mc-server-wrapper` changes, tracked in the [keep a changelog](https://k ### Internal * Added dependency on `time` 0.3 -* Updated `twilight` to 0.9 +* Updated `twilight` to 0.10 * Updated `tui` to 0.17 * Updated `crostterm` to 0.23.1 * Updated `textwrap` to 0.15 diff --git a/Cargo.lock b/Cargo.lock index 9a79751..b597283 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,9 +78,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block-buffer" -version = "0.9.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" dependencies = [ "generic-array", ] @@ -239,6 +239,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "crypto-common" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "dashmap" version = "5.2.0" @@ -252,11 +262,12 @@ dependencies = [ [[package]] name = "digest" -version = "0.9.0" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "generic-array", + "block-buffer", + "crypto-common", ] [[package]] @@ -962,12 +973,6 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "openssl-probe" version = "0.1.5" @@ -1325,15 +1330,13 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.8" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" dependencies = [ - "block-buffer", "cfg-if 1.0.0", "cpufeatures", "digest", - "opaque-debug", ] [[package]] @@ -1558,9 +1561,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.16.1" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e80b39df6afcc12cdf752398ade96a6b9e99c903dfdc36e53ad10b9c366bca72" +checksum = "06cda1232a49558c46f8a504d5b93101d42c0bf7f911f12a105ba48168f821ae" dependencies = [ "futures-util", "log", @@ -1654,9 +1657,9 @@ dependencies = [ [[package]] name = "tungstenite" -version = "0.16.0" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ad3713a14ae247f22a728a0456a545df14acf3867f905adff84be99e23b3ad1" +checksum = "d96a2dea40e7570482f28eb57afbe42d97551905da6a9400acc5c328d24004f5" dependencies = [ "base64", "byteorder", @@ -1675,9 +1678,9 @@ dependencies = [ [[package]] name = "twilight-cache-inmemory" -version = "0.9.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7fdab6174ff727f92190f3dd70cb1a9b53b601f6045fd10bf28b83fcdd8e78" +checksum = "644c73ca822657936e6da14b96c11808d6ec848798d1ea6ecc15aef1fc12a383" dependencies = [ "bitflags", "dashmap", @@ -1696,9 +1699,9 @@ dependencies = [ [[package]] name = "twilight-gateway" -version = "0.9.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e8f2a6c43168048a3084e66a415267fa889792723e8fba5615aa56e7d43223" +checksum = "aa5c2c66706ce4bdb31d743a563df70d5cc8ef9cbe00bb55b56c4bffe759cb56" dependencies = [ "bitflags", "flate2", @@ -1719,9 +1722,9 @@ dependencies = [ [[package]] name = "twilight-gateway-queue" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cee27ea2919e1e2c1a56e21ee1236a5865999457d37fcd445d01a1ba23d5dd" +checksum = "f0567f61d171e064275d5eda8106376979db347c3cc478aaf4c3963f4243abdf" dependencies = [ "tokio", "twilight-http", @@ -1729,9 +1732,9 @@ dependencies = [ [[package]] name = "twilight-http" -version = "0.9.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df85a243aea658cfe090be17b41b122e786b767e51d031e1c71a0aa61437f852" +checksum = "09403769d71a9d8708b992b7a3a41efd460dd3cd3d1c827abc6ca922beea4ec4" dependencies = [ "brotli", "hyper", @@ -1749,9 +1752,9 @@ dependencies = [ [[package]] name = "twilight-http-ratelimiting" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8cc3e7563b2d76949160753a275bc6fc4105bc70146b150e24e9662d2f5f6a" +checksum = "c6b692b85c75eb83f6d223bf0e437054c8e3c36083fa75c43e5e540441e1faa6" dependencies = [ "futures-util", "http", @@ -1760,18 +1763,18 @@ dependencies = [ [[package]] name = "twilight-mention" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ca93ef2cd61ca0f56ad89e8ca2e9aec447552c7baee8aa11a8c7bed8bbfe7a" +checksum = "4f4bd44b83e5cf601894d7fa79b09b31af2cf8d86bfc6280b6cb4b98ed9fd685" dependencies = [ "twilight-model", ] [[package]] name = "twilight-model" -version = "0.9.2" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50283cfe1a01c268899a29e3318de4f60b9877be6cc8e434e65c5d3ec95d49e" +checksum = "638caa27f669b7c20220460d35c0f89702452726e1547ae634c93e500ff80706" dependencies = [ "bitflags", "serde", @@ -1783,9 +1786,9 @@ dependencies = [ [[package]] name = "twilight-validate" -version = "0.9.2" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b499f9fec4ceff08abe8374acc162c021f593659759653ffe6c86c54fd818390" +checksum = "08e3c3917d90eeffa4ff69e4baab32c1cf1d7b5d522b03f597b5e2d0b96c7b6f" dependencies = [ "twilight-model", ] diff --git a/README.md b/README.md index 45df681..10d05e6 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,11 @@ discord = "Info" ### Discord bridge setup * Register an application and a bot with [Discord](https://discordapp.com/developers/applications) -* Toggle `Server Members Intent` to on under `Privileged Gateway Intents` - * This is used to receive member updates from your guild (such as when someone changes their nickname so we can change the name we display in-game) +* Enable some things in the `Privileged Gateway Intents` section of the bot's admin portal + * Toggle `Server Members Intent` on + * This is used to receive member updates from your guild (such as when someone changes their nickname so we can change the name we display in-game) + * Toggle `Message Content Intent` on + * This is used to receive messsage content from the channel for the chat bridge in Discord so we can relay chat there into Minecraft * Add the bot to the guild you want to bridge to * Get the ID of the channel you want to bridge to (Google this for instructions) * Provide the bot token and channel ID in the config file diff --git a/mc-server-wrapper/Cargo.toml b/mc-server-wrapper/Cargo.toml index 1bf70cf..5b23fdb 100644 --- a/mc-server-wrapper/Cargo.toml +++ b/mc-server-wrapper/Cargo.toml @@ -10,12 +10,12 @@ mc-server-wrapper-lib = { path = "../mc-server-wrapper-lib" } structopt = "0.3" tokio = { version = "1.15.0", features = ["full"] } futures = "0.3" -twilight-http = "0.9" -twilight-gateway = "0.9" -twilight-cache-inmemory = "0.9" -twilight-model = "0.9" +twilight-http = "0.10.1" +twilight-gateway = "0.10.1" +twilight-cache-inmemory = "0.10.1" +twilight-model = "0.10.1" twilight-command-parser = "0.9" -twilight-mention = "0.9" +twilight-mention = "0.10" # TODO: replace this with a crate of my own minecraft-chat = "0.1" log = "0.4" diff --git a/mc-server-wrapper/src/discord/mod.rs b/mc-server-wrapper/src/discord/mod.rs index 518ed4e..49bd425 100644 --- a/mc-server-wrapper/src/discord/mod.rs +++ b/mc-server-wrapper/src/discord/mod.rs @@ -104,7 +104,10 @@ impl DiscordBridge { ) -> Result<(Self, Events), anyhow::Error> { let (cluster, events) = Cluster::builder( token.clone(), - Intents::GUILDS | Intents::GUILD_MESSAGES | Intents::GUILD_MEMBERS, + Intents::GUILDS + | Intents::GUILD_MESSAGES + | Intents::GUILD_MEMBERS + | Intents::MESSAGE_CONTENT, ) .build() .await @@ -203,8 +206,8 @@ impl DiscordBridge { if let Some(channel_name) = guild .channels .iter() - .find(|c| c.id() == self.bridge_channel_id) - .map(|c| c.name()) + .find(|c| c.id == self.bridge_channel_id) + .and_then(|c| c.name.as_ref()) { info!( "Connected to guild '{}', bridging chat to '#{}'", @@ -350,7 +353,7 @@ impl DiscordBridge { mention.id, cmm.as_ref() .and_then(|cm| cm.nick()) - .unwrap_or_else(|| mention.name.as_str()), + .unwrap_or(mention.name.as_str()), ); } diff --git a/mc-server-wrapper/src/discord/util.rs b/mc-server-wrapper/src/discord/util.rs index 1bcff26..2f08ca5 100644 --- a/mc-server-wrapper/src/discord/util.rs +++ b/mc-server-wrapper/src/discord/util.rs @@ -83,8 +83,13 @@ pub fn format_mentions_in>( MessageSpan::Mention(mention_type, raw) => match mention_type { MentionType::Channel(id) => { let cow = cache - .guild_channel(id) - .map(|channel| Cow::from(format!("#{}", channel.name()))) + .channel(id) + .and_then(|channel| { + channel + .name + .as_ref() + .map(|channel_name| Cow::from(format!("#{}", channel_name))) + }) // Throughout this function we fallback to the raw, unformatted // text if we're unable to fetch relevant info from the cache .unwrap_or_else(|| Cow::from(raw)); @@ -316,7 +321,7 @@ mod sanitize_for_markdown { mod content_format_mentions { use twilight_gateway::Event; use twilight_model::{ - channel::{Channel, ChannelType, GuildChannel, TextChannel}, + channel::{Channel, ChannelType}, gateway::payload, guild::{Permissions, Role}, }; @@ -324,22 +329,35 @@ mod content_format_mentions { use super::*; fn make_text_channel() -> Event { - Event::ChannelCreate(payload::incoming::ChannelCreate(Channel::Guild( - GuildChannel::Text(TextChannel { - id: Id::new(1234), - guild_id: Some(Id::new(1)), - kind: ChannelType::GuildText, - last_message_id: None, - last_pin_timestamp: None, - name: "test-channel".into(), - nsfw: false, - permission_overwrites: vec![], - parent_id: None, - position: 0, - rate_limit_per_user: None, - topic: Some("a test channel".into()), - }), - ))) + Event::ChannelCreate(Box::new(payload::incoming::ChannelCreate(Channel { + application_id: None, + bitrate: None, + default_auto_archive_duration: None, + guild_id: Some(Id::new(1)), + icon: None, + id: Id::new(1234), + invitable: None, + kind: ChannelType::GuildText, + last_message_id: None, + last_pin_timestamp: None, + member: None, + member_count: None, + message_count: None, + name: Some("test-channel".into()), + newly_created: None, + nsfw: None, + owner_id: None, + parent_id: None, + permission_overwrites: None, + position: None, + rate_limit_per_user: None, + recipients: None, + rtc_region: None, + thread_metadata: None, + topic: None, + user_limit: None, + video_quality_mode: None, + }))) } fn make_role() -> Event { diff --git a/mc-server-wrapper/src/ui.rs b/mc-server-wrapper/src/ui.rs index 9da96a8..e7c2cc1 100644 --- a/mc-server-wrapper/src/ui.rs +++ b/mc-server-wrapper/src/ui.rs @@ -217,7 +217,7 @@ impl LogsState { .iter_mut() // Only wrap the records we could potentially be displaying .skip(num_records.saturating_sub(available_lines)) - .map(|r| { + .flat_map(|r| { // See if we can use a cached wrapped line if let Some(wrapped) = &r.1 { if wrapped.1 as usize == logs_area_width { @@ -239,8 +239,7 @@ impl LogsState { wrapped_lines_len += r.1.as_ref().unwrap().0.len(); r.1.as_ref().unwrap().0.clone() - }) - .flatten(), + }), ); if self.progress_bar.is_some() {