This repository has been archived by the owner on Oct 17, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
136 lines (119 loc) · 3.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// @ts-check
const discord = require("discord.js");
const parser = require("./parse.js");
const executor = require("./execute.js");
const { expandUrl } = require("./utils/expand.js");
const dotenv = require("dotenv").config();
const express = require("express");
const { join } = require("path");
const client = new discord.Client();
function extractTextLinks(message) {
const regex =
/(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/gi;
return message.match(regex);
}
/**
* Environment variables loaded from
* the .env file using the dotenv module.
* All these variables are added to the
* process environment variable
*/
const token = process.env.TOKEN;
const port = process.env.PORT || 3000;
const app = express();
app.use(express.static(join(__dirname, "views")));
app.get("/", (request, response) => {
response.sendFile("index.html");
});
app.get('/join',(request,response) => {
response.sendFile(join(__dirname,"views","join.html"))
})
// Get the number of servers the bot is working in
const getClientGuildCount = () => {
return client.guilds.cache.size;
};
app.get("/count", (request, response) => {
response.json({
count: getClientGuildCount(),
});
});
const yakhiMessage = (message) => {
message.channel.send(":slight_smile:").then((messageData) => {
setTimeout(() => {
messageData.edit(":wink:").then((editMessage) => {
setTimeout(() => {
editMessage.edit(":slight_smile:");
}, 200);
});
}, 500);
});
};
/**
* @constant
*
* Checks if the message if a bot command
*
* @param {discord.Message} message
* @returns {boolean} Whether or not the message content
* is a valid bot command
*/
const isBotCommand = (message) => {
return message.content.startsWith("yakhi ");
};
client.on("ready", async () => {
console.log("The bot has started");
const botGuildCount = client.guilds.cache.size;
await client.user.setPresence({
activity: {
name: `Watching ${botGuildCount} servers`,
type: "PLAYING",
},
});
await client.user.setStatus("idle");
console.log(client);
});
client.on("message", async (message) => {
if (message.author.bot || message.channel.type === "dm") return;
if (
message.content.toLowerCase() == "client" ||
message.content == "client, who are you?"
) {
message.channel.send(
"I am Yakhi, a bot powered by AI and created by code roller. Try `y! help all` for help."
);
}
if (isBotCommand(message)) {
const parsed = parser.parse(message.content);
executor.exec(
parsed.command,
parsed.subcommand,
parsed.args,
message,
client
);
} else {
const mentionedEveryone = message.mentions.everyone;
const links = extractTextLinks(message.content);
const warnUser =
!message.member.hasPermission("ADMINISTRATOR") && mentionedEveryone;
if (warnUser) {
// delete the message if the user pings
// @everyone(All the server members).
// This can be used to prevent spams and raids
await message.delete().then((deletedMessage) => {
deletedMessage.author.send(
"Please do not ping everyone :neutral_face:"
);
});
} else if (links) {
for (let index = 0; index < links.length; index++) {
expandUrl(links[index], true, message);
}
}
}
});
client.login(token);
app.listen(port, () => {
console.log(`Check out ${port}`);
});
module.exports = { token };