Merge branch 'V12' into 'master'

V12

See merge request LoicBersier/DiscordBot!2
This commit is contained in:
Loïc Bersier 2019-01-03 17:15:41 +00:00
commit 1e6e47c39b
31 changed files with 241 additions and 163 deletions

View file

@ -16,10 +16,6 @@
"error", "error",
"tab" "tab"
], ],
"linebreak-style": [
"error",
"windows"
],
"quotes": [ "quotes": [
"error", "error",
"single" "single"

5
.gitignore vendored
View file

@ -4,11 +4,8 @@ node_modules
node_modules\ node_modules\
.vscode .vscode
video.mp4 video.mp4
json/autoresponse.json
json/blacklist.json json/blacklist.json
json/customresponse.json json/customresponse.json
tag/*
starboard/*
tts.mp3 tts.mp3
ttsvc.mp3 ttsvc.mp3
package.json starboard/487640086859743232.json

View file

@ -37,7 +37,7 @@ class TagCommand extends Command {
fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) { fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) {
if (err) { if (err) {
fs.writeFile(`./tag/${message.guild.id}.json`, `{'${trigger}':'${response}'}`, function (err) { fs.writeFile(`./tag/${message.guild.id}.json`, `{"${trigger}":"${response}"}`, function (err) {
if (err) { if (err) {
console.log(err); console.log(err);
@ -49,7 +49,6 @@ class TagCommand extends Command {
json = JSON.stringify(customresponse); //convert it back to json json = JSON.stringify(customresponse); //convert it back to json
fs.writeFile(`./tag/${message.guild.id}.json`, json, 'utf8', function (err) { fs.writeFile(`./tag/${message.guild.id}.json`, json, 'utf8', function (err) {
if (err) { if (err) {
return console.log(err); return console.log(err);
} }
}); });

View file

@ -1,5 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const Discord = require('discord.js'); const { MessageEmbed } = require('discord.js');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
class AdviceCommand extends Command { class AdviceCommand extends Command {
@ -19,7 +19,7 @@ class AdviceCommand extends Command {
fetch('http://api.adviceslip.com/advice').then((response) => { fetch('http://api.adviceslip.com/advice').then((response) => {
return response.json(); return response.json();
}).then((response) => { }).then((response) => {
const adviceEmbed = new Discord.RichEmbed() const adviceEmbed = new MessageEmbed()
.setColor('#ff9900') .setColor('#ff9900')
.setTitle(response.slip.slip_id) .setTitle(response.slip.slip_id)
.setDescription(response.slip.advice); .setDescription(response.slip.advice);

View file

@ -21,6 +21,8 @@ class ClapCommand extends Command {
} }
async exec(message, args) { async exec(message, args) {
if (!args.text)
return;
let clap = args.text.replace(/ /g, ' 👏 '); let clap = args.text.replace(/ /g, ' 👏 ');
message.delete(); message.delete();
message.channel.send(`${clap} 👏`); message.channel.send(`${clap} 👏`);

View file

@ -23,6 +23,8 @@ class EmotesayCommand extends Command {
async exec(message, args) { async exec(message, args) {
let text = args.text; let text = args.text;
if (!text)
return;
message.delete(); message.delete();
let emojiArray = []; let emojiArray = [];

View file

@ -1,5 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const Discord = require('discord.js'); const { MessageEmbed } = require('discord.js');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
class RedditCommand extends Command { class RedditCommand extends Command {
@ -11,7 +11,7 @@ class RedditCommand extends Command {
args: [ args: [
{ {
id: 'sub', id: 'sub',
type: 'string' type: 'string',
} }
], ],
description: { description: {
@ -25,6 +25,8 @@ class RedditCommand extends Command {
async exec(message, args) { async exec(message, args) {
let sub = args.sub; let sub = args.sub;
let i, a; let i, a;
if (!sub)
return;
fetch('https://www.reddit.com/r/' + sub + '.json?limit=100').then((response) => { fetch('https://www.reddit.com/r/' + sub + '.json?limit=100').then((response) => {
return response.json(); return response.json();
@ -39,8 +41,7 @@ class RedditCommand extends Command {
} }
if (response.data.children[i].data.over_18 == true) if (response.data.children[i].data.over_18 == true)
return message.channel.send('No nsfw'); return message.channel.send('No nsfw');
const redditEmbed = new Discord.RichEmbed() const redditEmbed = new MessageEmbed() .setColor('#ff9900')
.setColor('#ff9900')
.setTitle(response.data.children[i].data.title) .setTitle(response.data.children[i].data.title)
.setImage(response.data.children[i].data.url) .setImage(response.data.children[i].data.url)
.setURL('https://reddit.com' + response.data.children[i].data.permalink) .setURL('https://reddit.com' + response.data.children[i].data.permalink)

View file

@ -15,13 +15,15 @@ class SayCommand extends Command {
description: { description: {
content: 'Repeat what you say but can also replace ', content: 'Repeat what you say but can also replace ',
usage: '[text]', usage: '[text]',
examples: ['[member] is a big [adverbs] [verb]'] examples: ['[member] is a big [adverb] [verb]']
} }
}); });
} }
async exec(message, args) { async exec(message, args) {
let text = args.text; let text = args.text;
if (!text)
return;
// Load all the different files // Load all the different files
const verb = require('../../dictionary/verbs.json'); const verb = require('../../dictionary/verbs.json');

View file

@ -23,6 +23,8 @@ class SaydCommand extends Command {
async exec(message, args) { async exec(message, args) {
let text = args.text; let text = args.text;
if (!text)
return;
// Load all the different files // Load all the different files
const verb = require('../../dictionary/verbs.json'); const verb = require('../../dictionary/verbs.json');

View file

@ -12,7 +12,8 @@ class IdubbbzCommand extends Command {
args: [ args: [
{ {
id: 'text', id: 'text',
type: 'string' type: 'string',
default: 'nigger fagget'
}, },
{ {
id: 'image', id: 'image',

View file

@ -11,7 +11,8 @@ class IdubbbzPaintCommand extends Command {
args: [ args: [
{ {
id: 'text', id: 'text',
type: 'string' type: 'string',
default: 'Perfection'
}, },
{ {
id: 'image', id: 'image',

View file

@ -20,10 +20,10 @@ class AvatarCommand extends Command {
} }
async exec(message, args) { async exec(message, args) {
if (!args.user) // While these kind of statments work you really should use {} if (!args.user)
return message.channel.send(`Your avatar:\n${message.author.displayAvatarURL}`); return message.channel.send(`Your avatar:\n${message.author.displayAvatarURL()}`);
else else
return message.channel.send(`${args.user.username}'s avatar:\n${args.user.displayAvatarURL}`); return message.channel.send(`${args.user.username}'s avatar:\n${args.user.displayAvatarURL()}`);
} }
} }

View file

@ -0,0 +1,21 @@
const { Command } = require('discord-akairo');
class creditCommand extends Command {
constructor() {
super('credit', {
aliases: ['credit'],
category: 'utility',
description: {
content: 'Show credits for the bot',
usage: '(optional) [@user]',
examples: ['', '@user']
}
});
}
async exec(message) {
message.channel.send('Thanks to Tina the Cyclops girl#0064 for inspiring me making a bot,\nThanks to discord.js team for making discord.js\nThanks to 1computer1 for making discord-akairo and the help command');
}
}
module.exports = creditCommand;

View file

@ -15,7 +15,7 @@ class InviteCommand extends Command {
} }
async exec(message) { async exec(message) {
message.channel.send('Check your dm') message.channel.send('Check your dm');
return message.author.send(`You can add me from here: https://discordapp.com/oauth2/authorize?client_id=${this.client.user.id}&scope=bot&permissions=0\nYou can also join my support server over here: ${supportServer} come and say hi :)`); return message.author.send(`You can add me from here: https://discordapp.com/oauth2/authorize?client_id=${this.client.user.id}&scope=bot&permissions=0\nYou can also join my support server over here: ${supportServer} come and say hi :)`);
} }
} }

View file

@ -16,7 +16,7 @@ class PingCommand extends Command {
async exec(message) { async exec(message) {
return message.util.reply('Pong!').then(sent => { return message.util.reply('Pong!').then(sent => {
const timeDiff = (sent.editedAt || sent.createdAt) - (message.editedAt || message.createdAt); const timeDiff = (sent.editedAt || sent.createdAt) - (message.editedAt || message.createdAt);
const text = `🔂\u2000**RTT**: ${timeDiff} ms\n💟\u2000**Heartbeat**: ${Math.round(this.client.ping)} ms`; const text = `🔂\u2000**PING**: ${timeDiff} ms`;
return message.util.reply(`Pong!\n${text}`); return message.util.reply(`Pong!\n${text}`);
}); });
} }

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const { MessageEmbed } = require('discord.js');
class ServerCommand extends Command { class ServerCommand extends Command {
constructor() { constructor() {
@ -15,19 +16,17 @@ class ServerCommand extends Command {
} }
async exec(message) { async exec(message) {
const customresponse = require(`../tag/${message.guild.id}.json`); const customresponse = require(`../../tag/${message.guild.id}.json`);
var count = Object.keys(customresponse).length; var count = Object.keys(customresponse).length;
const addEmbed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('Stats of the server')
.setAuthor(message.author.username)
.setDescription(`Member: **${message.guild.memberCount}** \nChannel number: **${message.guild.channels.size}**\nGuild created at **${message.guild.createdAt}**\nOwner: **${message.guild.owner}**\nTag number: **${count}**`)
.setTimestamp();
const addEmbed = {
color: 0x0099ff,
title: 'Stats of the server',
thumbnail: {
url: `${message.guild.iconURL}`,
},
description: `Member: **${message.guild.memberCount}** \nChannel number: **${message.guild.channels.size}**\nGuild created at **${message.guild.createdAt}**\nOwner: **${message.guild.owner}**\nTag number: **${count}**`,
};
message.channel.send({ embed: addEmbed }); message.channel.send({ embed: addEmbed });
} }

View file

@ -1,4 +1,6 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const { MessageEmbed } = require('discord.js');
const reload = require('auto-reload');
class StatsCommand extends Command { class StatsCommand extends Command {
constructor() { constructor() {
@ -14,6 +16,13 @@ class StatsCommand extends Command {
} }
async exec(message) { async exec(message) {
const autoresponse = reload('../../json/autoresponse.json');
let autoresponseStatus;
if (autoresponse[message.channel.id] == undefined || autoresponse[message.channel.id] == 'disable')
autoresponseStatus = 'disabled';
else if (autoresponse[message.channel.id] == 'enable')
autoresponseStatus = 'enabled';
let totalSeconds = (this.client.uptime / 1000); let totalSeconds = (this.client.uptime / 1000);
let days = Math.floor(totalSeconds / 86400); let days = Math.floor(totalSeconds / 86400);
let hours = Math.floor(totalSeconds / 3600); let hours = Math.floor(totalSeconds / 3600);
@ -21,7 +30,21 @@ class StatsCommand extends Command {
let minutes = Math.floor(totalSeconds / 60); let minutes = Math.floor(totalSeconds / 60);
let seconds = totalSeconds.toFixed(0) % 60; let seconds = totalSeconds.toFixed(0) % 60;
let uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`; let uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`;
return message.channel.send(`Servers: \`${this.client.guilds.size}\`\nChannels: \`${this.client.channels.size}\`\nUsers: \`${this.client.users.size}\`\nBot uptime: \`${uptime}\``); const used = process.memoryUsage().heapUsed / 1024 / 1024;
const statsEmbed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('Bot stats')
.setAuthor('Haha yes')
.addField('Servers', this.client.guilds.size, true)
.addField('Channels', this.client.channels.size, true)
.addField('Users', this.client.users.size, true)
.addField('Uptime', uptime, true)
.addField('Ram usage', `${Math.round(used * 100) / 100} MB`, true)
.addField('Autoresponse in this channel',autoresponseStatus,true)
.setTimestamp();
return message.channel.send(statsEmbed);
} }
} }

View file

@ -1,5 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const Discord = require('discord.js'); const { MessageEmbed } = require('discord.js');
const reload = require('auto-reload'); const reload = require('auto-reload');
const fs = require('fs'); const fs = require('fs');
@ -18,10 +18,13 @@ class taglistCommand extends Command {
} }
async exec(message) { async exec(message) {
let customresponse = reload(`../../tag/${message.guild.id}.json`); try {
let count = Object.keys(customresponse).length; var customresponse = reload(`../../tag/${message.guild.id}.json`);
var count = Object.keys(customresponse).length;
} catch (err) {
message.channel.send('An error has occured, do you have any tags on the server?');
console.error(err);
}
await fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) { await fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) {
if (err) { if (err) {
console.log(err); console.log(err);
@ -31,7 +34,7 @@ class taglistCommand extends Command {
let json = JSON.stringify(data); let json = JSON.stringify(data);
json = json.replace(/[{}'\\]+/g, ''); json = json.replace(/[{}'\\]+/g, '');
json = json.replace(/,+/g, '\n'); json = json.replace(/,+/g, '\n');
const tagEmbed = new Discord.RichEmbed() const tagEmbed = new MessageEmbed()
.setColor('#ff9900') .setColor('#ff9900')
.setTitle('Tags list') .setTitle('Tags list')
.setDescription(`Trigger:Response\n\n${json}`) .setDescription(`Trigger:Response\n\n${json}`)
@ -40,7 +43,6 @@ class taglistCommand extends Command {
message.channel.send(tagEmbed); message.channel.send(tagEmbed);
}); });
message.channel.send('An error has occured, do you have any tags on the server?');
} }
} }

View file

@ -1,5 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const Discord = require('discord.js'); const { MessageEmbed } = require('discord.js');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const { yandexAPI } = require('../../config.json'); const { yandexAPI } = require('../../config.json');
@ -8,11 +8,13 @@ class TranslationCommand extends Command {
super('translation', { super('translation', {
aliases: ['translation', 'trn'], aliases: ['translation', 'trn'],
category: 'utility', category: 'utility',
split: 'sticky',
args: [ args: [
{ {
id: 'language', id: 'language',
type: 'string', type: ['az','ml','sq','mt','am','mk','en','mi','ar','mr','hy','mhr','af','mn','eu','de','ba','ne','be','no','bn','pa','my','pap','bg','fa','bs','pl','cy','pt','hu','ro','vi','ru','ht','ceb','gl','sr','nl','si','mrj','sk','el','sl','ka','sw','gu','su','da','tg','he','th','yi','tl','id','ta','ga','tt','it','te','is','tr','es','udm','kk','uz','kn','uk','ca','ur','ky','fi','zh','fr','ko','hi','xh','hr','km','cs','lo','sv','la','gd','lv','et','lt','eo','lb','jv','mg','ja','ms'],
prompt: {
retry: 'That\'s not a valid language! try again.'
},
default: 'en' default: 'en'
}, },
{ {
@ -23,7 +25,7 @@ class TranslationCommand extends Command {
description: { description: {
content: 'Translate what you send in your desired language. You can find the language code here: https://tech.yandex.com/translate/doc/dg/concepts/api-overview-docpage/', content: 'Translate what you send in your desired language. You can find the language code here: https://tech.yandex.com/translate/doc/dg/concepts/api-overview-docpage/',
usage: '[language code] [Text to translate]', usage: '[language code] [Text to translate]',
examples: ['fr What are we doing today?', 'en Que faisons-nous aujourd\'hui?'] examples: ['fr "What are we doing today?"', 'en "Que faisons-nous aujourd\'hui?"']
} }
}); });
} }
@ -43,7 +45,7 @@ class TranslationCommand extends Command {
return message.channel.send('An error has occured'); return message.channel.send('An error has occured');
const translationEmbed = new Discord.RichEmbed() const translationEmbed = new MessageEmbed()
.setColor('#0099ff') .setColor('#0099ff')
.setTitle('Asked for the following translation:') .setTitle('Asked for the following translation:')
.setAuthor(message.author.username) .setAuthor(message.author.username)

View file

@ -1,4 +1,5 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const { MessageEmbed } = require('discord.js');
class UpdootCommand extends Command { class UpdootCommand extends Command {
constructor() { constructor() {
@ -15,17 +16,14 @@ class UpdootCommand extends Command {
} }
async exec(message) { async exec(message) {
const upDoot = { const upDoot = new MessageEmbed()
color: 0x93C54B, .setColor('#0099ff')
title: 'Vote for my bot', .setTitle('Vote for my bot')
url: 'https://discordbots.org/bot/377563711927484418/vote', .setURL('https://discordbots.org/bot/377563711927484418/vote')
description: 'You can vote for my bot if you think the bot is awesome!', .setAuthor(message.author.username)
timestamp: new Date(), .setDescription('You can vote for my bot if you think the bot is awesome!')
footer: { .setTimestamp()
text: 'Thanks for the updoots', .setFooter('Thanks for the updoots', 'https://cdn.discordapp.com/avatars/377563711927484418/1335d202aa466dbeaa4ed2e4b616484a.png?size=2048');
icon_url: 'https://cdn.discordapp.com/avatars/377563711927484418/1335d202aa466dbeaa4ed2e4b616484a.png?size=2048',
},
};
message.channel.send({ embed: upDoot }); message.channel.send({ embed: upDoot });
} }

View file

@ -1,33 +1,49 @@
const { AkairoClient } = require('discord-akairo'); const { AkairoClient, CommandHandler, InhibitorHandler, ListenerHandler } = require('discord-akairo');
const { token, prefix, ownerID, statsChannel } = require('./config.json'); const { token, prefix, ownerID } = require('./config.json');
const client = new AkairoClient({
class hahaYesClient extends AkairoClient {
constructor() {
super({
ownerID: ownerID, ownerID: ownerID,
}, {
disableEveryone: true
});
this.commandHandler = new CommandHandler(this, {
directory: './commands/',
prefix: prefix, prefix: prefix,
commandUtil: true,
commandUtilLifetime: 60000,
allowMention: true, allowMention: true,
handleEdits: true, handleEdits: true,
});
this.inhibitorHandler = new InhibitorHandler(this, {
directory: './inhibitors/',
emitters: { emitters: {
process process
}, },
commandUtil: true, });
commandUtilLifetime: 600000,
commandDirectory: './commands/',
inhibitorDirectory: './inhibitors/',
listenerDirectory: './listeners/'
}, {
disableEveryone: true
});
// Ready messages dosent work on the listeners event for some reasons this.listenerHandler = new ListenerHandler(this, {
client.on('ready', async () => { directory: './listeners/'
// Send stats to the console });
console.log(`\x1b[32mLogged in as \x1b[34m${client.user.tag}\x1b[0m! (\x1b[33m${client.user.id}\x1b[0m)`);
console.log(`Ready to serve in \x1b[33m${client.channels.size}\x1b[0m channels on \x1b[33m${client.guilds.size}\x1b[0m servers, for a total of \x1b[33m${client.users.size}\x1b[0m users. \x1b${client.readyAt}\x1b[0m`);
// Send stats to the 'stats' channel in the support server if its not the test bot
if (client.user.id == 377563711927484418) {
const channel = client.channels.get(statsChannel);
channel.send(`Ready to serve in ${client.channels.size} channels on ${client.guilds.size} servers, for a total of ${client.users.size} users. ${client.readyAt}`);
client.user.setActivity(`${prefix} feedback <feedback> to tell me what you think of the bot! | ${prefix} help`); }
});
this.listenerHandler.setEmitters({
commandHandler: this.commandHandler,
inhibitorHandler: this.inhibitorHandler,
listenerHandler: this.listenerHandler
});
this.commandHandler.useInhibitorHandler(this.inhibitorHandler);
this.commandHandler.useListenerHandler(this.listenerHandler);
this.listenerHandler.loadAll();
this.inhibitorHandler.loadAll();
this.commandHandler.loadAll();
}
}
const client = new hahaYesClient();
client.login(token); client.login(token);

1
json/autoresponse.json Normal file
View file

@ -0,0 +1 @@
{}

1
json/starboard.json Normal file
View file

@ -0,0 +1 @@
[]

View file

@ -1,16 +0,0 @@
const { Listener } = require('discord-akairo');
class UnhandledRejectionListener extends Listener {
constructor() {
super('unhandledRejection', {
eventName: 'unhandledRejection',
emitter: 'process'
});
}
exec(error) {
console.error(error);
}
}
module.exports = UnhandledRejectionListener;

View file

@ -4,7 +4,7 @@ class CommandBlockedListener extends Listener {
constructor() { constructor() {
super('commandBlocked', { super('commandBlocked', {
emitter: 'commandHandler', emitter: 'commandHandler',
eventName: 'commandBlocked' event: 'commandBlocked'
}); });
} }

View file

@ -1,5 +1,5 @@
const { Listener } = require('discord-akairo'); const { Listener } = require('discord-akairo');
const Discord = require('discord.js'); const { MessageEmbed } = require('discord.js');
const { statsChannel } = require('../config.json'); const { statsChannel } = require('../config.json');
@ -7,14 +7,14 @@ class guildCreateListener extends Listener {
constructor() { constructor() {
super('guildCreate', { super('guildCreate', {
emitter: 'client', emitter: 'client',
eventName: 'guildCreate' event: 'guildCreate'
}); });
} }
async exec(guild) { async exec(guild) {
console.log(`${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}`); console.log(`${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}`);
const channel = this.client.channels.get(statsChannel); const channel = this.client.channels.get(statsChannel);
const addEmbed = new Discord.RichEmbed() const addEmbed = new MessageEmbed()
.setColor('#52e80d') .setColor('#52e80d')
.setTitle('Someone added me ! YAY :D') .setTitle('Someone added me ! YAY :D')
.setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4') .setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4')

View file

@ -1,5 +1,5 @@
const { Listener } = require('discord-akairo'); const { Listener } = require('discord-akairo');
const Discord = require('discord.js'); const { MessageEmbed } = require('discord.js');
const { statsChannel } = require('../config.json'); const { statsChannel } = require('../config.json');
@ -7,7 +7,7 @@ class guildCreateListener extends Listener {
constructor() { constructor() {
super('guildDelete', { super('guildDelete', {
emitter: 'client', emitter: 'client',
eventName: 'guildDelete' event: 'guildDelete'
}); });
} }
@ -15,7 +15,7 @@ class guildCreateListener extends Listener {
console.log(`***BOT KICKED***\n${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}\n***BOT KICKED***`); console.log(`***BOT KICKED***\n${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}\n***BOT KICKED***`);
const channel = this.client.channels.get(statsChannel); const channel = this.client.channels.get(statsChannel);
const kickEmbed = new Discord.RichEmbed() const kickEmbed = new MessageEmbed()
.setColor('#FF0000') .setColor('#FF0000')
.setTitle('They kicked me out :(') .setTitle('They kicked me out :(')
.setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4') .setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4')

View file

@ -4,20 +4,26 @@ const reactObject = require('../json/react.json');
const imgResponseObject = require('../json/imgreply.json'); const imgResponseObject = require('../json/imgreply.json');
const reload = require('auto-reload'); const reload = require('auto-reload');
class MessageListener extends Listener { class messageListener extends Listener {
constructor() { constructor() {
super('message', { super('message', {
emitter: 'client', emitter: 'client',
eventName: 'message' event: 'message'
}); });
} }
async exec(message) { async exec(message) {
let autoresponse = reload('../json/autoresponse.json'); let autoresponse = reload('../json/autoresponse.json');
let message_content = message.content.toLowerCase(); let message_content = message.content.toLowerCase();
let customresponse = reload(`../tag/${message.guild.id}.json`);
if (message.author.bot) return; { if (message.author.bot) return; {
// User autoresponse
if(customresponse[message_content]) {
message.channel.send(customresponse[message_content]);
}
// If autoresponse is enable send the response // If autoresponse is enable send the response
if(autoresponse[message.channel.id] == 'enable') { if(autoresponse[message.channel.id] == 'enable') {
// Reply with images as attachement // Reply with images as attachement
@ -39,13 +45,8 @@ class MessageListener extends Listener {
message.react('496028845967802378'); message.react('496028845967802378');
} }
} }
let customresponse = reload(`../tag/${message.guild.id}.json`);
// User autoresponse
if(customresponse[message_content]) {
message.channel.send(customresponse[message_content]);
}
} }
} }
} }
module.exports = MessageListener; module.exports = messageListener;

View file

@ -1,51 +1,57 @@
const { Listener } = require('discord-akairo'); const { Listener } = require('discord-akairo');
const Discord = require('discord.js'); const { MessageEmbed } = require('discord.js');
const reload = require('auto-reload'); const reload = require('auto-reload');
let messageID = require('../json/starboard.json');
class MessageReactionAddListener extends Listener { class MessageReactionAddListener extends Listener {
constructor() { constructor() {
super('messagereactionadd', { super('messagereactionadd', {
emitter: 'client', emitter: 'client',
eventName: 'messageReactionAdd' event: 'messageReactionAdd'
}); });
} }
async exec(reaction, message, client) { async exec(reaction) {
let messageContent = reaction.message.content; let messageContent = reaction.message.content;
let messageAttachments = reaction.message.attachments.map(u=> `${u.url}`); let messageAttachments = reaction.message.attachments.map(u=> `${u.url}`);
if (reaction.emoji.name === '🌟' && reaction.count === 4) { if (reaction.emoji.name === '🌟' && reaction.count === 4) {
if (messageID.includes(reaction.message.id))
return console.log('Message already in starboard!');
messageID.push(reaction.message.id);
let starboardChannel = reload(`../starboard/${reaction.message.guild.id}.json`); let starboardChannel = reload(`../starboard/${reaction.message.guild.id}.json`);
const channel = this.client.channels.get(starboardChannel['starboard']); const channel = this.client.channels.get(starboardChannel['starboard']);
const starEmbed = new Discord.RichEmbed() const starEmbed = new MessageEmbed()
.setColor() .setColor()
.setDescription(messageContent) .setDescription(messageContent)
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL)
.setTimestamp() .setTimestamp();
channel.send({ embed: starEmbed}); channel.send({ embed: starEmbed});
return channel.send(`From: ${reaction.message.channel}\n${messageAttachments}`); return channel.send(`From: ${reaction.message.channel} ID: ${reaction.message.id} \n${messageAttachments}`);
} }
if (reaction.emoji.name === '✡' && reaction.count === 4) { if (reaction.emoji.name === '✡' && reaction.count === 4) {
let shameboardChannel = reload(`../starboard/${message.guild.id}.json`); if (messageID.includes(reaction.message.id))
const channel = client.channels.get(shameboardChannel['shameboard']); return console.log('Message already in starboard!');
const starEmbed = new Discord.RichEmbed() messageID.push(reaction.message.id);
let shameboardChannel = reload(`../starboard/${reaction.message.guild.id}.json`);
const channel = this.client.channels.get(shameboardChannel['shameboard']);
const shameEmbed = new MessageEmbed()
.setColor() .setColor()
.setDescription(messageContent) .setDescription(messageContent)
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL)
.setTimestamp() .setTimestamp();
try { channel.send({ embed: shameEmbed});
channel.send({ embed: starEmbed}); return channel.send(`From: ${reaction.message.channel} ID: ${reaction.message.id} \n${messageAttachments}`);
await channel.send(messageAttachments);
} catch(err) {
console.error('There is no shameboard');
} }
} }
}
} }
module.exports = MessageReactionAddListener; module.exports = MessageReactionAddListener;

26
listeners/ready.js Normal file
View file

@ -0,0 +1,26 @@
const { Listener } = require('discord-akairo');
const { prefix, statsChannel } = require('../config.json');
class ReadyListener extends Listener {
constructor() {
super('ready', {
emitter: 'client',
event: 'ready'
});
}
async exec() {
// Send stats to the console
console.log(`\x1b[32mLogged in as \x1b[34m${this.client.user.tag}\x1b[0m! (\x1b[33m${this.client.user.id}\x1b[0m)`);
console.log(`Ready to serve in \x1b[33m${this.client.channels.size}\x1b[0m channels on \x1b[33m${this.client.guilds.size}\x1b[0m servers, for a total of \x1b[33m${this.client.users.size}\x1b[0m users. \x1b${this.client.readyAt}\x1b[0m`);
// Send stats to the 'stats' channel in the support server if its not the test bot
if (this.client.user.id == 377563711927484418) {
const channel = this.client.channels.get(statsChannel);
channel.send(`Ready to serve in ${this.client.channels.size} channels on ${this.client.guilds.size} servers, for a total of ${this.client.users.size} users. ${this.client.readyAt}`);
this.client.user.setActivity(`${prefix} feedback <feedback> to tell me what you think of the bot! | ${prefix} help`);
}
}
}
module.exports = ReadyListener;

View file

@ -1,37 +1,32 @@
{ {
"name": "discordbot", "name": "hahayes",
"version": "1.0.0", "version": "2.1.0",
"description": "A simple discord bot made with discord.js and commando",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"auto-reload": "^0.1.0", "auto-reload": "^0.1.0",
"canvas": "^2.2.0", "canvas": "^2.2.0",
"eslint": "^5.11.1", "discord-akairo": "github:1Computer1/discord-akairo#master",
"eslint-config-standard": "^12.0.0", "discord.js": "github:discordjs/discord.js#master",
"discord.js": "^11.4.2",
"eslint-plugin-import": "^2.14.0",
"discord-akairo": "^7.5.5",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"node-fetch": "^2.3.0", "node-fetch": "^2.3.0",
"reload-json": "^0.3.1", "reload-json": "^0.3.1",
"superagent": "^4.1.0", "superagent": "^4.1.0",
"youtube-dl": "^1.12.2" "youtube-dl": "^1.12.2"
}, },
"devDependencies": {}, "devDependencies": {
"scripts": { "eslint": "^5.11.1",
"test": "echo \"Error: no test specified\" && exit 1" "eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://gitlab.com/LoicBersier/DiscordBot.git" "url": "git+https://gitlab.com/LoicBersier/DiscordBot.git"
}, },
"keywords": [],
"author": "",
"license": "ISC",
"bugs": { "bugs": {
"url": "https://gitlab.com/LoicBersier/DiscordBot/issues" "url": "https://gitlab.com/LoicBersier/DiscordBot/issues"
}, },
"homepage": "https://gitlab.com/LoicBersier/DiscordBot#readme" "homepage": "https://gitlab.com/LoicBersier/DiscordBot#readme",
"description": ""
} }