accept reference to pool rather than pool itself. response method on user_data to get text lines in locale. removed say_named trait

This commit is contained in:
jude
2020-09-01 17:07:51 +01:00
parent 74617d50a5
commit 9e737dc9d6
7 changed files with 106 additions and 100 deletions

View File

@ -24,10 +24,16 @@ use crate::{
#[command]
#[can_blacklist(false)]
async fn help(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
let user_data = UserData::from_id(&msg.author, &ctx, &pool).await.unwrap();
let desc = user_data.response(&pool, "help").await;
msg.channel_id.send_message(ctx, |m| m
.embed(|e| e
.embed(move |e| e
.title("Help")
.description("Help Description")
.description(desc)
.color(THEME_COLOR)
)
).await?;
@ -37,10 +43,16 @@ async fn help(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
#[command]
async fn info(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
let user_data = UserData::from_id(&msg.author, &ctx, &pool).await.unwrap();
let desc = user_data.response(&pool, "info").await;
msg.channel_id.send_message(ctx, |m| m
.embed(|e| e
.embed(move |e| e
.title("Info")
.description("Info Description")
.description(desc)
.color(THEME_COLOR)
)
).await?;
@ -50,10 +62,29 @@ async fn info(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
#[command]
async fn donate(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
let user_data = UserData::from_id(&msg.author, &ctx, &pool).await.unwrap();
let desc = user_data.response(&pool, "donate").await;
msg.channel_id.send_message(ctx, |m| m
.embed(|e| e
.embed(move |e| e
.title("Donate")
.description("Donate Description")
.description(desc)
.color(THEME_COLOR)
)
).await?;
Ok(())
}
#[command]
async fn dashboard(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
msg.channel_id.send_message(ctx, |m| m
.embed(move |e| e
.title("Dashboard")
.description("https://reminder-bot.com/dashboard")
.color(THEME_COLOR)
)
).await?;
@ -66,17 +97,17 @@ async fn clock(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
let user_data = UserData::from_id(&msg.author, &ctx, pool).await.unwrap();
let user_data = UserData::from_id(&msg.author, &ctx, &pool).await.unwrap();
let tz: Tz = user_data.timezone.parse().unwrap();
let now = Utc::now().with_timezone(&tz);
if args == "12".to_string() {
let _ = msg.channel_id.say(&ctx, format!("Current time: **{}**", now.format("%I:%M:%S %p"))).await;
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "clock/time").await.replacen("{}", &now.format("%I:%M:%S %p").to_string(), 1)).await;
}
else {
let _ = msg.channel_id.say(&ctx, format!("Current time: **{}**", now.format("%H:%M:%S"))).await;
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "clock/time").await.replacen("{}", &now.format("%H:%M:%S").to_string(), 1)).await;
}
Ok(())