regex word filters, optional case-sensitivity

このコミットが含まれているのは:
n9k 2021-07-18 04:59:06 +00:00
コミット fd058d2c78
2個のファイルの変更10行の追加4行の削除

ファイルの表示

@ -11,9 +11,12 @@ host = "Broadcaster"
anon = "Anonymous"
[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
block = [] # block message
censor = [] # censor word in message
ignore_case = true
tyranny = true # word filters don't apply to broadcaster
[secret_club]

ファイルの表示

@ -139,10 +139,13 @@ def _comment(text, token, c_response, c_ciphertext, nonce):
reaction = None
for key in ['censor', 'block', 'ban']:
for word in filters[key]:
word = escape(word) # escape for html
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)
word = escape(word) # escape for html
if word.startswith('re:'):
regex = word[3:]
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
# enact consequences of word filters
note = N_NONE