예제 #1
0
 public Bot(TwitterService twitter, TraceMoeService traceMoe, long?cutOff, int?wait, int?throughput)
 {
     _twitter     = twitter;
     _traceMoe    = traceMoe;
     _searchQueue = new Queue <Search>();
     _throughput  = throughput ?? 2;
     _cutOff      = cutOff / 100d ?? 0.7d;
     _wait        = wait ?? 1000 * 60 * 1; //Wait for a minute
     _adultTags   = new[] { "#nsfw", "#adult", "#p**n", "#hentai" };
 }
예제 #2
0
        static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         //.WriteTo.File("manga_sauce_bot.log")
                         .CreateLogger();
            var root   = Directory.GetCurrentDirectory();
            var dotenv = Path.Combine(root, ".env");

            DotEnv.Load(dotenv);
            var apiKey = DotEnv.Get("TRACE_MOE_API_KEY");
            var manga  = new TraceMoeService(
                "https://api.trace.moe",
                "https://media.trace.moe",
                apiKey);

            var mentionsContext = DotEnv.GetAsBool("USE_SQLITE")
                ? new MentionsContext(true)
                : new MentionsContext(
                DotEnv.Get("COSMOS_DB_ACCOUNT_ENDPOINT"),
                DotEnv.Get("COSMOS_DB_ACCOUNT_KEY"),
                DotEnv.Get("COSMOS_DB_DATABASE_NAME"));

            var repository = new MentionsRepository(
                mentionsContext);
            var twitter = new TwitterService(
                DotEnv.Get("TWITTER_CONSUMER_KEY"),
                DotEnv.Get("TWITTER_CONSUMER_SECRET"),
                DotEnv.Get("TWITTER_TOKEN"),
                DotEnv.Get("TWITTER_TOKEN_SECRET"),
                repository);

            var bot = new Bot(
                twitter,
                manga,
                DotEnv.GetAsLong("SEARCH_SIMILARITY_CUTOFF"),
                DotEnv.GetAsInt("BOT_SLEEP_TIMEOUT"),
                DotEnv.GetAsInt("BOT_REPLY_THROUGHPUT"));

            var runOnce = "true".Equals(DotEnv.Get("BOT_RUN_ONCE"));

            while (true)
            {
                try
                {
                    await bot.Run(runOnce);
                }
                catch (Exception e)
                {
                    Log.Error(e, "Exiting");
                    throw;
                }
            }
        }