public async void Process(TwitchClient client, string username, string commandText, bool isMod, JoinedChannel joinedChannel)
        {
            var commandSplit = commandText.SplitCommandText();

            if (!commandSplit.Any() || commandSplit.Length != 1 || !commandSplit[0].Contains("@"))
            {
                client.SendMessage(joinedChannel, $"Hey @{username}, you need to @ someone to shout them out!");
                return;
            }

            var twitchApi = _twitchApiFactory.Get();

            // Query twitch api to ensure that this user exists.
            var apiResult = await twitchApi.Helix.Users.GetUsersAsync(logins : new List <string> {
                commandSplit[0].Trim('@')
            });

            var verifiedUser = apiResult.Users.FirstOrDefault();

            if (verifiedUser == null)
            {
                client.SendMessage(joinedChannel,
                                   $"Hey @{username}, I think you may have typed that username wrong! :O");
                return;
            }

            client.SendMessage(joinedChannel, $"Go check out the awesome {verifiedUser.DisplayName} over at https://twitch.tv/{verifiedUser.Login} Make sure to drop a follow and check them out when they're next live!");
        }
        public async void Process(TwitchClient client, string username, string commandText, bool isMod, JoinedChannel joinedChannel)
        {
            try
            {
                var twitchApi = _twitchApiFactory.Get();
                var users = await twitchApi.Helix.Users.GetUsersAsync(logins: new List<string>(new[] {username}));
                var userId = users.Users[0].Id;

                if (userId == null) return;

                var follows = await twitchApi.Helix.Users.GetUsersFollowsAsync(fromId:userId, toId: _configService.Get<string>("ChannelId"));

                var followedChannel = follows?.Follows?.SingleOrDefault();
                if (followedChannel == null) return;

                var monthsFollowed = Math.Abs(12 * (followedChannel.FollowedAt.Year - DateTime.UtcNow.Year) +
                                              followedChannel.FollowedAt.Month - DateTime.UtcNow.Month);

                client.SendMessage(joinedChannel,
                    $"Hey @{username}, you have followed {_configService.Get<string>("StreamerChannel")} for {monthsFollowed} months!");
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error in FollowageCommand");
            }
        }
示例#3
0
        public async void Process(TwitchClient client, string username, string commandText, bool isMod, JoinedChannel joinedChannel)
        {
            var twitchApi = _twitchApiFactory.Get();
            var Stream    = await twitchApi.V5.Streams.GetStreamByUserAsync(_configService.Get <string>("ChannelId"));

            var streamGoLiveTime = Stream?.Stream?.CreatedAt;

            if (streamGoLiveTime != null)
            {
                var timeLiveFor = DateTime.UtcNow.Subtract(streamGoLiveTime.Value.ToUniversalTime());

                client.SendMessage(joinedChannel, $"Hey @{username}, {_configService.Get<string>("StreamerChannel")} has been live for: {timeLiveFor.Hours} hours and {timeLiveFor.Minutes} minutes.");
            }
            else
            {
                client.SendMessage(joinedChannel,
                                   $"Hey @{username}, {_configService.Get<string>("StreamerChannel")} seems to be offline right now");
            }
        }
示例#4
0
        public async void UpdateModList()
        {
            var errorCounter = 0;

            try
            {
                var twitchApi         = _twitchApiFactory.Get();
                var moderatorResponse =
                    await twitchApi.Helix.Moderation.GetModeratorsAsync(_configService.Get <string>("ChannelId"),
                                                                        accessToken : _secretService.GetSecret <string>("ChatbotAccessToken"));

                _moderators = moderatorResponse.Data.Select(m => m.UserName.ToLower()).ToArray();
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Could not access Twitch Helix API resource.");
                errorCounter++;

                if (errorCounter > 5)
                {
                    Chatters.chatters.moderators = null;
                }
            }
        }
        private void Reconnect()
        {
            var api = _twitchApiFactory.Get();

            _monitorService = new LiveStreamMonitorService(api);
        }