Verified Commit 9d2e0510 authored by Sigfried Seldeslachts's avatar Sigfried Seldeslachts
Browse files

Init

parents
DISCORD_TOKEN=""
CAT_API_KEY=""
CAT_API_USER_ID=""
DOG_API_KEY=""
\ No newline at end of file
node_modules
.env
\ No newline at end of file
This diff is collapsed.
# ISW discord bot
\ No newline at end of file
{
"name": "isw-discord-bot",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@discordjs/collection": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.5.tgz",
"integrity": "sha512-CU1q0UXQUpFNzNB7gufgoisDHP7n+T3tkqTsp3MNUkVJ5+hS3BCvME8uCXAUFlz+6T2FbTCu75A+yQ7HMKqRKw=="
},
"@types/node": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz",
"integrity": "sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ=="
},
"abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"requires": {
"event-target-shim": "^5.0.0"
}
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"axios": {
"version": "0.18.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz",
"integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==",
"requires": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
}
},
"boolbase": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
"integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24="
},
"cheerio": {
"version": "1.0.0-rc.3",
"resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.3.tgz",
"integrity": "sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA==",
"requires": {
"css-select": "~1.2.0",
"dom-serializer": "~0.1.1",
"entities": "~1.1.1",
"htmlparser2": "^3.9.1",
"lodash": "^4.15.0",
"parse5": "^3.0.1"
}
},
"combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"requires": {
"delayed-stream": "~1.0.0"
}
},
"css-select": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/css-select/-/css-select-1.2.0.tgz",
"integrity": "sha1-KzoRBTnFNV8c2NMUYj6HCxIeyFg=",
"requires": {
"boolbase": "~1.0.0",
"css-what": "2.1",
"domutils": "1.5.1",
"nth-check": "~1.0.1"
}
},
"css-what": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.3.tgz",
"integrity": "sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg=="
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
},
"discord.js": {
"version": "12.0.2",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.0.2.tgz",
"integrity": "sha512-iZiEA4Y61gqq/EjFfLXnkRK9pLapnax/vTVDUhs/mAhyqozAy0GOlk/MZI9rSa1iIoKTWRq6P9CRKhLNT2wUnA==",
"requires": {
"@discordjs/collection": "^0.1.5",
"abort-controller": "^3.0.0",
"form-data": "^3.0.0",
"node-fetch": "^2.6.0",
"prism-media": "^1.2.0",
"setimmediate": "^1.0.5",
"tweetnacl": "^1.0.3",
"ws": "^7.2.1"
}
},
"dom-serializer": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz",
"integrity": "sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA==",
"requires": {
"domelementtype": "^1.3.0",
"entities": "^1.1.1"
}
},
"domelementtype": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz",
"integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w=="
},
"domhandler": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz",
"integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==",
"requires": {
"domelementtype": "1"
}
},
"domutils": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz",
"integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=",
"requires": {
"dom-serializer": "0",
"domelementtype": "1"
}
},
"dotenv": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.2.0.tgz",
"integrity": "sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w=="
},
"entities": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz",
"integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w=="
},
"event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
}
},
"form-data": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
"integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"htmlparser2": {
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz",
"integrity": "sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==",
"requires": {
"domelementtype": "^1.3.1",
"domhandler": "^2.3.0",
"domutils": "^1.5.1",
"entities": "^1.1.1",
"inherits": "^2.0.1",
"readable-stream": "^3.1.1"
}
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"is-buffer": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
},
"mime-db": {
"version": "1.43.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz",
"integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ=="
},
"mime-types": {
"version": "2.1.26",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz",
"integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==",
"requires": {
"mime-db": "1.43.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"node-fetch": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
},
"nth-check": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz",
"integrity": "sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg==",
"requires": {
"boolbase": "~1.0.0"
}
},
"parse5": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz",
"integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==",
"requires": {
"@types/node": "*"
}
},
"prism-media": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.1.tgz",
"integrity": "sha512-R3EbKwJiYlTvGwcG1DpUt+06DsxOGS5W4AMEHT7oVOjG93MjpdhGX1whHyjnqknylLMupKAsKMEXcTNRbPe6Vw=="
},
"readable-stream": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.5.0.tgz",
"integrity": "sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
},
"safe-buffer": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
"integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg=="
},
"setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
},
"string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"requires": {
"safe-buffer": "~5.2.0"
}
},
"tweetnacl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"ws": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz",
"integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ=="
}
}
}
{
"name": "isw-discord-bot",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"dependencies": {
"axios": "^0.18.0",
"cheerio": "^1.0.0-rc.2",
"discord.js": "^12.0.2",
"dotenv": "^6.2.0"
},
"repository": {
"type": "git",
"url": ""
},
"author": "ISW Leuven",
"license": "GPL"
}
const fs = require('fs');
const path = require('path');
const globalPath = path.join(__dirname, "commands");
let commands = [];
// Get all the items in the commands directory
const items = fs.readdirSync(globalPath);
// Go over each of these items
items.forEach((item) => {
// Get the path of the item
const itemPath = path.join(globalPath, item);
// Check if it is a directory
if (fs.existsSync(itemPath) && fs.lstatSync(itemPath).isDirectory()) {
// Now go through every file and open it
fs.readdirSync(itemPath).forEach((file) => {
// Import the file
commands[`${item}-${file}`] = require(path.join(itemPath, file));
});
}
});
Object.assign(module.exports, commands);
\ No newline at end of file
const axios = require('axios');
/**
* @param {} msg
*/
const command = async (msg) => {
try {
const { data } = await axios.get('https://api.thecatapi.com/v1/images/search', {
headers: { 'x-api-key': process.env.CAT_API_KEY } });
msg.channel.send(data[0].url);
} catch (error) {
msg.channel.send("Ik kon geen afbeelding versturen.");
}
}
module.exports = {
aliases: ['cat', 'kat'],
info: {
"aliases": "cat, kat",
"name": "Kat",
"description": "Stuurt een foto van een kat.",
"author": "Sigfried"
},
onMessage: command,
};
\ No newline at end of file
/**
* @param {} msg
*/
const command = async (msg) => {
const result = (Math.floor(Math.random() * 2) == 0) ? 'Heads (kop)' : 'Tails (munt)';
message.reply(result);
}
module.exports = {
aliases: ['coinflip'],
info: {
"aliases": "coinflip",
"name": "Kop of munt?",
"description": "De bot gooit kop of munt.",
"author": "Sigfried"
},
onMessage: command,
};
\ No newline at end of file
const axios = require('axios');
/**
* @param {} msg
*/
const command = async (msg) => {
try {
const { data } = await axios.get('https://api.thedogapi.com/v1/images/search', {
headers: { 'x-api-key': process.env.DOG_API_KEY } });
msg.channel.send(data[0].url);
} catch (error) {
msg.channel.send("Ik kon geen afbeelding versturen.");
}
}
module.exports = {
aliases: ['dog', 'hond'],
info: {
"aliases": "dog, hond",
"name": "Hond",
"description": "Stuurt een foto van een hond.",
"author": "Sigfried"
},
onMessage: command,
};
\ No newline at end of file
/**
* @param {} msg
*/
const command = async (msg) => {
// Get the first user which is mentioned
const user = msg.mentions.users.first();
const member = msg.guild.member(user);
if (user && member) {
const userWhoDoubts = msg.member.user;
msg.channel.send([
`<@${user.id}>, <@${userWhoDoubts.id}> betwijfelt dat!`,
'https://sigfriedsimages.b-cdn.net/doubt.png'
]);;
} else {
msg.reply([
'jij betwijfelt dat!',
'https://sigfriedsimages.b-cdn.net/doubt.png'
]);
}
msg.delete();
}
module.exports = {
aliases: ['doubt'],
info: {
"aliases": "doubt",
"name": "Betwijfel",
"description": "Je betwijfelt dat!",
"author": "Sigfried"
},
onMessage: command,
};
\ No newline at end of file
const axios = require('axios');
/**
* @param {} msg
*/
const command = async (msg) => {
try {
const { data } = await axios.get('https://yesno.wtf/api')
msg.reply([
data.answer,
data.image
]);
} catch (e) {
msg.channel.send('Er ging iets mis en ik kon jammer genoeg niet antwoorden op jouw vraag.');
}
}
module.exports = {
aliases: ['eightball'],
info: {
"aliases": "eightball",
"name": "Eightball",
"description": "Stel een ja of nee vraag, en er wordt een antwoord opgegeven!",
"author": "Sigfried"
},
onMessage: command,
};
\ No newline at end of file
const Discord = require('discord.js');
const commands = require('../../commandInjector.js');
/**
* Shows the help message
* @param {} msg
*/
const command = async (msg) => {
const embed = {
title: "ISW Bot - Hulp",
description: "Hier kan je alle commando's vinden van de bot.",
fields: [],
}
Object.keys(commands).forEach((key) => {
const info = commands[key]['info'];
embed.fields.push({
name: info.name + " - " + info.aliases,
value: info.description
});
});
msg.channel.send({ embed });
}
module.exports = {
aliases: ['help', 'h'],
info: {
"aliases": "help, h",
"name": "Help",
"description": "Toont dit help scherm.",
"author": "Sigfried"
},
onMessage: command,
};
\ No newline at end of file
const axios = require('axios');
const cheerio = require('cheerio');
/**
* Shows the excuse
* @param {} msg
*/
const command = async (msg) => {
try {
const { data } = await axios.get('https://ipv6excuses.com/');
const HTML = await cheerio.load(data);
await msg.channel.send(`"${HTML('h1').text().trim()}"`);
} catch (error) {
msg.channel.send(error);
}
}
module.exports = {
aliases: ['ipv6e', 'ipv6excuse'],
info: {
"aliases": "ipv6e, ipv6excuse",
"name": "IPv6 excuus",
"description": "Toont een excuus om geen IPv6 te gebruiken",
"author": "Sigfried"
},
onMessage: command,
};
\ No newline at end of file
/**
* @param {} msg
*/
const command = async (msg) => {
msg.channel.send('https://sigfriedsimages.b-cdn.net/wut.jpg');
msg.delete();
}
module.exports = {
aliases: ['wut', 'wat'],
info: {
"aliases": "wuyt, wat",
"name": "WAT!?",
"description": "Wut...",
"author": "Sigfried"
},
onMessage: command,
};
\ No newline at end of file
require('dotenv').config();
/**
* Commands init
*/
const commands = require('./commandInjector.js');
/**
* Discord Init
*/
const client = new (require('discord.js')).Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
/**
* On message commands
*/
client.on('message', (msg) => {
if (!msg.content.startsWith('!')) return;
// Removes ! and splits by space and gets first item
const currentAlias = msg.content.substr(1).split(" ")[0];
Object.keys(commands).forEach((key) => {
const command = commands[key];
// Execute the custom activation function if present
if (command.activation) command.activation();