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

Antispam features #128

Merged
merged 9 commits into from
Feb 1, 2024
Merged

Antispam features #128

merged 9 commits into from
Feb 1, 2024

Conversation

Athozus
Copy link
Member

@Athozus Athozus commented Dec 26, 2023

This is WIP. It follows suggestions listed in #102.

Note that it contains many changes, such as :

  • Add warning, disabled and muted colors, respectively #FF8800, #332222 and #CCCCCC.
  • Enlarge boxes views to have enough space for new (un)mark as spam buttons
  • New message view layout for the same reason as before
  • Add a list setting type. I "cheated" a bit on an if statement so I will rework it later, but it works without any problem at the moment (to be sure it is completely modular).
  • Add a new Spam group to the settings groups, with the new setting Mute list (and a toggle button in message view, not visible yet in the screenshot)

It has a dependency with merge request #127

I will rebase (with some squashes) because it has some commits that are technically independent from the antispam itself.

More details about changes, check commits messages.

screenshot_20231226_174319
screenshot_20231226_190759

@Athozus Athozus added Enhancement New feature or request WIP labels Dec 26, 2023
@Athozus Athozus added this to the 1.4.0 milestone Dec 26, 2023
@Athozus Athozus mentioned this pull request Dec 26, 2023
3 tasks
@Athozus Athozus removed the WIP label Dec 29, 2023
@Athozus Athozus marked this pull request as ready for review December 29, 2023 21:59
@Athozus
Copy link
Member Author

Athozus commented Dec 29, 2023

There are some problems with luacheck (I don't really know how to fix it) but the table.indexof feature is available since 5.0.0.

@Niklp09
Copy link
Member

Niklp09 commented Dec 29, 2023

(I don't really know how to fix it) but the table.indexof feature is available since 5.0.0.

Luacheck doesn't know some functions since they don't belong to the lua specification.
You must add them manually to the read_globals table (table = {fields = {"indexof"}}).

@Niklp09 Niklp09 self-requested a review December 29, 2023 22:40
@Athozus
Copy link
Member Author

Athozus commented Dec 30, 2023

Thanks. All is ok for the review ?

@Athozus Athozus linked an issue Dec 31, 2023 that may be closed by this pull request
3 tasks
@Athozus
Copy link
Member Author

Athozus commented Jan 1, 2024

Until I do some fixes for that you can report, I plan to do the following steps :

@S-S-X
Copy link
Member

S-S-X commented Jan 3, 2024

Disable beerchat syncing until muting gets fixed

API should be fixed when mt-mods/beerchat#116 is merged.
If you want you could test it with upgrade-mute-bugs branch.

@Athozus
Copy link
Member Author

Athozus commented Jan 3, 2024

API should be fixed when mt-mods/beerchat#116 is merged. If you want you could test it with upgrade-mute-bugs branch.

It successfully works, thanks ! I git force push to remove the latest commit, because it is soon merged, or I let this fix and re-enable sync when it is merged in beerchat master ?

Copy link
Member

@BuckarooBanzay BuckarooBanzay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm if this is properly tested

return valid_players
end

--[[function mail.settings.mute_list.sync(name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are you planning to do with this function, this looks like a cpu-hog 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check (the end of the part of code) or sync ?

  • check is to be sure all usernames given are existing
  • sync is to get data from beerchat, but it is temporary disabled waiting for mute fixes merged

Copy link
Member

@S-S-X S-S-X Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do still think that data sync for muting could be a way better as event based specific checks than a static lists and settings sync.

Additionally for beerchat muting to stay sync globally both ways you do not really have to transfer any static data at all and also already has fairly good performance for most parts when used directly.

So making this side also event based would allow for example (if something in this list does not make sense feel free to ask for clarification):

  • getting rid of somewhat complicated data transfer between the mods.
  • likely better performance without additional optimizations, caching or usage restrictions.
  • no loading or syncing of data for players who do not use /mail.
  • data only fetched when it is actually needed.
  • data always up to date, no synchronization required ever.
  • no merging of data and no conflict resolutions for merge conflicts.
  • does not have to worry about merging possible offline data updates (external systems for example).
  • overall simpler compared to data synchronization.
  • automatic handling both public list (other mods) and private list (mail mod), just user interface could use specific code for public/private distinction.

I've not put a lot thought on config sync system so I'd love to hear what problems it can solve and why it would be preferred over on-demand API calls or other event based checks.

Basically just saying that my comments on #127 also apply here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-using beerchat disables the syncing script. This is on purpose : it syncs list only when the setting is called. I don't want to have mail storage outside mail : transfer is better than putting muting lists in beerchat. If beerchat is deleted, everything is out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If beerchat is deleted, everything is out.

Did I get it right: basically you want that beerchat configrations keep affecting mail even after beerchat has been removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Yes, and it saves resources by syncing only when needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually very likely wastes resources and has worse performance as it syncs what potentially isn't needed but also it is probably simplest way to keep configurations (both wanted and unwanted) after removing source mod.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually very likely wastes resources and has worse performance as it syncs what potentially isn't needed but also it is probably simplest way to keep configurations (both wanted and unwanted) after removing source mod.

If you have a better idea tell me, likely beerchat could have a similar transfer function ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually very likely wastes resources and has worse performance as it syncs what potentially isn't needed but also it is probably simplest way to keep configurations (both wanted and unwanted) after removing source mod.

If you have a better idea tell me, likely beerchat could have a similar transfer function ?

See comment in another thread (code comments) https://github.com/mt-mods/mail/pull/128/files#r1451568438

Comment on lines +101 to +102
minetest.get_player_by_name(name):get_meta():set_string(
"beerchat:muted:" .. other_player, "true")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad idea as it will likely change to mod storage (because player meta is very limitated).
For this I'd recommend using API as it will then actually keep working after beerchat's internal storage is updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally it introduces another inconsistency as it depends on /mute command which is not definition of beerchat mute functionality.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay because when I did it it was still the buggy muting API. I'm gonna make a commit in a second.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT : there's not yet a mute_player API command in plugin/mute.lua

Copy link
Member

@S-S-X S-S-X Jan 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muting API was not buggy for muting ever. Only for those shortcut API functions you can use to check if someone is muted.

Actual muting API uses event based checks, shortcut functions were not actually used anywhere (never called internally or externally) and were broken but those are only shortcuts for checking status. Muting is event based, not direct API call (because there's no single configuration for muting so you cannot store configuration for muting anywhere).

So, you implement check by adding this:

if minetest.get_modpath("beerchat") then
	beerchat.register_callback('before_send_pm', function(name, message, target)
		if mail.get_setting(target, "has_muted_"..name) then
			return false
		end
	end)
end

Then use that check by calling (this shortcut was function buggy before but is now fixed):
this should be added where mail is actually sent

if beerchat.allow_private_message(from, to) then
	mail.do_actually_deliver_mail_message_to_recipient(from, to, body)
end

Note that above code is just to explain basic concept by example, I've no idea about exact mail mod functions / mail mod settings storage but know it is something like this just with different naming / paths.

Note 2 this will automatically mute other things, both ways, like jailed players and teleport requests for muted players.

Note 3 this automatically supports (no additional code besides what I already wrote up there ^^) skipping muting for special cases like server admin or moderators if server owner wants that. Also any other muting behavior is automatically synced without having to write any code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for the suggestions (I already read them but didn't have the time to work on).

I can make a commit based on your suggestions, but I'm won't think it would be much better (we still have to get a copy for ourselves).

The idea is not to push to master a buggy PR, however my goal is to have #127 and #128 rebased to have a common base before merging new PRs (I don't want to treat a lot of merging conflicts).

Tell me if you're ok for the rebase. I already did a lot of tests, I fixed what I found, so for me it's stable actually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are based on current PR target branch which currently is master.

Any rebases on development branches are always fine, no issues with that and should be done whenever you feel it helps with development.

But you can always switch that to another dev branch, also rebase on that dev branch if needed and it is actually what I do too when not sure about something, want to compare different somewhat complicated approaches or just want to get easy view to big picture about possible changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the answer.

For me, it is now operational (might be some lost bugs, as any software), but there's not so much issues at the moment.

It is a big pull request (gonna be rebased, with some squashes btw), so I would like other maintainers advice before doing it (such as @BuckarooBanzay )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, it is now operational (might be some lost bugs, as any software), but there's not so much issues at the moment.

👍

It is a big pull request (gonna be rebased, with some squashes btw), so I would like other maintainers advice before doing it (such as @BuckarooBanzay )

just squashing sounds fine, i would even do that into the master branch IMO (if the code is properly tested)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I planned to do. I'm starting right now.

@Athozus Athozus mentioned this pull request Jan 29, 2024
4 tasks
Based on Minetest main menu orange color
@Athozus Athozus force-pushed the antispam-features branch 2 times, most recently from 7e7b6d7 to f60e6d9 Compare February 1, 2024 09:34
It checks during the sends if there are spam warnings then give to the message an attribute spam=true (only for receivers)
Resize boxes view, and modify the layout of message view
Athozus and others added 3 commits February 1, 2024 10:43
Add sharing between mute_list and beerchat

Add check for mute list
Fix luacheck warnings in spam.lua

Fix global variable initialization (was needed only locally)

Add beerchat to luacheck
@Athozus
Copy link
Member Author

Athozus commented Feb 1, 2024

@S-S-X @BuckarooBanzay

I followed what I said, following the suggestion from Buckaroo to squash #127 (I haven't understood when I answered, but after reading again the message it was clear).

Here's my working tree. I want to be sure that it's not polluting master branch, but I'm quite satisfied of I what I did, so I consider one approval so one of you will be ok for rebasing.

@S-S-X
Copy link
Member

S-S-X commented Feb 1, 2024

Don't really want approve as long as direct player metadata reading or writing is included. There's anyway one approval already...

If you believe it wont cause issues when metadata is obsoleted and/or cleaned up then probably fine, just keep in mind that it is completely private data that is not considered being part of beerchat API and should be refactored soon to allow missing features.

Additionally just a reminder, I didn't read code well enough to be sure but it seems to loop over all players and then read/write their metadata. Is there a checks in place to make sure it wont try to do it for offline players, I think no which might cause crash if sync is called while any of the registered players is offline.
edit. Did read a bit more and seems it just grabs names for offline players and wont try to use their meta which should be fine (but unnecessary cpu hog).

@Athozus Athozus merged commit c5fd218 into master Feb 1, 2024
20 checks passed
@Athozus Athozus deleted the antispam-features branch April 15, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spam features
4 participants