diff options
author | Ashelyn Rose <git@ashen.earth> | 2024-10-05 18:02:12 -0600 |
---|---|---|
committer | Ashelyn Rose <git@ashen.earth> | 2024-10-05 18:02:12 -0600 |
commit | ca4b0e32be531053f19ce2895b994130b247af4a (patch) | |
tree | bdfef248c6917109b6a768bed9733b0999ae0e2f /src/system/bot | |
parent | 4fa4907c3da23249ddec2bcb50e48f708152059e (diff) |
Add sent-message cache for looking up command targets
Diffstat (limited to 'src/system/bot')
-rw-r--r-- | src/system/bot/client.rs | 16 | ||||
-rw-r--r-- | src/system/bot/gateway.rs | 2 | ||||
-rw-r--r-- | src/system/bot/mod.rs | 8 |
3 files changed, 17 insertions, 9 deletions
diff --git a/src/system/bot/client.rs b/src/system/bot/client.rs index 006ce8f..61d7515 100644 --- a/src/system/bot/client.rs +++ b/src/system/bot/client.rs @@ -23,18 +23,22 @@ impl Client { } } - pub async fn refetch_message(&self, message_id: MessageId, channel_id: ChannelId) { + pub async fn fetch_message(&self, message_id: MessageId, channel_id: ChannelId) -> FullMessage { let client = self.client.lock().await; - let bot_conf = self.bot_conf.read().await; - let message_channel = bot_conf.message_handler.as_ref().expect("No message handler"); - let message = client + client .message(channel_id, message_id) .await .expect("Could not load message") .model() .await - .expect("Could not deserialize message"); + .expect("Could not deserialize message") + } + + pub async fn resend_message(&self, message_id: MessageId, channel_id: ChannelId) { + let bot_conf = self.bot_conf.read().await; + let message = self.fetch_message(message_id, channel_id).await; + let message_channel = bot_conf.message_handler.as_ref().expect("No message handler"); let timestamp = if message.edited_timestamp.is_some() { message.edited_timestamp.unwrap() @@ -43,7 +47,7 @@ impl Client { }; message_channel - .send((timestamp, Message::Complete(message))) + .send((timestamp, Message::Complete(message, bot_conf.member_id))) .await; } diff --git a/src/system/bot/gateway.rs b/src/system/bot/gateway.rs index 5a45083..5a343d1 100644 --- a/src/system/bot/gateway.rs +++ b/src/system/bot/gateway.rs @@ -94,7 +94,7 @@ impl Gateway { } message_channel - .send((message.timestamp, Message::Complete(message))) + .send((message.timestamp, Message::Complete(message, bot_conf.member_id))) .await; } diff --git a/src/system/bot/mod.rs b/src/system/bot/mod.rs index 3c4585f..2f38075 100644 --- a/src/system/bot/mod.rs +++ b/src/system/bot/mod.rs @@ -66,8 +66,12 @@ impl Bot { self.gateway.start_listening() } - pub async fn refetch_message(&self, message_id: MessageId, channel_id: ChannelId) { - self.client.refetch_message(message_id, channel_id).await; + pub async fn fetch_message(&self, message_id: MessageId, channel_id: ChannelId) -> TwiMessage { + self.client.fetch_message(message_id, channel_id).await + } + + pub async fn resend_message(&self, message_id: MessageId, channel_id: ChannelId) { + self.client.resend_message(message_id, channel_id).await; } pub async fn delete_message(&self, channel_id: ChannelId, message_id: MessageId) -> Result<(), TwiError> { |