summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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!"),
+            _ => (),
         }
     }
 }
+
+