feat: BootStrap bot
This commit is contained in:
parent
052c3946cf
commit
254e142608
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
|
|
||||||
|
.env
|
||||||
2393
Cargo.lock
generated
Normal file
2393
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,3 +4,5 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
poise = "0.6.1"
|
||||||
|
tokio = {version = "1.45.0", features = ["rt-multi-thread"]}
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
- Trivial Daily
|
- Trivial Daily
|
||||||
|
|
||||||
|
|
||||||
### Trivial Daily
|
### Trivial Daily
|
||||||
|
|
||||||
- Heure configurable (Pose de la question, Relevé des gagnant optionnel)
|
- Heure configurable (Pose de la question, Relevé des gagnant optionnel)
|
||||||
@ -15,15 +14,16 @@
|
|||||||
- Embed ou Message template ?
|
- Embed ou Message template ?
|
||||||
- List des questions
|
- List des questions
|
||||||
- Points ( 1er == 3, 2eme == 2, 3eme = 1; x = 0 ?)
|
- Points ( 1er == 3, 2eme == 2, 3eme = 1; x = 0 ?)
|
||||||
|
- Role a ping
|
||||||
|
|
||||||
#### Command
|
#### 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 list : List les activité
|
||||||
- [ADMIN] trivial config : Modification des paramétre de base d'un event
|
- [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 add-question : Ajout de question + réponse ou X réponse
|
||||||
- [ADMIN] trivial del-question : Suppression de question
|
- [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
|
- [ADMIN] trivial choose-chan : Choix du channel
|
||||||
- trivial scoreboard : Scoreboard
|
- trivial scoreboard : Scoreboard
|
||||||
- trivial score : Score d'une personne par défaut le sien
|
- trivial score : Score d'une personne par défaut le sien
|
||||||
|
|||||||
19
src/dotenv/mod.rs
Normal file
19
src/dotenv/mod.rs
Normal 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("\"", "")) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
src/main.rs
46
src/main.rs
@ -1,3 +1,45 @@
|
|||||||
fn main() {
|
use poise::serenity_prelude as serenity;
|
||||||
println!("Hello, world!");
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user