make sure to borrow in getters
This commit is contained in:
parent
29ed728fc1
commit
1ff95de3bf
9 changed files with 23 additions and 24 deletions
|
@ -23,7 +23,6 @@ pub async fn say(
|
||||||
if let Some(channel_id) = ctx
|
if let Some(channel_id) = ctx
|
||||||
.data()
|
.data()
|
||||||
.config
|
.config
|
||||||
.clone()
|
|
||||||
.discord_config()
|
.discord_config()
|
||||||
.channels()
|
.channels()
|
||||||
.log_channel_id()
|
.log_channel_id()
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub async fn stars(ctx: Context<'_>) -> Result<()> {
|
||||||
ctx.defer().await?;
|
ctx.defer().await?;
|
||||||
|
|
||||||
let count = if let Some(storage) = &ctx.data().storage {
|
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
|
count
|
||||||
} else {
|
} else {
|
||||||
let count = api::github::get_prism_stargazers_count().await?;
|
let count = api::github::get_prism_stargazers_count().await?;
|
||||||
|
|
|
@ -115,7 +115,7 @@ pub async fn set_welcome(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
trace!("Running set_welcome command!");
|
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 {
|
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 :(")
|
ctx.say("You don't have a welcome channel ID set, so I can't do anything :(")
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -10,7 +10,7 @@ impl Config {
|
||||||
Self { redis_url }
|
Self { redis_url }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_env() -> Self {
|
pub fn from_env() -> Self {
|
||||||
let redis_url = std::env::var("BOT_REDIS_URL").ok();
|
let redis_url = std::env::var("BOT_REDIS_URL").ok();
|
||||||
|
|
||||||
if let Some(url) = &redis_url {
|
if let Some(url) = &redis_url {
|
||||||
|
@ -22,7 +22,7 @@ impl Config {
|
||||||
Self::new(redis_url)
|
Self::new(redis_url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn redis_url(self) -> Option<String> {
|
pub fn redis_url(&self) -> Option<&str> {
|
||||||
self.redis_url
|
self.redis_url.as_deref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,12 @@ impl RefractionChannels {
|
||||||
.and_then(|env_var| ChannelId::from_str(&env_var).ok())
|
.and_then(|env_var| ChannelId::from_str(&env_var).ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_channel_id(self) -> Option<ChannelId> {
|
pub fn log_channel_id(&self) -> Option<&ChannelId> {
|
||||||
self.log_channel_id
|
self.log_channel_id.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn welcome_channel_id(self) -> Option<ChannelId> {
|
pub fn welcome_channel_id(&self) -> Option<&ChannelId> {
|
||||||
self.welcome_channel_id
|
self.welcome_channel_id.as_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,13 +60,13 @@ impl Config {
|
||||||
Self { channels }
|
Self { channels }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_env() -> Self {
|
pub fn from_env() -> Self {
|
||||||
let channels = RefractionChannels::new_from_env();
|
let channels = RefractionChannels::new_from_env();
|
||||||
|
|
||||||
Self::new(channels)
|
Self::new(channels)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn channels(self) -> RefractionChannels {
|
pub fn channels(&self) -> &RefractionChannels {
|
||||||
self.channels
|
&self.channels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,17 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_env() -> Self {
|
pub fn new_from_env() -> Self {
|
||||||
let bot = bot::Config::new_from_env();
|
let bot = bot::Config::from_env();
|
||||||
let discord = discord::Config::new_from_env();
|
let discord = discord::Config::from_env();
|
||||||
|
|
||||||
Self::new(bot, discord)
|
Self::new(bot, discord)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bot_config(self) -> bot::Config {
|
pub fn bot_config(&self) -> &bot::Config {
|
||||||
self.bot
|
&self.bot
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn discord_config(self) -> discord::Config {
|
pub fn discord_config(&self) -> &discord::Config {
|
||||||
self.discord
|
&self.discord
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 version_from_log = captures[0].replace("Prism Launcher version: ", "");
|
||||||
|
|
||||||
let latest_version = if let Some(storage) = &data.storage {
|
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
|
version
|
||||||
} else {
|
} else {
|
||||||
api::github::get_latest_prism_version().await?
|
api::github::get_latest_prism_version().await?
|
||||||
|
|
|
@ -53,7 +53,7 @@ async fn setup(
|
||||||
) -> Result<Data> {
|
) -> Result<Data> {
|
||||||
let config = Config::new_from_env();
|
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)?)
|
Some(Storage::from_url(url)?)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl Storage {
|
||||||
Ok(Self::new(client))
|
Ok(Self::new(client))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_connection(mut self) -> bool {
|
pub fn has_connection(&mut self) -> bool {
|
||||||
self.client.check_connection()
|
self.client.check_connection()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ impl Storage {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_launcher_version(&self) -> Result<String> {
|
pub async fn launcher_version(&self) -> Result<String> {
|
||||||
debug!("Fetching launcher version");
|
debug!("Fetching launcher version");
|
||||||
|
|
||||||
let mut con = self.client.get_multiplexed_async_connection().await?;
|
let mut con = self.client.get_multiplexed_async_connection().await?;
|
||||||
|
@ -79,7 +79,7 @@ impl Storage {
|
||||||
Ok(())
|
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");
|
debug!("Fetching launcher stargazer count");
|
||||||
|
|
||||||
let mut con = self.client.get_multiplexed_async_connection().await?;
|
let mut con = self.client.get_multiplexed_async_connection().await?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue