mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 06:37:32 +02:00
Cleverbot Command
This commit is contained in:
@@ -21,6 +21,7 @@ SUCCESS_EMOJI_NAME=
|
|||||||
|
|
||||||
# API Keys, IDs, and Secrets
|
# API Keys, IDs, and Secrets
|
||||||
ALPHA_VANTAGE_KEY=
|
ALPHA_VANTAGE_KEY=
|
||||||
|
CLEVERBOT_KEY=
|
||||||
CUSTOM_SEARCH_ID=
|
CUSTOM_SEARCH_ID=
|
||||||
DEVIANTART_ID=
|
DEVIANTART_ID=
|
||||||
DEVIANTART_SECRET=
|
DEVIANTART_SECRET=
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ Xiao is a Discord bot coded in JavaScript with
|
|||||||
7. Run `npm i -g pm2` to install PM2.
|
7. Run `npm i -g pm2` to install PM2.
|
||||||
8. Run `pm2 start Xiao.js --name xiao` to run the bot.
|
8. Run `pm2 start Xiao.js --name xiao` to run the bot.
|
||||||
|
|
||||||
## Commands (340)
|
## Commands (341)
|
||||||
### Utility:
|
### Utility:
|
||||||
|
|
||||||
* **eval:** Executes JavaScript code.
|
* **eval:** Executes JavaScript code.
|
||||||
@@ -410,6 +410,7 @@ Xiao is a Discord bot coded in JavaScript with
|
|||||||
|
|
||||||
### Other:
|
### Other:
|
||||||
|
|
||||||
|
* **cleverbot:** Talk to Cleverbot.
|
||||||
* **prune:** Deletes up to 99 messages from the current channel.
|
* **prune:** Deletes up to 99 messages from the current channel.
|
||||||
* **strawpoll:** Generates a Strawpoll with the options you provide.
|
* **strawpoll:** Generates a Strawpoll with the options you provide.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const request = require('node-superfetch');
|
||||||
|
const { CLEVERBOT_KEY } = process.env;
|
||||||
|
const blankResponses = ['What?', 'Huh?', 'I don\'t understand.', 'Speak up, please.'];
|
||||||
|
|
||||||
|
module.exports = class CleverbotCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, {
|
||||||
|
name: 'cleverbot',
|
||||||
|
aliases: ['clevs', 'chat'],
|
||||||
|
group: 'other',
|
||||||
|
memberName: 'cleverbot',
|
||||||
|
description: 'Talk to Cleverbot.',
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
key: 'text',
|
||||||
|
prompt: 'What do you want to say to Cleverbot?',
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
this.convos = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(msg, { text }) {
|
||||||
|
try {
|
||||||
|
const convo = this.convos.get(msg.channel.id);
|
||||||
|
const { body } = await request
|
||||||
|
.get('https://www.cleverbot.com/getreply')
|
||||||
|
.query({
|
||||||
|
key: CLEVERBOT_KEY,
|
||||||
|
cs: convo ? convo.cs : '',
|
||||||
|
input: text
|
||||||
|
});
|
||||||
|
if (convo) clearTimeout(convo.timeout);
|
||||||
|
const timeout = setTimeout(() => this.convos.delete(msg.channel.id), 600000);
|
||||||
|
this.convos.set(msg.channel.id, { cs: body.cs, timeout });
|
||||||
|
return msg.reply(body.output || blankResponses[Math.floor(Math.random() * blankResponses.length)]);
|
||||||
|
} catch (err) {
|
||||||
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "101.9.1",
|
"version": "101.10.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user