Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter responses and more filtering control #131

Merged
merged 3 commits into from
Oct 18, 2022

Conversation

jagerman
Copy link
Member

@jagerman jagerman commented Oct 1, 2022

This builds off PR #129 for language filtering, but revamps how languages are specified and overridden with a mechanism that we can use in the future for other room-specific settings, and that doesn't rely on room ids (but rather tokens).

Most notably, this PR (in addition to the language filtering added in #129) adds an ability to send responses to filtered messages either back to (just) the user who sent them (via a whisper), or to the whole room.

This allows configuration of the message (or multiple messages, for random selection), profile name, and uses a (simple) templating mechanism for the message so that you can (somewhat) personalize it for the user.

Other changes included here:

  • You can now control whether or not mods/admins are affected by filtering via a new filter_mods setting. (This is particularly useful for testing, but SOGS operators might also want to restrain their mods).

  • profanity filtering can be room specific.

  • alphabet filtering can be room specific (revamping how PR Allow rejection of postings written in a particular alphabet. #129 did room-specific settings).

  • alphabet filtering can be configurably silent or not, like profanity filtering.

  • added a new, separate example .ini file showing how to set things up with room-specific settings.

Copying from the added sogs.ini.filter-sample file for the detail on how the room-specific settings and auto-reply get configured:

;
; Room-specific filtering
;
; To set filtration rules for a specific room you add a [room:TOKEN] section and then set the
; rules that should apply to this specific room.  For example, to enable the profanity filter and
; disallow (only) cyrillic characters in the room with token 'sudoku' you would add:
;
;[room:sudoku]
;profanity_filter=yes
;profanity_silent=yes
;alphabet_filters=cyrillic
;
; This overrides the default from the main [messages] config section for any given keys, so it can
; be used to replace or change the rules that apply to a given room.  Currently only the
; profanity_filter, profanity_silent, alphabet_filters can be overridden in this way.

;
; Filtration responses
;
; When a message is filtered because of the profanity or alphabet filtrations SOGS can optionally
; send a reply in the room; this reply can either be visible to everyone, or just to the specific
; user.  To enable such a reply, add a filter section here: the section name consists of
; 'filter:TYPE:ROOM' where TYPE and ROOM are the filtration type and room token, or '*' to match all
; types/rooms.
;
; Section names for all filtered messages:
;[filter:*:*]
;
; Section names for a particular filtration type:
;[filter:*:profanity]
;[filter:*:alphabet]
;
; The "type" can also be a specific language:
;[filter:*:arabic]
;[filter:*:cyrillic]
; etc.
;
; Room-specific filtration section names:
;
;[filter:fishing:*]
;[filter:sudoku:profanity]
;
; If using both '*' and specific values, the value from the more specific section will be used where
; present.
;
; Within this section there are currently three settings:
;
; - reply -- the body of a reply to send (see details below).  If omitted or empty then no reply
;   will be sent.
; - profile_name -- the profile name to use in that reply.
; - public -- whether the reply should be seen by everyone or just the poster.  The default is 'no'
;   (i.e. only the user will see the reply).
;
; The `reply` value should be specified on a single line of the config, and supports the following
; substitutions:
;
; \@ - the profile name, in @tag form, of the poster whose message was declined.
; \p - the profile name in plain text.
; \r - the name of the room
; \t - the token of the room
; \n - a line break
; \\ - a literal \ character
;
; You can also randomize among multiple responses by specifying multiple lines in the config: each
; additional line must be indented in the .ini file to be properly recognized.
;
; For example if you use this config:
;

[messages]
profanity_filter=yes
profanity_silent=yes
alphabet_filters=arabic cyrillic
alphabet_silent=yes

[room:sailors]
profanity_filter=no

[filter:*:*]
profile_name=LanguagePolice
reply=Hi \@, I'm afraid your message couldn't be sent: \r is English-only!

[filter:*:profanity]
profile_name=Swear Jar
reply=Whoa there, \@!  That language is too strong for the \r group!  Try the Sailors group instead.

[filter:sudoku:profanity]
profile_name=Bot45
public=yes
reply=\@ got a little too enthusiastic today with their solve.  Maybe someone can assist?
 Uh oh, I think \@ has two 3s in the same row!
 I think \@'s sudoku broke 😦

; then arabic/cyrillic/person would be blocked everywhere, profanity would be blocked everywhere
; except the 'sailors' room, and when a message is blocked you would get a message such as one of
; the following depending on the room and the rule applied:
;
;
; (LanguagePolice)
; Hi @Foreignsailor1988, I'm afraid your message couldn't be set: Salty Sailors is English-only!
;
;
; (Swear Jar)
; Whoa there @87yearoldgrandma!  That language is too strong for the Cuddly Kittens group!  Try the Sailors group instead.
;
;
; (Bot45); [one of the following would be sent randomly, visible to everyone in the group]
; @87yearoldgrandma got a little too enthusiastic today with their solve.  Maybe someone can assist?
;
; Uh oh, I think @87yearoldgrandma has two 3s in the same row!
;
; I think @87yearoldgrandma's sudoku broke 😦

The user configures in `sogs.ini` a list of alphabets to reject by
default:

`alphabet_filters = [ arabic, cyrillic, persian ]`

If there are rooms in which these alphabets should be allowed, a list of
room ids per alphabet may be specified for whitelisting.

`alphabet_whitelist_arabic = [ 8 ]`
`alphabet_whitelist_cyrillic = [ 5, 13 ]`
`alphabet_whitelist_persian = [ 18 ]`

A list of valid room ids can be obtained with the following SQL:

`$ sudo sqlite3 /var/lib/session-open-group-server/sogs.db 'SELECT * FROM rooms;'`

The implementation can easily be extended to more alphabets.
This adds an ability to send responses to filtered messages either back
to (just) the user who sent them (via a whisper), or to the whole room.

This allows configuration of the message (or messages, for random
selection), profile name, and uses a (simple) templating mechanism for
the message so that you can (somewhat) personalize it for the user.

This builds off PR oxen-io#129 for language filtering, but revamps how
languages are specified and overridden with a mechanism that we can use
in the future for other room-specific settings, and that doesn't rely on
room ids (but rather tokens).

Other changes included here:

- You can now control whether or not mods/admins are affected by
  filtering via a new `filter_mods` setting.

- profanity filtering can be room specific.

- alphabet filtering can be room specific (revamping how PR oxen-io#129 did
  room-specific settings).

- alphabet filtering can be configurably silent or not, like profanity
  filtering.

- added a new, separate example .ini file showing how to set things up
  with room-specific settings.
If we aren't filtering there's no need to parse (this also unbreaks the
test suite, which uses various unparseable fake message data).
@jagerman jagerman merged commit c0dbb30 into oxen-io:dev Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants