'use strict'

const commando = require('discord.js-commando');
const path = require('path');
const oneLine = require('common-tags').oneLine;
const sqlite = require('sqlite');
const config = require('config.json')('./config.json');
const dataparser = require('./utilitys/dataparser.js');
const rankmanager = require('./utilitys/rankmanager.js')
const cleverbotio = require('cleverbot.io');

const client = new commando.Client({
	owner: config.owner,
	commandPrefix: '!',
	unknownCommandResponse: false
});

client.parser = new dataparser.Parser(client);;
client.rankmanager = new rankmanager.GuildRankManager(client);
var cleverbot = new cleverbotio(config.cleverbot.user, config.cleverbot.key);
cleverbot.setNick(config.cleverbot.session);
cleverbot.create(function (err, session) {
	client.cleverbot = cleverbot;
});

client
	.on('error', console.error)
	.on('warn', console.warn)
	.on('debug', console.log)
	.on('ready', () => {
		console.log(`Client ready; logged in as ${client.user.username}#${client.user.discriminator} (${client.user.id})`);
		client.user.setAvatar('./assets/img/pfp.png')
			.then("Set new avatar!");
	})
	.on('disconnect', () => { console.warn('Disconnected!'); })
	.on('reconnecting', () => { console.warn('Reconnecting...'); })
	.on('commandError', (cmd, err) => {
		if(err instanceof commando.FriendlyError) return;
		console.error(`Error in command ${cmd.groupID}:${cmd.memberName}`, err);
	})
	.on('commandBlocked', (msg, reason) => {
		console.log(oneLine`
			Command ${msg.command ? `${msg.command.groupID}:${msg.command.memberName}` : ''}
			blocked; ${reason}
		`);
	})
	.on('commandPrefixChange', (guild, prefix) => {
		console.log(oneLine`
			Prefix ${prefix === '' ? 'removed' : `changed to ${prefix || 'the default'}`}
			${guild ? `in guild ${guild.name} (${guild.id})` : 'globally'}.
		`);
	})
	.on('commandStatusChange', (guild, command, enabled) => {
		console.log(oneLine`
			Command ${command.groupID}:${command.memberName}
			${enabled ? 'enabled' : 'disabled'}
			${guild ? `in guild ${guild.name} (${guild.id})` : 'globally'}.
		`);
	})
	.on('groupStatusChange', (guild, group, enabled) => {
		console.log(oneLine`
			Group ${group.id}
			${enabled ? 'enabled' : 'disabled'}
			${guild ? `in guild ${guild.name} (${guild.id})` : 'globally'}.
		`);
	})
	.on('message', msg => {
		if (msg.channel.type != 'dm') {
				if (msg.guild.id == config.console.guild
					&& msg.channel.id == config.console.channel
					&& config.console.auth.indexOf(msg.author.id) >= 0) {
						var cmdmsg = new commando.CommandMessage(msg, client.registry.findCommands('eval')[0], msg.content);
						cmdmsg.run();
					}
					if (msg.mentions.has(client.user.id)
						&& client.provider.get(msg.guild, 'disableClever', true)
						&& !msg.mentions.everyone) {
						msg.channel.startTyping();
						client.cleverbot.ask(msg.content, function (err, response) {
							msg.reply(response);
							msg.channel.stopTyping();
						});
					}
			}
	});

client.registry
    .registerDefaults()
    .registerGroups([
		['info', 'Informational'],
		['opt', 'Option'],
		['voice', 'Voice'],
		['driver', 'Driver'],
		['mod', 'Moderator'],
		['lead', 'Leader'],
		['admin', 'Administrator'],
		['rowner', 'Room Owner']
    ])
	.registerCommandsIn(path.join(__dirname, 'commands'));

client.setProvider(
	sqlite.open(path.join(__dirname, 'database.sqlite3')).then(db => new commando.SQLiteProvider(db))
).catch(console.error);

client.login(config.token);

@@ -52,24 +52,72 @@
 commando');%0A
+const %7B MessageEmbed %7D = require('discord.js');%0A
 const path =
@@ -182,16 +182,74 @@
 neLine;%0A
+const stripIndents = require('common-tags').stripIndents;%0A
 const sq
@@ -3068,16 +3068,705 @@
 %09%7D%0A%09%09%09%7D%0A
+%09%7D)%0A%09.on('guildCreate', guild =%3E %7B%0A%09%09if (!config.guildUpdates) return;%0A%09%09if (!config.guildUpdates.guild %7C%7C !config.guildUpdates.channel) return;%0A%0A%09%09client.guilds.get(config.guildUpdates.guild)%0A%09%09.channels.get(config.guildUpdates.channel)%0A%09%09.send(new MessageEmbed()%0A%09%09.setAuthor(client.user.username, client.user.avatarURL())%0A%09%09.setTitle('New guild joined!')%0A%09%09.setColor('#19da2c')%0A%09%09.addField('Guild Details', stripIndents%60Name - $%7Bguild.name%7D%0A%09%09ID - $%7Bguild.id%7D%0A%09%09Member Count - $%7Bguild.memberCount%7D $%7Bguild.large ? '(Large)' : ''%7D%0A%09%09Owner - $%7Bguild.owner%7D ($%7Bguild.ownerID%7D)%0A%09%09Region - $%7Bguild.region%7D%0A%09%09Verification Level - $%7Bguild.verificationLevel%7D%0A%09%09Verified - $%7Bguild.verified%7D%60));%0A
 %09%7D);%0A%0Acl

Add guild join events