コード例 #1
0
        public async Task <UserMessagesResult> UserMessages(string user, int skip = 0, int count = 25)
        {
            var userInfo = await twitchApiService.GetChannelByName(user);

            if (userInfo == null)
            {
                throw new ArgumentException($"User {user} not found");
            }

            var messages = await messageRepository.GetMessages(uint.Parse(userInfo.Id), skip, count + 1);

            var messagesToReturn = messages.Take(count);
            var isMoreExist      = messages.Count > count;

            return(new UserMessagesResult(messagesToReturn, isMoreExist));
        }
コード例 #2
0
        protected override async Task Handle(NewChannelCommand request, CancellationToken cancellationToken)
        {
            var chatId      = request.ChatId;
            var channelName = request.ChannelName;

            var channel = await twitchApiService.GetChannelByName(channelName);

            if (channel == null)
            {
                await telegramBotClient.SendTextMessageAsync(
                    chatId : chatId,
                    text : $"Channel '{channelName}' was not found.",
                    parseMode : ParseMode.Html,
                    cancellationToken : cancellationToken
                    );

                return;
            }

            var alreadyExist = await userRepository.AddChannelToTrack(channel);

            if (alreadyExist)
            {
                await telegramBotClient.SendTextMessageAsync(
                    chatId : chatId,
                    text : $"Channel '{channelName}' has already been tracking.",
                    parseMode : ParseMode.Html,
                    cancellationToken : cancellationToken
                    );
            }
            else
            {
                await twitchBotOrchestratorClient.JoinChannelAsync(
                    new JoinChannelRequest { Channelname = channelName },
                    cancellationToken : cancellationToken);

                await telegramBotClient.SendTextMessageAsync(
                    chatId : chatId,
                    text : $"Channel '{channelName}' successfully added.",
                    parseMode : ParseMode.Html,
                    cancellationToken : cancellationToken
                    );
            }
        }