Skip to content

Commit

Permalink
Merge pull request #186 from Mirasaki/dev
Browse files Browse the repository at this point in the history
feat: allow dynamic events to be included in the kill-feed module
  • Loading branch information
Mirasaki authored Nov 30, 2023
2 parents 874ae93 + be0c117 commit c513621
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/servers.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ module.exports = [
USE_KILL_FEED: true,
KILL_FEED_DELAY: 5,
KILL_FEED_CHANNEL_ID: '806479539110674472',
KILL_FEED_MESSAGE_IDENTIFIER: ' got killed by ',
KILL_FEED_REMOVE_IDENTIFIER: false,

// Leaderboard config
OVERALL_RANKING_STAT: 'KILLS',
Expand Down
19 changes: 14 additions & 5 deletions src/modules/delayed-kill-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ const checkIsDelayedKillFeedMsg = async (msg) => {
author,
cleanContent
} = msg;
const isKillMsg = cleanContent.indexOf(' got killed by ') >= 0;
if (!isKillMsg) return false;

for await (const cfg of serverConfig) {
const {
USE_KILL_FEED,
KILL_FEED_DELAY,
KILL_FEED_CHANNEL_ID,
CFTOOLS_WEBHOOK_CHANNEL_ID,
CFTOOLS_WEBHOOK_USER_ID
CFTOOLS_WEBHOOK_USER_ID,
KILL_FEED_MESSAGE_IDENTIFIER,
KILL_FEED_REMOVE_IDENTIFIER
} = cfg;
const isKillMsg = cleanContent.indexOf(
KILL_FEED_MESSAGE_IDENTIFIER
?? ' got killed by '
) >= 0;
if (!isKillMsg) continue;

const isTargetChannel = channelId === CFTOOLS_WEBHOOK_CHANNEL_ID;
const isTargetUser = CFTOOLS_WEBHOOK_USER_ID === (
process.env.NODE_ENV === 'production'
Expand All @@ -36,7 +41,11 @@ const checkIsDelayedKillFeedMsg = async (msg) => {
// Send the notification
await new Promise((resolve) => {
setTimeout(async () => {
const feedMsg = await webhookTargetChannel.send(cleanContent);
const feedMsg = await webhookTargetChannel.send(
KILL_FEED_REMOVE_IDENTIFIER
? cleanContent.replaceAll(KILL_FEED_MESSAGE_IDENTIFIER, '')
: cleanContent
);
resolve(feedMsg);
}, KILL_FEED_DELAY * 1000);
});
Expand Down

0 comments on commit c513621

Please sign in to comment.