Skip to content

Commit

Permalink
Merge pull request #34 from Joehoel/v13
Browse files Browse the repository at this point in the history
Compagnon v2.0
  • Loading branch information
Joehoel authored Aug 12, 2021
2 parents e52d619 + 1c765e5 commit c592569
Show file tree
Hide file tree
Showing 57 changed files with 995 additions and 380 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
TOKEN=
CLIENT_ID=
PREFIX=
PORT=
API_KEY=
MONGO_URI=
NODE_ENV=
DATABASE_URL=
NODE_TLS_REJECT_UNAUTHORIZED=
COOKIE=
GENIUS_TOKEN=
REDIS_PATH=
REDIS_KEY_PREFIX=
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
"description": "Discord bot",
"main": "src/index.ts",
"dependencies": {
"@discordjs/builders": "^0.5.0",
"@discordjs/opus": "^0.3.3",
"@discordjs/rest": "^0.1.0-canary.0",
"@joehoel/discord-reply": "^1.0.3",
"axios": "^0.21.1",
"bad-words": "^3.0.4",
"consola": "^2.15.0",
"cross-fetch": "^3.0.6",
"discord-api-types": "^0.22.0",
"discord-paginationembed": "^2.1.0",
"discord-reply": "^0.1.2",
"discord-xp": "^1.1.14",
"discord.js": "^12.5.1",
"discord.js": "^13.0.1",
"distube": "^2.8.8",
"dotenv": "^8.2.0",
"express": "^4.17.1",
Expand Down Expand Up @@ -50,6 +53,7 @@
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.24.0",
"eslint-plugin-react-hooks": "4.2.0",
"gen-env-types": "^1.3.0",
"husky": "^6.0.0",
"jest-fetch-mock": "^3.0.3",
"lint-staged": "11.0.0",
Expand All @@ -69,7 +73,8 @@
"coverage": "jest --coverage",
"typeorm": "ts-node ./node_modules/typeorm/cli.js",
"lint": "eslint --fix \"./src/**/*.ts\"",
"prepare": "husky install"
"prepare": "husky install",
"gen-env-types": "gen-env-types .env -o src/typings/env.d.ts -e ."
},
"husky": {
"hooks": {
Expand All @@ -86,6 +91,6 @@
"@": "dist"
},
"keywords": [],
"author": "",
"author": "Joël Kuijper",
"license": "ISC"
}
39 changes: 39 additions & 0 deletions src/_commands/admin/clear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { wait } from "@/lib/helpers";
import SlashCommand, { CommandType } from "@/modules/SlashCommand";
import { Message, TextChannel } from "discord.js";

export default new SlashCommand({
name: "clear",
description: "Clear the chat",
options: [
{
name: "amount",
type: CommandType.NUMBER,
required: true,
description: "Amount of messages to clear from the chat",
},
],
async execute(interaction) {
const amount = interaction.options.getNumber("amount")!;

if (amount > 101) {
return interaction.reply({ content: "You can`t delete more than 100 messages at once!", ephemeral: true });
}

if (amount < 1) {
return interaction.reply({ content: "You have to delete at least 1 message!", ephemeral: true });
}

await interaction.channel!.messages.fetch({ limit: amount }).then((messages) => {
(interaction.channel as TextChannel).bulkDelete(messages);
});

const message = (await interaction.reply({
content: `Successfully deleted **${amount}** messages!`,
fetchReply: true,
})) as Message;

await wait(2000);
return message.delete();
},
});
41 changes: 41 additions & 0 deletions src/_commands/answer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { USERS } from "@/lib/contants";
import { embed } from "@/lib/helpers";
import SlashCommand, { CommandType } from "@/modules/SlashCommand";

export default new SlashCommand({
name: "answer",
description: "Answer the question of the day",
options: [
{
name: "answer",
description: "The answer to the question",
type: CommandType.STRING,
required: true,
},
],
async execute(interaction) {
const author = interaction.user;

// Get answer from the interaction
const answer = interaction.options.getString("answer")!;

// Reply to only the user that submitted the answer
interaction.reply({ ephemeral: true, content: answer });

// TODO: Change to USERS.JESSE
const member = await interaction.client.users.fetch(USERS.JESSE);

// Send answer to Jesse
await member.send({
embeds: [
embed({
description: answer,
author: {
name: author.username,
iconURL: author.displayAvatarURL() ?? author.defaultAvatarURL,
},
}),
],
});
},
});
12 changes: 12 additions & 0 deletions src/_commands/avatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import SlashCommand, { CommandType } from "@/modules/SlashCommand";

export default new SlashCommand({
name: "avatar",
description: "Get the avatar URL of the selected user, or your own avatar.",
options: [{ name: "target", description: "The user's avatar to show", type: CommandType.USER }],
execute(interaction) {
const user = interaction.options.getUser("target");
if (user) return interaction.reply(`${user.username}'s avatar: ${user.displayAvatarURL({ dynamic: true })}`);
return interaction.reply(`Your avatar: ${interaction.user.displayAvatarURL({ dynamic: true })}`);
},
});
11 changes: 11 additions & 0 deletions src/_commands/fun/dab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { gif } from "@/lib/helpers";
import SlashCommand from "@/modules/SlashCommand";

export default new SlashCommand({
name: "dab",
description: "Sends a random dab gif in chat",
async execute(interaction) {
const url = await gif("dab");
interaction.reply(url);
},
});
13 changes: 13 additions & 0 deletions src/_commands/fun/gif.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { gif } from "@/lib/helpers";
import SlashCommand, { CommandType } from "@/modules/SlashCommand";

export default new SlashCommand({
name: "gif",
description: "Sends a random GIF in chat",
options: [{ name: "tag", description: "Tag to search a gif for", type: CommandType.STRING, required: true }],
async execute(interaction) {
const tag = interaction.options.getString("tag")!;
const url = await gif(tag);
interaction.reply(url);
},
});
26 changes: 26 additions & 0 deletions src/_commands/fun/meme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Reddit from "@/lib/reddit";
import SlashCommand, { CommandType } from "@/modules/SlashCommand";
import { MessageEmbed } from "discord.js";

export default new SlashCommand({
name: "meme",
description: "Shows a random lit meme from the provided subreddit (defaults to 'r/dankmemes')",
options: [{ name: "sub", description: "subreddit", type: CommandType.STRING, required: false }],
async execute(interaction) {
const subreddit = interaction.options.getString("sub") ?? "dankmemes";

const reddit = new Reddit(subreddit);
const { title, url, date, author, sub, link } = await reddit.getRandomHotPost();

const embed = new MessageEmbed()
.setColor("#ffc600")
.setTitle(title)
.setDescription(sub)
.setFooter(author)
.setURL(link)
.setImage(url)
.setTimestamp(date);

return interaction.reply({ embeds: [embed] });
},
});
28 changes: 28 additions & 0 deletions src/_commands/ping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { embed } from "@/lib/helpers";
import SlashCommand from "@/modules/SlashCommand";
import { Message } from "discord.js";

export default new SlashCommand({
name: "ping",
description: "Pong!",
async execute(interaction) {
const message = (await interaction.reply({
embeds: [
embed({
description: `**Pong!**`,
}),
],
fetchReply: true,
})) as Message;

const ping = message.createdTimestamp - interaction.createdTimestamp!;

await message.edit({
embeds: [
embed({
description: `**Pong!** \`${ping}ms\``,
}),
],
});
},
});
109 changes: 109 additions & 0 deletions src/_commands/poll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { embed } from "@/lib/helpers";
import SlashCommand, { CommandType } from "@/modules/SlashCommand";
import { SlashCommandOptionBase } from "@discordjs/builders/dist/interactions/slashCommands/mixins/CommandOptionBase";
import { Interaction, Message } from "discord.js";

const options = [
"🇦",
"🇧",
"🇨",
"🇩",
"🇪",
"🇫",
"🇬",
"🇭",
"🇮",
"🇯",
"🇰",
"🇱",
"🇲",
"🇳",
"🇴",
"🇵",
"🇶",
"🇷",
"🇸",
"🇹",
"🇺",
"🇻",
"🇼",
"🇽",
"🇾",
"🇿",
];

const pollLog: { [userId: string]: { lastPoll: number } } = {};

function canSendPoll(userId: string): boolean {
if (pollLog[userId]) {
const timeSince = Date.now() - pollLog[userId].lastPoll;
if (timeSince < 30000) {
return false;
}
}
return true;
}

export default new SlashCommand({
name: "poll",
description: "Create a poll where people can react to vote",
options: [
{ name: "question", description: "question", type: CommandType.STRING },
{
name: "answer_1",
description: "optional answer",
required: false,
type: CommandType.STRING,
},
{
name: "answer_2",
description: "optional answer",
required: false,
type: CommandType.STRING,
},
{
name: "answer_3",
description: "optional answer",
required: false,
type: CommandType.STRING,
},
{
name: "answer_4",
description: "optional answer",
required: false,
type: CommandType.STRING,
},
{
name: "answer_5",
description: "optional answer",
required: false,
type: CommandType.STRING,
},
{
name: "answer_6",
description: "optional answer",
required: false,
type: CommandType.STRING,
},
],
async execute(interaction) {
const question = interaction.options.getString("question");
const author = interaction.user;

const message = (await interaction.reply({
embeds: [
embed({
title: `${question}`,
footer: {
text: `Poll started by: ${author.username}`,
iconURL: author.avatarURL()!,
},
}),
],
fetchReply: true,
})) as Message;
await message.react("👍");
await message.react("👎");
await message.react("🤷‍♀️");
},
});
16 changes: 9 additions & 7 deletions src/commands/admin/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export default new Command({
switch (type) {
case Type.SET:
Levels.setLevel(target.id, GUILD_ID, parseInt(lvl));
return message.channel.send(
embed({
title: "Level",
description: `Successfully updated ${target}'s level to **${Math.floor(parseInt(lvl))}**`,
timestamp: Date.now(),
})
);
return message.channel.send({
embeds: [
embed({
title: "Level",
description: `Successfully updated ${target}'s level to **${Math.floor(parseInt(lvl))}**`,
timestamp: Date.now(),
}),
],
});

default:
break;
Expand Down
16 changes: 9 additions & 7 deletions src/commands/admin/reactionrole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ export default new Command({
aliases: ["rr"],
exclusive: true,
async execute(_, message) {
const msg = await message.channel.send(
embed({
title: "Welkom",
description: `Reageer op dit bericht om jezelf een role te geven\n\n ${EMOJIS.MEMBER} - **Member**\n\n ${EMOJIS.SPEEDRUNNER} - **Speedrunner**\n\n ${EMOJIS.POLLER} - **Poller**\n\n ${EMOJIS.CONTESTANT} - **Contestant**\n\n`,
timestamp: undefined,
})
);
const msg = await message.channel.send({
embeds: [
embed({
title: "Welkom",
description: `Reageer op dit bericht om jezelf een role te geven\n\n ${EMOJIS.MEMBER} - **Member**\n\n ${EMOJIS.SPEEDRUNNER} - **Speedrunner**\n\n ${EMOJIS.POLLER} - **Poller**\n\n ${EMOJIS.CONTESTANT} - **Contestant**\n\n`,
timestamp: undefined,
}),
],
});
await msg.react(EMOJIS.MEMBER);
await msg.react(EMOJIS.SPEEDRUNNER);
await msg.react(EMOJIS.POLLER);
Expand Down
Loading

0 comments on commit c592569

Please sign in to comment.