Ejemplo n.º 1
0
        /// <summary>
        /// Initialises and loads all trackers
        /// </summary>
        public static void initTracking()
        {
            if (!init)
            {
                HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
                ServicePointManager.ServerCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => { return(true); };
                ServicePointManager.SecurityProtocol             = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
                HttpClient.DefaultRequestHeaders.ConnectionClose = true;
                HttpClient.Timeout = TimeSpan.FromSeconds(10);
                ServicePointManager.DefaultConnectionLimit  = 100;
                ServicePointManager.MaxServicePointIdleTime = 10000;

                Auth.SetUserCredentials(Program.Config["TwitterKey"], Program.Config["TwitterSecret"],
                                        Program.Config["TwitterToken"], Program.Config["TwitterAccessSecret"]);
                TweetinviConfig.CurrentThreadSettings.TweetMode = TweetMode.Extended;
                TweetinviConfig.ApplicationSettings.TweetMode   = TweetMode.Extended;
                Tweetinvi.ExceptionHandler.SwallowWebExceptions = false;
                Tweetinvi.RateLimit.RateLimitTrackerMode        = RateLimitTrackerMode.TrackOnly;
                TweetinviEvents.QueryBeforeExecute += Data.Tracker.TwitterTracker.QueryBeforeExecute;
                Tweetinvi.Logic.JsonConverters.JsonPropertyConverterRepository.JsonConverters.Remove(typeof(Tweetinvi.Models.Language));
                Tweetinvi.Logic.JsonConverters.JsonPropertyConverterRepository.JsonConverters.Add(typeof(Tweetinvi.Models.Language), new CustomJsonLanguageConverter());

                Trackers = new Dictionary <BaseTracker.TrackerType, Data.TrackerWrapper>();
                Trackers[BaseTracker.TrackerType.Twitter]     = new TrackerHandler <TwitterTracker>(1800000);
                Trackers[BaseTracker.TrackerType.Youtube]     = new TrackerHandler <YoutubeTracker>(3600000);
                Trackers[BaseTracker.TrackerType.Twitch]      = new TrackerHandler <TwitchTracker>(3600000);
                Trackers[BaseTracker.TrackerType.YoutubeLive] = new TrackerHandler <YoutubeLiveTracker>(900000);
                Trackers[BaseTracker.TrackerType.Reddit]      = new TrackerHandler <RedditTracker>();
                Trackers[BaseTracker.TrackerType.JSON]        = new TrackerHandler <JSONTracker>(updateInterval: 600000);
                Trackers[BaseTracker.TrackerType.Osu]         = new TrackerHandler <OsuTracker>();
                Trackers[BaseTracker.TrackerType.Overwatch]   = new TrackerHandler <OverwatchTracker>(3600000);
                Trackers[BaseTracker.TrackerType.TwitchGroup] = new TrackerHandler <TwitchGroupTracker>(60000);
                Trackers[BaseTracker.TrackerType.TwitchClip]  = new TrackerHandler <TwitchClipTracker>();
                Trackers[BaseTracker.TrackerType.OSRS]        = new TrackerHandler <OSRSTracker>();
                Trackers[BaseTracker.TrackerType.HTML]        = new TrackerHandler <HTMLTracker>();
                Trackers[BaseTracker.TrackerType.RSS]         = new TrackerHandler <RSSTracker>(3600000);
                Trackers[BaseTracker.TrackerType.Steam]       = new TrackerHandler <SteamTracker>();

                foreach (var tracker in Trackers)
                {
                    var trackerType = tracker.Key;

                    if (tracker.Key == BaseTracker.TrackerType.Twitch)
                    {
                        Task.Run(() => TwitchTracker.ObtainTwitchToken());
                        Task.Run(() =>
                        {
                            tracker.Value.PostInitialisation();
                            Trackers[BaseTracker.TrackerType.TwitchGroup].PostInitialisation();
                            TwitchGuilds = Database.GetCollection <Data.Entities.TwitchGuild>("TwitchGuilds").FindSync(x => true).ToEnumerable().ToDictionary(x => x.DiscordId);
                            TwitchUsers  = Database.GetCollection <Data.Entities.TwitchUser>("TwitchUsers").FindSync(x => true).ToEnumerable().ToDictionary(x => x.GuildPlusDiscordId);
                            foreach (var user in TwitchUsers)
                            {
                                user.Value.PostInitialisation();
                            }
                        });
                    }
                    else if (tracker.Key == BaseTracker.TrackerType.YoutubeLive)
                    {
                        Task.Run(() =>
                        {
                            tracker.Value.PostInitialisation();
                            YoutubeLiveTracker.fetchChannelsBatch().Wait();
                        });
                    }
                    else if (tracker.Key != BaseTracker.TrackerType.TwitchGroup)
                    {
                        Task.Run(() => tracker.Value.PostInitialisation());
                    }

                    Program.MopsLog(new LogMessage(LogSeverity.Info, "Tracker init", $"Initialising {trackerType.ToString()}"));
                    Task.Delay((int)(60000 / Trackers.Count)).Wait();
                }

                try{
                    ChannelJanitors = MopsBot.Data.Entities.ChannelJanitor.GetJanitors().Result;
                    Program.MopsLog(new LogMessage(LogSeverity.Error, "React init", $"Janitors started")).Wait();
                    WelcomeMessages = Database.GetCollection <Data.Entities.WelcomeMessage>("WelcomeMessages").FindSync(x => true).ToEnumerable().ToDictionary(x => x.GuildId);
                    Program.MopsLog(new LogMessage(LogSeverity.Error, "React init", $"Welcome messages loaded")).Wait();
                    ReactRoleJoin = new ReactionRoleJoin();
                    Program.MopsLog(new LogMessage(LogSeverity.Error, "React init", $"React role joins loaded")).Wait();
                    ReactGiveaways = new ReactionGiveaway();
                    Program.MopsLog(new LogMessage(LogSeverity.Error, "React init", $"React giveaways loaded")).Wait();
                } catch (Exception e) {
                    Program.MopsLog(new LogMessage(LogSeverity.Error, "React init", $"Weird thing happened", e)).Wait();
                }

                init = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialises and loads all trackers
        /// </summary>
        public static void initTracking()
        {
            if (!init)
            {
                HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
                ServicePointManager.ServerCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => { return(true); };
                ServicePointManager.SecurityProtocol             = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
                HttpClient.DefaultRequestHeaders.ConnectionClose = true;
                HttpClient.Timeout = TimeSpan.FromSeconds(10);
                ServicePointManager.DefaultConnectionLimit  = 100;
                ServicePointManager.MaxServicePointIdleTime = 10000;

                Auth.SetUserCredentials(Program.Config["TwitterKey"], Program.Config["TwitterSecret"],
                                        Program.Config["TwitterToken"], Program.Config["TwitterAccessSecret"]);
                TweetinviConfig.CurrentThreadSettings.TweetMode = TweetMode.Extended;
                TweetinviConfig.ApplicationSettings.TweetMode   = TweetMode.Extended;
                Tweetinvi.ExceptionHandler.SwallowWebExceptions = false;
                Tweetinvi.RateLimit.RateLimitTrackerMode        = RateLimitTrackerMode.TrackOnly;
                TweetinviEvents.QueryBeforeExecute += Data.Tracker.TwitterTracker.QueryBeforeExecute;
                Tweetinvi.Logic.JsonConverters.JsonPropertyConverterRepository.JsonConverters.Remove(typeof(Tweetinvi.Models.Language));
                Tweetinvi.Logic.JsonConverters.JsonPropertyConverterRepository.JsonConverters.Add(typeof(Tweetinvi.Models.Language), new CustomJsonLanguageConverter());

                Trackers = new Dictionary <BaseTracker.TrackerType, Data.TrackerWrapper>();
                //Trackers[BaseTracker.TrackerType.Twitter] = new TrackerHandler<TwitterTracker>(1800000);
                //Trackers[BaseTracker.TrackerType.Youtube] = new TrackerHandler<YoutubeTracker>(3600000);
                Trackers[BaseTracker.TrackerType.Twitch] = new TrackerHandler <TwitchTracker>(3600000);
                //Trackers[BaseTracker.TrackerType.YoutubeLive] = new TrackerHandler<YoutubeLiveTracker>(900000);
                //Trackers[BaseTracker.TrackerType.Mixer] = new TrackerHandler<MixerTracker>();
                //Trackers[BaseTracker.TrackerType.Reddit] = new TrackerHandler<RedditTracker>();
                //Trackers[BaseTracker.TrackerType.JSON] = new TrackerHandler<JSONTracker>(updateInterval: 600000);
                //Trackers[BaseTracker.TrackerType.Osu] = new TrackerHandler<OsuTracker>();
                //Trackers[BaseTracker.TrackerType.Overwatch] = new TrackerHandler<OverwatchTracker>(3600000);
                //Trackers[BaseTracker.TrackerType.TwitchClip] = new TrackerHandler<TwitchClipTracker>();
                //Trackers[BaseTracker.TrackerType.OSRS] = new TrackerHandler<OSRSTracker>();
                //Trackers[BaseTracker.TrackerType.HTML] = new TrackerHandler<HTMLTracker>();
                //Trackers[BaseTracker.TrackerType.RSS] = new TrackerHandler<RSSTracker>(3600000);
                //Trackers[BaseTracker.TrackerType.Steam] = new TrackerHandler<SteamTracker>();*/

                foreach (var tracker in Trackers)
                {
                    var trackerType = tracker.Key;

                    if (tracker.Key == BaseTracker.TrackerType.Twitch)
                    {
                        Task.Run(() => TwitchTracker.ObtainTwitchToken());
                        Task.Run(() =>
                        {
                            tracker.Value.PostInitialisation();
                        });
                    }
                    else if (tracker.Key == BaseTracker.TrackerType.YoutubeLive)
                    {
                        Task.Run(() =>
                        {
                            tracker.Value.PostInitialisation();
                            YoutubeLiveTracker.fetchChannelsBatch().Wait();
                        });
                    }
                    else if (tracker.Key != BaseTracker.TrackerType.TwitchGroup)
                    {
                        Task.Run(() => tracker.Value.PostInitialisation());
                    }

                    Program.MopsLog(new LogMessage(LogSeverity.Info, "Tracker init", $"Initialising {trackerType.ToString()}"));
                    Task.Delay((int)(60000 / Trackers.Count)).Wait();
                }

                BotCommunication.StartServer();
            }
        }