Created
July 17, 2020 15:52
-
-
Save helje5/7039697515597e31f7e373bd7ce72ce4 to your computer and use it in GitHub Desktop.
ASCII Cows for Slack, as a Slash Command - a SwiftBlocksUI demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift sh | |
import cows // @AlwaysRightInstitute ~> 1.0.0 | |
import SwiftBlocksUI // @SwiftBlocksUI ~> 0.8.0 | |
dotenv.config() | |
struct CowMessage: Blocks { | |
@Environment(\.messageText) private var query | |
private var cow : String { | |
return cows.allCows.first(where: { $0.contains(query) }) | |
?? cows.vaca() | |
} | |
var body: some Blocks { | |
Group { // only necessary on Swift <5.3 | |
Preformatted { | |
cow | |
} | |
Actions { | |
Button("Delete!") { response in | |
response.clear() | |
} | |
.confirm(message: "This will delete the message!", | |
confirmButton: "Cowsy!") | |
Button("More!") { response in | |
response.push { self } | |
} | |
Button("Reload") { response in | |
response.update() | |
} | |
} | |
} | |
} | |
} | |
struct Cows: App { | |
var body: some Endpoints { | |
Group { // only necessary w/ Swift <5.3 | |
Use(logger("dev"), | |
bodyParser.urlencoded(), | |
sslCheck(verifyToken(allowUnsetInDebug: true))) | |
Slash("vaca", scope: .userOnly) { | |
CowMessage() | |
} | |
} | |
} | |
} | |
try Cows.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment