Skip to content

Commit

Permalink
chore: run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhhleyyy committed Dec 19, 2024
1 parent d1a848a commit 14036be
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 79 deletions.
11 changes: 2 additions & 9 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ impl Handler<RegisterIntegrationsClient> for Controller {
self.integration_clients
.insert(message.channel.clone(), message.client);

let status = self
.status_by_channel
.entry(message.channel)
.or_default();
let status = self.status_by_channel.entry(message.channel).or_default();
status.game_version = message.game_version;
status.server_ip = message.server_ip;
}
Expand Down Expand Up @@ -235,11 +232,7 @@ impl Handler<OutgoingChat> for Controller {
impl Handler<OutgoingCommand> for Controller {
type Return = bool;

async fn handle(
&mut self,
message: OutgoingCommand,
_ctx: &mut Context<Self>,
) -> Self::Return {
async fn handle(&mut self, message: OutgoingCommand, _ctx: &mut Context<Self>) -> Self::Return {
println!(
"[{}] <@{}> /{}",
message.channel, message.sender, message.command
Expand Down
35 changes: 20 additions & 15 deletions src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl CacheHttp for CacheAndHttp {
fn http(&self) -> &Http {
&self.http
}

fn cache(&self) -> Option<&Arc<Cache>> {
Some(&self.cache)
}
Expand Down Expand Up @@ -201,24 +201,34 @@ impl Handler<ReportError> for DiscordClient {
if let (Some(cache_and_http), Some(webhook_config)) =
(&self.cache_and_http, &self.config.error_webhook)
{
if let Ok(webhook) = Webhook::from_id_with_token(cache_and_http, webhook_config.id, &webhook_config.token).await
if let Ok(webhook) = Webhook::from_id_with_token(
cache_and_http,
webhook_config.id,
&webhook_config.token,
)
.await
{
let embed = CreateEmbed::new()
.title(message.title)
.description(message.description)
.fields(if let Some(fields) = message.fields {
fields.iter().map(|(name, value)| {
(name.clone(), value.clone(), false)
}).collect::<Vec<_>>()
fields
.iter()
.map(|(name, value)| (name.clone(), value.clone(), false))
.collect::<Vec<_>>()
} else {
vec![]
});

let res = webhook
.execute(&cache_and_http, false, ExecuteWebhook::new()
.username("Backend Error Reporting")
.embed(embed))
.await;
.execute(
&cache_and_http,
false,
ExecuteWebhook::new()
.username("Backend Error Reporting")
.embed(embed),
)
.await;

if let Err(e) = res {
warn!("Failed to report error to discord: {}", e);
Expand All @@ -237,12 +247,7 @@ struct DiscordHandler {
}

impl DiscordHandler {
async fn handle_command(
&self,
tokens: &[&str],
ctx: &SerenityContext,
message: &Message,
) {
async fn handle_command(&self, tokens: &[&str], ctx: &SerenityContext, message: &Message) {
let admin = check_message_admin(ctx, message).await;

let result = match tokens {
Expand Down
27 changes: 20 additions & 7 deletions src/discord/lfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ impl Channel {
}

fn remove_registration(&mut self, user: UserId) -> Option<Registration> {
match self.registrations.iter().position(|r| r.user_id == user.get()) {
match self
.registrations
.iter()
.position(|r| r.user_id == user.get())
{
Some(idx) => Some(self.registrations.remove(idx)),
None => None,
}
Expand Down Expand Up @@ -141,7 +145,12 @@ impl Handler {

let register_message = message
.channel_id
.send_message(&ctx.http, CreateMessage::new().content(description).reactions(vec![REACTION]))
.send_message(
&ctx.http,
CreateMessage::new()
.content(description)
.reactions(vec![REACTION]),
)
.await?;

let channel = match message.channel(ctx).await {
Expand Down Expand Up @@ -172,10 +181,7 @@ impl Handler {
pub async fn handle_reaction_add(&self, ctx: &SerenityContext, reaction: Reaction) {
if let Some(channel) = self.get_channel(ctx, reaction.channel_id).await {
if let (Some(user), Some(guild_id)) = (reaction.user_id, reaction.guild_id) {
if let Err(err) = self
.add_registration(ctx, user, guild_id, channel)
.await
{
if let Err(err) = self.add_registration(ctx, user, guild_id, channel).await {
error!("Failed to add looking-for-player registration: {:?}", err);
}
}
Expand Down Expand Up @@ -221,7 +227,14 @@ impl Handler {

let message = channel
.webhook
.execute(&ctx.http, true, ExecuteWebhook::new().content(content).username(name).avatar_url(avatar))
.execute(
&ctx.http,
true,
ExecuteWebhook::new()
.content(content)
.username(name)
.avatar_url(avatar),
)
.await?;

if let Some(message) = message {
Expand Down
23 changes: 17 additions & 6 deletions src/discord/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ pub async fn send_system(discord: &mut DiscordClient, send_system: SendSystem) {
let relay_store = data.get::<StoreKey>().unwrap();
if let Some(relay) = relay_store.channel_to_relay.get(&send_system.channel) {
let result = ChannelId::new(relay.discord_channel)
.send_message(&cache_and_http.http, CreateMessage::new()
.content(send_system.content)
.allowed_mentions(CreateAllowedMentions::new())
.send_message(
&cache_and_http.http,
CreateMessage::new()
.content(send_system.content)
.allowed_mentions(CreateAllowedMentions::new()),
)
.await;

Expand Down Expand Up @@ -179,7 +181,10 @@ impl Handler {
match message.channel(ctx).await {
Ok(Channel::Guild(guild_channel)) => {
let webhook = guild_channel
.create_webhook(&ctx.http, CreateWebhook::new(format!("Relay ({})", channel)))
.create_webhook(
&ctx.http,
CreateWebhook::new(format!("Relay ({})", channel)),
)
.await?;

let relay = ChannelRelay {
Expand Down Expand Up @@ -227,7 +232,10 @@ impl Handler {
let data = ctx.data.read().await;

let relay_store = data.get::<StoreKey>().unwrap();
if let Some(channel) = relay_store.discord_to_channel.get(&message.channel_id.get()) {
if let Some(channel) = relay_store
.discord_to_channel
.get(&message.channel_id.get())
{
let message = self.parse_outgoing_chat_with_reply(ctx, message).await;

self.controller
Expand Down Expand Up @@ -277,7 +285,10 @@ impl Handler {
let data = ctx.data.read().await;

let relay_store = data.get::<StoreKey>().unwrap();
if let Some(channel) = relay_store.discord_to_channel.get(&message.channel_id.get()) {
if let Some(channel) = relay_store
.discord_to_channel
.get(&message.channel_id.get())
{
let command = self.sanitize_message_content(ctx, message).await[2..].to_owned();
let sender = self.sender_name(ctx, message).await;
let roles = if let Ok(member) = message.member(&ctx).await {
Expand Down
1 change: 0 additions & 1 deletion src/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ pub enum OutgoingMessage {

struct HandleIncomingMessage(Result<IncomingMessage>);


impl Handler<HandleIncomingMessage> for IntegrationsClient {
type Return = ();

Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ async fn main() {
env_logger::init();

let config = config::load();
let controller = xtra::spawn_tokio(Controller::new(config.clone())
.await, Mailbox::unbounded());
let controller = xtra::spawn_tokio(Controller::new(config.clone()).await, Mailbox::unbounded());

let mut futures = Vec::with_capacity(5);

Expand Down
6 changes: 1 addition & 5 deletions src/mojang_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ impl Handler<GetPlayerUsername> for MojangApiClient {
impl Handler<ClearCache> for MojangApiClient {
type Return = ();

async fn handle(
&mut self,
_message: ClearCache,
_ctx: &mut Context<Self>,
) -> Self::Return {
async fn handle(&mut self, _message: ClearCache, _ctx: &mut Context<Self>) -> Self::Return {
self.username_cache.clear();
}
}
Expand Down
36 changes: 6 additions & 30 deletions src/statistics/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,7 @@ pub struct GetPlayerStats {
impl Handler<GetPlayerStats> for StatisticDatabaseController {
type Return = StatisticsDatabaseResult<Option<PlayerStatsResponse>>;

async fn handle(
&mut self,
message: GetPlayerStats,
_ctx: &mut Context<Self>,
) -> Self::Return {
async fn handle(&mut self, message: GetPlayerStats, _ctx: &mut Context<Self>) -> Self::Return {
self.get_player_stats(&message.uuid, &message.namespace)
.await
}
Expand All @@ -444,11 +440,7 @@ pub struct GetGameStats(pub Uuid);
impl Handler<GetGameStats> for StatisticDatabaseController {
type Return = StatisticsDatabaseResult<Option<HashMap<Uuid, PlayerStatsResponse>>>;

async fn handle(
&mut self,
message: GetGameStats,
_ctx: &mut Context<Self>,
) -> Self::Return {
async fn handle(&mut self, message: GetGameStats, _ctx: &mut Context<Self>) -> Self::Return {
self.get_game_stats(&message.0).await
}
}
Expand All @@ -461,11 +453,7 @@ pub struct GetRecentGames {
impl Handler<GetRecentGames> for StatisticDatabaseController {
type Return = StatisticsDatabaseResult<Vec<RecentGame>>;

async fn handle(
&mut self,
message: GetRecentGames,
_ctx: &mut Context<Self>,
) -> Self::Return {
async fn handle(&mut self, message: GetRecentGames, _ctx: &mut Context<Self>) -> Self::Return {
self.get_recent_games(message.limit, message.player_id)
.await
}
Expand Down Expand Up @@ -518,11 +506,7 @@ pub struct GetLeaderboard(pub String);
impl Handler<GetLeaderboard> for StatisticDatabaseController {
type Return = StatisticsDatabaseResult<Option<Vec<LeaderboardEntry>>>;

async fn handle(
&mut self,
message: GetLeaderboard,
_ctx: &mut Context<Self>,
) -> Self::Return {
async fn handle(&mut self, message: GetLeaderboard, _ctx: &mut Context<Self>) -> Self::Return {
self.leaderboards.get_leaderboard(&message.0).await
}
}
Expand Down Expand Up @@ -560,11 +544,7 @@ pub struct DataQuery(pub DataQueryType);
impl Handler<DataQuery> for StatisticDatabaseController {
type Return = StatisticsDatabaseResult<Vec<Datapoint>>;

async fn handle(
&mut self,
message: DataQuery,
_ctx: &mut Context<Self>,
) -> Self::Return {
async fn handle(&mut self, message: DataQuery, _ctx: &mut Context<Self>) -> Self::Return {
self.data_query(message.0).await
}
}
Expand All @@ -574,11 +554,7 @@ pub struct WrappedData(pub Uuid);
impl Handler<WrappedData> for StatisticDatabaseController {
type Return = StatisticsDatabaseResult<PlayerWrappedData>;

async fn handle(
&mut self,
message: WrappedData,
_ctx: &mut Context<Self>,
) -> Self::Return {
async fn handle(&mut self, message: WrappedData, _ctx: &mut Context<Self>) -> Self::Return {
self.wrapped_data(&message.0).await
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ async fn get_player_stats(

if let Some(namespace) = &namespace {
for c in namespace.chars() {
if !(c.is_ascii_lowercase()
|| c.is_ascii_uppercase()
|| c.is_ascii_digit()
|| c == '_')
if !(c.is_ascii_lowercase() || c.is_ascii_uppercase() || c.is_ascii_digit() || c == '_')
{
return Ok(send_http_status(StatusCode::BAD_REQUEST));
}
Expand Down

0 comments on commit 14036be

Please sign in to comment.