initial commit

This commit is contained in:
2024-10-10 11:02:20 -04:00
commit 7976ac28c0
6 changed files with 2181 additions and 0 deletions

3
.dockerignore Normal file
View File

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

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/target
.env

2109
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

9
Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "bot"
version = "0.1.0"
edition = "2021"
[dependencies]
poise = "0.6.1"
tokio = { version = "1", features = ["full"] }
dotenv = "0.15.0"

10
Dockerfile Normal file
View File

@@ -0,0 +1,10 @@
FROM rust:1.81
WORKDIR /usr/src/bot
COPY . .
# FROM ubuntu:24.10
# COPY --from=builder /usr/local/cargo/bin/bot /usr/local/bin/bot
# temporary fix for slow cross compile builds.
# this will simply compile and run the code on `docker run`
CMD ["cargo", "run", "--release"]

48
src/main.rs Normal file
View File

@@ -0,0 +1,48 @@
use std::env;
use poise::serenity_prelude as serenity;
struct Data {}
type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;
#[poise::command(slash_command)]
async fn ping(ctx: Context<'_>) -> Result<(), Error> {
use std::time::Instant;
let start = Instant::now();
let msg = ctx.say("Pong! \u{1F3D3}").await?;
msg.edit(ctx, poise::reply::CreateReply::default()
.content(format!("Pong! \u{1F3D3}\nREST: {:.2?}\nGateway: {:.2?}",
start.elapsed(), ctx.ping().await))).await?;
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Error> {
dotenv::dotenv().ok();
let token = env::var("DISCORD_BOT_TOKEN")?;
let intents = serenity::GatewayIntents::non_privileged();
let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![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?;
Ok(())
}