Skip to content

Commit 68ef800

Browse files
authored
Merge pull request #1 from AnonDev-org/dev
v 1.0.2
2 parents 9664777 + 830e565 commit 68ef800

File tree

6 files changed

+118
-100
lines changed

6 files changed

+118
-100
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,5 @@ dist
121121
prettier.config.js
122122
json.sqlite
123123
.breakpoints
124-
package-lock.json
124+
package-lock.json
125+
json.sqlite

commands/info/help.js

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,63 @@
11
const {
2-
Command,
3-
MessageActionRow,
4-
MessageButton,
5-
ArgumentType,
2+
Command,
3+
MessageActionRow,
4+
MessageButton,
5+
ArgumentType,
66
} = require("gcommands");
77
const Discord = require("discord.js");
88

99
module.exports = class extends Command {
10-
constructor(...args) {
11-
super(...args, {
12-
name: "help",
13-
description: "Check bot's commands",
14-
});
15-
}
16-
async run({
17-
client,
18-
interaction,
19-
respond,
20-
guild,
21-
edit,
22-
member,
23-
author,
24-
args,
25-
objectArgs,
26-
message,
27-
}) {
28-
const embed = new Discord.MessageEmbed()
29-
.setTitle("Help menu")
30-
.setDescription(
31-
`:robot: This bot is powered by [AnonDev API](https://api.anondev.ml).\n\n**Commands:** W.I.P\n`
32-
)
33-
.setColor("#3f6fa1")
34-
.setFooter(client.user.username, client.user.avatarURL())
35-
.setTimestamp()
36-
.setThumbnail(client.user.avatarURL());
10+
constructor(...args) {
11+
super(...args, {
12+
name: "help",
13+
description: "Check bot's commands",
14+
});
15+
}
16+
async run({
17+
client,
18+
interaction,
19+
respond,
20+
guild,
21+
edit,
22+
member,
23+
author,
24+
args,
25+
objectArgs,
26+
message,
27+
}) {
28+
const embed = new Discord.MessageEmbed()
29+
.setTitle("Help menu")
30+
.setDescription(
31+
`:robot: This bot is powered by [AnonDev API](https://api.anondev.ml). You can find the source code on [GitHub](https://github.com/AnonDev-org/AnonDev-API-bot)\n\n**Commands:**\n`
32+
)
33+
.setColor("#3f6fa1")
34+
.setFooter(client.user.username, client.user.avatarURL())
35+
.setTimestamp()
36+
.setThumbnail(client.user.avatarURL());
3737

38-
let button1 = new MessageButton()
39-
.setLabel("API Link")
40-
.setEmoji("⚙️")
41-
.setURL(`https://api.anondev.ml`);
38+
client.gcommands.forEach((cmd) => {
39+
embed.addField(
40+
`**${client.config.prefix}${cmd.name} ${
41+
cmd.aliases && cmd.aliases.length > 1 ? `(${cmd.aliases})` : ""
42+
}**`,
43+
`${cmd.description}`,
44+
true
45+
);
46+
});
4247

43-
respond({
44-
embeds: [embed],
45-
ephemeral: false,
46-
components: [new MessageActionRow().addComponents([button1])],
47-
});
48-
}
48+
let button1 = new MessageButton()
49+
.setLabel("API Link")
50+
.setEmoji("⚙️")
51+
.setURL(`https://api.anondev.ml`);
52+
let button2 = new MessageButton()
53+
.setLabel("Repo Link")
54+
.setEmoji("🇬")
55+
.setURL(`https://github.com/AnonDev-org/AnonDev-API-bot`);
56+
57+
respond({
58+
embeds: [embed],
59+
ephemeral: false,
60+
components: [new MessageActionRow().addComponents([button1, button2])],
61+
});
62+
}
4963
};

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ module.exports = {
22
token: process.env.TOKEN,
33
apiKey: process.env.API_KEY,
44
prefix: "!",
5-
debug: false
5+
debug: false,
66
};

events/chatbot.js

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,62 @@
11
const { Event } = require("gcommands");
22

33
module.exports = class Chatbot extends Event {
4-
constructor(client) {
5-
super(client, {
6-
name: "message",
7-
once: false,
8-
ws: false,
9-
});
10-
}
4+
constructor(client) {
5+
super(client, {
6+
name: "message",
7+
once: false,
8+
ws: false,
9+
});
10+
}
1111

12-
async run(client, message) {
13-
if (message.author.bot) return;
14-
let channel = await client.db.get(`chatbot_${message.guild.id}`);
15-
if (!channel) return;
16-
if (message.channel.id == channel) {
17-
message.content = message.content.replace(/@(everyone)/gi, "everyone").replace(/@(here)/gi, "here");
18-
await message.channel.sendTyping();
19-
if (!message.content) return message.reply({ content: "**:x: Please say something**" })
12+
async run(client, message) {
13+
if (message.author.bot) return;
14+
let channel = await client.db.get(`chatbot_${message.guild.id}`);
15+
if (!channel) return;
16+
if (message.channel.id == channel) {
17+
message.content = message.content
18+
.replace(/@(everyone)/gi, "everyone")
19+
.replace(/@(here)/gi, "here");
20+
await message.channel.sendTyping();
21+
if (!message.content)
22+
return message.reply({ content: "**:x: Please say something**" });
2023

21-
const resp = await client
22-
.request(
23-
`/api/tools/chatbot?message=${encodeURIComponent(
24-
message.content
25-
)}&user=${encodeURIComponent(
26-
message.author.username
27-
)}&botname=${encodeURIComponent(client.user.username)}`,
28-
"GET"
29-
)
30-
.catch((err) => {
31-
console.log("Error while fetching API endpoint", err);
32-
return message.reply({
33-
content: `:x: Error while fetching API endpoint \`${err.message}\``,
34-
ephemeral: true,
35-
});
36-
});
37-
let data = await resp.json();
38-
if (!resp.ok) {
39-
console.log(
40-
`API returned error ${resp.status} ${resp.statusText}`,
41-
data
42-
);
43-
return message.reply({
44-
content: `:x: API returned error \`${resp.status} ${
45-
resp.statusText
46-
}\`\n\n> \`${JSON.stringify(data)}\``,
47-
ephemeral: true,
48-
});
49-
}
24+
const resp = await client
25+
.request(
26+
`/api/tools/chatbot?message=${encodeURIComponent(
27+
message.content
28+
)}&user=${encodeURIComponent(
29+
message.author.username
30+
)}&botname=${encodeURIComponent(client.user.username)}`,
31+
"GET"
32+
)
33+
.catch((err) => {
34+
console.log("Error while fetching API endpoint", err);
35+
return message.reply({
36+
content: `:x: Error while fetching API endpoint \`${err.message}\``,
37+
ephemeral: true,
38+
});
39+
});
40+
let data = await resp.json();
41+
if (!resp.ok) {
42+
console.log(
43+
`API returned error ${resp.status} ${resp.statusText}`,
44+
data
45+
);
46+
return message.reply({
47+
content: `:x: API returned error \`${resp.status} ${
48+
resp.statusText
49+
}\`\n\n> \`${JSON.stringify(data)}\``,
50+
ephemeral: true,
51+
});
52+
}
5053

51-
message.reply({
52-
content: data.reply, allowed_mentions: {
53-
"users": [client.user.id]
54-
}
55-
})
56-
57-
}
58-
}
54+
message.reply({
55+
content: data.reply,
56+
allowed_mentions: {
57+
users: [client.user.id],
58+
},
59+
});
60+
}
61+
}
5962
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "AnonDev-API-bot",
3-
"version": "1.0.0",
3+
"version": "1.0.2",
44
"description": "Example Discord.js v13 bot powered by AnonDev API",
55
"main": "index.js",
66
"scripts": {
@@ -24,5 +24,9 @@
2424
},
2525
"devDependencies": {
2626
"node": "^16.9.1"
27+
},
28+
"repository": {
29+
"type": "git",
30+
"url": "https://github.com/AnonDev-org/AnonDev-API-bot"
2731
}
2832
}

readme.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ This project is a Discord bot that is powered by [AnonDev API](https://api.anond
1515

1616
`npm start or node index.js` - Start the project
1717

18-
19-
2018
[![Run on Repl.it](https://repl.it/badge/github/AnonDev-org/AnonDev-API-bot)](https://repl.it/github/AnonDev-org/AnonDev-API-bot)
2119

22-
23-
2420
### Information
2521

2622
Developed by [AnonDev](https://anon.is-a.dev)

0 commit comments

Comments
 (0)