示例#1
0
文件: Bot.cs 项目: jeffffc/BigTwoBot
 internal static Message Edit(long chatId, int oldMessageId, string text, IReplyMarkup replyMarkup = null, ParseMode parseMode = ParseMode.Html, bool disableWebPagePreview = true, bool disableNotification = false)
 {
     try
     {
         return(BotMethods.Edit(chatId, oldMessageId, text, replyMarkup, parseMode, disableWebPagePreview, disableNotification));
     }
     catch (Exception ex)
     {
         ex.LogError();
         return(null);
     }
 }
示例#2
0
文件: Bot.cs 项目: jeffffc/BigTwoBot
 internal static Message SendSticker(long chatId, FileToSend sticker, IReplyMarkup replyMarkup = null, ParseMode parseMode = ParseMode.Html, bool disableWebPagePreview = true, bool disableNotification = false)
 {
     return(BotMethods.SendSticker(chatId, sticker, replyMarkup, disableNotification));
 }
示例#3
0
        public void HandleQuery(CallbackQuery query, string[] args)
        {
            try
            {
                // args[0] = GameGuid
                // args[1] = playerId
                // args[2] = "card" or "row"
                // args[2] = cardChosen
                var p = Players.FirstOrDefault(x => x.TelegramId == int.Parse(args[1]));
                _playCardSecondsToAdd += 3;
                switch (args[2])
                {
                case "card":
                    var chosen = args[3];
                    if (chosen == "dummy")
                    {
                        Bot.Api.AnswerCallbackQueryAsync(query.Id);
                    }
                    else if (chosen == "skip")
                    {
                        if (CurrentHand.Count == 0)     // no cards, you can use any cards
                        {
                            Bot.Api.AnswerCallbackQueryAsync(query.Id, GetTranslation("UseAnything"), true);
                            return;
                        }
                        Bot.Edit(query.Message.Chat.Id, query.Message.MessageId, GetTranslation("Pass"), GroupMarkup);
                        p.UpdateChosenIndexes(empty: true);
                        p.CurrentQuestion = null;
                        return;
                    }
                    else if (chosen == "invalid")
                    {
                        Bot.Api.AnswerCallbackQueryAsync(query.Id, GetTranslation("InvalidHand"), true);
                        return;
                    }
                    else if (chosen == "go")
                    {
                        var chosenCards = p.Hand.Cards.Where(x => p.DealCardMenu.LastValidIndexes.Contains(x.Index)).ToList();
                        if (p.FirstPlayer && !chosenCards.Any(x => x.GameValue == 3 && x.Suit == BTCardSuit.Diamonds))
                        {
                            Bot.Api.AnswerCallbackQueryAsync(query.Id, GetTranslation("MustUseDiamondThree"), true);
                            return;
                        }
                        if (chosenCards.CheckChosenCards() == null)
                        {
                            Bot.Api.AnswerCallbackQueryAsync(query.Id, GetTranslation("PlayCheckAgain"), true);
                            p.DealCardMenu.UpdateMenu();
                            Bot.Api.EditMessageReplyMarkupAsync(query.Message.Chat.Id, query.Message.MessageId, p.DealCardMenu.MarkUp);
                            return;
                        }
                        var res = chosenCards.CompareHandWith(CurrentHand);
                        if (!res.Success)
                        {
                            Bot.Api.AnswerCallbackQueryAsync(query.Id, res.Reason.ToString(), true);
                            return;
                        }
                        var text = chosenCards.GetString();
                        Bot.Edit(query.Message.Chat.Id, query.Message.MessageId, text, GroupMarkup);
                        p.UseCards(chosenCards);
                        CurrentHand       = chosenCards.ToList();
                        CurrentHandType   = CurrentHand.CheckChosenCards();
                        CurrentDealer     = p;
                        p.CurrentQuestion = null;
                        return;
                    }
                    else if (chosen == "reset")
                    {
                        p.UpdateChosenIndexes(empty: true);
                    }
                    else if (chosen == "sort")
                    {
                        p.DealCardMenu.SortBySuit = !p.DealCardMenu.SortBySuit;
                        p.DealCardMenu.UpdateMenu();
                    }
                    else
                    {
                        var indexChosen = int.Parse(args[3]);
                        p.UpdateChosenIndexes(indexChosen);

                        var cardChosen = p.Hand.FirstOrDefault(x => x.Index == indexChosen);
                    }
                    Bot.Api.EditMessageReplyMarkupAsync(query.Message.Chat.Id, query.Message.MessageId, p.DealCardMenu.MarkUp);

                    break;

                case "refresh":
                    if (Phase == GamePhase.InGame)
                    {
                        var txt = GetTranslation("CardsInHand") + Environment.NewLine + p.Hand.ToList().GetString();
                        if (txt != p.DeckText)
                        {
                            p.DeckText = txt;
                            Bot.Edit(query.Message.Chat.Id, query.Message.MessageId, txt, GetRefreshMarkup(p));
                        }
                        else
                        {
                            BotMethods.AnswerCallback(query, GetTranslation("CardsNoChange"), true);
                        }
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                Bot.Send(query.From.Id, e.Message + e.StackTrace);
            }
        }
示例#4
0
文件: Bot.cs 项目: jeffffc/BigTwoBot
 internal static Message Send(long chatId, string text, IReplyMarkup replyMarkup = null, ParseMode parseMode = ParseMode.Html, bool disableWebPagePreview = true, bool disableNotification = false)
 {
     return(BotMethods.Send(chatId, text, replyMarkup, parseMode, disableWebPagePreview, disableNotification));
 }
示例#5
0
 public Message Reply(int oldMessageId, string msg)
 {
     return(BotMethods.Reply(ChatId, oldMessageId, msg));
 }