Skip to content

Commit

Permalink
Merge branch 'raphazappa-custom-discord-prefix'
Browse files Browse the repository at this point in the history
  • Loading branch information
FKLC committed Nov 24, 2023
2 parents 6b122ae + e57a3d0 commit 441a5a0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ When enabled (enabled by default), the files received from Discord will be uploa
When disabled (enabled by default), the files received from Discord will be sent as links to WhatsApp.
- Format: `disableWAUpload`

## setDCPrefix
When set (your username by default), the prefix will be added to messages sent to WhatsApp from Discord.
- Format: `setDCPrefix`

## enableDCPrefix
When enabled (disabled by default), your Discord username will be added to messages sent to WhatsApp from Discord.
- Format: `enableDCPrefix`
Expand Down
16 changes: 13 additions & 3 deletions src/discordHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ const commands = {
: 'Whitelist is empty/inactive.',
);
},
async setdcprefix(message, params) {
if (params.length !== 0) {
const prefix = message.content.split(' ').slice(1).join(' ');
state.settings.DiscordPrefixText = prefix;
await controlChannel.send(`Discord prefix is set to ${prefix}!`);
} else {
state.settings.DiscordPrefixText = null;
await controlChannel.send('Discord prefix is set to your discord username!');
}
},
async enabledcprefix() {
state.settings.DiscordPrefix = true;
await controlChannel.send('Discord username prefix enabled!');
Expand Down Expand Up @@ -324,7 +334,7 @@ client.on('messageUpdate', async (_, message) => {
await message.channel.send("Couldn't edit the message. You can only edit the last 500 messages.");
return;
}

state.waClient.ev.emit('discordEdit', { jid, message });
})

Expand All @@ -341,7 +351,7 @@ client.on('messageReactionAdd', async (reaction, user) => {
if (user.id === state.dcClient.user.id) {
return;
}

state.waClient.ev.emit('discordReaction', { jid, reaction, removed: false });
});

Expand All @@ -358,7 +368,7 @@ client.on('messageReactionRemove', async (reaction, user) => {
if (user.id === state.dcClient.user.id) {
return;
}

state.waClient.ev.emit('discordReaction', { jid, reaction, removed: true });
});

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const storage = require('./storage.js');
const whatsappHandler = require('./whatsappHandler.js');

(async () => {
const version = 'v0.10.20';
const version = 'v0.10.21';
state.logger = pino({ mixin() { return { version }; } }, pino.destination('logs.txt'));
let autoSaver = setInterval(() => storage.save(), 5 * 60 * 1000);
['SIGINT', 'uncaughtException', 'SIGTERM'].forEach((eventName) => process.on(eventName, async (err) => {
Expand Down
1 change: 1 addition & 0 deletions src/state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
settings: {
Whitelist: [],
DiscordPrefixText: null,
DiscordPrefix: false,
WAGroupPrefix: false,
UploadAttachments: true,
Expand Down
2 changes: 1 addition & 1 deletion src/whatsappHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const connectToWhatsApp = async (retry = 1) => {
}

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

if (message.reference) {
Expand Down

0 comments on commit 441a5a0

Please sign in to comment.