diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/system/bot/gateway.rs | 4 | ||||
-rw-r--r-- | src/system/mod.rs | 5 | ||||
-rw-r--r-- | src/system/types.rs | 2 |
4 files changed, 11 insertions, 4 deletions
diff --git a/src/config.rs b/src/config.rs index 7f18365..28fe422 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,6 +3,8 @@ use std::collections::HashMap; use regex::{Regex, RegexBuilder}; use serde::{Deserialize, Deserializer, de::Error}; +use crate::system::UserId; + #[derive(Deserialize)] pub enum AutoProxyScope { Global, @@ -67,6 +69,8 @@ pub struct Member { #[serde(deserialize_with = "parse_regex")] pub message_pattern: Regex, pub discord_token: String, + #[serde(skip)] + pub user_id: Option<UserId>, pub presence: Option<PresenceMode>, pub status: Option<String>, } diff --git a/src/system/bot/gateway.rs b/src/system/bot/gateway.rs index 5a343d1..bfe4603 100644 --- a/src/system/bot/gateway.rs +++ b/src/system/bot/gateway.rs @@ -80,9 +80,9 @@ impl Gateway { } } Ok(event) => match event { - twilight_gateway::Event::Ready(_) => { + twilight_gateway::Event::Ready(ready) => { system_channel - .send(SystemEvent::GatewayConnected(bot_conf.member_id)) + .send(SystemEvent::GatewayConnected(bot_conf.member_id, ready.user.id)) .await; } diff --git a/src/system/mod.rs b/src/system/mod.rs index bd27f4a..6c4d95f 100644 --- a/src/system/mod.rs +++ b/src/system/mod.rs @@ -84,7 +84,10 @@ impl Manager { loop { match system_receiver.recv().await { - Some(SystemEvent::GatewayConnected(member_id)) => { + Some(SystemEvent::GatewayConnected(member_id, user_id)) => { + self.config.members.iter_mut().enumerate() + .find(|(id, _)| *id == member_id).unwrap().1.user_id = Some(user_id); + let member = self.find_member_by_id(member_id).unwrap(); println!("Gateway client {} ({}) connected", member.name, member_id); diff --git a/src/system/types.rs b/src/system/types.rs index 89eb189..bef6d6d 100644 --- a/src/system/types.rs +++ b/src/system/types.rs @@ -24,7 +24,7 @@ pub type CommandEvent = (Timestamp, ()); pub enum SystemEvent { // Process of operation - GatewayConnected(MemberId), + GatewayConnected(MemberId, UserId), GatewayError(MemberId, String), GatewayClosed(MemberId), RefetchMessage(MemberId, MessageId, ChannelId), |