Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #117 from ClarityMoe/lts
Browse files Browse the repository at this point in the history
0.3.5
  • Loading branch information
Ovyerus authored Oct 4, 2017
2 parents 64804c7 + f6c9098 commit 46a36b0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 89 deletions.
9 changes: 9 additions & 0 deletions Clara.komodoproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Komodo Project File - DO NOT EDIT -->
<project id="382ec3d2-ae87-454f-80c1-9be2e77910a8" kpf_version="5" name="Clara.komodoproject">
<preference-set idref="382ec3d2-ae87-454f-80c1-9be2e77910a8" id="project" preftype="project">
<long id="codeintel.scanner.max_depth">10</long>
<string id="import_exclude_matches">*.*~;*.bak;*.tmp;CVS;.#*;*.pyo;*.pyc;.svn;_svn;.git;.hg;.bzr;*%25*;tmp*.html;.DS_Store;*.swp;*.kpf;*.komodoproject;.komodotools;__pycache__</string>
<long id="prefs_version">1</long>
</preference-set>
</project>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clara",
"version": "0.3.4",
"version": "0.3.5",
"description": "A general-purpose discord bot.",
"main": "src/bot.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/commands/saucenao/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"main": "saucenao.js",
"dependencies": {
"sagiri": "^1.2.3"
}
}
57 changes: 0 additions & 57 deletions src/commands/saucenao/sauceQueryHandler.js

This file was deleted.

64 changes: 33 additions & 31 deletions src/commands/saucenao/saucenao.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,52 @@

/* eslint-env node */

//this handles the SauceNao handling
const Sagiri = require('sagiri');
let ayaneru;

const urlRegex = /^(?:(?:https?:)?\/\/)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
let sourcer;

exports.init = bot => {
ayaneru = new Sagiri(bot.config.sauceKey, 5);
sourcer = new Sagiri(bot.config.sauceKey);
};

exports.commands = [
'saucenao'
];

exports.saucenao = {
desc: 'Gets the image from the recent attachment or via a image link and looks for saucenao to check for the source of the image.',
desc: 'Tries to find the source for an image.',
usage: '<url or attachment>',
main(bot, ctx) {
return new Promise((resolve, reject) => {
if (!ctx.attachments[0]) {
return ctx.createMessage('Aw, no image here.');
} else if (ctx.attachments[0]) {
ayaneru.getSauce(ctx.attachments[0].url).then(res => {
let fields =[];
let ovy = JSON.parse(res).results;
for (res.results in res) {
fields.push(`${{name: ovy.name, value: `(Link)[${ovy.url}]`}}`, 0);
}
ctx.createMessage({embed: {
title: 'Saucenao query results',
description: 'this is what we can find',
fields
if (!ctx.attachments[0] && (!ctx.suffix || !urlRegex.test(ctx.suffix))) {
ctx.createMessage('Please provide an image.').then(resolve).catch(reject);
} else {
let url = ctx.attachments[0] ? ctx.attachments[0].url : ctx.suffix;

ctx.channel.sendTyping().then(() => sourcer.getSource(url)).then(res => {
return ctx.createMessage({embed: {
title: 'Source Found',
description: `[**Source URL**](${res[0].url})`,
thumbnail: {url: res[0].thumbnail},
fields: [
{
name: 'Site',
value: res[0].site,
inline: true
},
{
name: 'Similarity',
value: res[0].similarity.toString(),
inline: true
},
{
name: 'Other Matches',
value: res.slice(1).map(v => `**${v.similarity}** - [${v.site}](${v.url})`).join('\n')
}
]
}});
}).catch(reject);
} else if (ctx.suffix) {
ayaneru.getSauce(ctx.suffix).then(res => {
let ovy = JSON.parse(res.results);
for (ovy.data of ovy) {
const fields = [];
fields.push(`${{name: ovy.title, value: `(Link)[${ovy.url}]`, inline: true}}`, 0);
ctx.createMessage({embed: {
title: 'saucenao query',
description: 'this is what we can find from your image.',
fields
}});
}
}).catch(reject);
}).then(resolve).catch(reject);
}
});
}
Expand Down

0 comments on commit 46a36b0

Please sign in to comment.