Exemple #1
0
        static ChatRoomFlow GetOrCreate(Telegram.Bot.Types.Chat chat)
        {
            if (_chats.TryGetValue(chat.Id, out var existedChatRoom))
            {
                return(existedChatRoom);
            }

            var newChat     = new Chat(_botClient, chat);
            var newChatRoom = new ChatRoomFlow(newChat)
            {
                YaDictionaryApi = _yapiDicClient,
                YaTranslateApi  = _yapiTransClient,
                WordsService    = _wordsService
            };
            var task = newChatRoom.Run();

            task.ContinueWith((t) => Botlog.Write($"faulted {t.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
            _chats.TryAdd(chat.Id, newChatRoom);
            return(null);
        }
Exemple #2
0
        private static ChatRoomFlow GetOrCreate(Telegram.Bot.Types.Chat chat)
        {
            if (Chats.TryGetValue(chat.Id, out var existedChatRoom))
            {
                return(existedChatRoom);
            }

            var newChatRoom = new ChatRoomFlow(
                new ChatIO(_botClient, chat),
                new TelegramUserInfo(chat.Id, chat.FirstName, chat.LastName, chat.Username),
                _settings,
                _addWordService,
                _userWordService,
                _userService);

            var task = newChatRoom.Run();

            task.ContinueWith((t) => Botlog.Error(chat.Id, $"Faulted {t.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
            Chats.TryAdd(chat.Id, newChatRoom);
            return(newChatRoom);
        }