diff --git a/.gitignore b/.gitignore index 40d9aca..5e101cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/.idea \ No newline at end of file +/.idea +.env \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index f56dce9..b830943 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,6 +220,7 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" name = "count_bot" version = "0.1.0" dependencies = [ + "dotenv", "serenity", "tokio", ] @@ -318,6 +319,12 @@ dependencies = [ "syn 2.0.91", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "encoding_rs" version = "0.8.35" @@ -1358,15 +1365,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - [[package]] name = "skeptic" version = "0.13.7" @@ -1581,9 +1579,7 @@ dependencies = [ "bytes", "libc", "mio", - "parking_lot", "pin-project-lite", - "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.52.0", diff --git a/Cargo.toml b/Cargo.toml index 916ccd8..cadc310 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] +dotenv = "0.15.0" serenity = "0.12.4" -tokio = { version = "1.42.0", features = ["full"] } +tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] } diff --git a/src/main.rs b/src/main.rs index e7a11a9..fda6a3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,29 @@ -fn main() { - println!("Hello, world!"); +use dotenv::dotenv; + +use serenity::async_trait; +use serenity::model::channel::Message; +use serenity::prelude::*; + +struct Handler; + +#[async_trait] +impl EventHandler for Handler { + async fn message(&self, ctx: Context, new_message: Message) { + if new_message.content == "!ping" { + if let Err(why) = new_message.channel_id.say(&ctx.http, "Pong!").await { + println!("Error sending message: {why:?}"); + } + } + } +} + +#[tokio::main] +async fn main() { + dotenv().ok(); + let token = std::env::var("TOKEN").expect("TOKEN must be set"); + let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT; + let mut client = Client::builder(&token, intents).event_handler(Handler).await.expect("Error creating bot."); + if let Err(why) = client.start().await { + println!("Client error: {why:?}"); + } }