Added some more commands, updated packages

This commit is contained in:
TheEssem 2019-10-24 15:35:06 -05:00
parent d78bb8dff7
commit 346c40d492
9 changed files with 215 additions and 1027 deletions

22
commands/wall.js Normal file
View file

@ -0,0 +1,22 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
const fetch = require("node-fetch");
exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to make a wall from!`;
message.channel.sendTyping();
const imageData = await fetch(image.url);
const imageBuffer = await imageData.buffer();
gm(imageBuffer).resize(128).stream(async (error, output) => {
if (error) console.error;
const data = gm(output).virtualPixel("tile").matteColor("none").out("-background", "none").resize("512x512!").out("-distort").out("Perspective").out("0,0,57,42 0,128,63,130 128,0,140,60 128,128,140,140");
const resultBuffer = await gmToBuffer(data);
return message.channel.createMessage("", {
file: resultBuffer,
name: `wall.${image.type}`
});
});
};

27
commands/wdt.js Normal file
View file

@ -0,0 +1,27 @@
const gm = require("gm").subClass({
imageMagick: true
});
const gmToBuffer = require("../utils/gmbuffer.js");
const fetch = require("node-fetch");
const fs = require("fs");
exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to make a "who did this" meme!`;
message.channel.sendTyping();
const template = "./assets/images/whodidthis.png";
const imageData = await fetch(image.url);
const imageBuffer = await imageData.buffer();
const path = require("tempy").file({
extension: image.type
});
require("util").promisify(fs.writeFile)(path, imageBuffer);
const command = gm(template).composite(path).gravity("Center").geometry("374x374+0+0");
const resultBuffer = await gmToBuffer(command);
return message.channel.createMessage("", {
file: resultBuffer,
name: "wdt.png"
});
};
exports.aliases = ["whodidthis"];

21
commands/wikihow.js Normal file
View file

@ -0,0 +1,21 @@
const fetch = require("node-fetch");
const config = require("../config.json");
exports.run = async (message) => {
message.channel.sendTyping();
const request = await fetch("https://hargrimm-wikihow-v1.p.mashape.com/images?count=1", {
headers: {
"X-Mashape-Key": config.mashapeKey,
"Accept": "application/json"
}
});
const json = await request.json();
const image = await fetch(json["1"]);
const imageBuffer = await image.buffer();
return message.channel.createMessage("", {
file: imageBuffer,
name: json["1"].split("/")[json["1"].split("/").length - 1]
});
};
exports.aliases = ["wiki"];

7
commands/winxp.js Normal file
View file

@ -0,0 +1,7 @@
const playSound = require("../utils/soundplayer.js");
exports.run = async (message) => {
return playSound("./assets/audio/winxp.opus", message);
};
exports.aliases = ["windows", "xp"];

36
commands/woow.js Normal file
View file

@ -0,0 +1,36 @@
// really don't like this file
const gm = require("gm").subClass({
imageMagick: true
});
const tempy = require("tempy");
const fetch = require("node-fetch");
exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to mirror!`;
message.channel.sendTyping();
const imageData = await fetch(image.url);
const imageBuffer = await imageData.buffer();
const data = tempy.file({
extension: image.type
});
const data2 = tempy.file({
extension: image.type
});
gm(imageBuffer).gravity("North").crop(0, "50%").strip().write(data2, (error) => {
if (error) console.error;
gm(data2).flip().strip().write(data, async (error) => {
if (error) console.error;
gm(data2).append(data).toBuffer(image.type, (error, resultBuffer) => {
if (error) console.error;
return message.channel.createMessage("", {
file: resultBuffer,
name: `woow.${image.type}`
});
});
});
});
};
exports.aliases = ["magik5", "mirror3"];

19
commands/xkcd.js Normal file
View file

@ -0,0 +1,19 @@
const fetch = require("node-fetch");
exports.run = async (message, args) => {
const url = args.length > 0 && args[0].match(/^\d+$/) ? `http://xkcd.com/${args[0]}/info.0.json` : "http://xkcd.com/info.0.json";
const request = await fetch(url);
const json = await request.json();
const embed = {
"embed": {
"title": json.safe_title,
"url": `https://xkcd.com/${json.num}`,
"color": 16711680,
"description": json.alt,
"image": {
"url": json.img
}
}
};
return message.channel.createMessage(embed);
};

16
commands/youtube.js Normal file
View file

@ -0,0 +1,16 @@
const YouTube = require("simple-youtube-api");
const config = require("../config.json");
const youtube = new YouTube(config.googleKey);
exports.run = async (message, args) => {
if (args.length === 0) return `${message.author.mention}, you need to provide something to search for!`;
message.channel.sendTyping();
const result = await youtube.search(args.join(" "), 1);
if (result[0].type === "channel") {
return `<:youtube:637020823005167626> **${result[0].raw.snippet.title.replace("*", "\\*")}**\nhttps://youtube.com/channel/${result[0].id}`;
} else if (result[0].type === "playlist") {
return `<:youtube:637020823005167626> **${result[0].title.replace("*", "\\*")}**\nCreated by **${result[0].channel.title.replace("*", "\\*")}**\nhttps://youtube.com/playlist?list=${result[0].id}`;
} else {
return `<:youtube:637020823005167626> **${result[0].title.replace("*", "\\*")}**\nUploaded by **${result[0].channel.title.replace("*", "\\*")}** on **${result[0].publishedAt.toISOString().split("T")[0]}**\nhttps://youtube.com/watch?v=${result[0].id}`;
}
};

1088
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -31,11 +31,11 @@
"moment": "^2.24.0",
"moment-duration-format": "^2.3.2",
"node-fetch": "^2.6.0",
"node-opus": "^0.3.2",
"pageres": "^5.1.0",
"qrcode": "^1.4.1",
"node-opus": "^0.3.3",
"qrcode": "^1.4.2",
"retrotext": "github:TheEssem/retrotext",
"sharp": "^0.22.1",
"simple-youtube-api": "^5.2.1",
"tempy": "^0.2.1",
"url-unshort": "^5.0.0",
"uws": "^10.148.1",