Skip to content

Commit 5f56b91

Browse files
Fixed bot token containing newlines
1 parent 7cfd917 commit 5f56b91

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

urlwatcher/Sources/urlwatcher/main.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ let fileManager = FileManager.default
88
/// The directory, the executable is in
99
let currentPath = Bundle.main.bundlePath
1010
/// The telegram bot token is read from a file
11-
let telegramBotToken = try String(contentsOfFile: "\(currentPath)/../BOT_TOKEN", encoding: .utf8)
11+
guard let telegramBotToken = try String(contentsOfFile: "\(currentPath)/../BOT_TOKEN", encoding: .utf8).components(separatedBy: .newlines).first else {
12+
print("Unable to read bot token. Please place it into the file \(currentPath.components(separatedBy: "/").dropLast().joined(separator: "/"))/BOT_TOKEN")
13+
exit(1)
14+
}
1215
/// The script used to send the telegram messages
1316
let telegramScript = "\(currentPath)/../tools/telegram.sh"
1417

0 commit comments

Comments
 (0)