Skip to content

Commit 6919451

Browse files
Replaced urls.list separator with semicolon to allow for commas in /setcaptureelement etc.
1 parent a285bb1 commit 6919451

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

NotifierBot/Sources/Notifier/Commands/SetCaptureElementCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ struct SetCaptureElementCommand: Command {
3636
config[entryIndex!].captureElement = ""
3737
if args.count > 1 {
3838
let element = args[1...].joined(separator: " ")
39-
guard !element.contains(",") else {
40-
try bot.sendMessage("Please specify a HTML element that does not contain ','", to: chatID)
39+
guard !element.contains(configSeparator) else {
40+
try bot.sendMessage("Please specify a HTML element that does not contain '\(configSeparator)'", to: chatID)
4141
return
4242
}
4343
// If there was a new element supplied, set it

NotifierBot/Sources/Notifier/Commands/SetClickElementCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ struct SetClickElementCommand: Command {
3636
config[entryIndex!].clickElement = ""
3737
if args.count > 1 {
3838
let element = args[1...].joined(separator: " ")
39-
guard !element.contains(",") else {
40-
try bot.sendMessage("Please specify a HTML element that does not contain ','", to: chatID)
39+
guard !element.contains(configSeparator) else {
40+
try bot.sendMessage("Please specify a HTML element that does not contain '\(configSeparator)'", to: chatID)
4141
return
4242
}
4343
// If there was a new element supplied, set it

NotifierBot/Sources/Notifier/Commands/SetWaitElement.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ struct SetWaitElementCommand: Command {
3636
config[entryIndex!].waitElement = ""
3737
if args.count > 1 {
3838
let element = args[1...].joined(separator: " ")
39-
guard !element.contains(",") else {
40-
try bot.sendMessage("Please specify a HTML element that does not contain ','", to: chatID)
39+
guard !element.contains(configSeparator) else {
40+
try bot.sendMessage("Please specify a HTML element that does not contain '\(configSeparator)'", to: chatID)
4141
return
4242
}
4343
// If there was a new element supplied, set it

Shared/Sources/Shared/ConfigParser.swift

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ConfigParser {
3434
|| line.trimmingCharacters(in: .whitespaces).starts(with: "#") {
3535
continue
3636
}
37-
let components = line.components(separatedBy: ",")
37+
let components = line.components(separatedBy: configSeparator)
3838
// Name, x, y, width, height, url (url may contain comma)
3939
guard components.count >= 9 else {
4040
throw JFConfigError.malformedLineSegments(line)
@@ -55,7 +55,7 @@ public class ConfigParser {
5555
let unmuteDateStr = nextArg()
5656
let chatID = Int64(nextArg())
5757
// URL is the rest
58-
let url = args.joined(separator: ",").trimmingCharacters(in: .whitespaces)
58+
let url = args.joined(separator: configSeparator).trimmingCharacters(in: .whitespaces)
5959

6060
guard x != nil && y != nil && width != nil && height != nil && chatID != nil, delay != nil else {
6161
throw JFConfigError.malformedIntegers(line)
@@ -80,17 +80,28 @@ public class ConfigParser {
8080

8181
/// Parses the config back into a string and saves it to disk
8282
public static func saveConfig(_ config: Config) throws {
83-
var configString = ""
83+
var configLines: [String] = []
8484
for l in config {
8585
var unmuteDateStr = ""
8686
if let unmuteDate = l.unmuteDate {
8787
unmuteDateStr = dateFormatter.string(from: unmuteDate)
8888
}
89-
configString += "\(l.name),\(l.area.x),\(l.area.y),\(l.area.width),\(l.area.height),\(l.delay),\(l.captureElement),\(l.clickElement),\(l.waitElement),\(unmuteDateStr),\(l.chatID),\(l.url)\n"
89+
configLines.append([
90+
l.name,
91+
"\(l.area.x)",
92+
"\(l.area.y)",
93+
"\(l.area.width)",
94+
"\(l.area.height)",
95+
"\(l.delay)",
96+
l.captureElement,
97+
l.clickElement,
98+
l.waitElement,
99+
unmuteDateStr,
100+
"\(l.chatID)",
101+
l.url
102+
].joined(separator: configSeparator))
90103
}
91-
// Remove the trailing line break
92-
configString.removeLast()
93-
try configString.write(toFile: kURLListFile, atomically: true, encoding: .utf8)
104+
try configLines.joined(separator: "\n").write(toFile: kURLListFile, atomically: true, encoding: .utf8)
94105
}
95106

96107
public static func parsePermissions() -> [Int64: BotPermission] {

Shared/Sources/Shared/JFLiterals.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ public let kDiffFile = "diff.png"
7474
public let kNccThreshold = 0.999
7575
/// The duration for which a screenshot capture error has to persist for the user to be notified. Set to 0 to immediately notify on errors
7676
public let kErrorReportDuration: TimeInterval = 120 * 60 // 2 hours
77+
/// The string used to separate the values in the urls.list file
78+
public let configSeparator = ";"

0 commit comments

Comments
 (0)