Repost Command

This commit is contained in:
Dragon Fire
2021-05-01 10:17:09 -04:00
parent 5591562b0b
commit 5c9cee861d
2 changed files with 67 additions and 1 deletions
+66
View File
@@ -0,0 +1,66 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const UserAgent = require('user-agents');
const { stripIndents } = require('common-tags');
const fileTypeRe = /\.(jpe?g|png|gif|jfif|bmp)(\?.+)?$/i;
module.exports = class RepostCommand extends Command {
constructor(client) {
super(client, {
name: 'repost',
aliases: ['repost-sleuth'],
group: 'analyze',
memberName: 'repost',
description: 'Checks if an image is a repost.',
credit: [
{
name: 'Reddit Repost Sleuth',
url: 'https://www.repostsleuth.com/',
reason: 'API'
}
],
args: [
{
key: 'image',
prompt: 'What image would you like to check?',
type: 'image-or-avatar'
}
]
});
}
async run(msg, { image }) {
try {
const { body } = await request.get(image);
const results = await this.checkImage(body, image);
if (results === false) return msg.reply('This image is clean.');
return msg.reply(stripIndents`
This image may be a repost. I've seen it **${body.matches.length}** times.
The closest match is at **${body.closest_match.hamming_match_percent}%** similarity.
${body.closest_match.post.url}
`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async checkImage(image, fileurl) {
const { body } = await request
.post('https://api.repostsleuth.com/image')
.query({
filter: true,
same_sub: false,
filter_author: false,
only_older: false,
include_crossposts: false,
meme_filter: false,
target_match_percent: 90,
filter_dead_matches: false,
target_days_old: 0
})
.attach('image', image, `image.${fileurl.match(fileTypeRe)[1]}`)
.set({ 'user-agent': new UserAgent().toString() });
if (!body.closest_match) return false;
return body;
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "138.2.0",
"version": "138.3.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"private": true,