mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Cleverbot
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
const { TOKEN, OWNER, PREFIX, INVITE } = process.env;
|
const { TOKEN, OWNER, PREFIX, INVITE, CLEVS_KEY, CLEVS_USER } = process.env;
|
||||||
|
|
||||||
const { CommandoClient } = require('discord.js-commando');
|
const { CommandoClient } = require('discord.js-commando');
|
||||||
const client = new CommandoClient({
|
const client = new CommandoClient({
|
||||||
commandPrefix: PREFIX,
|
commandPrefix: PREFIX,
|
||||||
@@ -8,12 +9,20 @@ const client = new CommandoClient({
|
|||||||
unknownCommandResponse: false
|
unknownCommandResponse: false
|
||||||
});
|
});
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const { carbon, discordBots } = require('./structures/Stats');
|
const { carbon, discordBots } = require('./structures/Stats');
|
||||||
|
|
||||||
const SequelizeProvider = require('./providers/Sequelize');
|
const SequelizeProvider = require('./providers/Sequelize');
|
||||||
const Database = require('./structures/PostgreSQL');
|
const Database = require('./structures/PostgreSQL');
|
||||||
|
|
||||||
Database.start();
|
Database.start();
|
||||||
|
|
||||||
|
const Cleverbot = require('./structures/Cleverbot');
|
||||||
|
const clevs = new Cleverbot({
|
||||||
|
key: CLEVS_KEY,
|
||||||
|
user: CLEVS_USER,
|
||||||
|
nick: 'XiaoBot'
|
||||||
|
});
|
||||||
|
|
||||||
client.setProvider(new SequelizeProvider(Database.db));
|
client.setProvider(new SequelizeProvider(Database.db));
|
||||||
|
|
||||||
client.registry
|
client.registry
|
||||||
@@ -36,6 +45,19 @@ client.registry
|
|||||||
.registerDefaultCommands({ help: false })
|
.registerDefaultCommands({ help: false })
|
||||||
.registerCommandsIn(path.join(__dirname, 'commands'));
|
.registerCommandsIn(path.join(__dirname, 'commands'));
|
||||||
|
|
||||||
|
const mention = new RegExp(`(<!?@${client.user.id}>)`, 'g');
|
||||||
|
client.on('message', async (msg) => {
|
||||||
|
if (msg.isMentioned(client.user)) {
|
||||||
|
const message = msg.content.replace(mention, '');
|
||||||
|
try {
|
||||||
|
const { body } = await clevs.ask(message);
|
||||||
|
return msg.reply(body.response);
|
||||||
|
} catch (err) {
|
||||||
|
return msg.reply(err);
|
||||||
|
}
|
||||||
|
} else return;
|
||||||
|
});
|
||||||
|
|
||||||
client.dispatcher.addInhibitor(msg => {
|
client.dispatcher.addInhibitor(msg => {
|
||||||
if (msg.channel.type === 'dm') return false;
|
if (msg.channel.type === 'dm') return false;
|
||||||
const role = msg.guild.settings.get('singleRole');
|
const role = msg.guild.settings.get('singleRole');
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "18.8.3",
|
"version": "18.8.4",
|
||||||
"description": "A Discord Bot",
|
"description": "A Discord Bot",
|
||||||
"main": "shardingmanager.js",
|
"main": "shardingmanager.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
const request = require('superagent');
|
||||||
|
|
||||||
|
class Cleverbot {
|
||||||
|
constructor(options) {
|
||||||
|
this.key = options.key;
|
||||||
|
this.user = options.user;
|
||||||
|
this.nick = options.nick;
|
||||||
|
}
|
||||||
|
|
||||||
|
create() {
|
||||||
|
return request
|
||||||
|
.post('https://cleverbot.io/1.0/create')
|
||||||
|
.send({
|
||||||
|
user: this.user,
|
||||||
|
key: this.key,
|
||||||
|
nick: this.nick
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ask(text) {
|
||||||
|
return request
|
||||||
|
.post('https://cleverbot.io/1.0/ask')
|
||||||
|
.send({
|
||||||
|
user: this.user,
|
||||||
|
key: this.key,
|
||||||
|
nick: this.nick,
|
||||||
|
text
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Cleverbot;
|
||||||
Reference in New Issue
Block a user