Initial commit, ping pong works
This commit is contained in:
commit
646906c085
3 changed files with 64 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
.env
|
15
Cargo.toml
Normal file
15
Cargo.toml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[package]
|
||||||
|
name = "moover_rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cron = "0.12.0"
|
||||||
|
dotenv = "0.15.0"
|
||||||
|
mongodb = "2.4.0"
|
||||||
|
poise = "0.5.2"
|
||||||
|
serenity = { version = "0.11.5", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
|
||||||
|
serenity_utils = "0.7.0"
|
||||||
|
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }
|
47
src/main.rs
Normal file
47
src/main.rs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
extern crate dotenv;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use serenity::async_trait;
|
||||||
|
use serenity::model::channel::Message;
|
||||||
|
use serenity::model::gateway::Ready;
|
||||||
|
use serenity::prelude::*;
|
||||||
|
|
||||||
|
use dotenv::dotenv;
|
||||||
|
|
||||||
|
struct Handler;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl EventHandler for Handler {
|
||||||
|
async fn message(&self, ctx: Context, msg: Message) {
|
||||||
|
if msg.content == "!ping" {
|
||||||
|
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
|
||||||
|
println!("Error sending message: {:?}", why);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn ready(&self, _: Context, ready: Ready) {
|
||||||
|
println!("{} is connected!", ready.user.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
dotenv().ok();
|
||||||
|
let token;
|
||||||
|
let key = "TOKEN";
|
||||||
|
match env::var(key) {
|
||||||
|
Ok(val) => token = val,
|
||||||
|
Err(_) => return,
|
||||||
|
}
|
||||||
|
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 client");
|
||||||
|
|
||||||
|
if let Err(why) = client.start().await {
|
||||||
|
println!("Client error: {:?}", why);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue