Skip to content

Commit

Permalink
Fix some lints
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Jan 25, 2025
1 parent 0041ff1 commit f28b332
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 16 deletions.
13 changes: 6 additions & 7 deletions web/src/discord/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ use serenity::{
async_trait, Client,
};
use sqlx::PgPool;
use std::{
ops::Deref,
sync::{Arc, OnceLock},
};
use std::sync::{Arc, OnceLock};
use time::{Duration, OffsetDateTime};
use tokio::{
sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard},
Expand All @@ -41,7 +38,7 @@ pub struct DiscordClient {
impl std::fmt::Debug for DiscordClient {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DiscordClient")
.field("name", self.client_blocking().cache.current_user().deref())
.field("name", &*self.client_blocking().cache.current_user())
.finish()
}
}
Expand Down Expand Up @@ -374,6 +371,7 @@ impl DiscordClient {
Ok(())
}

#[allow(clippy::too_many_arguments)]
pub async fn send_queue_completion(
&self,
message_id: MessageId,
Expand Down Expand Up @@ -443,6 +441,7 @@ impl DiscordClient {
Ok(())
}

#[allow(clippy::too_many_arguments)]
async fn send_queue_completion_unsuccessful(
&self,
channel: ChannelId,
Expand Down Expand Up @@ -549,7 +548,7 @@ impl EventHandler for DiscordClient {
};
if is_connected {
match self.mark_user_connected(member.user.id).await {
Ok(_) => log::info!("Marked user {} as connected", member.user.id),
Ok(()) => log::info!("Marked user {} as connected", member.user.id),
Err(e) => log::error!(
"Error marking user {} as connected: {:?}",
member.user.id,
Expand Down Expand Up @@ -654,7 +653,7 @@ impl EventHandler for DiscordClient {
)
.await
{
Ok(_) => {
Ok(()) => {
log::info!("Gave roles {:?} to user {}", values, interaction.user.id);
}
Err(e) => {
Expand Down
1 change: 1 addition & 0 deletions web/src/discord/commands/queue_times.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
use poise::CreateReply;

#[poise::command(slash_command, rename = "queue", subcommands("datacenter", "world"))]
#[allow(clippy::unused_async)]
pub async fn queue_times(_: Context<'_>) -> Result<(), Error> {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/discord/commands/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub async fn stats(ctx: Context<'_>) -> Result<(), Error> {
.field("Uptime", format_duration(natives::process_uptime()?), true)
.field(
"Discord Latency",
latency.map(format_latency).unwrap_or("Unknown".to_string()),
latency.map_or("Unknown".to_string(), format_latency),
true,
);
ctx.send(CreateReply::default().embed(embed)).await?;
Expand Down
1 change: 1 addition & 0 deletions web/src/discord/commands/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use poise::CreateReply;
rename = "remind",
subcommands("datacenter", "world")
)]
#[allow(clippy::unused_async)]
pub async fn subscribe(_: Context<'_>) -> Result<(), Error> {
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions web/src/discord/commands/travel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use poise::{serenity_prelude as serenity, CreateReply};
interaction_context = "Guild|BotDm|PrivateChannel",
subcommands("datacenter", "world")
)]
#[allow(clippy::unused_async)]
pub async fn travel(_: Context<'_>) -> Result<(), Error> {
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions web/src/discord/commands/unsubscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use poise::CreateReply;
rename = "remindoff",
subcommands("datacenter", "world")
)]
#[allow(clippy::unused_async)]
pub async fn unsubscribe(_: Context<'_>) -> Result<(), Error> {
Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion web/src/discord/travel_param.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
use itertools::Itertools;
use poise::ChoiceParameter;
Expand Down Expand Up @@ -68,7 +70,7 @@ impl TravelData {
poise::CommandParameterChoice {
__non_exhaustive: (),
name: param.name(),
localizations: Default::default(),
localizations: HashMap::default(),
},
)
});
Expand Down
4 changes: 3 additions & 1 deletion web/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::too_many_lines)]

mod cache;
mod config;
mod crons;
Expand Down Expand Up @@ -56,7 +58,7 @@ async fn main() -> Result<(), ServerError> {
.add_source(File::new("config", FileFormat::Yaml))
.add_source(Environment::default())
.build()
.and_then(|v| v.try_deserialize())
.and_then(Config::try_deserialize)
.unwrap();

env_logger::init_from_env(
Expand Down
7 changes: 5 additions & 2 deletions web/src/middleware/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ impl UserAgentVersion {
configuration,
})
}
}

pub fn to_string(&self) -> String {
format!(
impl std::fmt::Display for UserAgentVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{major}.{minor}.{patch}-{configuration}",
major = self.major,
minor = self.minor,
Expand Down
2 changes: 1 addition & 1 deletion web/src/routes/api/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async fn create_recap(
let resp = db::create_recap(&pool, recap).await;

match resp {
Ok(_) => Ok(HttpResponse::Created().finish()),
Ok(()) => Ok(HttpResponse::Created().finish()),
Err(e) => Err(ErrorInternalServerError(e)),
}
}
Expand Down
7 changes: 4 additions & 3 deletions web/src/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use futures_util::{stream, StreamExt};
use redis::{aio::ConnectionManager, AsyncCommands, Cmd};
use serde::{Deserialize, Serialize};
use serenity::all::{CreateMessage, UserId};
use std::{ops::Deref, sync::Arc};
use std::sync::Arc;

#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down Expand Up @@ -146,13 +146,14 @@ impl SubscriptionManager {
&self,
publish_data: impl Into<EndpointPublishData>,
) -> Result<(), Error> {
const CHUNK_SIZE: usize = 32;

let publish_data: EndpointPublishData = publish_data.into();
let endpoint: Endpoint = (&*publish_data.0).into();

let key = endpoint.to_key(self.redis_config())?;
let mut redis = self.redis();

const CHUNK_SIZE: usize = 32;
loop {
let subscribers: Vec<Vec<u8>> = Cmd::spop(key.clone())
.arg(CHUNK_SIZE)
Expand All @@ -177,7 +178,7 @@ impl SubscriptionManager {
return;
}
};
if let Err(e) = self.publish_to(&subscriber, data.0.deref()).await {
if let Err(e) = self.publish_to(&subscriber, &data.0).await {
log::error!("Failed to publish to {:?}: {}", subscriber, e);
}
}
Expand Down

0 comments on commit f28b332

Please sign in to comment.