regex word filters, optional case-sensitivity
このコミットが含まれているのは:
コミット
fd058d2c78
|
@ -11,9 +11,12 @@ host = "Broadcaster"
|
||||||
anon = "Anonymous"
|
anon = "Anonymous"
|
||||||
|
|
||||||
[chat.filters]
|
[chat.filters]
|
||||||
|
# prepend strings with "re:" for regular expressions
|
||||||
|
# e.g. ban = ["re:\\bmelons?\\b", "re:(https?://)?([^.]+?\\.)*?example\\.com\\S*"]
|
||||||
ban = [] # block message & ban poster
|
ban = [] # block message & ban poster
|
||||||
block = [] # block message
|
block = [] # block message
|
||||||
censor = [] # censor word in message
|
censor = [] # censor word in message
|
||||||
|
ignore_case = true
|
||||||
tyranny = true # word filters don't apply to broadcaster
|
tyranny = true # word filters don't apply to broadcaster
|
||||||
|
|
||||||
[secret_club]
|
[secret_club]
|
||||||
|
|
|
@ -139,10 +139,13 @@ def _comment(text, token, c_response, c_ciphertext, nonce):
|
||||||
reaction = None
|
reaction = None
|
||||||
for key in ['censor', 'block', 'ban']:
|
for key in ['censor', 'block', 'ban']:
|
||||||
for word in filters[key]:
|
for word in filters[key]:
|
||||||
word = escape(word) # escape for html
|
word = escape(word) # escape for html
|
||||||
word = re.escape(word) # escape for regex
|
if word.startswith('re:'):
|
||||||
regex = r'\b{}\b'.format(word)
|
regex = word[3:]
|
||||||
markup, n = re.subn(regex, '<b class="censored">[CENSORED]</b>', markup, flags=re.IGNORECASE)
|
else:
|
||||||
|
word = re.escape(word) # escape for regex
|
||||||
|
regex = r'\b{}\b'.format(word)
|
||||||
|
markup, n = re.subn(regex, '<b class="censored">[CENSORED]</b>', markup, flags=re.IGNORECASE if filters['ignore_case'] else 0)
|
||||||
if n: reaction = key
|
if n: reaction = key
|
||||||
# enact consequences of word filters
|
# enact consequences of word filters
|
||||||
note = N_NONE
|
note = N_NONE
|
||||||
|
|
読み込み中…
新しいイシューから参照