Skip to content

Commit 763b1a6

Browse files
authored
Merge pull request #3 from ChiknNuggets/codex/add-discord-direct-message-handler
feat: handle direct messages
2 parents 3082a37 + 1fc3449 commit 763b1a6

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ const client = new DiscordBot({
3232
Discord.GatewayIntentBits.GuildMessages,
3333
Discord.GatewayIntentBits.MessageContent,
3434
Discord.GatewayIntentBits.GuildMembers,
35-
Discord.GatewayIntentBits.GuildVoiceStates],
35+
Discord.GatewayIntentBits.GuildVoiceStates,
36+
Discord.GatewayIntentBits.DirectMessages],
37+
partials: [Discord.Partials.Channel],
3638
retryLimit: 2,
3739
restRequestTimeout: 60000,
3840
disableEveryone: false

src/discordEvents/directMessage.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright (C) 2024 Alexander Emanuelsson (alexemanuelol)
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
https://github.com/alexemanuelol/rustplusplus
18+
19+
*/
20+
const DiscordVoice = require('../discordTools/discordVoice.js');
21+
22+
module.exports = {
23+
name: 'messageCreate',
24+
async execute(client, message) {
25+
if (message.guild) return;
26+
if (message.author.bot) return;
27+
28+
for (const [guildId, rustplus] of Object.entries(client.rustplusInstances)) {
29+
if (!rustplus || !rustplus.isOperational) continue;
30+
31+
const instance = client.getInstance(guildId);
32+
if (instance && instance.blacklist['discordIds'].includes(message.author.id)) continue;
33+
34+
await DiscordVoice.sendDiscordVoiceMessage(guildId, message.cleanContent);
35+
}
36+
37+
client.log(client.intlGet(null, 'infoCap'), client.intlGet(null, 'logDiscordMessage', {
38+
guild: 'DM',
39+
channel: 'DM',
40+
user: `${message.author.username} (${message.author.id})`,
41+
message: message.cleanContent
42+
}));
43+
},
44+
};
45+

src/discordEvents/messageCreate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const DiscordTools = require('../discordTools/discordTools');
2424
module.exports = {
2525
name: 'messageCreate',
2626
async execute(client, message) {
27+
if (!message.guild) return;
28+
2729
const instance = client.getInstance(message.guild.id);
2830
const rustplus = client.rustplusInstances[message.guild.id];
2931

0 commit comments

Comments
 (0)