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.rs14
-rw-r--r--src/system/bot/mod.rs4
2 files changed, 18 insertions, 0 deletions
diff --git a/src/system/bot/client.rs b/src/system/bot/client.rs
index a2d1b28..19fcbe6 100644
--- a/src/system/bot/client.rs
+++ b/src/system/bot/client.rs
@@ -23,6 +23,20 @@ impl Client {
         }
     }
 
+    pub async fn set_nick<'a>(&self, server_id: ServerId, nick: &'a str) -> Result<(), TwiError> {
+        let client = self.client.lock().await;
+
+        let current_user = client.current_user()
+            .await?.model().await.expect("Could not retrieve current user");
+
+        client
+           .update_guild_member(server_id, current_user.id)
+           .nick(Some(nick)).expect("Invalid nick")
+           .await?;
+
+        Ok(())
+    }
+
     pub async fn fetch_message(&self, message_id: MessageId, channel_id: ChannelId) -> FullMessage {
         let client = self.client.lock().await;
 
diff --git a/src/system/bot/mod.rs b/src/system/bot/mod.rs
index 2aa3e0a..0928a73 100644
--- a/src/system/bot/mod.rs
+++ b/src/system/bot/mod.rs
@@ -62,6 +62,10 @@ impl Bot {
         self.gateway.set_status(status).await;
     }
 
+    pub async fn set_nick(&self, server_id: ServerId, nick: String) {
+        self.client.set_nick(server_id, nick.as_str()).await.expect("Could not update nick")
+    }
+
     pub fn start(&self) {
         self.gateway.start_listening()
     }