Skip to content
This repository was archived by the owner on Jul 29, 2021. It is now read-only.

Added a command to send all emotes in the server #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# private files
config.json

# compiled files
node_modules/
.vscode/
coverage/
docs/
package-lock.json
package-lock.json

# development generated files
.idea/
.vscode/
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/SudoBot.iml

This file was deleted.

459 changes: 0 additions & 459 deletions .idea/dbnavigator.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

29 changes: 29 additions & 0 deletions app/commands/emotes.js
Original file line number Diff line number Diff line change
@@ -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,
};
81 changes: 81 additions & 0 deletions test/emotes.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});