nodeloc/flarum-auto-moderator
Composer 安装命令:
composer require nodeloc/flarum-auto-moderator
包简介
Automatically assign groups based on activity.
关键字:
README 文档
README
A Flarum extension.
CHanged.
Fix 2 issue
- Can't edit user information.
- When edit user info, all automated group will lost.
Core Concept
The core idea is as follows:
When a user meets criteria X, do Y. When a user no longer meets criteria X, do Z.
Let's define some key terms:
- Criteria Group: The set of all criteria that a user meets.
- Criteria (singular Criterion): An arbitrary set of conditions. Criteria are paired with triggers and actions, and are composed of:
- Metrics: A numerical condition. For example, post count or number of likes received. A criterion could require a range/minimum/maximum of metrics.
- Requirement: An abstract boolean condition. For example, not being suspended, or having an email that matches a certain regex.
- Action: Something that happens automatically when a criteria is met or lost. This could include anything from adding/removing a group to sending an email to suspending a user.
- Triggers: A set of events that would cause a user's criteria groups to be reevaluated. These are associated with metrics and Requirements.
LoggedInis automatically a trigger for all criteria.
This makes for an extremely powerful extension. Furthermore, since extensions can add their own metrics, requirements, and actions, this extension can automate away a lot of moderation. Beyond the examples listed below, some things that could be possible are:
- Automating assignment of achievements / badges
- Sending emails/notifications to users when they reach thresholds (or just when they register)
- Establishing a system of "trust levels" like Discourse
- Onboard/offboard users to/from external systems when they receive/lose certain group membership
- And a bunch more! The possibilities are endless.
Evaluation
When a trigger event occurs:
- All metrics will be calculated for the relevant user (what is the numerical value of the metric?)
- All requirements will be calculated for the relevant user (does the user satisfy each of the requirements?)
- The user's new criteria group will be computed and diffed against the user's current criteria group. The two sets will be diffed. Only criteria triggered by the event will be adjusted.
- Actions will be executed for any gained and lost criteria.
You can also use the php flarum criteria:recalculate console command to recalculate criteria for all users. Note that this will be quite slow, and shouldn't usually be done.
Examples
Example 1: Group Management
Criteria: Users that receive 50 or more likes and have started at least 10 discussions should placed in the "Active" group.
Here, the metrics are "received 50 or more likes" and "have started at least 10 discussions". Unsurprisingly, they come with the triggers (PostWasLiked, PostWasUnliked) and (Discussion\Started) respectively.
The actions are:
- When the criteria is met, add the user to the "Active" group
- When the criteria is lost, remove the user from the "Active" group
Example 2: Suspension
Criteria: If a user gets 15 warnings or more and is not an admin, suspend them.
Here, the metrics are "gets 15 warnings or more" and the requirements are "is not an admin". The triggers would be a new warning for the metric. The requirement has no triggers.
The actions are:
- When the criteria is met, suspend them
- When the criteria is lost, unsuspend them
Example 3: Auto Activation
Criteria: If a user's email matches a regex, activate their email.
The requirement is "a user's email matches a regex". The triggers are saving a user.
The actions are:
- When the criteria is met, auto activate the user's email
- When the criteria are not met, don't
Example 4: Default Group
Criteria: Add a user to a group
There are no metrics or requirements, so this will be applied to all users on login.
The actions are:
- Add all users to a group on login
Screenshots
Metrics vs Requirements
It's clear to see that any metric could be represented as a Requirement.
- A requirement must be specific. "More than 50 received likes" could be a requirement. However, metrics can allow for any range of values.
- Metrics can be stored and used for other purposes. For example, a planned feature is combining all metrics to provide a "reputation" score.
Settings
Requirements and actions can require settings in the admin dashboard. For example:
- The "add to group" action takes the group ID as a setting
- The "suspend" action takes the number of days and whether the suspension is indefinite as settings
- The "email matches regex" requirement takes the regex as a setting
Extensibility
This extension is extremely flexible. It can be considered a framework for automoderation actions.
Extensions can use the Askvortsov\AutoModerator\Extend\AutoModerator extender to add:
- Action drivers
- Metric drivers
- Requirement drivers
You should look at the source code of the default drivers for examples. They're fairly exhaustive of what's offered.
If your extension adds action or requirement drivers that consume settings, you have 2 options:
- Provide translation keys for the settings you need in the driver's
availableSettingsmethod. This is very easy, but also very restrictive. You can only use strings, and can't add any restrictions or UI. - You can declare a settings form component for your driver. See
js/src/admin/components/SuspendSelectorfor an example. The component should take a settings stream asthis.attrs.settings. The contents of the stream should be an object that maps setting keys to values. The component is responsible for updating the stream on input. You can register a form component by adding its class toapp.autoModeratorForms[DRIVER CATEGORY][TYPE], whereDRIVER CATEGORYis"action"or"requirement", andTYPEis the type string you registered your driver with inextend.php. Seejs/src/admin/index.jsfor the underlying data structure and examples.
TODO:
- Add support for more metrics:
- Posts read
- Time spent on forum
- Days visited
- Days since account creation
- Etc
- Add support for dated metrics (discussions created in the past X days)
- Introduce metric "weights", sum together to calculate a reputation. Make that reputation available as a metric.
- Develop a data collection extension, which could cache things such as like counts, to improve performance on large forums
- Investigate criterion "listeners": can we generalize stuff like removing links from posts of users without certain groups?
Contributions
Contributions and PRs are welcome! Any PRs adding new drivers should come with unit tests (like with all existing drivers).
Compatibility
Compatible starting with Flarum 1.0.
Installation
composer require nodeloc/flarum-auto-moderator:*
Updating
composer update nodeloc/flarum-auto-moderator
Links
nodeloc/flarum-auto-moderator 适用场景与选型建议
nodeloc/flarum-auto-moderator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.53k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「flarum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nodeloc/flarum-auto-moderator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nodeloc/flarum-auto-moderator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nodeloc/flarum-auto-moderator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Adds more BBCode
Output of discussions lists in form of cards
Allow users to log in with QQ
A headless CLI performance benchmarking tool for Flarum
The admin panel of afrux/asirem
Enhanced typography for french writings, mainly around punctuation.
统计信息
- 总下载量: 1.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-29