44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
use crate::{util::debug_say, DbConnPool};
|
|
use serenity::framework::standard::{macros::command, CommandResult};
|
|
use serenity::model::channel::Message;
|
|
use serenity::{async_trait, prelude::Context};
|
|
use sqlx::Error;
|
|
|
|
#[command]
|
|
async fn heck(ctx: &Context, msg: &Message) -> CommandResult {
|
|
let db_pool = ctx.data.clone();
|
|
let db_pool = db_pool.read().await;
|
|
let db_pool = db_pool
|
|
.get::<DbConnPool>()
|
|
.expect("No db pool in context?!");
|
|
let value = db_pool.get_heck().await;
|
|
|
|
debug_say(
|
|
msg,
|
|
ctx,
|
|
format!("This command has been hecked {} times", value?),
|
|
)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[async_trait]
|
|
trait HeckQueries {
|
|
async fn get_heck(&self) -> Result<i32, Error>;
|
|
}
|
|
|
|
#[async_trait]
|
|
impl HeckQueries for DbConnPool {
|
|
async fn get_heck(&self) -> Result<i32, Error> {
|
|
sqlx::query!("UPDATE Heck SET count = count + 1")
|
|
.execute(&self.pool)
|
|
.await?;
|
|
|
|
Ok(sqlx::query!("SELECT count FROM Heck")
|
|
.fetch_one(&self.pool)
|
|
.await?
|
|
.count)
|
|
}
|
|
}
|