fix for dev error showing instead of other errors. show shard number on help pages. cache guilds on join

This commit is contained in:
jellywx 2021-02-14 14:10:01 +00:00
parent e9e321ebb1
commit 93e372e53e
6 changed files with 65 additions and 33 deletions

2
Cargo.lock generated
View File

@ -1309,7 +1309,7 @@ dependencies = [
[[package]] [[package]]
name = "reminder_rs" name = "reminder_rs"
version = "1.4.5-rc.2" version = "1.4.5-rc.3"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"chrono", "chrono",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "reminder_rs" name = "reminder_rs"
version = "1.4.5-rc.2" version = "1.4.5-rc.3"
authors = ["jellywx <judesouthworth@pm.me>"] authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2018" edition = "2018"

View File

@ -13,6 +13,7 @@ use crate::{
THEME_COLOR, THEME_COLOR,
}; };
use serenity::builder::CreateEmbedFooter;
use std::sync::Arc; use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
@ -32,6 +33,20 @@ async fn ping(ctx: &Context, msg: &Message, _args: String) {
.await; .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] #[command]
#[can_blacklist(false)] #[can_blacklist(false)]
async fn help(ctx: &Context, msg: &Message, args: String) { async fn help(ctx: &Context, msg: &Message, args: String) {
@ -43,6 +58,7 @@ async fn help(ctx: &Context, msg: &Message, args: String) {
language: &str, language: &str,
) { ) {
let desc = lm.get(language, "help/desc").replace("{prefix}", prefix); let desc = lm.get(language, "help/desc").replace("{prefix}", prefix);
let footer = footer(ctx).await;
let _ = msg let _ = msg
.channel_id .channel_id
@ -81,13 +97,7 @@ async fn help(ctx: &Context, msg: &Message, args: String) {
true, true,
) )
.field(lm.get(language, "help/other_title"), "`timer`", true) .field(lm.get(language, "help/other_title"), "`timer`", true)
.footer(|f| { .footer(footer)
f.text(concat!(
env!("CARGO_PKG_NAME"),
" ver ",
env!("CARGO_PKG_VERSION")
))
})
.color(*THEME_COLOR) .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 language = UserData::language_of(&msg.author, &pool);
let prefix = GuildData::prefix_from_id(msg.guild_id, &pool); let prefix = GuildData::prefix_from_id(msg.guild_id, &pool);
let current_user = ctx.cache.current_user(); let current_user = ctx.cache.current_user();
let footer = footer(ctx).await;
let desc = lm let desc = lm
.get(&language.await, "info") .get(&language.await, "info")
@ -137,13 +148,7 @@ async fn info(ctx: &Context, msg: &Message, _args: String) {
m.embed(move |e| { m.embed(move |e| {
e.title("Info") e.title("Info")
.description(desc) .description(desc)
.footer(|f| { .footer(footer)
f.text(concat!(
env!("CARGO_PKG_NAME"),
" ver ",
env!("CARGO_PKG_VERSION")
))
})
.color(*THEME_COLOR) .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 language = UserData::language_of(&msg.author, &pool).await;
let desc = lm.get(&language, "donate"); let desc = lm.get(&language, "donate");
let footer = footer(ctx).await;
let _ = msg let _ = msg
.channel_id .channel_id
@ -163,13 +169,7 @@ async fn donate(ctx: &Context, msg: &Message, _args: String) {
m.embed(move |e| { m.embed(move |e| {
e.title("Donate") e.title("Donate")
.description(desc) .description(desc)
.footer(|f| { .footer(footer)
f.text(concat!(
env!("CARGO_PKG_NAME"),
" ver ",
env!("CARGO_PKG_VERSION")
))
})
.color(*THEME_COLOR) .color(*THEME_COLOR)
}) })
}) })
@ -178,19 +178,15 @@ async fn donate(ctx: &Context, msg: &Message, _args: String) {
#[command] #[command]
async fn dashboard(ctx: &Context, msg: &Message, _args: String) { async fn dashboard(ctx: &Context, msg: &Message, _args: String) {
let footer = footer(ctx).await;
let _ = msg let _ = msg
.channel_id .channel_id
.send_message(ctx, |m| { .send_message(ctx, |m| {
m.embed(move |e| { m.embed(move |e| {
e.title("Dashboard") e.title("Dashboard")
.description("https://reminder-bot.com/dashboard") .description("https://reminder-bot.com/dashboard")
.footer(|f| { .footer(footer)
f.text(concat!(
env!("CARGO_PKG_NAME"),
" ver ",
env!("CARGO_PKG_VERSION")
))
})
.color(*THEME_COLOR) .color(*THEME_COLOR)
}) })
}) })

View File

@ -1401,7 +1401,16 @@ async fn natural(ctx: &Context, msg: &Message, args: String) {
} else { } else {
let _ = msg let _ = msg
.channel_id .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; .await;
} }
} }

View File

@ -398,7 +398,16 @@ impl Framework for RegexFramework {
if command.check_permissions(&ctx, &guild, &member).await { if command.check_permissions(&ctx, &guild, &member).await {
dbg!(command.name); 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; (command.func)(&ctx, &msg, args).await;
} else if command.required_perms == PermissionLevel::Restricted } else if command.required_perms == PermissionLevel::Restricted

View File

@ -42,6 +42,7 @@ use serenity::futures::TryFutureExt;
use inflector::Inflector; use inflector::Inflector;
use log::info; use log::info;
use crate::models::GuildData;
use chrono_tz::Tz; use chrono_tz::Tz;
struct SQLPool; struct SQLPool;
@ -94,9 +95,26 @@ DELETE FROM channels WHERE channel = ?
async fn guild_create(&self, ctx: Context, guild: Guild, is_new: bool) { async fn guild_create(&self, ctx: Context, guild: Guild, is_new: bool) {
if is_new { if is_new {
let guild_id = guild.id.as_u64().to_owned();
{
let pool = ctx
.data
.read()
.await
.get::<SQLPool>()
.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") { if let Ok(token) = env::var("DISCORDBOTS_TOKEN") {
let shard_count = ctx.cache.shard_count().await; 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 let guild_count = ctx
.cache .cache