Skip to content

Commit

Permalink
feat(core): relay announcements to discord as well
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Jan 9, 2022
1 parent 8c8c755 commit a860a38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/discordBot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = class DiscordBot {
}

try {
this.announceChannel.send(message);
await this.announceChannel.send(message);
} catch (error) {
logError(`Error sending Discord announcement: ${error.message}`);
}
Expand Down
12 changes: 11 additions & 1 deletion src/webroutes/fxserver/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,23 @@ module.exports = async function FXServerCommands(ctx) {
//==============================================
} else if (action == 'admin_broadcast') {
if (!ensurePermission(ctx, 'players.message')) return false;
const message = (parameter ?? '').trim();

// Dispatch `txAdmin:events:announcement`
const cmdOk = globals.fxRunner.sendEvent('announcement', {
message,
author: ctx.session.auth.username,
message: (parameter ?? '').trim(),
});
ctx.utils.logAction(`Sending announcement: ${parameter}`);

// Sending discord announcement
const discMessage = message.replace(/\`/g, '\\`').replace(/\n/g, '\n> ');
const discMsgTitle = globals.translator.t(
'nui_menu.misc.announcement_title',
{author: ctx.session.auth.username}
);
await globals.discordBot.sendAnnouncement(`${discMsgTitle}\n> ${discMessage}`);

return ctx.send({
type: cmdOk ? 'success' : 'danger',
message: 'Announcement sent!',
Expand Down

0 comments on commit a860a38

Please sign in to comment.