From 5fd2a3923f4218bd873b3604ce1778dd3af6523e Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Fri, 17 May 2013 17:04:53 +0000 Subject: [PATCH 1/4] Add tracking for a certain hash This is a fairly simple hack to record any imgur URLs discovered via the random image facility that match a certain MD5 hash. A known bug with this commit is that it may crash the bot the first time the bot tries to add to the database, as the category is undefined. This can be easily worked around by ensuring that the category is prepopulated with at least one image before letting the bot add automatically. An issue should probably be opened to merge this code into something reading hashes from a configuration file: it's pretty hardcoded at the moment. --- modules/imgur/imgur.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/imgur/imgur.js b/modules/imgur/imgur.js index b412d4c..a546314 100644 --- a/modules/imgur/imgur.js +++ b/modules/imgur/imgur.js @@ -52,6 +52,14 @@ var imgur = function(dbot) { if(!error && response.statusCode == 200 && body.length != 492) { this.db.totalImages += 1; var hash = crypto.createHash('md5').update(body).digest("hex"); + if((hash == "e49e686582ce3f60cb51d00c10924861") && _.has(dbot.modules, 'quotes')){ + var qdb = dbot.db.quoteArrs["facebookman"]; + if (_.include(qdb, testUrl)){ + // do something + } else { + qdb.push(testUrl); + } + } callback(testUrl, testSlug,hash); } else { this.api.getRandomImage(callback); From fb24c4d8eef55ed5d925f47216c38efcaed32af3 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Mon, 20 May 2013 11:25:27 +0000 Subject: [PATCH 2/4] Add 5s timer functionality to random imgur * Add [.] key to enable timer * "Loading..." message turns red and italic when timer is active * Press [.] key to disable timer. After a bit of experimentation, 5s seemed optimal: 2 seconds would cause the imgur api to trip if the app is used more than once at a time; 5 seconds is enough time to view the image without feeling particularly slow. Maximums: 1 images in 5 seconds 3600 images in 5 minutes 43200 images in an hour --- public/imgurr.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/public/imgurr.js b/public/imgurr.js index 5c03f60..f8e5d41 100644 --- a/public/imgurr.js +++ b/public/imgurr.js @@ -49,6 +49,7 @@ function getNewImage() { $(getNewImage()); +var t; $(document).on('keydown', function(e){ switch(e.which){ case 82: // r @@ -72,5 +73,21 @@ $(document).on('keydown', function(e){ case 83: // s $('body').toggleClass('crop'); giveMessage("Toggled scrollbars.") + break; + case 190: // . + if(!t){ + giveMessage("Automation on."); + $('#loading').css("font-style", "italic"); + $('#loading').css("color","#BF2527"); + t = setInterval(function(){ + getNewImage(); + },5000); + } else { + giveMessage("Automation off."); + $('#loading').css("font-style","normal"); + $('#loading').css("color","#85BF25"); + clearTimeout(t); + t = undefined; + } }; }); From be1ea0acde8f97298c8bd8b01c88b13009cfc14f Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Mon, 20 May 2013 15:18:19 +0000 Subject: [PATCH 3/4] Adding config option to auto-add hashes to qdb This should be useful for keeping track of certain massively duplicated images. --- modules/imgur/config.json | 6 +++++- modules/imgur/imgur.js | 15 +++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/imgur/config.json b/modules/imgur/config.json index cc20a5d..853aa84 100644 --- a/modules/imgur/config.json +++ b/modules/imgur/config.json @@ -4,5 +4,9 @@ "imagelength": 5, "nsfwwarn": true, "apikey": "86fd3a8da348b65", - "highscore": "ricount" + "highscore": "ricount", + "autoadd": { + "e49e686582ce3f60cb51d00c10924861": "facebookman", + "b11b634c74562bcd4e5d17b0d90987be": "raffleguy" + } } diff --git a/modules/imgur/imgur.js b/modules/imgur/imgur.js index a546314..17cda65 100644 --- a/modules/imgur/imgur.js +++ b/modules/imgur/imgur.js @@ -52,12 +52,15 @@ var imgur = function(dbot) { if(!error && response.statusCode == 200 && body.length != 492) { this.db.totalImages += 1; var hash = crypto.createHash('md5').update(body).digest("hex"); - if((hash == "e49e686582ce3f60cb51d00c10924861") && _.has(dbot.modules, 'quotes')){ - var qdb = dbot.db.quoteArrs["facebookman"]; - if (_.include(qdb, testUrl)){ - // do something - } else { - qdb.push(testUrl); + if(_.has(dbot.modules, 'quotes')){ + // autoadd: {"abcdef": "facebookman"} + if(_.has(dbot.config.imgur.autoadd,hash)){ + var category = dbot.config.imgur.autoadd[hash]; + if (_.contains(category, testUrl)){ + // there's probably less than 62^5 chance of this happening + } else { + dbot.db.quoteArrs[category].push(testUrl); + } } } callback(testUrl, testSlug,hash); From 7303cfccf3556901ab6e6392615e656f1a265e2d Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Mon, 20 May 2013 15:23:11 +0000 Subject: [PATCH 4/4] Correct accidental Italian accent in admin module --- modules/admin/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/admin/strings.json b/modules/admin/strings.json index 0f3e5a0..e23e09f 100644 --- a/modules/admin/strings.json +++ b/modules/admin/strings.json @@ -106,7 +106,7 @@ "en": "{module} status: Failed to load: {reason}" }, "status_unloaded": { - "en": "Either thata module wasn't on the roster or shit is totally fucked." + "en": "Either that module wasn't on the roster or shit is totally fucked." }, "load_failed": { "en": "Failed to load {module}. See 'status {module}'."