-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
130 lines (118 loc) · 3.93 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
require("dotenv").config();
const { Client, GatewayIntentBits, InteractionType } = require("discord.js");
const genericCommands = require("./commands/generic");
const walkerCommands = require("./commands/walkers");
const clanCommands = require("./commands/clans");
const configuration = require("./helpers/config");
const slashCommandsRegister = require("./slashCommandsRegister");
const logger = require("./helpers/logger");
const autocompleteController = require("./commands/interaction_types/autocomplete");
const buttonController = require("./commands/interaction_types/button");
const commandController = require("./commands/interaction_types/command");
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});
client.on("ready", () => {
logger.info(`Logged in as ${client.user.tag}!`);
});
client.login(process.env.DISCORD_TOKEN);
client.on("ready", () => {
configuration.updateConfigurations(client);
if (process.env.APP_DEV) {
logger.info("Dev Mode");
client.guilds.cache.forEach((guild) => {
slashCommandsRegister.registerSlashCommands(guild.id);
});
console.log("Servers:" + client.guilds.cache.size);
} else {
slashCommandsRegister.registerSlashCommandsGlobal();
}
});
client.on("interactionCreate", async (interaction) => {
try {
if (interaction.type === InteractionType.ApplicationCommandAutocomplete) {
await autocompleteController.router(interaction);
} else if (interaction.isButton()) {
await buttonController.router(interaction);
} else if (interaction.type === InteractionType.ApplicationCommand) {
if (interaction.commandName === "lohelp") {
await interaction.reply(
genericCommands.getHelpContent(slashCommandsRegister.getCommands())
);
} else {
await commandController.router(interaction, client);
}
}
} catch (e) {
logger.error(e);
}
});
client.on("messageCreate", (msg) => {
try {
let guildConfig = null;
if (msg.guild.id) {
guildConfig = configuration.getConfiguration(msg.guild.id, client);
if (guildConfig != null) {
if (
Boolean(guildConfig.readclanlog) &&
msg.content.includes("traveled") &&
msg.author.bot
) {
let walkerId = 0;
let walkerName = "";
let lastUser = "";
if (/\((\d+)\)/.test(msg.content)) {
try {
walkerId = parseInt(msg.content.match(/\((\d+)\)/)[1]);
} catch (error) {
console.error(error);
}
}
if (/(?:``)(.+)(?:`` traveled)/.test(msg.content)) {
lastUser = msg.content.match(/(?:``)(.+)(?:`` traveled)/)[1];
}
if (/(?:with walker\s``)(.+)(?:``\s)/.test(msg.content)) {
walkerName = msg.content.match(
/(?:with walker\s``)(.+)(?:``\s)/
)[1];
}
if (guildConfig.walkerAlarm) {
walkerCommands.walkerAlarm(
{
walkerID: walkerId,
lastUser: lastUser,
name: walkerName,
},
msg
);
}
walkerCommands.insertNewWalker(
{
walkerID: walkerId,
lastUser: lastUser,
name: walkerName,
},
msg.guild.id
);
if (guildConfig.setnotreadypvp) {
walkerCommands.setnotreadypvp(walkerId, msg);
}
}
if (
Boolean(guildConfig.automatickick) &&
msg.content.includes("kicked") &&
msg.author.bot
) {
if (/(?:``)(.+)(?:`` kicked)/.test(msg.content)) {
const user = msg.content.match(/(?:``)(.+)(?:`` kicked)/)[1];
clanCommands.kickMember(msg, user);
}
}
} else {
configuration.createConfiguration(msg.guild.id);
}
}
} catch (e) {
logger.error(e);
}
});