123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using MafiaTelegramBot.Models.Commands;
- using MafiaTelegramBot.Models.Inlines;
- using MafiaTelegramBot.Models.Replies;
- using MafiaTelegramBot.Resources;
- using Telegram.Bot;
- using Telegram.Bot.Types;
- using Telegram.Bot.Types.Enums;
- using Telegram.Bot.Types.ReplyMarkups;
- namespace MafiaTelegramBot.Models
- {
- public static class Bot
- {
- private static TelegramBotClient _client;
- private static List<Command> _commandsList;
- private static List<Query> _queriesList;
- private static List<Reply> _repliesList;
-
- public static IReadOnlyList<Command> Commands => _commandsList.AsReadOnly();
- public static IReadOnlyList<Query> Queries => _queriesList.AsReadOnly();
- public static IReadOnlyList<Reply> Replies => _repliesList.AsReadOnly();
- public static readonly List<long> UsersThatChangesNickname = new();
- public static readonly Dictionary<long, string[]> UsersThatCreatesRoom = new();
- public static readonly List<long> UserThatEntersPrivateCode = new();
- public static TelegramBotClient Get()
- {
- if (_client != null) return _client;
- InitCommands();
- InitQueries();
- InitReplies();
- _client = new TelegramBotClient(AppSettings.Token);
- //var hook = string.Format(AppSettings.Url, "api/message/update");
- //await _client.SetWebhookAsync(hook);
- return _client;
- }
- private static void InitCommands()
- {
- //TODO fill commands array
- _commandsList = new List<Command>
- {
- new StartCommand(),
- new CreateGameCommand(),
- new ConnectGameCommand(),
- new ShowProfileCommand(),
- new RoomSettingsCommand(),
- new LeaveCommand(),
-
- //it always in end of array, handle all messages, that doesn't contains command string
- new CustomMessageHandlingCommand()
- };
- }
-
- private static void InitQueries()
- {
- //TODO fill inline keyboard array
- _queriesList = new List<Query>
- {
- new MyRolesQuery(),
- new ShopQuery(),
- new MakePrivateRoomQuery(),
- new MakePublicRoomQuery(),
- new MakeStandartGameQuery(),
- new MakeExtendedGameQuery(),
- new MakePublicRoomQuery(),
- new SettingsQuery(),
- new ChangeNameQuery(),
- new SettingsRoomQuery(),
- new ConnectToPrivateRoomQuery(),
- new LookUsersListQuery(),
- new IncreaseRoomMaxCapacityQuery(),
- new DecreaseRoomMaxCapacity(),
- new ConnectToPublicRoomQuery(),
- new ConnectToSelectedRoomQuery()
- };
- }
-
- private static void InitReplies()
- {
- //TODO fill inline keyboard array
- _repliesList = new List<Reply>
- {
-
- };
- }
-
- public static async Task<Message> SendWithMarkdown2(long chatId, string message, IReplyMarkup replyMarkup = null)
- {
- var newMessage = await Task.Run(()=> message
- .Replace(".", "\\.")
- .Replace("@", "\\@")
- .Replace("#", "\\#")
- .Replace("!", "\\!")
- .Replace("-", "\\-")
- );
- return replyMarkup == null
- ? await Get().SendTextMessageAsync(chatId, newMessage, ParseMode.MarkdownV2)
- : await Get().SendTextMessageAsync(chatId, newMessage, ParseMode.MarkdownV2, replyMarkup: replyMarkup);
- }
- }
- }
|