Skip to content

Commit

Permalink
Plugged in
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfingers23 committed Apr 21, 2024
1 parent 69e2ac7 commit f5bd7d7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ pub fn register() -> CreateCommand {
BroadcastType::Invite.to_string(),
BroadcastType::Invite.to_slug(),
)
.add_string_choice(
BroadcastType::PersonalBest.to_string(),
BroadcastType::PersonalBest.to_slug(),
)
.required(true),
)
.add_option(CreateCommandOption::new(
Expand Down
13 changes: 9 additions & 4 deletions trackscape-discord-shared/src/osrs_broadcast_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub mod osrs_broadcast_extractor {
ExpelledFromClan,
CofferDonation,
CofferWithdrawal,
BossPB,
PersonalBest,
Unknown,
}

Expand All @@ -275,7 +275,7 @@ pub mod osrs_broadcast_extractor {
BroadcastType::ExpelledFromClan => "Expelled From Clan".to_string(),
BroadcastType::CofferDonation => "Coffer Donation".to_string(),
BroadcastType::CofferWithdrawal => "Coffer Withdrawal".to_string(),
BroadcastType::BossPB => "Boss PB".to_string(),
BroadcastType::PersonalBest => "Personal Best".to_string(),
}
}

Expand All @@ -292,7 +292,7 @@ pub mod osrs_broadcast_extractor {
"XP Milestone" => BroadcastType::XPMilestone,
"Level Milestone" => BroadcastType::LevelMilestone,
"Collection Log" => BroadcastType::CollectionLog,
"Boss PB" => BroadcastType::BossPB,
"Personal Best" => BroadcastType::PersonalBest,
_ => BroadcastType::Unknown,
}
}
Expand All @@ -315,7 +315,7 @@ pub mod osrs_broadcast_extractor {
BroadcastType::ExpelledFromClan,
BroadcastType::CofferDonation,
BroadcastType::CofferWithdrawal,
BroadcastType::BossPB,
BroadcastType::PersonalBest,
]
}

Expand Down Expand Up @@ -743,6 +743,11 @@ pub mod osrs_broadcast_extractor {
if message_content.contains("withdrawn") && message_content.contains("from the coffer.") {
return BroadcastType::CofferWithdrawal;
}
if message_content.contains("has achieved a new")
&& message_content.contains("personal best:")
{
return BroadcastType::PersonalBest;
}
return BroadcastType::Unknown;
}

Expand Down
96 changes: 76 additions & 20 deletions trackscape-discord-shared/src/osrs_broadcast_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::osrs_broadcast_extractor::osrs_broadcast_extractor::{
collection_log_broadcast_extractor, diary_completed_broadcast_extractor,
drop_broadcast_extractor, expelled_from_clan_broadcast_extractor, get_broadcast_type,
invite_broadcast_extractor, left_the_clan_broadcast_extractor,
levelmilestone_broadcast_extractor, pet_broadcast_extractor, pk_broadcast_extractor,
quest_completed_broadcast_extractor, raid_broadcast_extractor, xpmilestone_broadcast_extractor,
BroadcastType, ClanMessage,
levelmilestone_broadcast_extractor, personal_best_broadcast_extractor, pet_broadcast_extractor,
pk_broadcast_extractor, quest_completed_broadcast_extractor, raid_broadcast_extractor,
xpmilestone_broadcast_extractor, BroadcastType, ClanMessage,
};
use crate::wiki_api::wiki_api::WikiQuest;
use log::error;
Expand Down Expand Up @@ -506,6 +506,7 @@ impl<T: DropLogs, CL: ClanMateCollectionLogTotals, CM: ClanMates, J: JobQueue>
}
}
}
BroadcastType::PersonalBest => self.personal_best_handler(),
_ => None,
}
}
Expand Down Expand Up @@ -747,23 +748,6 @@ impl<T: DropLogs, CL: ClanMateCollectionLogTotals, CM: ClanMates, J: JobQueue>
}
}

fn check_if_allowed_broad_cast(&self, broadcast_type: BroadcastType) -> bool {
let is_disallowed = self
.registered_guild
.disallowed_broadcast_types
.iter()
.find(|&x| {
if broadcast_type.to_string() == x.to_string() {
return true;
}
false
});
if is_disallowed.is_some() {
return true;
}
false
}

async fn collection_log_handler(&self) -> Option<BroadcastMessageToDiscord> {
let possible_collection_log =
collection_log_broadcast_extractor(self.clan_message.message.clone());
Expand Down Expand Up @@ -819,6 +803,78 @@ impl<T: DropLogs, CL: ClanMateCollectionLogTotals, CM: ClanMates, J: JobQueue>
}
}
}

fn personal_best_handler(&self) -> Option<BroadcastMessageToDiscord> {
let personal_best = personal_best_broadcast_extractor(self.clan_message.message.clone());
match personal_best {
None => {
error!(
"Failed to extract Personal Best info from message: {}",
self.clan_message.message.clone()
);
None
}
Some(exported_data) => {
let is_disallowed = self
.registered_guild
.disallowed_broadcast_types
.iter()
.find(|&x| {
if let BroadcastType::PersonalBest = x {
return true;
}
false
});
if is_disallowed.is_some() {
return None;
}

Some(BroadcastMessageToDiscord {
type_of_broadcast: BroadcastType::Diary,
player_it_happened_to: exported_data.player,
message: self.clan_message.message.clone(),
icon_url: Some(
self.best_guest_pb_icon(exported_data.activity.clone())
.to_string(),
),
title: ":stopwatch: New Personal Best!".to_string(),
item_quantity: None,
})
}
}
}

fn best_guest_pb_icon(&self, activity: String) -> String {
match activity.as_str().to_lowercase() {
x if x.contains("theatre of blood") => {
"https://oldschool.runescape.wiki/images/Theatre_of_Blood_logo.png".to_string()
}
x if x.contains("chambers of xeric") => {
"https://oldschool.runescape.wiki/images/Chambers_of_Xeric_logo.png".to_string()
}
x if x.contains("tombs of amascut") => {
"https://oldschool.runescape.wiki/images/Tombs_of_Amascut.png".to_string()
}
_ => format!("https://oldschool.runescape.wiki/images/{}.png", activity).to_string(),
}
}

fn check_if_allowed_broad_cast(&self, broadcast_type: BroadcastType) -> bool {
let is_disallowed = self
.registered_guild
.disallowed_broadcast_types
.iter()
.find(|&x| {
if broadcast_type.to_string() == x.to_string() {
return true;
}
false
});
if is_disallowed.is_some() {
return true;
}
false
}
}

#[cfg(test)]
Expand Down

0 comments on commit f5bd7d7

Please sign in to comment.