Forbidden words comment field.
This commit is contained in:
parent
06b9417650
commit
b8aef07182
2
client/@types/global.d.ts
vendored
2
client/@types/global.d.ts
vendored
@ -55,6 +55,8 @@ declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_REGEXP_LABEL: s
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_REGEXP_DESC: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_APPLYTOMODERATORS_LABEL: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_APPLYTOMODERATORS_DESC: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_COMMENTS_LABEL: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_COMMENTS_DESC: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_LABEL: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_DESC: string
|
||||
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_COMMAND_CMD_LABEL: string
|
||||
|
@ -101,6 +101,16 @@
|
||||
/>
|
||||
<p class="form-group-description">{{forbiddenWordsReasonDesc}}</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="peertube-livechat-forbidden-words-comments-{{fieldNumber}}">{{forbiddenWordsComments}}</label>
|
||||
{{! warning: don't add extra line break in textarea! }}
|
||||
<textarea
|
||||
name="forbidden_words_comments_{{fieldNumber}}"
|
||||
id="peertube-livechat-forbidden-words-comments-{{fieldNumber}}"
|
||||
class="form-control"
|
||||
>{{comments}}</textarea>
|
||||
<p class="form-group-description">{{forbiddenWordsCommentsDesc}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/forbiddenWordsArray}}
|
||||
|
@ -91,6 +91,12 @@ async function fillLabels (
|
||||
view.forbiddenWordsApplyToModeratorsDesc = await peertubeHelpers.translate(
|
||||
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_APPLYTOMODERATORS_DESC
|
||||
)
|
||||
view.forbiddenWordsComments = await peertubeHelpers.translate(
|
||||
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_COMMENTS_LABEL
|
||||
)
|
||||
view.forbiddenWordsCommentsDesc = await peertubeHelpers.translate(
|
||||
LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_COMMENTS_DESC
|
||||
)
|
||||
view.quoteLabel = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_LABEL)
|
||||
view.quoteDesc = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_DESC)
|
||||
view.quoteDesc2 = await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_QUOTE_DESC2)
|
||||
|
@ -43,7 +43,8 @@ async function getConfigurationChannelViewData (
|
||||
joinedEntries: fw.entries.join('\n'),
|
||||
regexp: !!fw.regexp,
|
||||
applyToModerators: fw.applyToModerators,
|
||||
reason: fw.reason
|
||||
reason: fw.reason,
|
||||
comments: fw.comments
|
||||
})
|
||||
}
|
||||
// Ensuring we have at least N blocks:
|
||||
@ -57,7 +58,8 @@ async function getConfigurationChannelViewData (
|
||||
joinedEntries: '',
|
||||
regexp: false,
|
||||
applyToModerators: false,
|
||||
reason: ''
|
||||
reason: '',
|
||||
comments: ''
|
||||
})
|
||||
continue
|
||||
}
|
||||
@ -231,6 +233,7 @@ async function vivifyConfigurationChannel (
|
||||
const regexp = data.get('forbidden_words_regexp_' + i.toString())
|
||||
const applyToModerators = data.get('forbidden_words_applytomoderators_' + i.toString())
|
||||
const reason = data.get('forbidden_words_reason_' + i.toString())?.toString()
|
||||
const comments = data.get('forbidden_words_comments_' + i.toString())?.toString()
|
||||
const fw: ChannelConfigurationOptions['bot']['forbiddenWords'][0] = {
|
||||
entries,
|
||||
applyToModerators: !!applyToModerators,
|
||||
@ -239,6 +242,9 @@ async function vivifyConfigurationChannel (
|
||||
if (reason) {
|
||||
fw.reason = reason
|
||||
}
|
||||
if (comments) {
|
||||
fw.comments = comments
|
||||
}
|
||||
channelConfigurationOptions.bot.forbiddenWords.push(fw)
|
||||
}
|
||||
|
||||
|
@ -336,6 +336,10 @@ livechat_configuration_channel_forbidden_words_applytomoderators_label: "Also m
|
||||
livechat_configuration_channel_forbidden_words_applytomoderators_desc: |
|
||||
By default, moderator messages will not be deleted when containing forbidden words.
|
||||
By checking this option, messages from moderators will also be deleted.
|
||||
livechat_configuration_channel_forbidden_words_comments_label: "Comments"
|
||||
livechat_configuration_channel_forbidden_words_comments_desc: |
|
||||
You can add here some comments about this rule, to remember how and why you created it.
|
||||
These comments are purely indicative, and have no influence on the bot's behavior.
|
||||
livechat_configuration_channel_quote_label: "Pre-recorded messages"
|
||||
livechat_configuration_channel_quote_desc: |
|
||||
You can configure several pre-recorded messages.
|
||||
|
@ -105,6 +105,19 @@ function _readStringArray (data: any, f: string): string[] {
|
||||
return result
|
||||
}
|
||||
|
||||
function _readMultiLineString (data: any, f: string): string {
|
||||
if (!(f in data)) {
|
||||
return ''
|
||||
}
|
||||
if (typeof data[f] !== 'string') {
|
||||
throw new Error('Invalid data type for field ' + f)
|
||||
}
|
||||
// Removing control characters.
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const s = (data[f] as string).replace(/[\u0000-\u001F\u007F-\u009F]/g, '')
|
||||
return s
|
||||
}
|
||||
|
||||
async function _readRegExpArray (data: any, f: string): Promise<string[]> {
|
||||
// Note: this function can instanciate a lot of RegExp.
|
||||
// To avoid freezing the server, we make it async, and will validate each regexp in a separate tick.
|
||||
@ -153,12 +166,14 @@ async function _readForbiddenWords (botData: any): Promise<ChannelConfigurationO
|
||||
}
|
||||
const applyToModerators = _readBoolean(fw, 'applyToModerators')
|
||||
const reason = fw.reason ? _readSimpleInput(fw, 'reason') : undefined
|
||||
const comments = fw.comments ? _readMultiLineString(fw, 'comments') : undefined
|
||||
|
||||
result.push({
|
||||
regexp,
|
||||
entries,
|
||||
applyToModerators,
|
||||
reason
|
||||
reason,
|
||||
comments
|
||||
})
|
||||
}
|
||||
return result
|
||||
|
@ -61,6 +61,7 @@ interface ChannelConfigurationOptions {
|
||||
regexp?: boolean
|
||||
applyToModerators?: boolean
|
||||
reason?: string
|
||||
comments?: string
|
||||
}>
|
||||
quotes: Array<{
|
||||
messages: string[]
|
||||
|
@ -52,3 +52,7 @@ By checking this option, each line of the "{{% livechat_label livechat_configura
|
||||
## {{% livechat_label livechat_configuration_channel_forbidden_words_reason_label %}}
|
||||
|
||||
{{% livechat_label livechat_configuration_channel_forbidden_words_reason_desc %}}
|
||||
|
||||
## {{% livechat_label livechat_configuration_channel_forbidden_words_comments_label %}}
|
||||
|
||||
{{% livechat_label livechat_configuration_channel_forbidden_words_comments_desc %}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user