make sure to borrow in getters

This commit is contained in:
seth 2024-03-30 03:42:53 -04:00
parent 29ed728fc1
commit 1ff95de3bf
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
9 changed files with 23 additions and 24 deletions

View file

@ -23,7 +23,6 @@ pub async fn say(
if let Some(channel_id) = ctx
.data()
.config
.clone()
.discord_config()
.channels()
.log_channel_id()

View file

@ -13,7 +13,7 @@ pub async fn stars(ctx: Context<'_>) -> Result<()> {
ctx.defer().await?;
let count = if let Some(storage) = &ctx.data().storage {
if let Ok(count) = storage.get_launcher_stargazer_count().await {
if let Ok(count) = storage.launcher_stargazer_count().await {
count
} else {
let count = api::github::get_prism_stargazers_count().await?;

View file

@ -115,7 +115,7 @@ pub async fn set_welcome(
) -> Result<()> {
trace!("Running set_welcome command!");
let configured_channels = ctx.data().config.clone().discord_config().channels();
let configured_channels = ctx.data().config.discord_config().channels();
let Some(channel_id) = configured_channels.welcome_channel_id() else {
ctx.say("You don't have a welcome channel ID set, so I can't do anything :(")
.await?;

View file

@ -10,7 +10,7 @@ impl Config {
Self { redis_url }
}
pub fn new_from_env() -> Self {
pub fn from_env() -> Self {
let redis_url = std::env::var("BOT_REDIS_URL").ok();
if let Some(url) = &redis_url {
@ -22,7 +22,7 @@ impl Config {
Self::new(redis_url)
}
pub fn redis_url(self) -> Option<String> {
self.redis_url
pub fn redis_url(&self) -> Option<&str> {
self.redis_url.as_deref()
}
}

View file

@ -46,12 +46,12 @@ impl RefractionChannels {
.and_then(|env_var| ChannelId::from_str(&env_var).ok())
}
pub fn log_channel_id(self) -> Option<ChannelId> {
self.log_channel_id
pub fn log_channel_id(&self) -> Option<&ChannelId> {
self.log_channel_id.as_ref()
}
pub fn welcome_channel_id(self) -> Option<ChannelId> {
self.welcome_channel_id
pub fn welcome_channel_id(&self) -> Option<&ChannelId> {
self.welcome_channel_id.as_ref()
}
}
@ -60,13 +60,13 @@ impl Config {
Self { channels }
}
pub fn new_from_env() -> Self {
pub fn from_env() -> Self {
let channels = RefractionChannels::new_from_env();
Self::new(channels)
}
pub fn channels(self) -> RefractionChannels {
self.channels
pub fn channels(&self) -> &RefractionChannels {
&self.channels
}
}

View file

@ -16,17 +16,17 @@ impl Config {
}
pub fn new_from_env() -> Self {
let bot = bot::Config::new_from_env();
let discord = discord::Config::new_from_env();
let bot = bot::Config::from_env();
let discord = discord::Config::from_env();
Self::new(bot, discord)
}
pub fn bot_config(self) -> bot::Config {
self.bot
pub fn bot_config(&self) -> &bot::Config {
&self.bot
}
pub fn discord_config(self) -> discord::Config {
self.discord
pub fn discord_config(&self) -> &discord::Config {
&self.discord
}
}

View file

@ -195,7 +195,7 @@ async fn outdated_launcher(log: &str, data: &Data) -> Result<Issue> {
let version_from_log = captures[0].replace("Prism Launcher version: ", "");
let latest_version = if let Some(storage) = &data.storage {
if let Ok(version) = storage.get_launcher_version().await {
if let Ok(version) = storage.launcher_version().await {
version
} else {
api::github::get_latest_prism_version().await?

View file

@ -53,7 +53,7 @@ async fn setup(
) -> Result<Data> {
let config = Config::new_from_env();
let storage = if let Some(url) = &config.clone().bot_config().redis_url() {
let storage = if let Some(url) = config.bot_config().redis_url() {
Some(Storage::from_url(url)?)
} else {
None

View file

@ -25,7 +25,7 @@ impl Storage {
Ok(Self::new(client))
}
pub fn has_connection(mut self) -> bool {
pub fn has_connection(&mut self) -> bool {
self.client.check_connection()
}
@ -60,7 +60,7 @@ impl Storage {
Ok(())
}
pub async fn get_launcher_version(&self) -> Result<String> {
pub async fn launcher_version(&self) -> Result<String> {
debug!("Fetching launcher version");
let mut con = self.client.get_multiplexed_async_connection().await?;
@ -79,7 +79,7 @@ impl Storage {
Ok(())
}
pub async fn get_launcher_stargazer_count(&self) -> Result<u32> {
pub async fn launcher_stargazer_count(&self) -> Result<u32> {
debug!("Fetching launcher stargazer count");
let mut con = self.client.get_multiplexed_async_connection().await?;