public void ImgurSetup() { string imgID = REGISTY.GetString("imgur_id"); string imgSec = REGISTY.GetString("imgur_secret"); if (string.IsNullOrWhiteSpace(imgID) || string.IsNullOrWhiteSpace(imgSec)) { Write("Please enter Imgur API information:"); imgID = GetInput("Imgur API ID"); imgSec = GetInput("Imgur API Sec"); } Write("Connecting to imgur... ", false); try { _imgurClient = new ImgurClient(imgID, imgSec); albumEndpoint = new AlbumEndpoint(_imgurClient); } catch (Exception e) { Write("Failed!"); Write(e.Message); _imgurClient = null; } Write("Done!"); REGISTY.SetValue("imgur_id", imgID); REGISTY.SetValue("imgur_secret", imgSec); }
public void Setup() { try { Write("Connecting to reddit... ", false); string user = REGISTY.GetString("reddit_user"); string pass = REGISTY.GetString("reddit_pass"); if (string.IsNullOrWhiteSpace(user) || string.IsNullOrWhiteSpace(pass)) { Write("Please enter your reddit Credentials"); user = GetInput("Username"); pass = GetInput("Pass", true); } try { _reddit = new Reddit(); //TODO: implement OAuth }catch (Exception e) { Write("Failed!"); Write(e.Message); Write("Try again"); return; } Write("Done!"); REGISTY.SetValue("reddit_user", user); REGISTY.SetValue("reddit_pass", pass); ImgurSetup(); Write("Loading Prefs... ", false); if (!string.IsNullOrWhiteSpace(REGISTY.GetString("baseDir"))) { baseDir = REGISTY.GetString("baseDir"); } if (REGISTY.GetInt("updateRate") != null) { updateRate = (int)REGISTY.GetInt("updateRate"); } int c; if (REGISTY.GetInt("reddit_postsToGet") == null) { c = 100; } else { c = (int)REGISTY.GetInt("reddit_postsToGet"); } postsToGet = c; string mode = REGISTY.GetString("reddit_searchMode"); SetSearchMode(string.IsNullOrWhiteSpace(mode) ? "new" : mode); LoadSubs(); Write("Done!"); } catch (Exception e) { Write("Failed to Start" + e.Message); Write(e.StackTrace); } }
//Set Save Dir public void SetSaveDir(string dir) { if (_reddit == null || _imgurClient == null) { Setup(); } baseDir = dir; REGISTY.SetValue("baseDir", dir); }
private void LoadSubs() { string oldData = REGISTY.GetString("reddit_subs"); if (!string.IsNullOrWhiteSpace(oldData)) { subreddits.AddRange(oldData.Split('|')); } }
//Set Update Rate public void SetUpdateRate(string rate) { if (_reddit == null || _imgurClient == null) { Setup(); } int updateRate; if (int.TryParse(rate, out updateRate)) { this.updateRate = updateRate * 60 * 1000; } REGISTY.SetValue("updateRate", this.updateRate); }
private void SaveSubs() { string subs = ""; foreach (string s in subreddits) { if (subs == "") { subs += s; } else { subs += "|" + s; } } REGISTY.SetValue("reddit_subs", subs); }
public CrawlerCommand() : base("crawl", "Connects to reddit and downloads images from specified subreddits") { bool?auto = REGISTY.GetBool("redditAutostart"); _autoStart = (auto == null) ? false : (auto == true) ? true : false; crawler = new RedditCrawler(); RegisterOption('c', crawler.SetPostsToGet, "Sets the number of posts to get"); RegisterOption('v', crawler.SetVerbose, "Toggles Verbose logging mode"); RegisterOption('a', crawler.AddSub, "Add a subredit"); RegisterOption('m', crawler.SetSearchMode, "Set the search mode"); RegisterOption('r', crawler.RemoveSub, "Remove a subreddit"); RegisterOption('f', crawler.SetGetFrom, "Sets a single subreddit to be crawled from"); RegisterOption('d', crawler.SetSaveDir, "Sets the save location for images"); RegisterOption('t', crawler.SetUpdateRate, "Sets the interval at which the bot will cycle in minutes"); RegisterOption('i', crawler.AlbumDownload, "Downloads and album from imgur"); RegisterKeyword("get", crawler.Get, "Get images from subreddit(s) without looping"); RegisterKeyword("list", crawler.ListSubs, "Shows the list of all subreddits to be searched"); RegisterKeyword("status", crawler.Status, "Shows the current status of the bot"); RegisterKeyword("start", crawler.Start, "Start a crawl of all subreddits on the list at a set interval"); RegisterKeyword("stop", crawler.Stop, "Stop all processes"); RegisterKeyword("autostart", () => { _autoStart = !_autoStart; REGISTY.SetValue("redditAutostart", _autoStart); Write("Autostart " + ((_autoStart) ? "enabled" : "disabled")); }, "enable/disable autostart"); RegisterKeyword("imgur", () => { Write("Reset Imgur"); REGISTY.SetValue("imgur_id", ""); REGISTY.SetValue("imgur_secret", ""); crawler.ImgurSetup(); }, "Link Imgur API"); init = () => { if (_autoStart) { crawler.Start(); } }; }
public RinDBCommand() : base("rindb", "RinDB server side") { _default = Default; bool?auto = REGISTY.GetBool("RinDB.autoStart"); _autoStart = (auto == null) ? false : (auto == true) ? true : false; RegisterKeyword("stop", Stop, "stops the bot"); RegisterKeyword("autostart", () => { _autoStart = !_autoStart; REGISTY.SetValue("RinDB.autoStart", _autoStart); Write($"Autostart {((_autoStart) ? "enabled" : "disabled")}"); }, "enable/disable autostart"); RegisterKeyword("rebuild", Rebuild, "Rebuild the database"); RegisterKeyword("addTag", AddTag, "Add a tag to the database"); RegisterKeyword("build", Build, "Add the files in a specified folder to the database"); RegisterKeyword("genThumbs", GenerateThumbs, "Generate thumbnails"); RegisterOption('u', u => { _dbUser = u; REGISTY.SetValue("RinDB.user", u); }, "Sets the database user"); RegisterOption('p', p => { _dbPass = p; REGISTY.SetValue("RinDB.pass", p); }, "Sets the database password"); RegisterOption('d', d => { _dbName = d; REGISTY.SetValue("RinDB.name", d); }, "Sets the database name"); RegisterOption('l', l => _buildDir = l, "Specify the directory to add to the database"); RegisterOption('n', n => _buildNsfw = n.ToLower(), "Specify is the current build is nsfw"); RegisterOption('t', t => _buildTag = t, "Specify a tag"); RegisterOption('i', i => _tagInfo = i, "Specfiy tag info"); RegisterOption('y', y => _tagType = y.ToLower(), "Specfiy tage type; tag | character | artist | work | meta"); _dbUser = REGISTY.GetString("RinDB.user"); _dbPass = REGISTY.GetString("RinDB.pass"); _dbName = REGISTY.GetString("RinDB.name"); init = () => { if (_autoStart) { _default(); } }; }