feat: BootStrap bot

This commit is contained in:
Max batleforc 2025-05-17 01:51:59 +02:00
parent 052c3946cf
commit 254e142608
No known key found for this signature in database
GPG Key ID: 25D243AB4B6AC9E7
6 changed files with 2463 additions and 5 deletions

2
.gitignore vendored
View File

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

2393
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,3 +4,5 @@ version = "0.1.0"
edition = "2024"
[dependencies]
poise = "0.6.1"
tokio = {version = "1.45.0", features = ["rt-multi-thread"]}

View File

@ -4,7 +4,6 @@
- Trivial Daily
### Trivial Daily
- Heure configurable (Pose de la question, Relevé des gagnant optionnel)
@ -15,15 +14,16 @@
- Embed ou Message template ?
- List des questions
- Points ( 1er == 3, 2eme == 2, 3eme = 1; x = 0 ?)
- Role a ping
#### Command
- [ADMIN] trivial init : Creer une activité Trivial Daily
- [ADMIN] trivial init : Creer une activité Trivial Daily
- [ADMIN] trivial list : List les activité
- [ADMIN] trivial config : Modification des paramétre de base d'un event
- [ADMIN] trivial add-question : Ajout de question + réponse ou X réponse
- [ADMIN] trivial del-question : Suppression de question
- [ADMIN] trivial load-question : Charge un fichier/lien de question
- [ADMIN] trivial load-question : Charge un fichier/lien de question
- [ADMIN] trivial choose-chan : Choix du channel
- trivial scoreboard : Scoreboard
- trivial score : Score d'une personne par défaut le sien

19
src/dotenv/mod.rs Normal file
View File

@ -0,0 +1,19 @@
use std::{env::set_var, io::Read};
// Load environment variables from a .env file without external dependencies
pub fn load_dot_env() {
if let Ok(mut file) = std::fs::File::open(".env") {
let mut contents = String::new();
if file.read_to_string(&mut contents).is_ok() {
for line in contents.lines() {
if line.is_empty() || line.starts_with('#') {
continue; // Skip empty lines and comments
}
if let Some((key, value)) = line.split_once('=') {
unsafe { set_var(key.trim(), value.trim().replace("\"", "")) };
}
}
}
}
}

View File

@ -1,3 +1,45 @@
fn main() {
println!("Hello, world!");
use poise::serenity_prelude as serenity;
pub mod dotenv;
struct Data {} // User data, which is stored and accessible in all command invocations
type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;
/// Displays your or another user's account creation date
#[poise::command(slash_command, prefix_command)]
async fn age(
ctx: Context<'_>,
#[description = "Selected user"] user: Option<serenity::User>,
) -> Result<(), Error> {
let u = user.as_ref().unwrap_or_else(|| ctx.author());
let response = format!("{}'s account was created at {}", u.name, u.created_at());
ctx.say(response).await?;
Ok(())
}
#[tokio::main]
async fn main() {
dotenv::load_dot_env(); // Load environment variables from .env file
let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
print!("Starting bot with token: {}", token);
let intents = serenity::GatewayIntents::non_privileged();
let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![age()],
..Default::default()
})
.setup(|ctx, _ready, framework| {
Box::pin(async move {
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
Ok(Data {})
})
})
.build();
let client = serenity::ClientBuilder::new(token, intents)
.framework(framework)
.await;
client.unwrap().start().await.unwrap();
}