Bot.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using MafiaTelegramBot.Models.Commands;
  4. using MafiaTelegramBot.Models.Inlines;
  5. using MafiaTelegramBot.Models.Replies;
  6. using MafiaTelegramBot.Resources;
  7. using Telegram.Bot;
  8. using Telegram.Bot.Types;
  9. using Telegram.Bot.Types.Enums;
  10. using Telegram.Bot.Types.ReplyMarkups;
  11. namespace MafiaTelegramBot.Models
  12. {
  13. public static class Bot
  14. {
  15. private static TelegramBotClient _client;
  16. private static List<Command> _commandsList;
  17. private static List<Query> _queriesList;
  18. private static List<Reply> _repliesList;
  19. public static IReadOnlyList<Command> Commands => _commandsList.AsReadOnly();
  20. public static IReadOnlyList<Query> Queries => _queriesList.AsReadOnly();
  21. public static IReadOnlyList<Reply> Replies => _repliesList.AsReadOnly();
  22. public static readonly List<long> UsersThatChangesNickname = new();
  23. public static readonly Dictionary<long, string[]> UsersThatCreatesRoom = new();
  24. public static readonly List<long> UserThatEntersPrivateCode = new();
  25. public static TelegramBotClient Get()
  26. {
  27. if (_client != null) return _client;
  28. InitCommands();
  29. InitQueries();
  30. InitReplies();
  31. _client = new TelegramBotClient(AppSettings.Token);
  32. //var hook = string.Format(AppSettings.Url, "api/message/update");
  33. //await _client.SetWebhookAsync(hook);
  34. return _client;
  35. }
  36. private static void InitCommands()
  37. {
  38. //TODO fill commands array
  39. _commandsList = new List<Command>
  40. {
  41. new StartCommand(),
  42. new CreateGameCommand(),
  43. new ConnectGameCommand(),
  44. new ShowProfileCommand(),
  45. new RoomSettingsCommand(),
  46. new LeaveCommand(),
  47. new LookPlayersListCommand(),
  48. new KickPlayerCommand()
  49. };
  50. }
  51. private static void InitQueries()
  52. {
  53. //TODO fill inline keyboard array
  54. _queriesList = new List<Query>
  55. {
  56. new ShowMyRolesQuery(),
  57. new ShopMenuQuery(),
  58. new MakePrivateRoomQuery(),
  59. new MakePublicRoomQuery(),
  60. new MakeNormalGameQuery(),
  61. new MakeExtendedGameQuery(),
  62. new MakePublicRoomQuery(),
  63. new SettingsProfileQuery(),
  64. new ChangeNickNameQuery(),
  65. new SettingsRoomQuery(),
  66. new ConnectToPrivateRoomQuery(),
  67. new SetPlayersMaximumQuery(),
  68. new ConnectToPublicRoomQuery(),
  69. new ConnectToSelectedRoomQuery(),
  70. new KickSelectedPlayerQuery()
  71. };
  72. }
  73. private static void InitReplies()
  74. {
  75. //TODO fill inline keyboard array
  76. _repliesList = new List<Reply>
  77. {
  78. };
  79. }
  80. public static async Task<Message> SendWithMarkdown2(long chatId, string message, IReplyMarkup replyMarkup = null)
  81. {
  82. return await Get().SendTextMessageAsync(chatId, await Utilities.ToMarkdownString(message),
  83. ParseMode.MarkdownV2, replyMarkup: replyMarkup);
  84. }
  85. }
  86. }