Skip to content

Commit 1f301bb

Browse files
Deactivated alpha channel inspection for NCC
Fixed float comparison in urlwatcher.sh Fixed sending of multiline text in JFUtils
1 parent b4e31b2 commit 1f301bb

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

NotifierBot/Sources/Notifier/JFUtils.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ struct JFUtils {
5050
static private func sendImageOrFile(path: String, chatID: Int64, isFile: Bool, text: String? = nil) {
5151
var command = "\(kTelegramScript) -t \(token!) -c \(chatID) -\(isFile ? "f" : "i") \(path)"
5252
if let text = text {
53-
command += " \(text)"
53+
// Encase the lines in parantheses
54+
let lines = text.components(separatedBy: .newlines).map({ "\"\($0)\"" })
55+
// Join the lines using line breaks
56+
command += " \(lines.joined(separator: "$'\n'"))"
5457
}
5558
shell(command)
5659
}

urlwatcher/urlwatcher.sh

100644100755
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ function screenshotsMatch {
106106
local IMAGE_LATEST="$2"
107107

108108
# Calculate the normalized cross correllation between both images
109-
NCC=$(compare -quiet -metric NCC "$IMAGE_OLD" "$IMAGE_LATEST" "$DIFF_FILE" 2>&1)
109+
NCC=$(compare -quiet -alpha deactivate -metric NCC "$IMAGE_OLD" "$IMAGE_LATEST" "$DIFF_FILE" 2>&1)
110110

111-
if [ "$NCC" -lt "$NCC_THRESHOLD" ]; then
111+
# Compare floats
112+
if [ $(echo "${NCC}<${NCC_THRESHOLD}" | bc -l) -eq 1 ]; then
112113
# The screenshots are not identical
113114
echo "Possible change detected. Confirming..."
114115

@@ -131,25 +132,25 @@ function screenshotsMatch {
131132

132133
# Compare the two cropped screenshots again
133134
# Calculate the normalized cross correllation between both images
134-
NCC=$(compare -quiet -metric NCC "$IMAGE_OLD" "$IMAGE_LATEST" "$DIFF_FILE" 2>&1)
135+
NCC=$(compare -quiet -alpha deactivate -metric NCC "$IMAGE_OLD" "$IMAGE_LATEST" "$DIFF_FILE" 2>&1)
135136

136-
if [ "$NCC" -lt "$NCC_THRESHOLD" ]; then
137+
if [ $(echo "${NCC}<${NCC_THRESHOLD}" | bc -l) -eq 1 ]; then
137138
# The screenshots do not match. The website has changed
138139

139140
# Write detailed NCC information to a file (and don't overwrite the diff file)
140-
compare -verbose -metric NCC "$IMAGE_OLD" "$IMAGE_LATEST" /dev/null &> "$NCC_FILE"
141+
compare -verbose -alpha deactivate -metric NCC "$IMAGE_OLD" "$IMAGE_LATEST" /dev/null &> "$NCC_FILE"
141142

142143
# Return false, as the screenshots do not match
143-
# In bash: 1 == false
144+
# In bash: return value 1 == error == false
144145
return 1
145146
fi
146147
fi
147148

148149
# Write detailed NCC information to a file (and don't overwrite the diff file)
149-
compare -verbose -metric NCC "$IMAGE_OLD" "$IMAGE_LATEST" /dev/null &> "$NCC_FILE"
150+
compare -verbose -alpha deactivate -metric NCC "$IMAGE_OLD" "$IMAGE_LATEST" /dev/null &> "$NCC_FILE"
150151

151152
# If statement above didn't exit, that means we have no mismatching hashes and therefore the screenshots match (return true)
152-
# In bash: 0 == true
153+
# In bash: return value 0 == true
153154
return 0
154155
}
155156

0 commit comments

Comments
 (0)