用於刪除 Mastodon 垃圾帳戶貼文的腳本 - 刪除 Mastodon 上的垃圾帳戶貼文

3 min

language: ja bn en es hi pt ru zh-cn zh-tw

大家好,我是無能。

由於 Mastodon 的垃圾訊息非常嚴重,我在此提供一個刪除腳本。

這並非用於刪除垃圾訊息使用者。它只是刪除貼文和已收到的通知。
此外,由於無法保證其使用,請自行承擔風險。

https://github.com/haturatu/mastodon-spam-remove/blob/master/spam_remove.rb

我的環境

Devuan + Mastodon 4.2.7 + Ruby 3.2.0

使用方法

※為了安全起見,請切換到 Mastodon 使用者,或使用 sudo -u mastodon 進行操作,最後請務必使用 chown mastodon:mastodon spam_remove.rb 將所有者權限設定為 Mastodon 使用者來進行操作。
此外,請務必備份您的資料庫和 Mastodon。

使用 wget 或複製貼上腳本。

將路徑更改為您正在使用的 Mastodon 目錄中包含environment 的路徑。

require_relative '/your/mastodon/live/config/environment

判斷僅依據以下條件進行。
目前是根據提及的 @ 符號數量來判斷。

def spam_detected?(message)
message.scan(/@/).size >= 5
end

保存並賦予執行權限。

chmod +x spam_remove.rb

執行。

./spam_remove.rb

如果貼文數量很多,可能需要相當長的時間,請注意。

如果運作正常,請使用 crontab -e 定期執行它。
如果是 root 使用者的 crontab:

0 */4 * * * sudo -u mastodon /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb

如果是 Mastodon 使用者:

0 */4 * * * /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb

在上述情況下,腳本將每 4 小時執行一次。

貼文等中含有 5 個以上 @ 符號的內容將會被刪除,即使是過去的正常貼文,如果含有 5 個 @ 符號也會被刪除。請透過更改判斷條件來處理。


AI 翻譯

為了安全起見,請確保您切換到 Mastodon 使用者或使用 sudo -u mastodon 執行操作。最後,請確保您始終以 Mastodon 使用者的所有權限執行操作,方法是執行 chown mastodon:mastodon spam_remove.rb。此外,在繼續之前,請記住備份您的資料庫和 Mastodon。

使用 wget 或複製貼上來獲取腳本。

將路徑更改為您正在使用的 Mastodon 目錄中包含 environment 的路徑。

require_relative '/your/mastodon/live/config/environment'

檢測僅基於訊息中提及的數量。

def spam_detected?(message) message.scan(/@/).size >= 5 end

保存並授予執行權限。

chmod +x spam_remove.rb

執行腳本。

./spam_remove.rb

請注意,如果貼文數量很多,可能需要相當長的時間。

如果它運作正常,請使用 crontab -e 定期安排它運行。(root crontab)

0 */4 * * * sudo -u mastodon /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb

對於 Mastodon 使用者的 crontab

0 */4 * * * /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb

在上述範例中,腳本將每 4 小時運行一次。

含有五個或更多 @ 符號的貼文將會被刪除,即使它們是過去的正常貼文,只要含有五個 @ 符號也會被刪除。請相應調整檢測標準。

Related Posts