CommandoClient, Change Filenames, etc.

This commit is contained in:
Daniel Odendahl Jr
2017-05-23 16:14:48 +00:00
parent 38674485d1
commit 67f888e7b0
44 changed files with 77 additions and 54 deletions
+11 -1
View File
@@ -1 +1,11 @@
node_modules/
# Logs
logs
*.log
npm-debug.log*
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules
+1 -1
View File
@@ -1 +1 @@
worker: node shardingmanager.js
worker: node Shard.js
+7 -3
View File
@@ -1,13 +1,17 @@
# XiaoBot
[![Discord](https://discordapp.com/api/guilds/252317073814978561/embed.png)](https://discord.gg/fqQF8mc)
Public Source Code for the Discord Bot XiaoBot, a Discord bot coded in JavaScript with [discord.js](https://github.com/hydrabolt/discord.js) using the [Commando](https://github.com/Gawdl3y/discord.js-commando) command framework.
Public Source Code for the Discord Bot XiaoBot, a Discord bot coded in
JavaScript with [discord.js](https://github.com/hydrabolt/discord.js) using the
[Commando](https://github.com/Gawdl3y/discord.js-commando) command framework.
## Adding it to Your Server
You can add XiaoBot to your server with [this link](https://discordapp.com/oauth2/authorize?client_id=278305350804045834&scope=bot&permissions=1345846343).
Visit XiaoBot's page on the Discord Bots list, which is quite fancy, with
[this link](https://bots.discord.pw/bots/278305350804045834).
## Home Server
You can join the home server with [this link](https://discord.gg/fqQF8mc).
## Licensing
The bot is licensed under an [ISC License](https://opensource.org/licenses/ISC). See the file `LICENSE.md` for more information.
The bot is licensed under an [ISC License](https://opensource.org/licenses/ISC).
See the file `LICENSE.md` for more information.
+1 -1
View File
@@ -1,4 +1,4 @@
const { ShardingManager } = require('discord.js');
const { TOKEN } = process.env;
const Manager = new ShardingManager('./index.js', { token: TOKEN });
const Manager = new ShardingManager('./XiaoBot.js', { token: TOKEN });
Manager.spawn(2);
+18 -30
View File
@@ -1,5 +1,7 @@
const { TOKEN, OWNER, PREFIX, INVITE, CLEVS_KEY, CLEVS_USER, CLEVS_NICK } = process.env;
const { CommandoClient, FriendlyError } = require('discord.js-commando');
const { TOKEN, OWNER, PREFIX, INVITE } = process.env;
const path = require('path');
const { FriendlyError } = require('discord.js-commando');
const CommandoClient = require('./structures/CommandoClient');
const client = new CommandoClient({
commandPrefix: PREFIX,
owner: OWNER,
@@ -8,21 +10,10 @@ const client = new CommandoClient({
unknownCommandResponse: false
});
const { RichEmbed } = require('discord.js');
const path = require('path');
const { carbon, dBots } = require('./structures/Stats');
const SequelizeProvider = require('./providers/Sequelize');
const Database = require('./structures/PostgreSQL');
const Cleverbot = require('cleverio');
const clevs = new Cleverbot({
key: CLEVS_KEY,
user: CLEVS_USER,
nick: CLEVS_NICK
});
Database.start();
clevs.create();
client.setProvider(new SequelizeProvider(Database.db));
client.setProvider(new SequelizeProvider(client.database));
client.registry
.registerDefaultTypes()
@@ -45,11 +36,9 @@ client.registry
.registerDefaultCommands({ help: false })
.registerCommandsIn(path.join(__dirname, 'commands'));
let mention;
client.on('ready', () => {
console.log(`[Ready] Shard ${client.shard.id} Logged in!`);
client.user.setGame(`x;help | Shard ${client.shard.id}`);
mention = new RegExp(`(<!?@${client.user.id}>)`, 'g');
});
client.on('disconnect', (event) => {
@@ -66,6 +55,17 @@ client.on('commandError', (command, err) => {
console.error(command.name, err);
});
client.dispatcher.addInhibitor(msg => {
if (msg.channel.type === 'dm') return false;
const role = msg.guild.settings.get('singleRole');
if (!role) return false;
if (!msg.guild.roles.has(role)) return false;
if (client.isOwner(msg.author)) return false;
if (msg.member.hasPermission('ADMINISTRATOR')) return false;
if (!msg.member.roles.has(role))
return ['singleRole', msg.reply(`Only the ${msg.guild.roles.get(role).name} role may use commands.`)];
});
client.on('message', async (msg) => {
if (msg.guild && msg.guild.settings.get('inviteGuard') && /(discord(\.gg\/|app\.com\/invite\/|\.me\/))/gi.test(msg.content)) {
if (msg.author.bot ||
@@ -85,9 +85,9 @@ client.on('message', async (msg) => {
if (role && !msg.member.roles.has(role)) return;
}
msg.channel.startTyping();
const message = msg.content.replace(mention, '');
const message = msg.content.replace(client.mentionRegex, '');
try {
const { response } = await clevs.ask(message);
const { response } = await client.cleverbot.ask(message);
return msg.reply(response)
.then(() => msg.channel.stopTyping());
} catch (err) {
@@ -119,16 +119,6 @@ client.on('messageReactionAdd', (reaction, user) => {
return channel.send({ embed });
});
client.dispatcher.addInhibitor(msg => {
if (msg.channel.type === 'dm') return false;
const role = msg.guild.settings.get('singleRole');
if (!role) return false;
if (client.isOwner(msg.author)) return false;
if (msg.member.hasPermission('ADMINISTRATOR')) return false;
if (!msg.member.roles.has(role))
return ['singleRole', msg.reply(`Only the ${msg.guild.roles.get(role).name} role may use commands.`)];
});
client.on('guildMemberAdd', (member) => {
const role = member.guild.roles.get(member.guild.settings.get('joinRole'));
if (member.guild.me.hasPermission('MANAGE_ROLES') && role)
@@ -158,7 +148,6 @@ client.on('guildCreate', async (guild) => {
console.log(`[Guild] I have joined ${guild.name}! (${guild.id})`);
const guilds = await client.shard.fetchClientValues('guilds.size');
const count = guilds.reduce((prev, val) => prev + val, 0);
console.log(`[Count] ${count}`);
carbon(count);
dBots(count, client.user.id);
});
@@ -167,7 +156,6 @@ client.on('guildDelete', async (guild) => {
console.log(`[Guild] I have left ${guild.name}... (${guild.id})`);
const guilds = await client.shard.fetchClientValues('guilds.size');
const count = guilds.reduce((prev, val) => prev + val, 0);
console.log(`[Count] ${count}`);
carbon(count);
dBots(count, client.user.id);
});
@@ -7,10 +7,10 @@ require('moment-duration-format');
module.exports = class GuildInfoCommand extends Command {
constructor(client) {
super(client, {
name: 'server',
aliases: ['guild', 'server-info', 'guild-info'],
name: 'server-info',
aliases: ['guild', 'server', 'guild-info'],
group: 'guildinfo',
memberName: 'server',
memberName: 'server-info',
description: 'Gives some info on the current server.',
guildOnly: true
});
@@ -5,7 +5,7 @@ module.exports = class QuantumCoinCommand extends Command {
constructor(client) {
super(client, {
name: 'quantum-coin',
aliases: ['qcoin'],
aliases: ['q-coin'],
group: 'response',
memberName: 'quantum-coin',
description: 'Flips a coin that lands on nothing.'
@@ -7,8 +7,8 @@ require('moment-duration-format');
module.exports = class UserInfoCommand extends Command {
constructor(client) {
super(client, {
name: 'user',
aliases: ['user-info', 'member', 'member-info'],
name: 'user-info',
aliases: ['user', 'member', 'member-info'],
group: 'userinfo',
memberName: 'user',
description: 'Gives some info on a user.',
@@ -7,7 +7,7 @@ module.exports = class ShardInfoCommand extends Command {
constructor(client) {
super(client, {
name: 'shard-info',
aliases: ['shard'],
aliases: ['shard', 'shard-stats'],
group: 'util',
memberName: 'shard-info',
description: 'Gives some bot info for the Shard you specify.',
+2 -4
View File
@@ -1,17 +1,15 @@
<div class="content">
<style>
.xiaobox {
.xiaobox2 {
border-radius: 5px;
padding: 15px;
font-size: 100%;
border-style: solid;
border-color: lime;
background-image: url("https://i.imgur.com/LJsgebW.jpg");
box-shadow: 10px 10px 5px #888888;
text-shadow: 2px 2px #3333ff;
}
</style>
<div class="xiaobox">
<div class="xiaobox2">
<h2>Features</h2>
<ol>
<li>Cleverbot!</li>
+2 -4
View File
@@ -1,17 +1,15 @@
<div class="content">
<style>
.xiaobox {
.xiaobox2 {
border-radius: 5px;
padding: 15px;
font-size: 100%;
border-style: solid;
border-color: lime;
background-image: url("https://i.imgur.com/LJsgebW.jpg");
box-shadow: 10px 10px 5px #888888;
text-shadow: 2px 2px #3333ff;
}
</style>
<div class="xiaobox">
<div class="xiaobox2">
<h2>Notes:</h2>
<ol>
<li>Moderation Commands Require a Channel set with x;modchannel to send Ban/Softban/Kick/Unban/Warn Logs</li>
+3 -3
View File
@@ -1,11 +1,11 @@
{
"name": "xiaobot",
"version": "19.13.0",
"version": "20.0.0",
"description": "A Discord Bot",
"main": "shardingmanager.js",
"main": "Shard.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node shardingmanager.js"
"start": "node Shard.js"
},
"repository": {
"type": "git",
+25
View File
@@ -0,0 +1,25 @@
const { Client } = require('discord.js-commando');
const Database = require('./PostgreSQL');
const Cleverbot = require('cleverio');
const { CLEVS_KEY, CLEVS_USER, CLEVS_NICK } = process.env;
class CommandoClient extends Client {
constructor(options) {
super(options);
this.database = Database.db;
this.cleverbot = new Cleverbot({
key: CLEVS_KEY,
user: CLEVS_USER,
nick: CLEVS_NICK
});
Database.start();
this.cleverbot.create();
}
get mentionRegex() {
return new RegExp(`<!?@${this.user.id}>`, 'g');
}
}
module.exports = CommandoClient;