Skip to content

Commit 624fbe9

Browse files
committed
Looks like its working? Just needs testing
1 parent f23e3d0 commit 624fbe9

File tree

4 files changed

+198
-10
lines changed

4 files changed

+198
-10
lines changed

Diff for: trackscape-discord-api/src/controllers/chat_controller.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{handler, ChatServerHandle};
33
use actix_web::web::Data;
44
use actix_web::{error, post, web, Error, HttpRequest, HttpResponse, Scope};
55
use celery::Celery;
6-
use log::{error, info};
6+
use log::error;
77
use serenity::all::{ChannelId, CreateEmbed, CreateEmbedAuthor};
88
use serenity::builder::CreateMessage;
99
use serenity::http::Http;
@@ -243,7 +243,36 @@ async fn new_clan_chats(
243243
let possible_broadcast = handler.extract_message().await;
244244

245245
match possible_broadcast {
246-
None => {}
246+
None => {
247+
if league_world {
248+
let possible_leagues_message = handler.extract_leagues_message().await;
249+
if let Some(leagues_message) = possible_leagues_message {
250+
let mut broadcast_embed = CreateEmbed::new()
251+
.title(leagues_message.title.clone())
252+
.description(leagues_message.message.clone())
253+
.color(0x0000FF)
254+
.timestamp(right_now);
255+
match leagues_message.icon_url {
256+
None => {}
257+
Some(icon_url) => {
258+
broadcast_embed = broadcast_embed.image(icon_url);
259+
}
260+
}
261+
let broadcast_message = CreateMessage::new().embed(broadcast_embed);
262+
//Only send if theres a leagues channel
263+
if let Some(channel_to_send_broadcast) =
264+
registered_guild.leagues_broadcast_channel
265+
{
266+
let new_broad_cast = ChannelId::new(channel_to_send_broadcast)
267+
.send_message(&*discord_http_client, broadcast_message)
268+
.await;
269+
if let Err(e) = new_broad_cast {
270+
error!("Error sending broadcast: {:?}", e);
271+
}
272+
}
273+
}
274+
}
275+
}
247276
Some(broadcast) => {
248277
let _ = mongodb
249278
.broadcasts

Diff for: trackscape-discord-bot/src/commands/set_leagues_broadcast_channel.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use serenity::builder::{CreateCommand, CreateMessage};
66
use serenity::client::Context;
77
use serenity::model::channel::ChannelType;
88
use serenity::model::prelude::Permissions;
9-
use std::any::Any;
109
use tracing::info;
1110
use trackscape_discord_shared::database::BotMongoDb;
1211

Diff for: trackscape-discord-shared/src/osrs_broadcast_extractor.rs

+109-2
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,37 @@ pub mod osrs_broadcast_extractor {
257257
pub time_in_seconds: f64,
258258
}
259259

260+
//Leagues broadcasts
261+
//TODO may come back and add more descriptive broadcasts for Leagues, but right now just going the "firehose" route
262+
// #[derive(Clone, Debug, Serialize, Deserialize)]
263+
// pub struct AreaUnlockBroadcast {
264+
// pub area: String,
265+
// pub player: String
266+
// }
267+
268+
// #[derive(Clone, Debug, Serialize, Deserialize)]
269+
// pub struct LeaguesRankBroadcast {
270+
// pub area: String,
271+
// pub player: String
272+
// }
273+
274+
// #[derive(Clone, Debug, Serialize, Deserialize)]
275+
// pub struct CombatMasteriesBroadcast {
276+
// pub player: String,
277+
// pub combat_mastery: String,
278+
// pub rank: i64,
279+
// }
280+
281+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
282+
pub enum LeaguesBroadCastType {
283+
AreaUnlock,
284+
LeaguesRank,
285+
CombatMasteries,
286+
RelicTier,
287+
//Normal broadcast but for leagues, like drops
288+
NormalBroadCast
289+
}
290+
260291
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
261292
pub enum BroadcastType {
262293
ItemDrop,
@@ -274,7 +305,12 @@ pub mod osrs_broadcast_extractor {
274305
ExpelledFromClan,
275306
CofferDonation,
276307
CofferWithdrawal,
277-
PersonalBest,
308+
PersonalBest,
309+
//Leagues Broadcasts
310+
AreaUnlock,
311+
LeaguesRank,
312+
CombatMasteries,
313+
RelicTier,
278314
Unknown,
279315
}
280316

@@ -297,7 +333,12 @@ pub mod osrs_broadcast_extractor {
297333
BroadcastType::ExpelledFromClan => "Expelled From Clan".to_string(),
298334
BroadcastType::CofferDonation => "Coffer Donation".to_string(),
299335
BroadcastType::CofferWithdrawal => "Coffer Withdrawal".to_string(),
300-
BroadcastType::PersonalBest => "Personal Best".to_string(),
336+
BroadcastType::PersonalBest => "Personal Best".to_string(),
337+
//Leagues Broadcasts
338+
BroadcastType::AreaUnlock => "Area Unlock".to_string(),
339+
BroadcastType::LeaguesRank => "Leagues Rank".to_string(),
340+
BroadcastType::CombatMasteries => "Combat Masteries".to_string(),
341+
BroadcastType::RelicTier => "Relic Tier".to_string(),
301342
}
302343
}
303344

@@ -315,6 +356,11 @@ pub mod osrs_broadcast_extractor {
315356
"Level Milestone" => BroadcastType::LevelMilestone,
316357
"Collection Log" => BroadcastType::CollectionLog,
317358
"Personal Best" => BroadcastType::PersonalBest,
359+
//Leagues Broadcasts
360+
"Area Unlock" => BroadcastType::AreaUnlock,
361+
"Leagues Rank" => BroadcastType::LeaguesRank,
362+
"Combat Masteries" => BroadcastType::CombatMasteries,
363+
"Relic Tier" => BroadcastType::RelicTier,
318364
_ => BroadcastType::Unknown,
319365
}
320366
}
@@ -338,6 +384,11 @@ pub mod osrs_broadcast_extractor {
338384
BroadcastType::CofferDonation,
339385
BroadcastType::CofferWithdrawal,
340386
BroadcastType::PersonalBest,
387+
//Leagues Broadcasts
388+
BroadcastType::AreaUnlock,
389+
BroadcastType::LeaguesRank,
390+
BroadcastType::CombatMasteries,
391+
BroadcastType::RelicTier,
341392
]
342393
}
343394

@@ -650,6 +701,23 @@ pub mod osrs_broadcast_extractor {
650701
}
651702
}
652703

704+
pub fn leagues_catch_all_broadcast_extractor(
705+
message: String,
706+
) -> Option<LeaguesBroadCastType> {
707+
if message.contains("has earned") && message.contains("Combat mastery") {
708+
return Some(LeaguesBroadCastType::CombatMasteries);
709+
}
710+
711+
if message.contains("has unlocked") && message.contains("League area") {
712+
return Some(LeaguesBroadCastType::AreaUnlock);
713+
}
714+
715+
if message.contains("has unlocked") && message.contains("League relic!") {
716+
return Some(LeaguesBroadCastType::RelicTier);
717+
}
718+
None
719+
}
720+
653721
/// Parses a time string in the format of `HH:MM:SS` or `MM:SS` and returns the time in seconds
654722
pub fn osrs_time_parser(time: &str) -> f64 {
655723
let split_sub_second: Vec<&str> = time.split(".").collect();
@@ -826,6 +894,7 @@ mod tests {
826894
LevelMilestoneBroadcast, PersonalBestBroadcast, PetDropBroadcast, PkBroadcast,
827895
QuestCompletedBroadcast, XPMilestoneBroadcast,
828896
};
897+
use osrs_broadcast_extractor::LeaguesBroadCastType;
829898
use rstest::rstest;
830899
use tracing::info;
831900

@@ -1453,6 +1522,21 @@ mod tests {
14531522
}
14541523
}
14551524

1525+
#[test]
1526+
fn test_leagues_catch_all_broadcast_extractor() {
1527+
let test_leagues_catch_all = get_leagues_catch_all_broadcast_messages();
1528+
for test_leagues_catch_all in test_leagues_catch_all {
1529+
let possible_leagues_catch_all_extract =
1530+
osrs_broadcast_extractor::leagues_catch_all_broadcast_extractor(
1531+
test_leagues_catch_all.message.clone(),
1532+
);
1533+
let leagues_catch_all = possible_leagues_catch_all_extract.unwrap();
1534+
info!("{:?}", leagues_catch_all);
1535+
assert_eq!(leagues_catch_all, test_leagues_catch_all.broadcast);
1536+
}
1537+
}
1538+
1539+
14561540
#[rstest]
14571541
#[case("0:56.40", 56.40)]
14581542
#[case("1:25", 85.0)]
@@ -2302,4 +2386,27 @@ mod tests {
23022386

23032387
messages
23042388
}
2389+
2390+
fn get_leagues_catch_all_broadcast_messages() -> Vec<TestBroadcast<LeaguesBroadCastType>> {
2391+
let mut messages: Vec<TestBroadcast<LeaguesBroadCastType>> = Vec::new();
2392+
2393+
messages.push(TestBroadcast {
2394+
message: "RuneScape Player has earned their 6th Combat mastery point!".to_string(),
2395+
broadcast: LeaguesBroadCastType::CombatMasteries,
2396+
});
2397+
2398+
messages.push(TestBroadcast {
2399+
message: "RuneScape Player has unlocked their 3rd League area!".to_string(),
2400+
broadcast: LeaguesBroadCastType::AreaUnlock,
2401+
});
2402+
2403+
messages.push(TestBroadcast {
2404+
message: "RuneScape Player has unlocked their tier 3 League relic!".to_string(),
2405+
broadcast: LeaguesBroadCastType::RelicTier,
2406+
});
2407+
2408+
//TODO add rank as we find more examples
2409+
2410+
messages
2411+
}
23052412
}

Diff for: trackscape-discord-shared/src/osrs_broadcast_handler.rs

+58-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ use crate::osrs_broadcast_extractor::osrs_broadcast_extractor::{
99
coffer_donation_broadcast_extractor, coffer_withdrawal_broadcast_extractor,
1010
collection_log_broadcast_extractor, diary_completed_broadcast_extractor,
1111
drop_broadcast_extractor, expelled_from_clan_broadcast_extractor, get_broadcast_type,
12-
invite_broadcast_extractor, left_the_clan_broadcast_extractor,
13-
levelmilestone_broadcast_extractor, personal_best_broadcast_extractor, pet_broadcast_extractor,
14-
pk_broadcast_extractor, quest_completed_broadcast_extractor, raid_broadcast_extractor,
15-
xpmilestone_broadcast_extractor, BroadcastType, ClanMessage,
12+
invite_broadcast_extractor, leagues_catch_all_broadcast_extractor,
13+
left_the_clan_broadcast_extractor, levelmilestone_broadcast_extractor,
14+
personal_best_broadcast_extractor, pet_broadcast_extractor, pk_broadcast_extractor,
15+
quest_completed_broadcast_extractor, raid_broadcast_extractor, xpmilestone_broadcast_extractor,
16+
BroadcastType, ClanMessage, LeaguesBroadCastType,
1617
};
1718
use crate::wiki_api::wiki_api::WikiQuest;
18-
use log::error;
19+
use log::{error, info};
1920
use num_format::{Locale, ToFormattedString};
2021
use serde::{Deserialize, Serialize};
2122
use std::sync::Arc;
@@ -508,6 +509,10 @@ impl<T: DropLogs, CL: ClanMateCollectionLogTotals, CM: ClanMates, J: JobQueue>
508509
}
509510
}
510511
BroadcastType::PersonalBest => self.personal_best_handler().await,
512+
// BroadcastType::AreaUnlock
513+
// | BroadcastType::LeaguesRank
514+
// | BroadcastType::CombatMasteries
515+
// | BroadcastType::RelicTier => self.leagues_handler().await,
511516
_ => None,
512517
}
513518
}
@@ -845,6 +850,54 @@ impl<T: DropLogs, CL: ClanMateCollectionLogTotals, CM: ClanMates, J: JobQueue>
845850
}
846851
}
847852

853+
pub async fn extract_leagues_message(&self) -> Option<BroadcastMessageToDiscord> {
854+
let possible_leagues_broad_cast_type =
855+
leagues_catch_all_broadcast_extractor(self.clan_message.message.clone());
856+
info!(
857+
"possible_leagues_broad_cast_type: {:?}",
858+
possible_leagues_broad_cast_type
859+
);
860+
match possible_leagues_broad_cast_type {
861+
Some(leagues_broadcast_type) => match leagues_broadcast_type {
862+
LeaguesBroadCastType::AreaUnlock => Some(BroadcastMessageToDiscord {
863+
type_of_broadcast: BroadcastType::AreaUnlock,
864+
player_it_happened_to: "".to_string(),
865+
message: self.clan_message.message.clone(),
866+
icon_url: Some("https://oldschool.runescape.wiki/images/Leagues_V-_Raging_Echoes_-_Summer_Summit_2024_%282%29.png?3877a".to_string()),
867+
title: ":new: New Leagues Area Unlock!".to_string(),
868+
item_quantity: None,
869+
}),
870+
LeaguesBroadCastType::LeaguesRank => Some(BroadcastMessageToDiscord {
871+
type_of_broadcast: BroadcastType::LeaguesRank,
872+
player_it_happened_to: "".to_string(),
873+
message: self.clan_message.message.clone(),
874+
icon_url: Some("https://oldschool.runescape.wiki/images/thumb/Leagues_icon.png/260px-Leagues_icon.png?0570b".to_string()),
875+
title: ":new: New Leagues Rank Unlock!".to_string(),
876+
item_quantity: None,
877+
}),
878+
LeaguesBroadCastType::CombatMasteries => Some(BroadcastMessageToDiscord {
879+
type_of_broadcast: BroadcastType::CombatMasteries,
880+
player_it_happened_to: "".to_string(),
881+
message: self.clan_message.message.clone(),
882+
icon_url: Some("https://oldschool.runescape.wiki/images/Raging_Echoes_League_combat_masteries_icon.png?4e2c2".to_string()),
883+
title: ":new: New Leagues Combat Mastery earned!".to_string(),
884+
item_quantity: None,
885+
}),
886+
LeaguesBroadCastType::RelicTier => Some(BroadcastMessageToDiscord {
887+
type_of_broadcast: BroadcastType::RelicTier,
888+
player_it_happened_to: "".to_string(),
889+
message: self.clan_message.message.clone(),
890+
icon_url: Some("https://oldschool.runescape.wiki/images/thumb/Leagues_icon.png/260px-Leagues_icon.png?0570b".to_string()),
891+
title: ":new: New Leagues Relic unlocked!".to_string(),
892+
item_quantity: None,
893+
}),
894+
//Ideally previous broadcast logic should catch this and we just come to leagues for the new types
895+
LeaguesBroadCastType::NormalBroadCast => None,
896+
},
897+
None => None,
898+
}
899+
}
900+
848901
fn best_guest_pb_icon(&self, activity: String) -> String {
849902
match activity.as_str().to_lowercase() {
850903
x if x.contains("theatre of blood") => {

0 commit comments

Comments
 (0)