mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-11 03:14:35 +02:00
Revamp Cleverbot
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
const request = require('node-superfetch');
|
||||
const { CLEVERBOT_KEY } = process.env;
|
||||
const blankResponses = ['What?', 'Huh?', 'I don\'t understand.', 'Speak up, please.'];
|
||||
|
||||
module.exports = class Cleverbot {
|
||||
constructor(client, channelID, authorID, key = CLEVERBOT_KEY) {
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
this.channelID = channelID;
|
||||
this.authorID = authorID;
|
||||
this.cs = null;
|
||||
this.timeout = this.setTimeout();
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
async respond(input) {
|
||||
const { body } = await request
|
||||
.get('https://www.cleverbot.com/getreply')
|
||||
.query({
|
||||
key: this.key,
|
||||
cs: this.cs || '',
|
||||
input
|
||||
});
|
||||
clearTimeout(this.timeout);
|
||||
this.timeout = this.setTimeout();
|
||||
this.cs = body.cs;
|
||||
return body.output || blankResponses[Math.floor(Math.random() * blankResponses.length)];
|
||||
}
|
||||
|
||||
shouldRespond(msg) {
|
||||
return msg.channel.id === this.channelID && msg.author.id === this.authorID;
|
||||
}
|
||||
|
||||
setTimeout() {
|
||||
return setTimeout(() => {
|
||||
this.manager.delete(this.channelID);
|
||||
if (!this.channel) return;
|
||||
this.channel.send('Conversation timed out.').catch(() => null);
|
||||
}, 600000);
|
||||
}
|
||||
|
||||
get channel() {
|
||||
return this.client.channels.cache.get(channelID);
|
||||
}
|
||||
|
||||
get author() {
|
||||
return this.client.users.cache.get(authorID);
|
||||
}
|
||||
};
|
||||
@@ -39,6 +39,7 @@ module.exports = class XiaoClient extends CommandoClient {
|
||||
this.pokemon = new PokemonStore();
|
||||
this.games = new Collection();
|
||||
this.dispatchers = new Map();
|
||||
this.cleverbots = new Map();
|
||||
this.phone = new PhoneManager(this);
|
||||
this.activities = activities;
|
||||
this.leaveMessages = leaveMsgs;
|
||||
|
||||
Reference in New Issue
Block a user