@@ -30,21 +30,36 @@ class ConfigParser {
3030 guard components. count >= 9 else {
3131 throw JFBotError . malformedLineSegments ( line)
3232 }
33- let name = components [ 0 ] . trimmingCharacters ( in: . whitespaces)
34- let x = Int ( components [ 1 ] . trimmingCharacters ( in: . whitespaces) )
35- let y = Int ( components [ 2 ] . trimmingCharacters ( in: . whitespaces) )
36- let width = Int ( components [ 3 ] . trimmingCharacters ( in: . whitespaces) )
37- let height = Int ( components [ 4 ] . trimmingCharacters ( in: . whitespaces) )
38- let delay = Int ( components [ 5 ] . trimmingCharacters ( in: . whitespaces) )
39- let element = components [ 6 ] . trimmingCharacters ( in: . whitespaces)
40- let chatID = Int64 ( components [ 7 ] . trimmingCharacters ( in: . whitespaces) )
41- let url = components [ 8 ... ] . joined ( separator: " , " ) . trimmingCharacters ( in: . whitespaces)
33+ var args = components
34+
35+ func nextArg( ) -> String { args. removeFirst ( ) . trimmingCharacters ( in: . whitespaces) }
36+
37+ let name = nextArg ( )
38+ let x = Int ( nextArg ( ) )
39+ let y = Int ( nextArg ( ) )
40+ let width = Int ( nextArg ( ) )
41+ let height = Int ( nextArg ( ) )
42+ let delay = Int ( nextArg ( ) )
43+ let captureElement = nextArg ( )
44+ let clickElement = nextArg ( )
45+ let waitElement = nextArg ( )
46+ let chatID = Int64 ( nextArg ( ) )
47+ // URL is the rest
48+ let url = args. joined ( separator: " , " ) . trimmingCharacters ( in: . whitespaces)
4249
4350 guard x != nil && y != nil && width != nil && height != nil && chatID != nil , delay != nil else {
4451 throw JFBotError . malformedIntegers ( line)
4552 }
4653
47- entries. append ( URLEntry ( name: name, url: url, area: Rectangle ( x: x!, y: y!, width: width!, height: height!) , chatID: chatID!, delay: delay!, element: element) )
54+ entries. append ( URLEntry (
55+ name: name,
56+ url: url,
57+ area: Rectangle ( x: x!, y: y!, width: width!, height: height!) ,
58+ chatID: chatID!,
59+ delay: delay!,
60+ captureElement: captureElement,
61+ clickElement: clickElement,
62+ waitElement: waitElement) )
4863 }
4964
5065 return entries
@@ -54,7 +69,7 @@ class ConfigParser {
5469 static func saveConfig( _ config: Config ) throws {
5570 var configString = " "
5671 for l in config {
57- configString += " \( l. name) , \( l. area. x) , \( l. area. y) , \( l. area. width) , \( l. area. height) , \( l. delay) , \( l. element ) , \( l. chatID) , \( l. url) \n "
72+ configString += " \( l. name) , \( l. area. x) , \( l. area. y) , \( l. area. width) , \( l. area. height) , \( l. delay) , \( l. captureElement ) , \( l . clickElement ) , \( l . waitElement ) , \( l. chatID) , \( l. url) \n "
5873 }
5974 // Remove the trailing line break
6075 configString. removeLast ( )
@@ -111,7 +126,9 @@ struct URLEntry {
111126 var area : Rectangle
112127 var chatID : Int64
113128 var delay : Int = 0
114- var element : String = " "
129+ var captureElement : String = " "
130+ var clickElement : String = " "
131+ var waitElement : String = " "
115132
116133}
117134
0 commit comments