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]]
name = "reminder_rs"
version = "1.4.5-rc.2"
version = "1.4.5-rc.3"
dependencies = [
"Inflector",
"chrono",

View File

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

View File

@ -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)
})
})

View File

@ -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;
}
}

View File

@ -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

View File

@ -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::<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") {
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