Skip to content

Instantly share code, notes, and snippets.

@helje5
Created July 17, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helje5/7039697515597e31f7e373bd7ce72ce4 to your computer and use it in GitHub Desktop.
Save helje5/7039697515597e31f7e373bd7ce72ce4 to your computer and use it in GitHub Desktop.
ASCII Cows for Slack, as a Slash Command - a SwiftBlocksUI demo
#!/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