Esempio n. 1
0
        public override async Task <bool> Invoke(ChatMessage message)
        {
            var game = await _twitchApiHelper.GetStreamGame(message.Channel);

            if (game == null)
            {
                _twitchClient.SendMessage(message.Channel,
                                          "The streamer either is not online or does not have a game set!");

                return(await Task.FromResult(false));
            }

            if (game.Name != "Fortnite")
            {
                return(await Task.FromResult(false));
            }

            var fortniteStats = await _fortniteApi.Get();

            var totalWins = fortniteStats.LifeTimeStats.FirstOrDefault(s => s.Key == "Wins");

            if (totalWins == null)
            {
                return(await Task.FromResult(false));
            }

            _twitchClient.SendMessage(message.Channel, $"Total Fortnite Wins: {totalWins.Value}");

            return(await Task.FromResult(true));
        }
Esempio n. 2
0
        public override async Task <bool> Invoke(ChatMessage message)
        {
            var game = await _twitchApiHelper.GetStreamGame(message.Channel);

            if (game == null)
            {
                _twitchClient.SendMessage(message.Channel,
                                          "The streamer either is not online or does not have a game set!");

                return(await Task.FromResult(false));
            }

            var counter = _counterService.GetCounter($"{game.Name}Wins");

            _twitchClient.SendMessage(message.Channel,
                                      counter == null
                    ? $"There are no wins recorded for {game.Name}!"
                    : $"Current {game.Name} Wins: {counter.Count}");

            return(await Task.FromResult(true));
        }
Esempio n. 3
0
        /// <inheritdoc />
        /// <summary>
        ///     Get the currently streamed game.
        /// </summary>
        /// <param name="variableContext">Context of the variable.</param>
        /// <returns>Game name that is currently being streamed.</returns>
        public override async Task <string> GetValue(VariableContext variableContext)
        {
            var game = await _twitchApiHelper.GetStreamGame(variableContext.StreamerUserName);

            return(game == null ? "" : game.Name);
        }
Esempio n. 4
0
        public async Task Announce(IEnumerable <Host> hosts, ulong guildId, ulong channelId, ulong roleId)
        {
            var stopWatch = Stopwatch.StartNew();

            _logger.Information("Starting stream announcer");

            try
            {
                var guild = _discordClient.GetGuild(guildId);

                if (guild == null)
                {
                    _logger.Error("Could not find guild!");

                    return;
                }

                var channel = guild.GetTextChannel(channelId);

                if (channel == null)
                {
                    _logger.Error($"Could not find channel (ID = {channelId}) to announce streams!");

                    return;
                }

                var role = guild.GetRole(roleId);

                if (role == null)
                {
                    _logger.Error("Could not find host role!");

                    return;
                }

                var users = new Dictionary <Host, (User, Stream, Game)>();

                foreach (var host in hosts)
                {
                    var user = await _twitchApiHelper.GetUser(host.TwitchUsername);

                    if (user == null)
                    {
                        continue;
                    }

                    var stream = await _twitchApiHelper.GetStream(user);

                    if (stream == null)
                    {
                        continue;
                    }

                    var game = await _twitchApiHelper.GetStreamGame(stream);

                    if (game == null)
                    {
                        continue;
                    }

                    // Only announce Fortnite and Zone Wars
                    if (game.Name != "Fortnite" ||
                        !_settings.CreativeStreamTitles.Any(x =>
                                                            stream.Title.StartsWith(x, StringComparison.InvariantCultureIgnoreCase) ||
                                                            stream.Title.StartsWith(
                                                                $"Viewer{x}", StringComparison.InvariantCultureIgnoreCase) ||
                                                            stream.Title.StartsWith($"Enigma {x}", StringComparison.InvariantCultureIgnoreCase) ||
                                                            stream.Title.StartsWith($"Enigma's {x}", StringComparison.InvariantCultureIgnoreCase)))
                    {
                        continue;
                    }

                    users.Add(host, (user, stream, game));
                }

                // Delete all previous messages from the bot
                var message =
                    (await channel.GetMessagesAsync().FlattenAsync()).FirstOrDefault(m =>
                                                                                     m.Author.Id == _discordClient.CurrentUser.Id) as RestUserMessage;

                if (message == null)
                {
                    _logger.Information("Sending new announcement message");

                    await channel.SendMessageAsync(string.Empty,
                                                   embed : EmbedHelper.GetStreamAnnouncementEmbed("Verified Hosts", "No verified hosts are online!",
                                                                                                  role.Color, users));
                }

                if (message != null)
                {
                    _logger.Information("Editing announcement message");

                    await message.ModifyAsync(msg =>
                    {
                        msg.Content = string.Empty;
                        msg.Embed   = EmbedHelper.GetStreamAnnouncementEmbed("Verified Hosts",
                                                                             "No verified hosts are online!",
                                                                             role.Color, users);
                    });
                }
            }
            catch (Exception exception)
            {
                _logger.Error(exception, $"Error occured while announcing streams: {exception}");
            }

            stopWatch.Stop();
            _logger.Information($"Finished stream announcer ({stopWatch.ElapsedMilliseconds}ms)");
        }