commit ig

This commit is contained in:
Ladislav Hano 2023-07-07 10:55:59 +02:00
parent 6621bbbba9
commit b756df8894
4 changed files with 56 additions and 16 deletions

View file

@ -8,8 +8,8 @@ edition = "2021"
[dependencies] [dependencies]
cron = "0.12.0" cron = "0.12.0"
dotenv = "0.15.0" dotenv = "0.15.0"
mongodb = "2.4.0" mongodb = "2.6.0"
poise = "0.5.2" poise = "0.5.5"
serenity = { version = "0.11.5", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] } serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "http"] }
serenity_utils = "0.7.0" serenity_utils = "0.7.0"
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }

View file

@ -1,13 +1,15 @@
extern crate dotenv; use std::sync::Arc;
use std::env;
use poise::serenity_prelude::GuildChannel;
use serenity::async_trait; use serenity::async_trait;
use serenity::model::channel::Message; use serenity::model::channel::Message;
use serenity::model::gateway::Ready; use serenity::model::gateway::Ready;
use serenity::model::id::ChannelId;
use serenity::prelude::*; use serenity::prelude::*;
use util::security::dotenv_var;
use serenity::http::{self, Http};
use dotenv::dotenv; mod util;
struct Handler; struct Handler;
@ -21,25 +23,50 @@ impl EventHandler for Handler {
} }
} }
async fn ready(&self, _: Context, ready: Ready) { async fn ready(&self, ctx: Context, ready: Ready) {
println!("{} is connected!", ready.user.name); println!("{} is connected!", ready.user.name);
// if (ready.user.name != "MOOver Debug") {
let messages = ["AAAAAAAAAAAAAAAAAAAA", "Henlooo", "Good day y'all!",
"May have crashed...", "MOOOooo", "Heyyyyy!", "I'm baaaaack!",
"Whom'st have summoned the ancient one?"];
// }
let opt_token = dotenv_var("TOKEN");
if opt_token.is_none() {
return;
}
let token = opt_token.unwrap();
let channel_result = ctx.http.get_channel(780439236867653635).await;
let channel = channel_result.unwrap();
// let channel = await http.get_channel(780439236867653635);
// GuildChannel::say(&self, http, content)
// self.message(ctx, new_message)
// C = ;
// const debug_channel =
} }
} }
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
dotenv().ok(); let opt_token = dotenv_var("TOKEN");
let token; if opt_token.is_none() {
let key = "TOKEN"; return;
match env::var(key) {
Ok(val) => token = val,
Err(_) => return,
} }
let token = opt_token.unwrap();
let intents = GatewayIntents::GUILD_MESSAGES let intents = GatewayIntents::GUILD_MESSAGES
| GatewayIntents::DIRECT_MESSAGES | GatewayIntents::DIRECT_MESSAGES
| GatewayIntents::MESSAGE_CONTENT; | GatewayIntents::MESSAGE_CONTENT;
let mut client = Client::builder(&token, intents).event_handler(Handler).await.expect("Error creating client"); let mut client = Client::builder(&token, intents)
.event_handler(Handler)
.await.expect("Error creating client");
if let Err(why) = client.start().await { if let Err(why) = client.start().await {
println!("Client error: {:?}", why); println!("Client error: {:?}", why);

1
src/util/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod security;

12
src/util/security.rs Normal file
View file

@ -0,0 +1,12 @@
use dotenv::dotenv;
use std::env;
pub fn dotenv_var(key: &str) -> Option<String> {
dotenv().ok();
let key = "TOKEN";
match env::var(key) {
Ok(val) => return Some(val),
Err(_) => None,
}
}