@@ -257,6 +257,37 @@ pub mod osrs_broadcast_extractor {
257
257
pub time_in_seconds : f64 ,
258
258
}
259
259
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
+
260
291
#[ derive( PartialEq , Deserialize , Serialize , Debug , Clone ) ]
261
292
pub enum BroadcastType {
262
293
ItemDrop ,
@@ -274,7 +305,12 @@ pub mod osrs_broadcast_extractor {
274
305
ExpelledFromClan ,
275
306
CofferDonation ,
276
307
CofferWithdrawal ,
277
- PersonalBest ,
308
+ PersonalBest ,
309
+ //Leagues Broadcasts
310
+ AreaUnlock ,
311
+ LeaguesRank ,
312
+ CombatMasteries ,
313
+ RelicTier ,
278
314
Unknown ,
279
315
}
280
316
@@ -297,7 +333,12 @@ pub mod osrs_broadcast_extractor {
297
333
BroadcastType :: ExpelledFromClan => "Expelled From Clan" . to_string ( ) ,
298
334
BroadcastType :: CofferDonation => "Coffer Donation" . to_string ( ) ,
299
335
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 ( ) ,
301
342
}
302
343
}
303
344
@@ -315,6 +356,11 @@ pub mod osrs_broadcast_extractor {
315
356
"Level Milestone" => BroadcastType :: LevelMilestone ,
316
357
"Collection Log" => BroadcastType :: CollectionLog ,
317
358
"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 ,
318
364
_ => BroadcastType :: Unknown ,
319
365
}
320
366
}
@@ -338,6 +384,11 @@ pub mod osrs_broadcast_extractor {
338
384
BroadcastType :: CofferDonation ,
339
385
BroadcastType :: CofferWithdrawal ,
340
386
BroadcastType :: PersonalBest ,
387
+ //Leagues Broadcasts
388
+ BroadcastType :: AreaUnlock ,
389
+ BroadcastType :: LeaguesRank ,
390
+ BroadcastType :: CombatMasteries ,
391
+ BroadcastType :: RelicTier ,
341
392
]
342
393
}
343
394
@@ -650,6 +701,23 @@ pub mod osrs_broadcast_extractor {
650
701
}
651
702
}
652
703
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
+
653
721
/// Parses a time string in the format of `HH:MM:SS` or `MM:SS` and returns the time in seconds
654
722
pub fn osrs_time_parser ( time : & str ) -> f64 {
655
723
let split_sub_second: Vec < & str > = time. split ( "." ) . collect ( ) ;
@@ -826,6 +894,7 @@ mod tests {
826
894
LevelMilestoneBroadcast , PersonalBestBroadcast , PetDropBroadcast , PkBroadcast ,
827
895
QuestCompletedBroadcast , XPMilestoneBroadcast ,
828
896
} ;
897
+ use osrs_broadcast_extractor:: LeaguesBroadCastType ;
829
898
use rstest:: rstest;
830
899
use tracing:: info;
831
900
@@ -1453,6 +1522,21 @@ mod tests {
1453
1522
}
1454
1523
}
1455
1524
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
+
1456
1540
#[ rstest]
1457
1541
#[ case( "0:56.40" , 56.40 ) ]
1458
1542
#[ case( "1:25" , 85.0 ) ]
@@ -2302,4 +2386,27 @@ mod tests {
2302
2386
2303
2387
messages
2304
2388
}
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
+ }
2305
2412
}
0 commit comments