summary refs log tree commit diff
path: root/src/main.rs
blob: 02fba8625aac6d45b94d1d48d9b5a6c4e1885188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
mod config;
use config::Config;
use twilight_gateway::{Intents, Shard, ShardId};

#[tokio::main(flavor = "current_thread")]
async fn main() {
    println!("Hello, world!");

    let config_str = include_str!("../config.toml");
    let config = Config::load(config_str.to_string());

    let token = config.systems.get("ashe-test").unwrap().members
        .iter().find(|member| member.name == "test").unwrap()
        .discord_token.clone();

    println!("Token: {}", token);

    let intents = Intents::GUILD_MEMBERS | Intents::GUILD_PRESENCES | Intents::GUILD_MESSAGES | Intents::MESSAGE_CONTENT;

    let mut shard = Shard::new(ShardId::ONE, token, intents);

    loop {
        let event = match shard.next_event().await {
            Ok(event) => event,
            Err(source) => {
                println!("error receiving event");

                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!"),
            _ => (),
        }
    }
}