Skip to content

Commit b25723c

Browse files
Fixed ncc file not being generated when there was no change
Fixed error when ncc file did not exist. Now the bot sends the diff file without text. Fixed /diff not using the actual capitalized name
1 parent 4b87238 commit b25723c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

NotifierBot/Sources/Notifier/Commands/DiffCommand.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ struct DiffCommand: Command {
2626
let name = args.joined(separator: " ")
2727
// Check if an entry with this name exists
2828
let config = try ConfigParser.getConfig()
29-
guard config.contains(where: { $0.name.lowercased() == name.lowercased() && $0.chatID == chatID }) else {
29+
guard let entry = config.first(where: { $0.name.lowercased() == name.lowercased() && $0.chatID == chatID }) else {
3030
try bot.sendMessage("There is no entry with the name '\(name)'", to: chatID)
3131
return
3232
}
33+
let realName = entry.name
3334
// Send the diff file and the contents of the ncc file
34-
let nccInfo = try String(contentsOfFile: "\(mainDirectory!)/urlwatcher/images/\(name)/\(nccFile)")
35-
JFUtils.sendImage(path: "\(mainDirectory!)/urlwatcher/images/\(name)/\(diffFile)", chatID: chatID, text: nccInfo)
35+
let nccInfo = try? String(contentsOfFile: "\(mainDirectory!)/urlwatcher/images/\(realName)/\(nccFile)")
36+
JFUtils.sendImage(path: "\(mainDirectory!)/urlwatcher/images/\(realName)/\(diffFile)", chatID: chatID, text: nccInfo)
3637
}
3738
}

urlwatcher/urlwatcher.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function screenshotsMatch {
135135

136136
if [ "NCC" -lt "$NCC_THRESHOLD" ]; then
137137
# The screenshots do not match. The website has changed
138+
138139
# Write detailed NCC information to a file (and don't overwrite the diff file)
139140
compare -verbose -metric NCC "$IMAGE_OLD" "$IMAGE_LATEST" /dev/null > "$NCC_FILE"
140141

@@ -144,6 +145,9 @@ function screenshotsMatch {
144145
fi
145146
fi
146147

148+
# 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+
147151
# If statement above didn't exit, that means we have no mismatching hashes and therefore the screenshots match (return true)
148152
# In bash: 0 == true
149153
return 0
@@ -224,7 +228,7 @@ while IFS='' read -r line || [ -n "${line}" ]; do
224228

225229
# If the new screenshot is all black or all white (some display error), ignore it
226230
mean=$(convert latest.png -format "%[mean]" info:)
227-
if [ "$mean" == "0" || "$mean" == "65535" ]; then
231+
if [ "$mean" == "0" ] || [ "$mean" == "65535" ]; then
228232
rollBack
229233
# Skip this entry
230234
cd ../..

0 commit comments

Comments
 (0)