diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b08bac6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "assets/images/country-flags"] + path = assets/images/country-flags + url = https://github.com/hjnilsson/country-flags.git diff --git a/assets/images/pirateflag.png b/assets/images/pirateflag.png new file mode 100644 index 0000000..5321f2b Binary files /dev/null and b/assets/images/pirateflag.png differ diff --git a/commands/flag.js b/commands/flag.js new file mode 100644 index 0000000..5879be1 --- /dev/null +++ b/commands/flag.js @@ -0,0 +1,26 @@ +const gm = require("gm").subClass({ + imageMagick: true +}); +const emojiRegex = require("emoji-regex"); +const emoji = require("node-emoji"); + +exports.run = async (message, args) => { + message.channel.sendTyping(); + const image = await require("../utils/imagedetect.js")(message); + if (image === undefined) return `${message.author.mention}, you need to provide an image to overlay a flag onto!`; + if (!args[0].match(emojiRegex)) return `${message.author.mention}, you need to provide an emoji of a flag to overlay!`; + const flag = emoji.unemojify(args[0]).replace(/:/g, "").replace("flag-", ""); + let path = `./assets/images/country-flags/png1000px/${flag}.png`; + if (flag === "🏴‍☠️") path = "./assets/images/pirateflag.png"; + console.log(flag); + const size = await gm(image.path).sizePromise(); + const buffer = await gm(image.path).coalesce().out("null:").out("(", path, "-alpha", "set", "-channel", "A", "-evaluate", "multiply", "0.4", "+channel", ")").gravity("North").scale(...(size.width < size.height ? ["%[fx:u.w]", null] : [null, "%[fx:u.h]"])).out("-layers", "composite").bufferPromise(image.type, image.delay); + return { + file: buffer, + name: `flag.${image.type}` + }; +}; + +exports.params = "[flag]"; +exports.category = 5; +exports.help = "Overlays a flag onto an image"; \ No newline at end of file diff --git a/events/messageCreate.js b/events/messageCreate.js index 109a002..a1dade2 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -40,7 +40,8 @@ module.exports = async (message) => { logger.log("info", `${message.author.username} (${message.author.id}) ran command ${command}`); try { const global = (await database.global.findOne({}).exec()); - global.cmdCounts.set(collections.aliases.has(command) ? collections.aliases.get(command) : command, ((isNaN(global.cmdCounts.get(command)) ? 0 : parseFloat(global.cmdCounts.get(command))) + 1).toFixed()); + const count = global.cmdCounts.get(collections.aliases.has(command) ? collections.aliases.get(command) : command); + global.cmdCounts.set(collections.aliases.has(command) ? collections.aliases.get(command) : command, parseInt(count) + 1); await global.save(); const result = await cmd(message, args, content.replace(command, "").trim()); // we also provide the message content as a parameter for cases where we need more accuracy if (typeof result === "string" || (typeof result === "object" && result.embed)) { diff --git a/package-lock.json b/package-lock.json index 8226d41..b7a0faa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1462,6 +1462,11 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, + "lodash.toarray": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.toarray/-/lodash.toarray-4.4.0.tgz", + "integrity": "sha1-JMS/zWsvuji/0FlNsRedjptlZWE=" + }, "logform": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/logform/-/logform-2.1.2.tgz", @@ -1711,6 +1716,14 @@ "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.0.tgz", "integrity": "sha512-sSHCgWfJ+Lui/u+0msF3oyCgvdkhxDbkCS6Q8uiJquzOimkJBvX6hl5aSSA7DR1XbMpdM8r7phjcF63sF4rkKg==" }, + "node-emoji": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.10.0.tgz", + "integrity": "sha512-Yt3384If5H6BYGVHiHwTL+99OzJKHhgp82S8/dktEK73T26BazdgZ4JZh92xSVtGNJvz9UbXdNAc5hcrXV42vw==", + "requires": { + "lodash.toarray": "^4.4.0" + } + }, "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", diff --git a/package.json b/package.json index 4335708..286abc5 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "moment": "^2.26.0", "moment-duration-format": "^2.3.2", "mongoose": "^5.9.19", + "node-emoji": "^1.10.0", "node-fetch": "^2.6.0", "node-tweet": "^0.1.4", "puppeteer-core": "^2.1.1",