public readonly string botRating; //added new string public TwitterBot(DatabaseManager db, IEnumerable <IBooru> boorus, TwitterBotInfo info, TwitterClient client) { Id = info.Id; Name = info.Name; Rating = info.Rating; botRating = info.botRating; // added new string Database = db; Boorus = boorus; Client = client; }
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(); }