こんにちは、@kirupa様
私も同様の問題を抱えていました。
私のフォーラムでは、自動的にフラグ付けされた(システムおよびAkismetによる)数千件の投稿/ユーザーを確認しました。
システムとAkismetの両方の精度は、ほぼ100%に近かったです(私の知る限り、2500件のフラグに対して1件の誤検知)。これはすべてのフォーラムに当てはまるわけではないので、自動的にフラグ付けされたユーザーの自動禁止を自動化したい場合は、自分が何をしているのかを確信する必要があります。
最終的に、DiscourseのWebhookデータを使用してPHPスクリプトを作成しました。
まずWebhookを作成しました。
次に、Use Discourse webhooks with PHP を使用してリクエストを受信し、データを解析しました。
カスタムコードを追加して、任意の基準に基づいてDiscourseへのAPIリクエストを送信することにより、自動禁止をトリガーしました。
最終的なコードは次のとおりです。
<?php
// Immediately verify the authenticity of the request.
if (array_key_exists('HTTP_X_DISCOURSE_EVENT_SIGNATURE', $_SERVER)) {
$discourse_payload_raw = file_get_contents('php://input');
$discourse_payload_sha256 = substr($_SERVER['HTTP_X_DISCOURSE_EVENT_SIGNATURE'], 7);
// For security, configure the webhook with a secret in Discourse and set it below.
$discourse_payload_secret = 'xxxxxxxxxxxxxxxxxxxxx';
// Verify that the request was sent from an authorized webhook.
if (hash_hmac('sha256', $discourse_payload_raw, $discourse_payload_secret) == $discourse_payload_sha256) {
echo 'received';
}
else {
die('authentication failed');
}
}
else {
die('access denied');
}
// Prepare the payload for use in the PHP script.
$discourse_json = json_decode($discourse_payload_raw);
$reviewable = $discourse_json->reviewable;
// Set up the API URL
$api_url = "https://unicyclist.com/review/$reviewable->id/perform/delete_user?version=0";
// Verify that the "type" and "score" properties are valid
if (($reviewable->type == "ReviewableUser" || $reviewable->type == "ReviewableAkismetUser" || $reviewable->type == "ReviewableQueuedPost") && $reviewable->score > 0) {
// Set up the curl options
$options = array(
CURLOPT_URL => $api_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PUT", // Set the request method to PUT
CURLOPT_HTTPHEADER => array(
"Api-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Api-Username: system"
)
);
// Initialize the curl session
$curl = curl_init();
curl_setopt_array($curl, $options);
// Make the API call
$response = curl_exec($curl);
curl_close($curl);
// Decode the response
$response_data = json_decode($response);
print_r($response_data);
} else {
exit;
}
?>
今のところ完璧に機能しています。
私のコードは、他のコンテキストで使用すると非常に危険である可能性があり、コンテンツは慎重に検討する必要があることに注意してください。
たとえば、「ReviewableUser」フラグは、ユーザーを手動で検証する必要があるフォーラムのユーザーに設定される可能性があります(そうかどうかはわかりませんが、単なる例です)。他のフォーラムでは、設定でスパマー検出のしきい値が変更されている可能性があり、または自動検出がそれらのフォーラムでは単に精度が低い可能性があります。
