New option for the moderation bot: forbid duplicate messages (#516).
This commit is contained in:
@ -57,7 +57,18 @@ async function sanitizeChannelConfigurationOptions (
|
||||
applyToModerators: false
|
||||
}
|
||||
if (!_assertObjectType(botData.forbidSpecialChars)) {
|
||||
throw new Error('Invalid data.forbidSpecialChars data type')
|
||||
throw new Error('Invalid data.bot.forbidSpecialChars data type')
|
||||
}
|
||||
|
||||
// noDuplicate comes with livechat 11.1.0
|
||||
botData.noDuplicate ??= {
|
||||
enabled: false,
|
||||
reason: '',
|
||||
delay: 60,
|
||||
applyToModerators: false
|
||||
}
|
||||
if (!_assertObjectType(botData.noDuplicate)) {
|
||||
throw new Error('Invalid data.bot.noDuplicate data type')
|
||||
}
|
||||
|
||||
// terms not present in livechat <= 10.2.0
|
||||
@ -76,6 +87,7 @@ async function sanitizeChannelConfigurationOptions (
|
||||
nickname: _readSimpleInput(botData, 'nickname', true),
|
||||
forbiddenWords: await _readForbiddenWords(botData),
|
||||
forbidSpecialChars: await _readForbidSpecialChars(botData),
|
||||
noDuplicate: await _readNoDuplicate(botData),
|
||||
quotes: _readQuotes(botData),
|
||||
commands: _readCommands(botData)
|
||||
// TODO: bannedJIDs
|
||||
@ -266,6 +278,21 @@ async function _readForbidSpecialChars (
|
||||
return result
|
||||
}
|
||||
|
||||
async function _readNoDuplicate (
|
||||
botData: Record<string, unknown>
|
||||
): Promise<ChannelConfigurationOptions['bot']['noDuplicate']> {
|
||||
if (!_assertObjectType(botData.noDuplicate)) {
|
||||
throw new Error('Invalid forbidSpecialChars data')
|
||||
}
|
||||
const result: ChannelConfigurationOptions['bot']['noDuplicate'] = {
|
||||
enabled: _readBoolean(botData.noDuplicate, 'enabled'),
|
||||
reason: _readSimpleInput(botData.noDuplicate, 'reason'),
|
||||
delay: _readInteger(botData.noDuplicate, 'delay', 0, 24 * 3600),
|
||||
applyToModerators: _readBoolean(botData.noDuplicate, 'applyToModerators')
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function _readQuotes (botData: Record<string, unknown>): ChannelConfigurationOptions['bot']['quotes'] {
|
||||
if (!Array.isArray(botData.quotes)) {
|
||||
throw new Error('Invalid quotes data')
|
||||
|
@ -50,6 +50,12 @@ function getDefaultChannelConfigurationOptions (_options: RegisterServerOptions)
|
||||
tolerance: 0,
|
||||
applyToModerators: false
|
||||
},
|
||||
noDuplicate: {
|
||||
enabled: false,
|
||||
reason: '',
|
||||
delay: 60,
|
||||
applyToModerators: false
|
||||
},
|
||||
quotes: [],
|
||||
commands: []
|
||||
},
|
||||
@ -124,6 +130,11 @@ function channelConfigurationOptionsToBotRoomConf (
|
||||
handlersIds.set(id, true)
|
||||
handlers.push(_getForbidSpecialCharsHandler(id, channelConfigurationOptions.bot.forbidSpecialChars))
|
||||
}
|
||||
if (channelConfigurationOptions.bot.noDuplicate.enabled) {
|
||||
const id = 'no_duplicate'
|
||||
handlersIds.set(id, true)
|
||||
handlers.push(_getNoDuplicateHandler(id, channelConfigurationOptions.bot.noDuplicate))
|
||||
}
|
||||
channelConfigurationOptions.bot.quotes.forEach((v, i) => {
|
||||
const id = 'quote_' + i.toString()
|
||||
handlersIds.set(id, true)
|
||||
@ -254,6 +265,23 @@ function _getForbidSpecialCharsHandler (
|
||||
return handler
|
||||
}
|
||||
|
||||
function _getNoDuplicateHandler (
|
||||
id: string,
|
||||
noDuplicate: ChannelConfigurationOptions['bot']['noDuplicate']
|
||||
): ConfigHandler {
|
||||
const handler: ConfigHandler = {
|
||||
type: 'no-duplicate',
|
||||
id,
|
||||
enabled: true,
|
||||
options: {
|
||||
reason: noDuplicate.reason,
|
||||
delay: noDuplicate.delay,
|
||||
applyToModerators: !!noDuplicate.applyToModerators
|
||||
}
|
||||
}
|
||||
return handler
|
||||
}
|
||||
|
||||
function _getQuotesHandler (
|
||||
id: string,
|
||||
quotes: ChannelConfigurationOptions['bot']['quotes'][0]
|
||||
|
Reference in New Issue
Block a user