Skip to content

Commit

Permalink
Change notification message sending to parallel processing
Browse files Browse the repository at this point in the history
  • Loading branch information
azhuge233 committed Feb 15, 2025
1 parent 5abca04 commit bdd0d7b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions GOGGiveawayNotifier/Module/NotifyOP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,30 @@ public async Task Notify(NotifyConfig config, List<GiveawayRecord> game) {
try {
_logger.LogDebug(debugNotify);

var notifyTask = new List<Task>();

// Telegram notifications
if (config.EnableTelegram) {
_logger.LogInformation(debugEnabledFormat, "Telegram");
await services.GetRequiredService<TgBot>().SendMessage(config, game);
notifyTask.Add(services.GetRequiredService<TgBot>().SendMessage(config, game));
} else _logger.LogInformation(debugDisabledFormat, "Telegram");

// Bark notifications
if (config.EnableBark) {
_logger.LogInformation(debugEnabledFormat, "Bark");
await services.GetRequiredService<Barker>().SendMessage(config, game);
notifyTask.Add(services.GetRequiredService<Barker>().SendMessage(config, game));
} else _logger.LogInformation(debugDisabledFormat, "Bark");

//QQ notifications
if (config.EnableQQ) {
_logger.LogInformation(debugEnabledFormat, "QQ");
await services.GetRequiredService<QQPusher>().SendMessage(config, game);
notifyTask.Add(services.GetRequiredService<QQPusher>().SendMessage(config, game));
} else _logger.LogInformation(debugDisabledFormat, "QQ");

//QQ Red (Chronocat) notifications
if (config.EnableRed) {
_logger.LogInformation(debugEnabledFormat, "QQ Red (Chronocat)");
await services.GetRequiredService<QQRed>().SendMessage(config, game);
notifyTask.Add(services.GetRequiredService<QQRed>().SendMessage(config, game));
} else _logger.LogInformation(debugDisabledFormat, "QQ Red (Chronocat)");

// PushPlus notifications
Expand All @@ -65,27 +67,29 @@ public async Task Notify(NotifyConfig config, List<GiveawayRecord> game) {
// DingTalk notifications
if (config.EnableDingTalk) {
_logger.LogInformation(debugEnabledFormat, "DingTalk");
await services.GetRequiredService<DingTalk>().SendMessage(config, game);
notifyTask.Add(services.GetRequiredService<DingTalk>().SendMessage(config, game));
} else _logger.LogInformation(debugDisabledFormat, "DingTalk");

// PushDeer notifications
if (config.EnablePushDeer) {
_logger.LogInformation(debugEnabledFormat, "PushDeer");
await services.GetRequiredService<PushDeer>().SendMessage(config, game);
notifyTask.Add(services.GetRequiredService<PushDeer>().SendMessage(config, game));
} else _logger.LogInformation(debugDisabledFormat, "PushDeer");

// Discord notifications
if (config.EnableDiscord) {
_logger.LogInformation(debugEnabledFormat, "Discord");
await services.GetRequiredService<Discord>().SendMessage(config, game);
notifyTask.Add(services.GetRequiredService<Discord>().SendMessage(config, game));
} else _logger.LogInformation(debugDisabledFormat, "Discord");

//Email notifications
if (config.EnableEmail) {
_logger.LogInformation(debugEnabledFormat, "Email");
await services.GetRequiredService<Email>().SendMessage(config, game);
notifyTask.Add(services.GetRequiredService<Email>().SendMessage(config, game));
} else _logger.LogInformation(debugDisabledFormat, "Email");

await Task.WhenAll(notifyTask);

_logger.LogDebug($"Done: {debugNotify}");
} catch (Exception) {
_logger.LogError($"Error: {debugNotify}");
Expand Down

0 comments on commit bdd0d7b

Please sign in to comment.