Haha-Yes/index.js

149 lines
6.9 KiB
JavaScript
Raw Normal View History

2018-09-18 21:33:52 +02:00
const { CommandoClient } = require('discord.js-commando');
2018-09-26 13:35:43 +02:00
const Discord = require('discord.js');
2018-09-24 17:10:49 +02:00
const path = require('path');
2018-09-29 11:22:59 +02:00
const { token, prefix, statsChannel, ownerID, supportServer } = require('./config.json');
2018-09-20 17:50:47 +02:00
const responseObject = require("./json/reply.json");
const reactObject = require("./json/react.json");
2018-09-21 19:12:11 +02:00
const imgResponseObject = require("./json/imgreply.json");
2018-11-28 01:35:26 +01:00
const SelfReloadJSON = require('self-reload-json');
2018-09-07 21:28:42 +02:00
// Prefix and ownerID and invite to support server
2018-09-07 00:24:03 +02:00
const client = new CommandoClient({
commandPrefix: prefix,
owner: ownerID,
invite: supportServer,
2018-09-10 18:52:19 +02:00
unknownCommandResponse: false,
disableEveryone: true,
2018-09-07 00:24:03 +02:00
});
2018-09-07 21:28:42 +02:00
// Command groups
2018-09-07 00:24:03 +02:00
client.registry
2018-09-07 19:07:10 +02:00
.registerDefaultTypes()
.registerGroups([
['fun', 'Fun'],
2018-10-15 00:32:19 +02:00
['images', 'Images'],
['utility', 'Utility'],
2018-12-20 03:08:43 +01:00
['reserved', 'Reserved'],
['admin', 'Admins'],
['owner', 'Owner'],
2018-10-15 00:32:19 +02:00
2018-09-07 19:07:10 +02:00
])
.registerDefaultGroups()
2018-10-08 18:10:07 +02:00
.registerDefaultCommands({
2018-10-09 16:31:23 +02:00
ping: false
2018-10-08 18:10:07 +02:00
})
2018-09-07 19:07:10 +02:00
.registerCommandsIn(path.join(__dirname, 'commands'));
2018-09-18 21:33:52 +02:00
// Ready messages
2018-09-19 16:43:51 +02:00
client.on('ready', async () => {
2018-09-18 21:33:52 +02:00
// Send stats to the console
2018-10-10 12:05:46 +02:00
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`);
2018-09-18 21:33:52 +02:00
// Send stats to the "stats" channel in the support server if its not the test bot
2018-09-29 18:06:41 +02:00
if (client.user.id == 377563711927484418) {
2018-09-18 21:33:52 +02:00
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`); }
2018-09-18 21:33:52 +02:00
});
2018-09-29 11:21:28 +02:00
2018-09-18 21:33:52 +02:00
// When bot join a guild send embeds with details about it.
2018-09-19 16:43:51 +02:00
client.on("guildCreate", async guild => {
2018-09-23 23:04:13 +02:00
console.log(`${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}`);
2018-09-18 21:33:52 +02:00
const channel = client.channels.get(statsChannel);
2018-09-26 13:35:43 +02:00
const addEmbed = new Discord.RichEmbed()
2018-09-27 15:19:24 +02:00
.setColor("#52e80d")
2018-09-26 13:35:43 +02:00
.setTitle('Someone added me ! YAY :D')
2018-10-09 22:53:45 +02:00
.setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4')
.setThumbnail(guild.iconURL)
.setDescription(`${guild.name}\n${guild.id}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\n(${guild.owner.id})`)
2018-09-26 13:35:43 +02:00
.setTimestamp()
2018-09-18 21:33:52 +02:00
channel.send({ embed: addEmbed }`\n\nIm now in **${client.guilds.size}** servers with **${client.users.size}** users`);
2018-09-29 11:21:28 +02:00
});
2018-09-18 21:33:52 +02:00
// When bot get kicked from a guild send embeds with details about it.
2018-09-19 16:43:51 +02:00
client.on("guildDelete", async guild => {
2018-09-23 23:04:13 +02:00
console.log(`***BOT KICKED***\n${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}\n***BOT KICKED***`);
2018-09-18 21:33:52 +02:00
const channel = client.channels.get(statsChannel);
2018-09-29 11:21:28 +02:00
2018-09-26 13:35:43 +02:00
const kickEmbed = new Discord.RichEmbed()
.setColor("#FF0000")
.setTitle('They kicked me out :(')
2018-10-09 22:53:45 +02:00
.setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4')
.setThumbnail(guild.iconURL)
.setDescription(`${guild.name}\n${guild.id}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\n(${guild.owner.id})`)
2018-09-26 13:35:43 +02:00
.setTimestamp()
console.log('***BOT KICKED***')
channel.send({ embed: kickEmbed }`\n\nIm now in **${client.guilds.size}** servers with **${client.users.size}** users`);
2018-09-29 11:21:28 +02:00
});
2018-09-08 23:34:08 +02:00
2018-09-19 16:43:51 +02:00
client.on("message", async (message) => {
2018-12-08 05:13:05 +01:00
try {
var customresponse = new SelfReloadJSON(`./tag/${message.guild.id}.json`)
var autoresponse = new SelfReloadJSON('./json/autoresponse.json');
2018-12-06 18:50:18 +01:00
2018-12-08 05:13:05 +01:00
let message_content = message.content.toLowerCase();
2018-12-14 14:36:20 +01:00
// fix a stupid bug that happen for idk wich reasons pls why tf it happen
2018-12-09 07:53:53 +01:00
if (message_content == ('stop')) return;
if (message_content == ('is')) return;
if (message_content == ('on')) return;
if (message_content == ('once')) return;
2018-12-14 14:36:20 +01:00
if (message_content == ('save')) return;
2018-12-08 05:13:05 +01:00
if (message.author.bot) return; {
// User autoresponse
2018-12-09 07:53:53 +01:00
if(customresponse[message_content]) {
2018-12-08 05:13:05 +01:00
message.channel.send(customresponse[message_content])
2018-12-09 07:53:53 +01:00
}
2018-12-08 05:13:05 +01:00
// If autoresponse is enable send the response
if(autoresponse[message.channel.id] == 'enable') {
// Reply with images as attachement
if(imgResponseObject[message_content]) {
message.channel.send({files: [imgResponseObject[message_content]]});
}
// React only to the messages
else if(reactObject[message_content]) {
message.react(reactObject[message_content]);
}
// auto respond to messages
else if(responseObject[message_content]) {
message.channel.send(responseObject[message_content]);
// If it contain "like if" react with 👍
} else if (message_content.includes("like if")) {
message.react("\u{1F44D}")
// If it contain "jeff" react with a jeff emote
} else if (message_content.includes("jeff")) {
message.react("496028845967802378")
}
}}
} catch(err) {
console.error(err)
}
})
2018-09-08 01:37:16 +02:00
2018-11-30 05:02:21 +01:00
// Very basic starboard
client.on('messageReactionAdd', async (reaction, message) => {
let messageContent = reaction.message.content;
let messageAttachments = reaction.message.attachments.map(u=> `${u.url}`);
let messageAuthor = reaction.message.author.username;
let messageChannel = reaction.message.channel.name;
if (reaction.emoji.name === '🌟' && reaction.count === 4) {
const channel = client.channels.find(channel => channel.name === "starboard");
channel.send(`From the channel: **${messageChannel}**\n${messageAuthor}\n${messageContent}\n${messageAttachments}`)
2018-12-02 22:18:32 +01:00
.catch
console.error('There is no starboard')
2018-11-30 05:02:21 +01:00
}
if (reaction.emoji.name === '✡' && reaction.count === 4) {
const channel = client.channels.find(channel => channel.name === "shameboard");
channel.send(`From the channel: **${messageChannel}**\n${messageAuthor}\n${messageContent}\n${messageAttachments}`)
2018-12-02 22:18:32 +01:00
.catch
console.error('There is no shameboard')
2018-11-30 05:02:21 +01:00
}
2018-12-02 22:18:32 +01:00
})
2018-11-30 05:02:21 +01:00
2018-09-07 19:07:10 +02:00
client.on('error', console.error);
2018-09-20 17:46:08 +02:00
process.on('unhandledRejection', error => console.error('Uncaught Promise Rejection', error));
2018-09-07 00:24:03 +02:00
2018-09-07 19:07:10 +02:00
client.login(token);