Skip to content

Commit 0bbc9fd

Browse files
committed
Update Twilight to 0.10
1 parent b1c2c2c commit 0bbc9fd

File tree

7 files changed

+95
-69
lines changed

7 files changed

+95
-69
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Notable `mc-server-wrapper` changes, tracked in the [keep a changelog](https://k
1212
### Internal
1313

1414
* Added dependency on `time` 0.3
15-
* Updated `twilight` to 0.9
15+
* Updated `twilight` to 0.10
1616
* Updated `tui` to 0.17
1717
* Updated `crostterm` to 0.23.1
1818
* Updated `textwrap` to 0.15

Cargo.lock

Lines changed: 38 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ discord = "Info"
8888
### Discord bridge setup
8989

9090
* Register an application and a bot with [Discord](https://discordapp.com/developers/applications)
91-
* Toggle `Server Members Intent` to on under `Privileged Gateway Intents`
92-
* 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)
91+
* Enable some things in the `Privileged Gateway Intents` section of the bot's admin portal
92+
* Toggle `Server Members Intent` on
93+
* 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)
94+
* Toggle `Message Content Intent` on
95+
* This is used to receive messsage content from the channel for the chat bridge in Discord so we can relay chat there into Minecraft
9396
* Add the bot to the guild you want to bridge to
9497
* Get the ID of the channel you want to bridge to (Google this for instructions)
9598
* Provide the bot token and channel ID in the config file

mc-server-wrapper/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ mc-server-wrapper-lib = { path = "../mc-server-wrapper-lib" }
1010
structopt = "0.3"
1111
tokio = { version = "1.15.0", features = ["full"] }
1212
futures = "0.3"
13-
twilight-http = "0.9"
14-
twilight-gateway = "0.9"
15-
twilight-cache-inmemory = "0.9"
16-
twilight-model = "0.9"
13+
twilight-http = "0.10.1"
14+
twilight-gateway = "0.10.1"
15+
twilight-cache-inmemory = "0.10.1"
16+
twilight-model = "0.10.1"
1717
twilight-command-parser = "0.9"
18-
twilight-mention = "0.9"
18+
twilight-mention = "0.10"
1919
# TODO: replace this with a crate of my own
2020
minecraft-chat = "0.1"
2121
log = "0.4"

mc-server-wrapper/src/discord/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ impl DiscordBridge {
104104
) -> Result<(Self, Events), anyhow::Error> {
105105
let (cluster, events) = Cluster::builder(
106106
token.clone(),
107-
Intents::GUILDS | Intents::GUILD_MESSAGES | Intents::GUILD_MEMBERS,
107+
Intents::GUILDS
108+
| Intents::GUILD_MESSAGES
109+
| Intents::GUILD_MEMBERS
110+
| Intents::MESSAGE_CONTENT,
108111
)
109112
.build()
110113
.await
@@ -203,8 +206,8 @@ impl DiscordBridge {
203206
if let Some(channel_name) = guild
204207
.channels
205208
.iter()
206-
.find(|c| c.id() == self.bridge_channel_id)
207-
.map(|c| c.name())
209+
.find(|c| c.id == self.bridge_channel_id)
210+
.and_then(|c| c.name.as_ref())
208211
{
209212
info!(
210213
"Connected to guild '{}', bridging chat to '#{}'",
@@ -350,7 +353,7 @@ impl DiscordBridge {
350353
mention.id,
351354
cmm.as_ref()
352355
.and_then(|cm| cm.nick())
353-
.unwrap_or_else(|| mention.name.as_str()),
356+
.unwrap_or(mention.name.as_str()),
354357
);
355358
}
356359

mc-server-wrapper/src/discord/util.rs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@ pub fn format_mentions_in<S: AsRef<str>>(
8383
MessageSpan::Mention(mention_type, raw) => match mention_type {
8484
MentionType::Channel(id) => {
8585
let cow = cache
86-
.guild_channel(id)
87-
.map(|channel| Cow::from(format!("#{}", channel.name())))
86+
.channel(id)
87+
.and_then(|channel| {
88+
channel
89+
.name
90+
.as_ref()
91+
.map(|channel_name| Cow::from(format!("#{}", channel_name)))
92+
})
8893
// Throughout this function we fallback to the raw, unformatted
8994
// text if we're unable to fetch relevant info from the cache
9095
.unwrap_or_else(|| Cow::from(raw));
@@ -316,30 +321,43 @@ mod sanitize_for_markdown {
316321
mod content_format_mentions {
317322
use twilight_gateway::Event;
318323
use twilight_model::{
319-
channel::{Channel, ChannelType, GuildChannel, TextChannel},
324+
channel::{Channel, ChannelType},
320325
gateway::payload,
321326
guild::{Permissions, Role},
322327
};
323328

324329
use super::*;
325330

326331
fn make_text_channel() -> Event {
327-
Event::ChannelCreate(payload::incoming::ChannelCreate(Channel::Guild(
328-
GuildChannel::Text(TextChannel {
329-
id: Id::new(1234),
330-
guild_id: Some(Id::new(1)),
331-
kind: ChannelType::GuildText,
332-
last_message_id: None,
333-
last_pin_timestamp: None,
334-
name: "test-channel".into(),
335-
nsfw: false,
336-
permission_overwrites: vec![],
337-
parent_id: None,
338-
position: 0,
339-
rate_limit_per_user: None,
340-
topic: Some("a test channel".into()),
341-
}),
342-
)))
332+
Event::ChannelCreate(Box::new(payload::incoming::ChannelCreate(Channel {
333+
application_id: None,
334+
bitrate: None,
335+
default_auto_archive_duration: None,
336+
guild_id: Some(Id::new(1)),
337+
icon: None,
338+
id: Id::new(1234),
339+
invitable: None,
340+
kind: ChannelType::GuildText,
341+
last_message_id: None,
342+
last_pin_timestamp: None,
343+
member: None,
344+
member_count: None,
345+
message_count: None,
346+
name: Some("test-channel".into()),
347+
newly_created: None,
348+
nsfw: None,
349+
owner_id: None,
350+
parent_id: None,
351+
permission_overwrites: None,
352+
position: None,
353+
rate_limit_per_user: None,
354+
recipients: None,
355+
rtc_region: None,
356+
thread_metadata: None,
357+
topic: None,
358+
user_limit: None,
359+
video_quality_mode: None,
360+
})))
343361
}
344362

345363
fn make_role() -> Event {

mc-server-wrapper/src/ui.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl LogsState {
217217
.iter_mut()
218218
// Only wrap the records we could potentially be displaying
219219
.skip(num_records.saturating_sub(available_lines))
220-
.map(|r| {
220+
.flat_map(|r| {
221221
// See if we can use a cached wrapped line
222222
if let Some(wrapped) = &r.1 {
223223
if wrapped.1 as usize == logs_area_width {
@@ -239,8 +239,7 @@ impl LogsState {
239239

240240
wrapped_lines_len += r.1.as_ref().unwrap().0.len();
241241
r.1.as_ref().unwrap().0.clone()
242-
})
243-
.flatten(),
242+
}),
244243
);
245244

246245
if self.progress_bar.is_some() {

0 commit comments

Comments
 (0)