diff --git a/.gitignore b/.gitignore index 12d4bfc..b4224b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,12 @@ +# private files config.json + +# compiled files node_modules/ -.vscode/ coverage/ docs/ -package-lock.json \ No newline at end of file +package-lock.json + +# development generated files +.idea/ +.vscode/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e0..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/SudoBot.iml b/.idea/SudoBot.iml deleted file mode 100644 index c956989..0000000 --- a/.idea/SudoBot.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml deleted file mode 100644 index d9deacc..0000000 --- a/.idea/dbnavigator.xml +++ /dev/null @@ -1,459 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index fe0f42b..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/commands/emotes.js b/app/commands/emotes.js new file mode 100644 index 0000000..8de744a --- /dev/null +++ b/app/commands/emotes.js @@ -0,0 +1,29 @@ +/** + * Execute on emotes command + * @param {Discord.Message} msg - discord message + * @param {Array} args - passed arguments + */ +const emotes = async (msg, args) => { + const emote_arr = msg.guild.emojis.cache.map((e) => e.toString()); + var output = "", + batch = 1, + batch_size = args[0]; + if (!batch_size) { + batch_size = 10; + } + for (var i = 0; i < emote_arr.length; i++) { + output += emote_arr[i]; + if (i == batch_size * batch - 1) { + msg.author.send(output, { split: true }); + output = ""; + batch += 1; + } + } + if (output) msg.author.send(output); + msg.reply("I've sent you a DM with all emotes!"); +}; +module.exports = { + name: "emotes", + description: "Send you the set of all emotes in the server", + execute: emotes, +}; diff --git a/test/emotes.test.js b/test/emotes.test.js new file mode 100644 index 0000000..92895b4 --- /dev/null +++ b/test/emotes.test.js @@ -0,0 +1,81 @@ +// const cmd = require("../app/commands/ping"); + +jest.useFakeTimers(); +const fs = require("fs"), + Discord = require("discord.js"); + +const { client } = require("../app/utils/Discord"); +const commandFiles = fs + .readdirSync("./app/commands") + .filter((file) => file.endsWith(".js")); +for (const file of commandFiles) { + const command = require(`../app/commands/${file}`); + // set a new item in the Collection + // with the key as the command name and the value as the exported module + client.commands.set(command.name, command); +} +let user, guild, channel, channel_projects, msg; +describe("testing commands", () => { + beforeAll(() => { + user = new Discord.User(client, { + id: Discord.SnowflakeUtil.generate(), + }); + guild = new Discord.Guild(client, { + id: Discord.SnowflakeUtil.generate(), + name: "test_guild_name", + }); + channel = Discord.Channel.create( + client, + { + id: Discord.SnowflakeUtil.generate(), + rawPosition: 11, + topic: null, + parentID: Discord.SnowflakeUtil.generate(), + name: "", + type: 0, + }, + guild + ); + channel_projects = Discord.Channel.create( + client, + { + id: Discord.SnowflakeUtil.generate(), + name: "/projects", + type: 0, + }, + guild + ); + msg = new Discord.Message( + client, + { + id: Discord.SnowflakeUtil.generate(), + content: "content", + author: user, + }, + channel + ); + }); + var cmd = client.commands.get("emotes"); + it(`test ${cmd.name} - without batch_size`, () => { + // target + msg.author.send = jest.fn(); + msg.reply = jest.fn(); + args = []; + // call execute function + cmd.execute(msg, args); + // test if target has been used + // expect(msg.author.send).toHaveBeenCalled(); + expect(msg.reply).toHaveBeenCalled(); + }); + it(`test ${cmd.name} - with batch_size`, () => { + // target + msg.author.send = jest.fn(); + msg.reply = jest.fn(); + args = [10]; + // call execute function + cmd.execute(msg, args); + // test if target has been used + // expect(msg.author.send).toHaveBeenCalled(); + expect(msg.reply).toHaveBeenCalled(); + }); +});