mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
hash util function
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const snekfetch = require('snekfetch');
|
||||
const crypto = require('crypto');
|
||||
const { hash } = require('../../util/Util');
|
||||
|
||||
module.exports = class GravatarCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -22,16 +22,16 @@ module.exports = class GravatarCommand extends Command {
|
||||
}
|
||||
|
||||
async run(msg, { email }) {
|
||||
const hash = crypto.createHash('md5').update(email).digest('hex');
|
||||
const emailHash = hash(email, 'md5');
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.get(`https://www.gravatar.com/avatar/${hash}`)
|
||||
.get(`https://www.gravatar.com/avatar/${emailHash}`)
|
||||
.query({
|
||||
size: 500,
|
||||
default: 404,
|
||||
rating: msg.channel.nsfw ? 'r' : 'pg'
|
||||
});
|
||||
return msg.say({ files: [{ attachment: body, name: `${hash}.jpg` }] });
|
||||
return msg.say({ files: [{ attachment: body, name: `${emailHash}.jpg` }] });
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const crypto = require('crypto');
|
||||
const { hash } = require('../../util/Util');
|
||||
|
||||
module.exports = class MD5Command extends Command {
|
||||
constructor(client) {
|
||||
@@ -20,6 +20,6 @@ module.exports = class MD5Command extends Command {
|
||||
}
|
||||
|
||||
run(msg, { text }) {
|
||||
return msg.say(crypto.createHash('md5').update(text).digest('hex'));
|
||||
return msg.say(hash(text, 'md5'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const crypto = require('crypto');
|
||||
const { hash } = require('../../util/Util');
|
||||
|
||||
module.exports = class SHA256Command extends Command {
|
||||
constructor(client) {
|
||||
@@ -20,6 +20,6 @@ module.exports = class SHA256Command extends Command {
|
||||
}
|
||||
|
||||
run(msg, { text }) {
|
||||
return msg.say(crypto.createHash('sha256').update(text).digest('hex'));
|
||||
return msg.say(hash(text, 'sha256'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const crypto = require('crypto');
|
||||
const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea'];
|
||||
const no = ['no', 'n', 'nah', 'nope'];
|
||||
|
||||
@@ -55,6 +56,10 @@ class Util {
|
||||
return Buffer.from(text).toString('base64');
|
||||
}
|
||||
|
||||
static hash(text, algorithm) {
|
||||
return crypto.createHash(algorithm).update(text).digest('hex');
|
||||
}
|
||||
|
||||
static cleanXML(text) {
|
||||
return text
|
||||
.replace(/<br \/>/g, '')
|
||||
|
||||
Reference in New Issue
Block a user