Skip to content

Commit

Permalink
Add /timetablenotify command
Browse files Browse the repository at this point in the history
  • Loading branch information
litolax committed Oct 2, 2023
1 parent 1a6100f commit 6598914
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
25 changes: 22 additions & 3 deletions TeachersTimetable/Services/CommandsService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Telegram.BotAPI.AvailableMethods;
using MongoDB.Driver;
using Telegram.BotAPI.AvailableMethods;
using Telegram.BotAPI.AvailableTypes;
using TelegramBot_Timetable_Core;
using TelegramBot_Timetable_Core.Models;
Expand Down Expand Up @@ -120,8 +121,26 @@ private async void OnMessageReceive(Message message)
{
var lowerMessageText = messageText.ToLower();

// if (lowerMessageText.Contains("/notify"))
// await this._parserService.SendNewDayTimetables(null, true);
if (lowerMessageText.Contains("/timetablenotify"))
{
var notificationUsers = new List<Models.User>();
notificationUsers.AddRange(
(await this._mongoService.Database.GetCollection<Models.User>("Users")
.FindAsync(u => u.Teacher != null && u.Notifications)).ToList());

if (notificationUsers.Count == 0) return;

_ = Task.Run(() =>
{
foreach (var user in notificationUsers)
{
_ = this._distributionService.SendDayTimetable(user);
}
this._botService.SendAdminMessageAsync(new SendMessageArgs(0,
$"{notificationUsers.Count} notifications sent"));
});
}
}

await this._interfaceService.NotifyAllUsers(message);
Expand Down
4 changes: 2 additions & 2 deletions TeachersTimetable/Services/ParseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ParseService(IMongoService mongoService, IBotService botService, IFirefox
};
}

public async Task ParseDay()
private async Task ParseDay()
{
Console.WriteLine("Start day parse");

Expand Down Expand Up @@ -227,7 +227,7 @@ public async Task ParseDay()
});
}

public async Task ParseWeek()
private async Task ParseWeek()
{
Console.WriteLine("Start week parse");

Expand Down

0 comments on commit 6598914

Please sign in to comment.