ソースを参照

reaction filters

Drn 2 年 前
コミット
1efa3d8bdd
2 ファイル変更45 行追加7 行削除
  1. 7 4
      README.md
  2. 38 3
      downloads.go

+ 7 - 4
README.md

@@ -377,14 +377,17 @@ The bot accepts `.json` or `.jsonc` for comment-friendly json.
         "blockedRoles": [ "" ], // by Discord ID.
         "allowedRoles": [ "" ], // by Discord ID.
 
-        "blockedExtensions": [ ".htm", ".html", ".php", ".exe", ".dll", ".bin", ".cmd", ".sh", ".py", ".jar" ],
-        "allowedExtensions": [ "" ],
-
         "blockedDomains": [ "" ],
         "allowedDomains": [ "" ],
 
+        "blockedExtensions": [ ".htm", ".html", ".php", ".exe", ".dll", ".bin", ".cmd", ".sh", ".py", ".jar" ],
+        "allowedExtensions": [ "" ],
+
         "blockedFilenames": [ "" ], // List of phrases to check for in original filename, pre-formatting.
-        "allowedFilenames": [ "" ]
+        "allowedFilenames": [ "" ],
+
+        "blockedReactions": [ "" ], // List of reactions to block or allow, by ID only.
+        "allowedReactions": [ "" ]
     },
     // duplicate image filtering
     // caching of image data is stored via a database file; it will not read all pre-existing images.

+ 38 - 3
downloads.go

@@ -45,9 +45,10 @@ const (
 	downloadSkipped
 	downloadSkippedDuplicate
 	downloadSkippedUnpermittedDomain
+	downloadSkippedUnpermittedExtension
 	downloadSkippedUnpermittedFilename
+	downloadSkippedUnpermittedReaction
 	downloadSkippedUnpermittedType
-	downloadSkippedUnpermittedExtension
 	downloadSkippedDetectedDuplicate
 
 	downloadFailed
@@ -97,12 +98,14 @@ func getDownloadStatusString(status downloadStatus) string {
 		return "Skipped - Duplicate"
 	case downloadSkippedUnpermittedDomain:
 		return "Skipped - Unpermitted Domain"
+	case downloadSkippedUnpermittedExtension:
+		return "Skipped - Unpermitted File Extension"
 	case downloadSkippedUnpermittedFilename:
 		return "Skipped - Unpermitted Filename Content"
+	case downloadSkippedUnpermittedReaction:
+		return "Skipped - Unpermitted Message Reaction"
 	case downloadSkippedUnpermittedType:
 		return "Skipped - Unpermitted File Type"
-	case downloadSkippedUnpermittedExtension:
-		return "Skipped - Unpermitted File Extension"
 	case downloadSkippedDetectedDuplicate:
 		return "Skipped - Detected Duplicate"
 	//
@@ -749,6 +752,38 @@ func (download downloadRequestStruct) tryDownload() (downloadStatusStruct, int64
 			}
 		}
 
+		// Check Reactions
+		if channelConfig.Filters.AllowedReactions != nil || channelConfig.Filters.BlockedReactions != nil {
+			shouldAbort := false
+			if channelConfig.Filters.AllowedReactions != nil {
+				shouldAbort = true
+			}
+
+			if download.Message.Reactions != nil {
+				for _, reaction := range download.Message.Reactions {
+					if channelConfig.Filters.BlockedReactions != nil {
+						if stringInSlice(reaction.Emoji.ID, *channelConfig.Filters.BlockedReactions) {
+							shouldAbort = true
+						}
+					}
+					if channelConfig.Filters.AllowedReactions != nil {
+						if stringInSlice(reaction.Emoji.ID, *channelConfig.Filters.AllowedReactions) {
+							shouldAbort = false
+						}
+					}
+				}
+			}
+
+			// Abort
+			if shouldAbort {
+				if !download.HistoryCmd {
+					log.Println(lg("Download", "Skip", color.GreenString,
+						"Did not meet reaction filter criteria"))
+				}
+				return mDownloadStatus(downloadSkippedUnpermittedReaction), 0
+			}
+		}
+
 		// Extension
 		download.Extension = strings.ToLower(filepath.Ext(download.Filename))
 		if filepath.Ext(download.Filename) == "" {