bool RollDices(TelegramBotClient bot, Message message, string messageBody) { messageBody = messageBody.Replace(" ", string.Empty); BigInteger number = 1, add = 0; if (!BigInteger.TryParse(messageBody, out BigInteger faces)) { Match match = new Regex(@"(?<number>\d+)[dD](?<faces>\d+)(?<add>\+\d+)?").Match(messageBody); if (!match.Success) { return(false); } number = BigInteger.Parse(match.Groups["number"].Value); faces = BigInteger.Parse(match.Groups["faces"].Value); add = match.Groups["add"].Success ? BigInteger.Parse(match.Groups["add"].Value) : 0; } Feature.Roll.Roll roll = new Feature.Roll.Roll(number, faces, add); bot.SendTextMessageAsync( message.Chat.Id, RollDicesMessage(roll), Telegram.Bot.Types.Enums.ParseMode.Markdown, replyToMessageId: message.MessageId ); return(true); }
private string RollDicesMessage(Feature.Roll.Roll roll) { StringBuilder builder = new StringBuilder(); builder.AppendLine("骰子骰子咕噜转…………"); if (roll.Number > 1 && roll.DiceResults != null) { builder.AppendLine("`" + string.Join(" + ", roll.DiceResults) + "`"); } builder.AppendLine($"结果是:{roll.RollResult}"); return(builder.ToString()); }