misc: Add gimg and fimg

This commit is contained in:
Cynthia Foxwell 2022-03-28 16:12:10 -06:00
parent 0218f0f0e0
commit 1f1e7531af
3 changed files with 158 additions and 0 deletions

View file

@ -20,6 +20,7 @@
"colorcolor": "^1.1.1", "colorcolor": "^1.1.1",
"dumpy": "github:Cynosphere/dumpy.js", "dumpy": "github:Cynosphere/dumpy.js",
"eris": "^0.16.1", "eris": "^0.16.1",
"google-images": "^2.1.0",
"jimp": "^0.16.1", "jimp": "^0.16.1",
"murmurhash": "^2.0.0", "murmurhash": "^2.0.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",

View file

@ -5,6 +5,7 @@ specifiers:
dumpy: github:Cynosphere/dumpy.js dumpy: github:Cynosphere/dumpy.js
eris: ^0.16.1 eris: ^0.16.1
eslint: ^7.26.0 eslint: ^7.26.0
google-images: ^2.1.0
jimp: ^0.16.1 jimp: ^0.16.1
murmurhash: ^2.0.0 murmurhash: ^2.0.0
node-fetch: ^2.6.1 node-fetch: ^2.6.1
@ -17,6 +18,7 @@ dependencies:
colorcolor: 1.1.1 colorcolor: 1.1.1
dumpy: github.com/Cynosphere/dumpy.js/5fc22353cdcb97084bab572266390e780d9f7a7b dumpy: github.com/Cynosphere/dumpy.js/5fc22353cdcb97084bab572266390e780d9f7a7b
eris: 0.16.1 eris: 0.16.1
google-images: 2.1.0
jimp: 0.16.1 jimp: 0.16.1
murmurhash: 2.0.0 murmurhash: 2.0.0
node-fetch: 2.6.1 node-fetch: 2.6.1
@ -621,6 +623,11 @@ packages:
engines: {node: '>=6'} engines: {node: '>=6'}
dev: true dev: true
/capture-stack-trace/1.0.1:
resolution: {integrity: sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw==}
engines: {node: '>=0.10.0'}
dev: false
/caseless/0.12.0: /caseless/0.12.0:
resolution: {integrity: sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=} resolution: {integrity: sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=}
dev: false dev: false
@ -709,6 +716,13 @@ packages:
resolution: {integrity: sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=} resolution: {integrity: sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=}
dev: false dev: false
/create-error-class/3.0.2:
resolution: {integrity: sha1-Br56vvlHo/FKMP1hBnHUAbyot7Y=}
engines: {node: '>=0.10.0'}
dependencies:
capture-stack-trace: 1.0.1
dev: false
/cross-spawn/7.0.3: /cross-spawn/7.0.3:
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
@ -787,6 +801,10 @@ packages:
resolution: {integrity: sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==} resolution: {integrity: sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==}
dev: false dev: false
/duplexer3/0.1.4:
resolution: {integrity: sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=}
dev: false
/ecc-jsbn/0.1.2: /ecc-jsbn/0.1.2:
resolution: {integrity: sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=} resolution: {integrity: sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=}
dependencies: dependencies:
@ -1055,6 +1073,11 @@ packages:
wide-align: 1.1.3 wide-align: 1.1.3
dev: false dev: false
/get-stream/3.0.0:
resolution: {integrity: sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=}
engines: {node: '>=4'}
dev: false
/getpass/0.1.7: /getpass/0.1.7:
resolution: {integrity: sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=} resolution: {integrity: sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=}
dependencies: dependencies:
@ -1123,6 +1146,30 @@ packages:
type-fest: 0.20.2 type-fest: 0.20.2
dev: true dev: true
/google-images/2.1.0:
resolution: {integrity: sha1-EnSuQEgll4Jk06T48tUmuI0L8Cw=}
engines: {node: '>= 4'}
dependencies:
got: 6.7.1
dev: false
/got/6.7.1:
resolution: {integrity: sha1-JAzQV4WpoY5WHcG0S0HHY+8ejbA=}
engines: {node: '>=4'}
dependencies:
create-error-class: 3.0.2
duplexer3: 0.1.4
get-stream: 3.0.0
is-redirect: 1.0.0
is-retry-allowed: 1.2.0
is-stream: 1.1.0
lowercase-keys: 1.0.1
safe-buffer: 5.2.1
timed-out: 4.0.1
unzip-response: 2.0.1
url-parse-lax: 1.0.0
dev: false
/graceful-fs/4.2.6: /graceful-fs/4.2.6:
resolution: {integrity: sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==} resolution: {integrity: sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==}
dev: false dev: false
@ -1253,6 +1300,21 @@ packages:
is-extglob: 2.1.1 is-extglob: 2.1.1
dev: true dev: true
/is-redirect/1.0.0:
resolution: {integrity: sha1-HQPd7VO9jbDzDCbk+V02/HyH3CQ=}
engines: {node: '>=0.10.0'}
dev: false
/is-retry-allowed/1.2.0:
resolution: {integrity: sha512-RUbUeKwvm3XG2VYamhJL1xFktgjvPzL0Hq8C+6yrWIswDy3BIXGqCxhxkc30N9jqK311gVU137K8Ei55/zVJRg==}
engines: {node: '>=0.10.0'}
dev: false
/is-stream/1.1.0:
resolution: {integrity: sha1-EtSj3U5o4Lec6428hBc66A2RykQ=}
engines: {node: '>=0.10.0'}
dev: false
/is-typedarray/1.0.0: /is-typedarray/1.0.0:
resolution: {integrity: sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=} resolution: {integrity: sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=}
dev: false dev: false
@ -1358,6 +1420,11 @@ packages:
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
dev: true dev: true
/lowercase-keys/1.0.1:
resolution: {integrity: sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==}
engines: {node: '>=0.10.0'}
dev: false
/lru-cache/6.0.0: /lru-cache/6.0.0:
resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==}
engines: {node: '>=10'} engines: {node: '>=10'}
@ -1710,6 +1777,11 @@ packages:
engines: {node: '>= 0.8.0'} engines: {node: '>= 0.8.0'}
dev: true dev: true
/prepend-http/1.0.4:
resolution: {integrity: sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=}
engines: {node: '>=0.10.0'}
dev: false
/prettier/2.3.0: /prettier/2.3.0:
resolution: {integrity: sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==} resolution: {integrity: sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==}
engines: {node: '>=10.13.0'} engines: {node: '>=10.13.0'}
@ -2107,6 +2179,11 @@ packages:
resolution: {integrity: sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=} resolution: {integrity: sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=}
dev: true dev: true
/timed-out/4.0.1:
resolution: {integrity: sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=}
engines: {node: '>=0.10.0'}
dev: false
/timm/1.7.1: /timm/1.7.1:
resolution: {integrity: sha512-IjZc9KIotudix8bMaBW6QvMuq64BrJWFs1+4V0lXwWGQZwH+LnX87doAYhem4caOEusRP9/g6jVDQmZ8XOk1nw==} resolution: {integrity: sha512-IjZc9KIotudix8bMaBW6QvMuq64BrJWFs1+4V0lXwWGQZwH+LnX87doAYhem4caOEusRP9/g6jVDQmZ8XOk1nw==}
dev: false dev: false
@ -2158,11 +2235,23 @@ packages:
engines: {node: '>=8'} engines: {node: '>=8'}
dev: true dev: true
/unzip-response/2.0.1:
resolution: {integrity: sha1-0vD3N9FrBhXnKmk17QQhRXLVb5c=}
engines: {node: '>=4'}
dev: false
/uri-js/4.4.1: /uri-js/4.4.1:
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
dependencies: dependencies:
punycode: 2.1.1 punycode: 2.1.1
/url-parse-lax/1.0.0:
resolution: {integrity: sha1-evjzA2Rem9eaJy56FKxovAYJ2nM=}
engines: {node: '>=0.10.0'}
dependencies:
prepend-http: 1.0.4
dev: false
/utif/2.0.1: /utif/2.0.1:
resolution: {integrity: sha512-Z/S1fNKCicQTf375lIP9G8Sa1H/phcysstNrrSdZKj1f9g58J4NMgb5IgiEZN9/nLMPDwF0W7hdOe9Qq2IYoLg==} resolution: {integrity: sha512-Z/S1fNKCicQTf375lIP9G8Sa1H/phcysstNrrSdZKj1f9g58J4NMgb5IgiEZN9/nLMPDwF0W7hdOe9Qq2IYoLg==}
dependencies: dependencies:

View file

@ -3,6 +3,9 @@ const CATEGORY = "misc";
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const {hastebin, safeString, parseHtmlEntities} = require("../lib/utils.js"); const {hastebin, safeString, parseHtmlEntities} = require("../lib/utils.js");
const GoogleImages = require("google-images");
const imagesClient = new GoogleImages(hf.apikeys.gimg, hf.apikeys.google);
const yt = new Command("youtube"); const yt = new Command("youtube");
yt.addAlias("yt"); yt.addAlias("yt");
@ -144,3 +147,68 @@ wolfram.callback = async function (msg, line) {
} }
}; };
hf.registerCommand(wolfram); hf.registerCommand(wolfram);
const gimg = new Command("gimg");
gimg.category = CATEGORY;
gimg.helpText = "Search Google Images";
gimg.usage = "[query]";
gimg.addAlias("img");
gimg.callback = async function (msg, line) {
if (!line) return "No arguments given.";
const images = await imagesClient.search(line, {
safe:
msg.channel.nsfw && !msg.channel?.topic.includes("[no_nsfw]")
? "off"
: "high",
});
const index = Math.floor(Math.random() * images.length);
const image = images[index];
return {
embeds: [
{
title: image.description,
url: image.parentPage,
image: {
url: image.url,
},
footer: {
text: `Image ${index}/${images.length}. Rerun to get a different image.`,
},
},
],
};
};
hf.registerCommand(gimg);
const fimg = new Command("fimg");
fimg.category = CATEGORY;
fimg.helpText = "Send first result from Google Images";
fimg.usage = "[query]";
fimg.callback = async function (msg, line) {
if (!line) return "No arguments given.";
const images = await imagesClient.search(line, {
safe:
msg.channel.nsfw && !msg.channel?.topic.includes("[no_nsfw]")
? "off"
: "high",
});
const image = images[0];
return {
embeds: [
{
title: image.description,
url: image.parentPage,
image: {
url: image.url,
},
},
],
};
};
hf.registerCommand(fimg);