Skip to content

Commit

Permalink
dmk: remove broadcast messages by default
Browse files Browse the repository at this point in the history
  • Loading branch information
wacky6 committed Jan 9, 2019
1 parent e63b8b3 commit 264dc59
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
29 changes: 25 additions & 4 deletions handlers/dmk.js
Expand Up @@ -5,12 +5,25 @@ const { defaultEndpoint, defaultExchangeName, defaultHealthExchangeName } = requ
const { MongoDump } = require('../lib/_mongo')
const AmqpPublisher = require('../lib/amqp-publish')
const expandStringTemplate = require('../lib/string-template')
const shortid = require('shortid')
const setupSigterm = require('../lib/sigterm-handler')
const RaffleFilter = require('../lib/raffle-filter')

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))

const BROADCAST_CMDS = new Set([
'SYS_MSG',
'NOTICE_MSG',
'GUARD_LOTTERY_START',
'ROOM_RANK',
'WISH_BOTTLE',
'TV_START',
'TV_END',
'ACTIVITY_EVENT',
'GUARD_MSG',
'RAFFLE_START',
'SYS_GIFT',
])

function transformDanmaku(dmk) {
if (!dmk) return dmk

Expand Down Expand Up @@ -102,6 +115,12 @@ module.exports = {
describe: 'amqp publish exchange name',
default: defaultExchangeName,
})
.option('b', {
alias: 'publish-broadcast',
type: 'boolean',
describe: 'publish broadcast messages (SYS, NOTICE, LOTTERY, RAFFLE, ACTIVITY, WISH)',
default: false,
})
.option('w', {
alias: 'worker',
type: 'string',
Expand All @@ -125,6 +144,7 @@ module.exports = {
publishUrl,
publishName,
publishHealth,
publishBroadcast: publishBroadcastMessages,
worker,
db,
dump,
Expand All @@ -134,7 +154,6 @@ module.exports = {
const publisher = publish && new AmqpPublisher(publishUrl, publishName)
const healthPublisher = publishHealth && new AmqpPublisher(publishUrl, defaultHealthExchangeName)
const dbConn = dump && new MongoDump(db, 'danmaku')
const procId = shortid.generate()

setupSigterm()

Expand Down Expand Up @@ -180,11 +199,14 @@ module.exports = {
roomId,
time: Date.now(),
worker,
proc: procId,
})
})

const processPayload = payload => {
// ignore broadcast-like messages
if (!publishBroadcastMessages && BROADCAST_CMDS.has(payload.cmd)) {
return
}
publisher && publisher.send(payload)
dbConn && dbConn.send({
...payload,
Expand All @@ -201,7 +223,6 @@ module.exports = {
_rxTime: meta.rx_time,
_txServer: meta.server,
_worker: worker,
_proc: procId,
}
if (payload.cmd === 'DANMU_MSG' && enableRaffleFilter) {
raffleFilter(payload.text, payload)
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -17,7 +17,6 @@
"dateformat": "^3.0.3",
"mkdirp": "^0.5.1",
"mongodb": "^3.1.10",
"shortid": "^2.2.14",
"shuffle-array": "^1.0.1",
"superagent": "^3.8.3",
"winston": "^3.0.0",
Expand Down
12 changes: 0 additions & 12 deletions yarn.lock
Expand Up @@ -496,11 +496,6 @@ ms@^2.1.1:
version "2.1.1"
resolved "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"

nanoid@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-2.0.0.tgz#e1ab4a4b024a38d15531ba34a712a201540de639"
integrity sha512-SG2qscLE3iM4C0CNzGrsAojJHSVHMS1J8NnvJ31P1lH8P0hGHOiafmniNJz6w6q7vuoDlV7RdySlJgtqkFEVtQ==

npm-run-path@^2.0.0:
version "2.0.2"
resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
Expand Down Expand Up @@ -680,13 +675,6 @@ shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"

shortid@^2.2.14:
version "2.2.14"
resolved "https://registry.npmjs.org/shortid/-/shortid-2.2.14.tgz#80db6aafcbc3e3a46850b3c88d39e051b84c8d18"
integrity sha512-4UnZgr9gDdA1kaKj/38IiudfC3KHKhDc1zi/HSxd9FQDR0VLwH3/y79tZJLsVYPsJgIjeHjqIWaWVRJUj9qZOQ==
dependencies:
nanoid "^2.0.0"

shuffle-array@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/shuffle-array/-/shuffle-array-1.0.1.tgz#c4ff3cfe74d16f93730592301b25e6577b12898b"
Expand Down

0 comments on commit 264dc59

Please sign in to comment.