initial_bot #1

Open
eoghanconlon73 wants to merge 4 commits from initial_bot into main
4 changed files with 39 additions and 15 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target /target
/.idea /.idea
.env

18
Cargo.lock generated
View file

@ -220,6 +220,7 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
name = "count_bot" name = "count_bot"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dotenv",
"serenity", "serenity",
"tokio", "tokio",
] ]
@ -318,6 +319,12 @@ dependencies = [
"syn 2.0.91", "syn 2.0.91",
] ]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.35" version = "0.8.35"
@ -1358,15 +1365,6 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 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]] [[package]]
name = "skeptic" name = "skeptic"
version = "0.13.7" version = "0.13.7"
@ -1581,9 +1579,7 @@ dependencies = [
"bytes", "bytes",
"libc", "libc",
"mio", "mio",
"parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry",
"socket2", "socket2",
"tokio-macros", "tokio-macros",
"windows-sys 0.52.0", "windows-sys 0.52.0",

View file

@ -4,5 +4,6 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
dotenv = "0.15.0"
serenity = "0.12.4" serenity = "0.12.4"
tokio = { version = "1.42.0", features = ["full"] } tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }

View file

@ -1,3 +1,29 @@
fn main() { use dotenv::dotenv;
println!("Hello, world!");
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:?}");
}
} }