Skip to content

Commit

Permalink
feat: move MESSAGE_PREFIX locally (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
seqre authored and m4tx committed Jan 17, 2024
1 parent e959495 commit e2d7222
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 1 addition & 5 deletions chombot-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ pub fn start_tournaments_watcher<T: TournamentWatcherChannelListProvider + 'stat
channel_list_provider: T,
ctx: SerenityContext,
) {
const MESSAGE_PREFIX: &str =
"**TOURNAMENTS UPDATE** (http://mahjong-europe.org/ranking/Calendar.html)\n\n";

let notifier =
TournamentsChannelMessageNotifier::new(channel_list_provider, String::from(MESSAGE_PREFIX));
let notifier = TournamentsChannelMessageNotifier::new(channel_list_provider);
tokio::spawn(async move {
DataWatcher::new(notifier, get_rcr_tournaments)
.run(&ctx)
Expand Down
13 changes: 7 additions & 6 deletions chombot-common/src/tournaments_watcher/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use crate::data_watcher::DataUpdateNotifier;
use crate::discord_utils::send_with_overflow;
use crate::tournaments_watcher::ema::{TournamentStatus, TournamentStatuses, Tournaments};

const MESSAGE_PREFIX: &str =
"**TOURNAMENTS UPDATE** (http://mahjong-europe.org/ranking/Calendar.html)\n\n";

#[async_trait]
pub trait TournamentsUpdateNotifier<R: Send + Sync> {
async fn notify(&self, ranking: &R);
Expand Down Expand Up @@ -45,21 +48,19 @@ impl<T: TournamentWatcherChannelListProvider> TournamentWatcherChannelListProvid

pub struct TournamentsChannelMessageNotifier<T> {
channel_list_provider: T,
message: String,
}

impl<T: TournamentWatcherChannelListProvider> TournamentsChannelMessageNotifier<T> {
#[must_use]
pub const fn new(channel_list_provider: T, message: String) -> Self {
pub const fn new(channel_list_provider: T) -> Self {
Self {
channel_list_provider,
message,
}
}

#[must_use]
fn build_message(&self, tournament_statuses: &TournamentStatuses) -> String {
format!("{}{}", self.message, build_message(tournament_statuses))
fn build_message(tournament_statuses: &TournamentStatuses) -> String {
format!("{}{}", MESSAGE_PREFIX, build_message(tournament_statuses))
}
}

Expand Down Expand Up @@ -122,7 +123,7 @@ impl<T: TournamentWatcherChannelListProvider> DataUpdateNotifier<Option<Tourname
for TournamentsChannelMessageNotifier<T>
{
async fn notify(&self, diff: TournamentStatuses, ctx: &Context) {
let text = self.build_message(&diff);
let text = Self::build_message(&diff);

let channel_list: Vec<ChannelId> = self
.channel_list_provider
Expand Down

0 comments on commit e2d7222

Please sign in to comment.