diff --git a/Cargo.lock b/Cargo.lock index 007dd73..b4b5931 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1309,7 +1309,7 @@ dependencies = [ [[package]] name = "reminder_rs" -version = "1.4.5-rc.2" +version = "1.4.5-rc.3" dependencies = [ "Inflector", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 2283aab..f660d2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reminder_rs" -version = "1.4.5-rc.2" +version = "1.4.5-rc.3" authors = ["jellywx "] edition = "2018" diff --git a/src/commands/info_cmds.rs b/src/commands/info_cmds.rs index 331a70d..c598bb1 100644 --- a/src/commands/info_cmds.rs +++ b/src/commands/info_cmds.rs @@ -13,6 +13,7 @@ use crate::{ THEME_COLOR, }; +use serenity::builder::CreateEmbedFooter; use std::sync::Arc; use std::time::{SystemTime, UNIX_EPOCH}; @@ -32,6 +33,20 @@ async fn ping(ctx: &Context, msg: &Message, _args: String) { .await; } +async fn footer(ctx: &Context) -> impl FnOnce(&mut CreateEmbedFooter) -> &mut CreateEmbedFooter { + let shard_count = ctx.cache.shard_count().await; + let shard = ctx.shard_id; + + move |f| { + f.text(format!( + "{}\nshard {} of {}", + concat!(env!("CARGO_PKG_NAME"), " ver ", env!("CARGO_PKG_VERSION")), + shard, + shard_count, + )) + } +} + #[command] #[can_blacklist(false)] async fn help(ctx: &Context, msg: &Message, args: String) { @@ -43,6 +58,7 @@ async fn help(ctx: &Context, msg: &Message, args: String) { language: &str, ) { let desc = lm.get(language, "help/desc").replace("{prefix}", prefix); + let footer = footer(ctx).await; let _ = msg .channel_id @@ -81,13 +97,7 @@ async fn help(ctx: &Context, msg: &Message, args: String) { true, ) .field(lm.get(language, "help/other_title"), "`timer`", true) - .footer(|f| { - f.text(concat!( - env!("CARGO_PKG_NAME"), - " ver ", - env!("CARGO_PKG_VERSION") - )) - }) + .footer(footer) .color(*THEME_COLOR) }) }) @@ -124,6 +134,7 @@ async fn info(ctx: &Context, msg: &Message, _args: String) { let language = UserData::language_of(&msg.author, &pool); let prefix = GuildData::prefix_from_id(msg.guild_id, &pool); let current_user = ctx.cache.current_user(); + let footer = footer(ctx).await; let desc = lm .get(&language.await, "info") @@ -137,13 +148,7 @@ async fn info(ctx: &Context, msg: &Message, _args: String) { m.embed(move |e| { e.title("Info") .description(desc) - .footer(|f| { - f.text(concat!( - env!("CARGO_PKG_NAME"), - " ver ", - env!("CARGO_PKG_VERSION") - )) - }) + .footer(footer) .color(*THEME_COLOR) }) }) @@ -156,6 +161,7 @@ async fn donate(ctx: &Context, msg: &Message, _args: String) { let language = UserData::language_of(&msg.author, &pool).await; let desc = lm.get(&language, "donate"); + let footer = footer(ctx).await; let _ = msg .channel_id @@ -163,13 +169,7 @@ async fn donate(ctx: &Context, msg: &Message, _args: String) { m.embed(move |e| { e.title("Donate") .description(desc) - .footer(|f| { - f.text(concat!( - env!("CARGO_PKG_NAME"), - " ver ", - env!("CARGO_PKG_VERSION") - )) - }) + .footer(footer) .color(*THEME_COLOR) }) }) @@ -178,19 +178,15 @@ async fn donate(ctx: &Context, msg: &Message, _args: String) { #[command] async fn dashboard(ctx: &Context, msg: &Message, _args: String) { + let footer = footer(ctx).await; + let _ = msg .channel_id .send_message(ctx, |m| { m.embed(move |e| { e.title("Dashboard") .description("https://reminder-bot.com/dashboard") - .footer(|f| { - f.text(concat!( - env!("CARGO_PKG_NAME"), - " ver ", - env!("CARGO_PKG_VERSION") - )) - }) + .footer(footer) .color(*THEME_COLOR) }) }) diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index b17a9fe..7b2ec23 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -1401,7 +1401,16 @@ async fn natural(ctx: &Context, msg: &Message, args: String) { } else { let _ = msg .channel_id - .say(&ctx, "DEV ERROR: Failed to invoke Python") + .send_message(ctx, |m| { + m.embed(move |e| { + e.title( + lm.get(&user_data.language, "remind/title") + .replace("{number}", "0"), + ) + .description(lm.get(&user_data.language, "natural/invalid_time")) + .color(*THEME_COLOR) + }) + }) .await; } } diff --git a/src/framework.rs b/src/framework.rs index 3a3d215..6172170 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -398,7 +398,16 @@ impl Framework for RegexFramework { if command.check_permissions(&ctx, &guild, &member).await { dbg!(command.name); - GuildData::from_guild(guild, &pool).await; + { + let guild_id = guild.id.as_u64().to_owned(); + + GuildData::from_guild(guild, &pool).await.expect( + &format!( + "Failed to create new guild object for {}", + guild_id + ), + ); + } (command.func)(&ctx, &msg, args).await; } else if command.required_perms == PermissionLevel::Restricted diff --git a/src/main.rs b/src/main.rs index 2b83ff9..402a45b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,7 @@ use serenity::futures::TryFutureExt; use inflector::Inflector; use log::info; +use crate::models::GuildData; use chrono_tz::Tz; struct SQLPool; @@ -94,9 +95,26 @@ DELETE FROM channels WHERE channel = ? async fn guild_create(&self, ctx: Context, guild: Guild, is_new: bool) { if is_new { + let guild_id = guild.id.as_u64().to_owned(); + + { + let pool = ctx + .data + .read() + .await + .get::() + .cloned() + .expect("Could not get SQLPool from data"); + + GuildData::from_guild(guild, &pool).await.expect(&format!( + "Failed to create new guild object for {}", + guild_id + )); + } + if let Ok(token) = env::var("DISCORDBOTS_TOKEN") { let shard_count = ctx.cache.shard_count().await; - let current_shard_id = shard_id(guild.id.as_u64().to_owned(), shard_count); + let current_shard_id = shard_id(guild_id, shard_count); let guild_count = ctx .cache