@@ -9,17 +9,20 @@ use std::sync::Arc;
99
1010use anyhow:: Error ;
1111use chombot_common:: chombot:: ChombotBase ;
12+ use chombot_common:: data_watcher:: DataWatcher ;
13+ use chombot_common:: ranking_watcher:: notifier:: ChannelMessageNotifier ;
14+ use chombot_common:: ranking_watcher:: usma:: get_ranking;
1215use chombot_common:: slash_commands:: hand:: hand;
1316use chombot_common:: slash_commands:: score:: score;
1417use chombot_common:: { start_tournaments_watcher, ChombotPoiseUserData } ;
1518use clap:: Parser ;
1619use log:: { error, info, LevelFilter } ;
17- use poise:: serenity_prelude:: { ClientBuilder , GatewayIntents } ;
20+ use poise:: serenity_prelude:: { ClientBuilder , Context as SerenityContext , GatewayIntents } ;
1821use poise:: { Command , Context , Framework , FrameworkOptions } ;
1922use tokio:: sync:: RwLock ;
2023
2124use crate :: args:: Arguments ;
22- use crate :: config:: ChombotConfig ;
25+ use crate :: config:: { ChombotConfig , RankingWatcherChannelListProvider } ;
2326use crate :: tournament_watcher:: tournament_watcher;
2427
2528mod args;
@@ -39,6 +42,27 @@ impl ChombotPoiseUserData for PoiseUserData {
3942
4043pub type PoiseContext < ' a > = Context < ' a , PoiseUserData , anyhow:: Error > ;
4144
45+ fn start_ranking_watcher < T : RankingWatcherChannelListProvider + ' static > (
46+ channel_list_provider : T ,
47+ ctx : SerenityContext ,
48+ ) {
49+ tokio:: spawn ( async move {
50+ let channels = channel_list_provider. ranking_watcher_channels ( ) . await ;
51+ for channel_id in channels {
52+ let notifier = ChannelMessageNotifier :: new (
53+ channel_id,
54+ String :: from ( "https://ranking.cvgo.re/ ranking update" ) ,
55+ ) ;
56+ let ctx_clone = ctx. clone ( ) ;
57+ tokio:: spawn ( async move {
58+ DataWatcher :: new ( notifier, get_ranking)
59+ . run ( & ctx_clone)
60+ . await ;
61+ } ) ;
62+ }
63+ } ) ;
64+ }
65+
4266fn get_command_list ( ) -> Vec < Command < PoiseUserData , Error > > {
4367 vec ! [ hand( ) , score( ) , tournament_watcher( ) ]
4468}
@@ -63,6 +87,9 @@ async fn main() {
6387 } )
6488 . setup ( move |ctx, ready, framework| {
6589 Box :: pin ( async move {
90+ if args. feature_ranking_watcher {
91+ start_ranking_watcher ( config_ref. clone ( ) , ctx. clone ( ) ) ;
92+ }
6693 start_tournaments_watcher ( config_ref. clone ( ) , ctx. clone ( ) ) ;
6794 poise:: builtins:: register_globally ( ctx, & framework. options ( ) . commands ) . await ?;
6895 info ! ( "{} is connected!" , ready. user. name) ;
0 commit comments