Skip to content

Commit 441a5a0

Browse files
committed
Merge branch 'raphazappa-custom-discord-prefix'
2 parents 6b122ae + e57a3d0 commit 441a5a0

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

docs/commands.md

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ When enabled (enabled by default), the files received from Discord will be uploa
4343
When disabled (enabled by default), the files received from Discord will be sent as links to WhatsApp.
4444
- Format: `disableWAUpload`
4545

46+
## setDCPrefix
47+
When set (your username by default), the prefix will be added to messages sent to WhatsApp from Discord.
48+
- Format: `setDCPrefix`
49+
4650
## enableDCPrefix
4751
When enabled (disabled by default), your Discord username will be added to messages sent to WhatsApp from Discord.
4852
- Format: `enableDCPrefix`

src/discordHandler.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ const commands = {
197197
: 'Whitelist is empty/inactive.',
198198
);
199199
},
200+
async setdcprefix(message, params) {
201+
if (params.length !== 0) {
202+
const prefix = message.content.split(' ').slice(1).join(' ');
203+
state.settings.DiscordPrefixText = prefix;
204+
await controlChannel.send(`Discord prefix is set to ${prefix}!`);
205+
} else {
206+
state.settings.DiscordPrefixText = null;
207+
await controlChannel.send('Discord prefix is set to your discord username!');
208+
}
209+
},
200210
async enabledcprefix() {
201211
state.settings.DiscordPrefix = true;
202212
await controlChannel.send('Discord username prefix enabled!');
@@ -324,7 +334,7 @@ client.on('messageUpdate', async (_, message) => {
324334
await message.channel.send("Couldn't edit the message. You can only edit the last 500 messages.");
325335
return;
326336
}
327-
337+
328338
state.waClient.ev.emit('discordEdit', { jid, message });
329339
})
330340

@@ -341,7 +351,7 @@ client.on('messageReactionAdd', async (reaction, user) => {
341351
if (user.id === state.dcClient.user.id) {
342352
return;
343353
}
344-
354+
345355
state.waClient.ev.emit('discordReaction', { jid, reaction, removed: false });
346356
});
347357

@@ -358,7 +368,7 @@ client.on('messageReactionRemove', async (reaction, user) => {
358368
if (user.id === state.dcClient.user.id) {
359369
return;
360370
}
361-
371+
362372
state.waClient.ev.emit('discordReaction', { jid, reaction, removed: true });
363373
});
364374

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const storage = require('./storage.js');
77
const whatsappHandler = require('./whatsappHandler.js');
88

99
(async () => {
10-
const version = 'v0.10.20';
10+
const version = 'v0.10.21';
1111
state.logger = pino({ mixin() { return { version }; } }, pino.destination('logs.txt'));
1212
let autoSaver = setInterval(() => storage.save(), 5 * 60 * 1000);
1313
['SIGINT', 'uncaughtException', 'SIGTERM'].forEach((eventName) => process.on(eventName, async (err) => {

src/state.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
settings: {
33
Whitelist: [],
4+
DiscordPrefixText: null,
45
DiscordPrefix: false,
56
WAGroupPrefix: false,
67
UploadAttachments: true,

src/whatsappHandler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const connectToWhatsApp = async (retry = 1) => {
154154
}
155155

156156
if (state.settings.DiscordPrefix) {
157-
content.text = `[${message.member?.nickname || message.author.username}] ${content.text}`;
157+
content.text = `[${state.settings.DiscordPrefixText || message.member?.nickname || message.author.username}] ${content.text}`;
158158
}
159159

160160
if (message.reference) {

0 commit comments

Comments
 (0)