public static void OnNewSubscriber(object sender, OnNewSubscriberArgs e)
 {
     HandleNewSubscriber(sender, e, _viewerCollection.GetAsync("viewer-username", e.Subscriber.DisplayName.ToLowerInvariant()).GetAwaiter().GetResult().FirstOrDefault()?.Value).GetAwaiter().GetResult();
     _client.SendMessage(e.Channel,
                         e.Subscriber.SubscriptionPlan == SubscriptionPlan.Prime
             ? $"Welcome {e.Subscriber.DisplayName} to the {_account.TwitchBotSettings.CommunityName}! You just earned {_account.TwitchBotSettings.NewSubAwardAmount} {_account.TwitchBotSettings.PointsName}! May the Lords bless you for using your Twitch Prime!"
             : $"Welcome {e.Subscriber.DisplayName} to the {_account.TwitchBotSettings.CommunityName}! You just earned {_account.TwitchBotSettings.NewSubAwardAmount} {_account.TwitchBotSettings.PointsName}!");
 }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var appSettingsCollection = new CouchDbStore <ApplicationSettings>(ApplicationSettings.CouchDbUrl);
            var accountCollection     = new CouchDbStore <Account>(ApplicationSettings.CouchDbUrl);

            var appSettings = appSettingsCollection.GetAsync().Result.FirstOrDefault()?.Value;
            var account     = accountCollection.GetAsync("account-email", "*****@*****.**").Result.FirstOrDefault()?.Value;

            if (appSettings == null || account == null)
            {
                Console.WriteLine("Settings could not be found...");
                return;
            }

            var app = new KungBot(appSettings, account);

            try
            {
                app.Initialize();
                app.Configure();
            }
            catch (Exception e)
            {
                Console.WriteLine($"Configuration failed. \n{e.Message}\n{e.StackTrace}");
            }

            app.RunBotAsync().GetAwaiter().GetResult();
        }
Beispiel #3
0
        public void SetupTests()
        {
            var settingsCollection = new CouchDbStore <ApplicationSettings>(ApplicationSettings.CouchDbUrl);
            var settings           = settingsCollection.GetAsync().Result.FirstOrDefault()?.Value;

            _seClient         = new StreamElementsService(settings);
            _viewerCollection = new CouchDbStore <Viewer>(ApplicationSettings.CouchDbUrl);
        }
        public void TestTheShitThatWasJustAdded()
        {
            var results = _vodCollection.GetAsync().GetAwaiter().GetResult();
            var expectedTitlePartial = "Lil Tuggz";

            var video = results.FirstOrDefault(v => v.Value.Video.Title.Contains(expectedTitlePartial));

            Assert.IsNotNull(video);
            Assert.IsTrue(video.Value.Video.Title.Contains(expectedTitlePartial));
        }
        public BaseApiController(IConfiguration configuration)
        {
            Configuration = configuration;

            var configSettings = Configuration.GetSection("Settings");

            var settingCollection = new CouchDbStore <ApplicationSettings>(configSettings.GetSection("CouchDbUri").Value);

            TokenCollection = new CouchDbStore <Token>(configSettings.GetSection("CouchDbUri").Value);

            _settings = settingCollection.GetAsync().GetAwaiter().GetResult().FirstOrDefault()?.Value;

            GoogleClient = new GoogleService(_settings);
        }
        public async Task <string> GetVodByGame(string channelName, string game)
        {
            Video video;

            var dbVideos = (await _vodCollection.GetAsync()).ToList();

            if (!dbVideos.All(v => v.Value.Video.Channel.Name.Contains(channelName)))
            {
                var channelId = await _twitchClient.GetChannelIdFromChannelName(channelName);

                video = await _twitchClient.GetVideoFromChannelIdWithGame(channelId, game);
            }
            else
            {
                try
                {
                    var videoRow = dbVideos.Where(dbv => dbv.Value.Video.Game.Contains(game)).Select(v => v.Value)
                                   .FirstOrDefault();
                    video = videoRow?.Video;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            if (video == null)
            {
                return("No video for that game could be found. Please try another.");
            }

            var shortUrl = _googleService.UrlShortener.ShortenUrl($"https://www.twitch.tv/videos/{video.Id}");

            return($"{video.Title} - {shortUrl}");
        }
Beispiel #7
0
        public KungBot(TwitchClient client, TwitchPubSub twitchPubSub)
        {
            _client       = client;
            _twitchPubSub = twitchPubSub;

            var appSettingsCollection = new CouchDbStore <ApplicationSettings>(ApplicationSettings.CouchDbUrl);
            var accountCollection     = new CouchDbStore <Account>(ApplicationSettings.CouchDbUrl);

            _appSettings = appSettingsCollection.GetAsync().Result.FirstOrDefault()?.Value;
            _account     = accountCollection.GetAsync().Result.FirstOrDefault()?.Value;

            _viewerCollection = new CouchDbStore <Viewer>(ApplicationSettings.CouchDbUrl);

            var commandCollection = new CouchDbStore <Command>(ApplicationSettings.CouchDbUrl);

            _commandSettings = commandCollection.GetAsync().Result.Select(row => row.Value).ToList();
        }
Beispiel #8
0
        public void Perform(TwitchClient client, TwitchService service, ChatCommand chatCommand, Command command)
        {
            if (!command.IsActive)
            {
                return;
            }

            var _viewerCollection     = new CouchDbStore <Viewer>(ApplicationSettings.CouchDbUrl);
            var _viewerRankCollection = new CouchDbStore <ViewerRank>(ApplicationSettings.CouchDbUrl);

            var dbViewer  = (_viewerCollection.GetAsync("viewer-username", chatCommand.ChatMessage.Username).GetAwaiter().GetResult()).FirstOrDefault()?.Value;
            var viewRanks = _viewerRankCollection.GetAsync().GetAwaiter().GetResult();

            if (dbViewer != null)
            {
                var viewerRank = viewRanks
                                 .LastOrDefault(r => r.Value.ExperienceRequired <= dbViewer.Points)?.Value.RankName;

                client.SendMessage(chatCommand.ChatMessage.Channel, $"{chatCommand.ChatMessage.Username}, Your rank is {viewerRank}! You have {dbViewer.Points} experience! kungraHYPERS");
            }
        }
        public async Task <ActionResult> Get()
        {
            List <Row <Account> > accounts;

            try
            {
                var dbUsers = await _accountCollection.GetAsync();

                accounts = dbUsers.ToList();
                accounts.ForEach(account =>
                {
                    account.Value.Password     = string.Empty;
                    account.Value.PasswordSalt = string.Empty;
                });
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, Json(e)));
            }

            return(Json(accounts));
        }
Beispiel #10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure <ApplicationSettings>(Configuration);

            var configSettings     = Configuration.GetSection("Settings");
            var settingsCollection = new CouchDbStore <ApplicationSettings>(configSettings.GetSection("CouchDbUri").Value);

            var settings = settingsCollection.GetAsync().GetAwaiter().GetResult().FirstOrDefault()?.Value;

            services.AddResponseCaching(options =>
            {
                options.UseCaseSensitivePaths = true;
                options.MaximumBodySize       = 1024;
            });

            services.AddApiVersioning(api =>
            {
                api.DefaultApiVersion = new ApiVersion(1, 0);
                api.AssumeDefaultVersionWhenUnspecified = true;
                api.ReportApiVersions = true;
            });

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = "JwtBearer";
                options.DefaultChallengeScheme    = "JwtBearer";
            })
            .AddJwtBearer("JwtBearer", jwtBearerOptions =>
            {
                jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         =
                        new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settings?.Keys.JWTSecurityKey)),

                    ValidateIssuer = true,
                    ValidIssuer    = "kungraseri-api",

                    ValidateAudience = true,
                    ValidAudience    = "kungraseri-audience",

                    ValidateLifetime = true,
                    ClockSkew        = TimeSpan.FromMinutes(5)
                };
            });

            services.Configure <IISOptions>("api.kungraseri.ninja", options => { });
            services.AddMvc(options =>
            {
                options.CacheProfiles.Add("Default",
                                          new CacheProfile
                {
                    Duration = 60
                });
                options.CacheProfiles.Add("Never",
                                          new CacheProfile
                {
                    Location = ResponseCacheLocation.None,
                    NoStore  = true
                });
            });

            services.AddWebSocketManager();
        }
        public TwitchCommands()
        {
            var settingsCollection = new CouchDbStore <ApplicationSettings>(ApplicationSettings.CouchDbUrl);

            _settings = settingsCollection.GetAsync().Result.FirstOrDefault()?.Value;
        }