initial commit
This commit is contained in:
commit
2afd097149
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
/.env
|
2115
Cargo.lock
generated
Normal file
2115
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "deerbot-rebleated"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dotenv = "0.15.0"
|
||||
log = "0.4.21"
|
||||
poise = "0.6.1"
|
||||
pretty_env_logger = "0.5.0"
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
12
src/command/fun.rs
Normal file
12
src/command/fun.rs
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
use crate::Context;
|
||||
use crate::Error;
|
||||
|
||||
/// MAKE HER BLEAT
|
||||
#[poise::command(slash_command)]
|
||||
pub async fn bleat(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.say("BLEAT TEST")
|
||||
.await?;
|
||||
info!("Executed command `bleat` successfully");
|
||||
Ok(())
|
||||
}
|
2
src/command/mod.rs
Normal file
2
src/command/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod util;
|
||||
pub mod fun;
|
29
src/command/util.rs
Normal file
29
src/command/util.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use poise::serenity_prelude as serenity;
|
||||
|
||||
use crate::Context;
|
||||
use crate::Error;
|
||||
|
||||
/// Displays your or another user's account creation date
|
||||
#[poise::command(slash_command)]
|
||||
pub 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?;
|
||||
info!("Executed command `age` successfully");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Show information about this bot
|
||||
#[poise::command(slash_command)]
|
||||
pub async fn info(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.say(format!(
|
||||
"DeerBot ReBleated v{} was created by Shibe Drill (@shibedrill) using Rust and Poise.\nVisit her website: https://riverdev.carrd.co\nCheck out her Github: https://github.com/shibedrill",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
))
|
||||
.await?;
|
||||
info!("Executed command `info` successfully");
|
||||
Ok(())
|
||||
}
|
60
src/main.rs
Normal file
60
src/main.rs
Normal file
@ -0,0 +1,60 @@
|
||||
use dotenv::dotenv;
|
||||
|
||||
use poise::serenity_prelude as serenity;
|
||||
|
||||
extern crate pretty_env_logger;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod command;
|
||||
use crate::command::{util::*, fun::*,};
|
||||
|
||||
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>;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Get secure env vars from .env file
|
||||
dotenv().ok();
|
||||
// Get token from environment
|
||||
let token = std::env::var("TOKEN").expect("Getting TOKEN from environment failed");
|
||||
// Set up some non privileged intents
|
||||
let intents = serenity::GatewayIntents::non_privileged();
|
||||
|
||||
// Initialize logging
|
||||
pretty_env_logger::init();
|
||||
|
||||
// Set up framework
|
||||
let framework = poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![age(), info(), bleat()],
|
||||
..Default::default()
|
||||
})
|
||||
.setup(|ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
Ok(Data {})
|
||||
})
|
||||
})
|
||||
.build();
|
||||
|
||||
// Log pertinent info
|
||||
info!("Built framework successfully");
|
||||
{
|
||||
let mut commands: Vec<&str> = vec![];
|
||||
framework
|
||||
.options()
|
||||
.commands
|
||||
.iter()
|
||||
.for_each(|c| commands.push(&c.name));
|
||||
info!("Registered commands: {:?}", commands);
|
||||
}
|
||||
|
||||
let client = serenity::ClientBuilder::new(token, intents)
|
||||
.framework(framework)
|
||||
.await;
|
||||
info!("Built client successfully");
|
||||
info!("Starting client");
|
||||
client.unwrap().start().await.unwrap();
|
||||
}
|
Loading…
Reference in New Issue
Block a user