예제 #1
0
        // ReSharper disable once SuggestBaseTypeForParameter
        public DanbooruModule(Danbooru booru, BooruRepository repository, SubscriptionService service, IOptionsSnapshot <BooruOptions> options) : base(repository)
        {
            this._service = service;
            this.Booru    = booru;

            var opts = options.Get("danbooru");

            if (!opts.Username.IsEmpty())
            {
                this.Booru.WithAuthentication(opts.Username, opts.ApiKey);
            }
        }
예제 #2
0
 // ReSharper disable once SuggestBaseTypeForParameter
 public KonachanModule(KonaChan booru, BooruRepository repository, SubscriptionService service) : base(repository)
 {
     this._service = service;
     this.Booru    = booru;
 }
예제 #3
0
 // ReSharper disable once SuggestBaseTypeForParameter
 public YandereModule(Yandere booru, BooruRepository repository, SubscriptionService service) : base(repository)
 {
     this._service = service;
     this.Booru    = booru;
 }
예제 #4
0
        public static void Main(string[] args)
        {
            Cancellation.Token.Register(() => MRE.Set());
            Console.CancelKeyPress += (s, e) => { e.Cancel = true; Cancellation.Cancel(); };
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;



            Log($@"KotoriNSFW v{Version}", ConsoleColor.Green);
            Log(@"THis is still experimental, don't look at it.");
            Log(@"WARNING: THIS WILL POST NSFW EVEN IF BOT_RATING IS SET TO S", ConsoleColor.DarkRed);
            Log(@"Press any key if you understand and are ok with this...");
            Console.ReadKey();

            LogHeader(@"Creating database manager...");
            Database = new DatabaseManager();

            LogHeader(@"Running migrations...");
            Database.RunMigrations();

            MigrateIni();

            if (string.IsNullOrEmpty(Database.ReadConfig(@"twitter_consumer_key")))
            {
                LogHeader(@"Set up Twitter API keys...");
                Log(@"Please enter your Twitter Consumer Key:");
                Database.WriteConfig(@"twitter_consumer_key", Console.ReadLine());
                Log(@"And now your Twitter Consumer Secret:");
                Database.WriteConfig(@"twitter_consumer_secret", Console.ReadLine());
            }

            LogHeader(@"Creating booru clients...");

            IBooru[] boorus = new IBooru[] {
                new Danbooru(HttpClient),
                new Gelbooru(HttpClient),
                new Safebooru(HttpClient),
                new Yandere(HttpClient),
                new Konachan(HttpClient),
            };
            IConsumerCredentials cc = new ConsumerCredentials(
                Database.ReadConfig(@"twitter_consumer_key"),
                Database.ReadConfig(@"twitter_consumer_secret")
                );

            LogHeader(@"Creating bots...");

            lock (Bots)
                foreach (TwitterBotInfo botInfo in Database.GetBots())
                {
                    if (Cancellation.IsCancellationRequested)
                    {
                        break;
                    }

                    ITwitterCredentials creds;

                    if (string.IsNullOrEmpty(botInfo.AccessToken) || string.IsNullOrEmpty(botInfo.AccessTokenSecret))
                    {
                        IAuthenticationContext ac = TwitterClient.BeginCreateClient(cc);
                        Log();
                        Log($@"====> Authenticate {botInfo.Name} <====", ConsoleColor.Yellow);
                        Log(ac.AuthorizationURL);
                        Log(@"Enter the pin code you received:");

                        string pin = Console.ReadLine();
                        creds = TwitterClient.EndCreateClient(ac, pin);
                    }
                    else
                    {
                        creds = new TwitterCredentials(cc.ConsumerKey, cc.ConsumerSecret, botInfo.AccessToken, botInfo.AccessTokenSecret);
                    }

                    TwitterBot bot = new TwitterBot(
                        Database,
                        boorus,
                        botInfo,
                        new TwitterClient(creds)
                        );
                    bot.SaveCredentials();
                    Bots.Add(bot);
                }

            LogHeader(@"Checking cache for all bots...");
            lock (Bots)
                foreach (TwitterBot bot in Bots)
                {
                    if (!bot.EnsureCacheReady())
                    {
                        Log($@"Refreshing cache for {bot.Name}, this may take a little bit...");
                        bot.RefreshCache();
                    }
                }

#if DEBUG
            Run();
            Console.ReadLine();
#else
            Log($@"Posting after {UntilNextRun}, then a new post will be made every {Interval}!", ConsoleColor.Magenta);
            StartTimer(Run);
            MRE.WaitOne();
#endif

            lock (Bots)
                foreach (TwitterBot bot in Bots)
                {
                    bot.Dispose();
                }

            Database.Dispose();
        }