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 fc9b395 commit c10dd92
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
26 changes: 23 additions & 3 deletions StudentsTimetable/Services/CommandsService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Telegram.BotAPI.AvailableMethods;
using System.Text.RegularExpressions;
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 +122,26 @@ private async void OnMessageReceive(Message message)
{
var lowerMessageText = messageText.ToLower();

// if (lowerMessageText.Contains("/notify"))
// await this._parserService.SendNewDayTimetables();
if (lowerMessageText.Contains("/timetablenotify"))
{
var notificationUsers = new List<Models.User>();
notificationUsers.AddRange(
(await this._mongoService.Database.GetCollection<Models.User>("Users")
.FindAsync(u => u.Group != 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 StudentsTimetable/Services/ParseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class ParseService : IParseService
};
}

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

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

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

Expand Down

0 comments on commit c10dd92

Please sign in to comment.