mirror of
https://github.com/dsec-hub/dsec-discord-bot.git
synced 2026-09-22 07:44:26 +00:00
first commit
This commit is contained in:
commit
05af0ab9a4
6 changed files with 2669 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
.env
|
||||
2531
Cargo.lock
generated
Normal file
2531
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "DSEC_discord_bot"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
dotenv = "0.15.0"
|
||||
poise = "0.6.1"
|
||||
serenity = "0.12"
|
||||
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }
|
||||
tracing-subscriber = "0.3.20"
|
||||
39
commands.txt
Normal file
39
commands.txt
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use poise::{CreateReply, ReplyHandle};
|
||||
use serenity::all::EditMessage;
|
||||
|
||||
use crate::{Context, Error};
|
||||
use std::time::Instant;
|
||||
|
||||
/// Show this help menu
|
||||
#[poise::command(track_edits, slash_command)]
|
||||
pub async fn help(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Specific command to show help about"]
|
||||
#[autocomplete = "poise::builtins::autocomplete_command"]
|
||||
command: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
poise::builtins::help(
|
||||
ctx,
|
||||
command.as_deref(),
|
||||
poise::builtins::HelpConfiguration {
|
||||
extra_text_at_bottom: "This is an example bot made to showcase features of my custom Discord bot framework",
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ping the bot
|
||||
#[poise::command(slash_command)]
|
||||
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let start = Instant::now();
|
||||
|
||||
let msg = ctx.say("Pinging... ").await?;
|
||||
|
||||
let elapsed_ms = start.elapsed().as_millis();
|
||||
|
||||
let new_msg = CreateReply::content(msg, format!("Pong!\nLatency: {} ms", elapsed_ms));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
51
src/commands.rs
Normal file
51
src/commands.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use poise::CreateReply;
|
||||
use serenity::all::CreateEmbed;
|
||||
|
||||
use crate::{Context, Error};
|
||||
use std::time::Instant;
|
||||
|
||||
/// Show this help menu
|
||||
#[poise::command(track_edits, slash_command)]
|
||||
pub async fn help(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Specific command to show help about"]
|
||||
#[autocomplete = "poise::builtins::autocomplete_command"]
|
||||
command: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
poise::builtins::help(
|
||||
ctx,
|
||||
command.as_deref(),
|
||||
poise::builtins::HelpConfiguration {
|
||||
extra_text_at_bottom: "This is an example bot made to showcase features of my custom Discord bot framework",
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ping the bot
|
||||
// #[poise::command(slash_command)]
|
||||
// pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
||||
// let start = Instant::now();
|
||||
|
||||
// let msg = ctx.say("Pinging... ").await?;
|
||||
|
||||
// let elapsed_ms = start.elapsed().as_millis();
|
||||
|
||||
// msg.edit(
|
||||
// ctx,
|
||||
// CreateReply::default().content(format!("Pong!\nTime elapsed: {elapsed_ms} ms")),
|
||||
// )
|
||||
// .await?;
|
||||
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
/// Ping the bot
|
||||
#[poise::command(slash_command)]
|
||||
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let start = Instant::now();
|
||||
|
||||
let start_embed_msg = CreateEmbed::new().title("Pinging...").color();
|
||||
}
|
||||
35
src/main.rs
Normal file
35
src/main.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#![warn(clippy::str_to_string)]
|
||||
use dotenv;
|
||||
use poise::serenity_prelude as serenity;
|
||||
mod commands;
|
||||
|
||||
struct Data {}
|
||||
|
||||
// Types used by all command functions
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenv::dotenv().ok();
|
||||
let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
|
||||
let intents = serenity::GatewayIntents::non_privileged();
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![commands::help(), commands::ping()],
|
||||
..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 a new issue