Skip to content

Commit

Permalink
Add current teachers displaying on change
Browse files Browse the repository at this point in the history
  • Loading branch information
wh0o7 committed Oct 21, 2023
1 parent 317458c commit 594018e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
7 changes: 7 additions & 0 deletions TeachersTimetable/Services/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IAccountService
Task<Models.User?> CreateAccount(User telegramUser);
Task<bool> ChangeTeacher(User telegramUser, string? teacher);
Task UpdateNotificationsStatus(User telegramUser);
Task<Models.User?> GetUserById(long id);
}

public class AccountService : IAccountService
Expand Down Expand Up @@ -40,6 +41,12 @@ public AccountService(IMongoService mongoService, IParseService parseService, IB
return user;
}

public async Task<Models.User?> GetUserById(long id)
{
var userCollection = this._mongoService.Database.GetCollection<Models.User>("Users");
return (await userCollection.FindAsync(u => u.UserId == id)).FirstOrDefault();
}

public async Task<bool> ChangeTeacher(User telegramUser, string? teacherName)
{
if (teacherName is null) return false;
Expand Down
55 changes: 30 additions & 25 deletions TeachersTimetable/Services/CommandsService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MongoDB.Driver;
using TeachersTimetable.Config;
using Telegram.BotAPI.AvailableMethods;
using Telegram.BotAPI.AvailableMethods.FormattingOptions;
using Telegram.BotAPI.AvailableTypes;
using TelegramBot_Timetable_Core;
using TelegramBot_Timetable_Core.Config;
Expand All @@ -21,9 +22,10 @@ public class CommandsService : ICommandsService
private readonly IMongoService _mongoService;
private readonly IBotService _botService;
private readonly IDistributionService _distributionService;
private static string _teachersList;
private static string _teachersList;

public CommandsService(IInterfaceService interfaceService, IAccountService accountService, IMongoService mongoService,
public CommandsService(IInterfaceService interfaceService, IAccountService accountService,
IMongoService mongoService,
IBotService botService, IDistributionService distributionService)
{
Core.OnMessageReceive += this.OnMessageReceive;
Expand Down Expand Up @@ -72,26 +74,26 @@ private async void OnMessageReceive(Message message)
case "/belltime":
{
this._botService.SendMessage(new SendMessageArgs(sender.Id, $"""
Расписание звонков:

Будние дни:

1) 09:00 - 09:45 | 09:55 - 10:40
2) 10:50 - 11:35 | 11:55 - 12:40
3) 13:00 - 13:45 | 13:55 - 14:40
4) 14:50 - 15:35 | 15:45 - 16:30
5) 16:40 - 17:25 | 17:35 - 18:20
6) 18:30 - 19:15 | 19:25 - 20:10

Суббота:

1) 09:00 - 09:45 | 09:55 - 10:40
2) 10:50 - 11:35 | 11:50 - 12:35
3) 12:50 - 13:35 | 13:45 - 14:30
4) 14:40 - 15:25 | 15:35 - 16:20
5) 16:30 - 17:15 | 17:25 - 18:10
6) 18:20 - 19:05 | 19:15 - 20:00
"""));
Расписание звонков:
Будние дни:
1) 09:00 - 09:45 | 09:55 - 10:40
2) 10:50 - 11:35 | 11:55 - 12:40
3) 13:00 - 13:45 | 13:55 - 14:40
4) 14:50 - 15:35 | 15:45 - 16:30
5) 16:40 - 17:25 | 17:35 - 18:20
6) 18:30 - 19:15 | 19:25 - 20:10

Суббота:
1) 09:00 - 09:45 | 09:55 - 10:40
2) 10:50 - 11:35 | 11:50 - 12:35
3) 12:50 - 13:35 | 13:45 - 14:30
4) 14:40 - 15:25 | 15:35 - 16:20
5) 16:30 - 17:15 | 17:25 - 18:10
6) 18:20 - 19:05 | 19:15 - 20:00
"""));
break;
}
case "Посмотреть расписание на день":
Expand All @@ -108,7 +110,10 @@ private async void OnMessageReceive(Message message)
case "Сменить преподавателя":
{
this._botService.SendMessage(new SendMessageArgs(sender.Id,
$"Для оформления подписки на преподавателей отправьте их фамилии.(Максимум - 5. Пример: Кулецкая, Шавейко, Потоцкий, Левонюк, Протасеня )"));
$"Для оформления подписки на преподавателей отправьте их фамилии.(Максимум - 5. Пример: Кулецкая, Шавейко, Потоцкий, Левонюк, Протасеня)\nВаши выбранные преподаватели:```{string.Join(", ", (await this._accountService.GetUserById(sender.Id))?.Teachers ?? Array.Empty<string>())}```")
{
ParseMode = ParseMode.Markdown
});

this._mongoService.CreateState(new UserState(message.Chat.Id, "changeTeacher"));

Expand All @@ -129,7 +134,7 @@ private async void OnMessageReceive(Message message)
if (messageText is not null)
{
var lowerMessageText = messageText.ToLower();

if (lowerMessageText.Contains("/timetablenotify"))
{
var notificationUsers = new List<Models.User>();
Expand All @@ -151,7 +156,7 @@ private async void OnMessageReceive(Message message)
});
}
}

await this._interfaceService.NotifyAllUsers(message);
}
catch (Exception e)
Expand Down

0 comments on commit 594018e

Please sign in to comment.