summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
authorAshelyn Dawn <git@ashen.earth>2024-07-02 18:36:25 -0600
committerAshelyn Rose <git@ashen.earth>2024-07-02 22:11:54 -0600
commit5dc71ca03b5402c0a284e25492e63c696f7bdec6 (patch)
tree834d6361bf50beeb689013b82785baf8c0aed6da /src/main.rs
parent526d3c9eb93611567717df1ffc50fe47ec01ec42 (diff)
basic twilight client
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs
index 5e34924..02fba86 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
 mod config;
 use config::Config;
-use serenity::{all::{GatewayIntents, Message}, client::{Context, EventHandler}, Client};
+use twilight_gateway::{Intents, Shard, ShardId};
 
 #[tokio::main(flavor = "current_thread")]
 async fn main() {
@@ -15,28 +15,31 @@ async fn main() {
 
     println!("Token: {}", token);
 
-    let mut client = Client::builder(token, GatewayIntents::all())
-        .event_handler(MessageHandler).await.unwrap();
-        
-    client.start().await.unwrap()
-}
+    let intents = Intents::GUILD_MEMBERS | Intents::GUILD_PRESENCES | Intents::GUILD_MESSAGES | Intents::MESSAGE_CONTENT;
 
+    let mut shard = Shard::new(ShardId::ONE, token, intents);
 
-struct MessageHandler;
+    loop {
+        let event = match shard.next_event().await {
+            Ok(event) => event,
+            Err(source) => {
+                println!("error receiving event");
 
-#[serenity::async_trait]
-impl EventHandler for MessageHandler {
-    async fn message(&self, context: Context, msg: Message) {
-        if msg.member.unwrap().user.unwrap().bot { // TODO crashes
-            return
-        }
-        
-        println!("Got message");
-        println!("{}", msg.content);
-        if let Ok(_test) = msg.channel_id.say(&context, "message acknowledged").await {
-            println!("Reply sent")
-        } else {
-            println!("Error encountered")
+                if source.is_fatal() {
+                    break;
+                }
+
+                continue;
+            }
+        };
+
+        match event {
+            twilight_gateway::Event::MessageCreate(message) => println!("Message: {:?}", message),
+            twilight_gateway::Event::MessageUpdate(_) => println!("Message updated"),
+            twilight_gateway::Event::Ready(_) => println!("Bot ready!"),
+            _ => (),
         }
     }
 }
+
+