summary refs log tree commit diff
path: root/src/system/bot
diff options
context:
space:
mode:
Diffstat (limited to 'src/system/bot')
-rw-r--r--src/system/bot/client.rs18
-rw-r--r--src/system/bot/mod.rs5
2 files changed, 18 insertions, 5 deletions
diff --git a/src/system/bot/client.rs b/src/system/bot/client.rs
index c55759a..006ce8f 100644
--- a/src/system/bot/client.rs
+++ b/src/system/bot/client.rs
@@ -52,6 +52,8 @@ impl Client {
         let delete_result = client.delete_message(channel_id, message_id).await;
         let member_id = self.bot_conf.read().await.member_id;
 
+        drop(client);
+
         match delete_result {
             Err(err) => {
                 match &err.kind() {
@@ -60,11 +62,7 @@ impl Client {
                             // Code for "Missing Permissions": https://discord.com/developers/docs/topics/opcodes-and-status-codes#json-json-error-codes
                             if err.code == 50013 {
                                 println!("ERROR: Client {} doesn't have permissions to delete message", member_id);
-                                let _ = client.create_reaction(
-                                    channel_id,
-                                    message_id,
-                                    &RequestReactionType::Unicode { name: "🔐" }
-                                ).await;
+                                let _ = self.react_message(channel_id, message_id, &RequestReactionType::Unicode { name: "🔐" }).await;
                             }
                         },
                         _ => (),
@@ -78,6 +76,16 @@ impl Client {
         }
     }
 
+    pub async fn react_message(&self, channel_id: ChannelId, message_id: MessageId, react: &'_ RequestReactionType<'_>) -> Result<(), TwiError> {
+        let _ = self.client.lock().await.create_reaction(
+            channel_id,
+            message_id,
+            react
+        ).await;
+
+        return Ok(())
+    }
+
     pub async fn duplicate_message(&self, message: &TwiMessage, content: &str) -> Result<TwiMessage, MessageDuplicateError> {
         let client = self.client.lock().await;
 
diff --git a/src/system/bot/mod.rs b/src/system/bot/mod.rs
index 6bf8d78..3c4585f 100644
--- a/src/system/bot/mod.rs
+++ b/src/system/bot/mod.rs
@@ -5,6 +5,7 @@ use std::sync::Arc;
 use tokio::sync::mpsc::Sender;
 use tokio::sync::RwLock;
 use twilight_http::error::Error as TwiError;
+use twilight_http::request::channel::reaction::RequestReactionType;
 
 pub use super::types::*;
 pub use client::MessageDuplicateError;
@@ -73,6 +74,10 @@ impl Bot {
         self.client.delete_message(channel_id, message_id).await
     }
 
+    pub async fn react_message(&self, channel_id: ChannelId, message_id: MessageId, react: &'_ RequestReactionType<'_>) -> Result<(), TwiError> {
+        self.client.react_message(channel_id, message_id, react).await
+    }
+
     pub async fn duplicate_message(&self, message_id: &TwiMessage, content: &str) ->  Result<TwiMessage, MessageDuplicateError> {
         self.client.duplicate_message(message_id, content).await
     }