treewide: allow for running w/o storage

This commit is contained in:
seth 2024-03-27 18:55:31 -04:00
parent 827b5a4bd7
commit a9a63f36ad
14 changed files with 174 additions and 90 deletions

View file

@ -1,6 +1,7 @@
use crate::Context;
use eyre::{OptionExt, Result};
use log::trace;
use poise::serenity_prelude::{CreateEmbed, CreateEmbedAuthor, CreateMessage};
/// Say something through the bot
@ -34,7 +35,14 @@ pub async fn say(
ctx.say("I said what you said!").await?;
}
if let Some(channel_id) = ctx.data().config.discord.channels().say_log_channel_id() {
if let Some(channel_id) = ctx
.data()
.config
.clone()
.discord_config()
.channels()
.say_log_channel_id()
{
let log_channel = guild
.channels
.iter()
@ -54,6 +62,8 @@ pub async fn say(
let message = CreateMessage::new().embed(embed);
log_channel.1.send_message(ctx, message).await?;
} else {
trace!("Not sending /say log as no channel is set");
}
Ok(())

View file

@ -1,6 +1,6 @@
use crate::{consts, Context};
use crate::{api, consts, Context};
use eyre::{Context as _, Result};
use eyre::Result;
use log::trace;
use poise::serenity_prelude::CreateEmbed;
use poise::CreateReply;
@ -12,18 +12,17 @@ pub async fn stars(ctx: Context<'_>) -> Result<()> {
ctx.defer().await?;
let prismlauncher = ctx
.data()
.octocrab
.repos("PrismLauncher", "PrismLauncher")
.get()
.await
.wrap_err("Couldn't get PrismLauncher/PrismLauncher from GitHub!")?;
let count = if let Some(count) = prismlauncher.stargazers_count {
count.to_string()
let count = if let Some(storage) = &ctx.data().storage {
if let Ok(count) = storage.get_launcher_stargazer_count().await {
count
} else {
let count = api::github::get_prism_stargazers_count().await?;
storage.cache_launcher_stargazer_count(count).await?;
count
}
} else {
"undefined".to_string()
trace!("Not caching launcher stargazer count, as we're running without a storage backend");
api::github::get_prism_stargazers_count().await?
};
let embed = CreateEmbed::new()