123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Linq;
- using System.Threading.Tasks;
- using MafiaTelegramBot.Models;
- using MafiaTelegramBot.Resources;
- using Telegram.Bot.Types;
- namespace MafiaTelegramBot
- {
- public static class Utilities
- {
- public static Task<Message> GetResultCodeMessage(ResultCode code, long chatId)
- {
- return code switch
- {
- ResultCode.TooManyPlayers => Bot.SendWithMarkdown2(chatId, strings.too_many_players),
- ResultCode.TooFewPlayers => Bot.SendWithMarkdown2(chatId, strings.too_few_players),
- ResultCode.GameAlreadyRunning => Bot.SendWithMarkdown2(chatId, strings.game_already_running),
- ResultCode.GameAlreadyExists => Bot.SendWithMarkdown2(chatId, strings.game_already_exists),
- ResultCode.UserAlreadyInGame => Bot.SendWithMarkdown2(chatId, strings.user_already_in_game),
- ResultCode.UserNotInGame => Bot.SendWithMarkdown2(chatId, strings.user_not_in_game),
- ResultCode.RoomIsFilled => Bot.SendWithMarkdown2(chatId, strings.room_is_filled),
- ResultCode.RoomDoesNotExist => Bot.SendWithMarkdown2(chatId, strings.room_does_not_exists),
- ResultCode.RolesNotEqualPlayers => Bot.SendWithMarkdown2(chatId, strings.players_not_equal_roles),
- _ => Bot.SendWithMarkdown2(chatId, strings.unexpected_error)
- };
- }
- public static async Task<string> ToMarkdownString(string src)
- {
- return src != null
- ? await Task.Run(()=>
- {
- var newStr = src
- .Replace(".", "\\.")
- .Replace("#", "\\#")
- .Replace("[", "\\[")
- .Replace("]", "\\]")
- .Replace("|", "\\|")
- .Replace("!", "\\!")
- .Replace("-", "\\-");
- return newStr;
- }) : "";
- }
-
- public static async Task<string> EscapeSpecific(string src)
- {
- return src != null
- ? await Task.Run(()=>
- {
- var newStr = src
- .Replace("_", "\\_")
- .Replace("*", "\\*")
- .Replace("(", "\\(")
- .Replace(")", "\\)")
- .Replace("~", "\\~")
- .Replace("`", "\\`")
- .Replace(">", "\\>")
- .Replace("+", "\\+")
- .Replace("=", "\\=")
- .Replace("{", "\\{")
- .Replace("}", "\\}")
- .Replace("@", "\\@")
- .Replace("'", "\\'");
- return newStr;
- }) :"";
- }
- }
- }
|