コード例 #1
0
ファイル: Program.cs プロジェクト: NatShep/ChoTISkazal
        private static void BotClientOnOnUpdate(object sender, UpdateEventArgs e)
        {
            long?chatId = null;

            try
            {
                Botlog.WriteInfo($"Trying to got query: {e.Update.Type}...");

                if (e.Update.Message != null)
                {
                    chatId = e.Update.Message.Chat?.Id;
                    Botlog.WriteInfo($"Got query: {e.Update.Type}", chatId.ToString());
                    var chatRoom = GetOrCreate(e.Update.Message.Chat);
                    chatRoom?.ChatIo.OnUpdate(e.Update);
                }
                else if (e.Update.CallbackQuery != null)
                {
                    chatId = e.Update.CallbackQuery.Message.Chat?.Id;
                    Botlog.WriteInfo($"Got query: {e.Update.Type}", chatId.ToString());

                    var chatRoom = GetOrCreate(e.Update.CallbackQuery.Message.Chat);
                    chatRoom?.ChatIo.OnUpdate(e.Update);
                }
            }
            catch (Exception)
            {
                Botlog.WriteError(chatId, $"BotClientOnOnUpdate Failed: {e.Update.Type}", true);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: NatShep/ChoTISkazal
        private static void RunChatRoom(Chat chat, MainFlow newMain)
        {
            var task = newMain.Run();

            task.ContinueWith(
                (t) =>
            {
                Botlog.WriteError(chat.Id, $"Faulted {t.Exception}", true);
                Chats.TryRemove(chat.Id, out _);
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: NatShep/ChoTISkazal
        private static void OnBotWokeUp(Update update)
        {
            Telegram.Bot.Types.Chat chat = null;
            Telegram.Bot.Types.User user = null;
            try
            {
                if (update?.Message != null)
                {
                    chat = update.Message.Chat;
                    user = update.Message.From;
                }
                else if (update?.CallbackQuery != null)
                {
                    chat = update.CallbackQuery.Message.Chat;
                    user = update.CallbackQuery.From;
                }
                else
                {
                    return;
                }

                if (Chats.TryGetValue(chat.Id, out _))
                {
                    return;
                }

                var chatRoom = CreateChatRoom(chat);
                if (chatRoom == null)
                {
                    return;
                }
                chatRoom.ChatIo.SendMessageAsync(new EnglishTexts().DidYouWriteSomething).Wait();
                chatRoom.ChatIo.OnUpdate(
                    new Update {
                    Message = new Message {
                        Text = "/start", From = user
                    }
                });

                RunChatRoom(chat, chatRoom);
            }
            catch (Exception e)
            {
                Botlog.WriteError(chat?.Id, "WokeUpfailed" + e, true);
            }
        }