我用SlackKit
和Swift 4.0
写了一个Slackbot。我从Peter Zignego
他在Heroku
部署了他的机器人首先出现的问题是我使用了一个数组扩展,它给出了一个给定集合中的随机项:
extension Array {
/// Picks `n` random elements (partial Fisher-Yates shuffle approach)
subscript (randomPick n: Int) -> [Element] {
var copy = self
for i in stride(from: count - 1, to: count - n - 1, by: -1) {
copy.swapAt(i, Int(arc4random_uniform(UInt32(i + 1))))
}
return Array(copy.suffix(n))
}
}
使用此代码我没有构建问题,我想将我的代码推送到Heroku
,但是当它运行时抛出部署会发生错误:
error: use of unresolved identifier 'arc4random_uniform'
搜索后我发现Swift报告Bug并将我的代码更改为:
extension Array {
/// Picks `n` random elements (partial Fisher-Yates shuffle approach)
subscript (randomPick n: Int) -> [Element] {
var copy = self
for i in stride(from: count - 1, to: count - n - 1, by: -1) {
#if os(Linux)
copy.swapAt(i, Int(random() % (i + 1)))
#else
copy.swapAt(i, Int(arc4random_uniform(UInt32(i + 1))))
#endif
}
return Array(copy.suffix(n))
}
}
现在我的代码已成功推送并部署在Heroku
上。
但是当我想在我的Slack
频道中启动Bot时:
rf24-dev-mac-1:support-dialer konstantin$ heroku run:detached slackbot
Running slackbot on ⬢ support-dialer... done, run.1246 (Free)
Run heroku logs --app support-dialer --dyno run.1246 to view the output.
并运行输出命令我得到这个:
2017-09-25T13:37:27.762135+00:00 heroku[run.1246]: Starting process with command `.build/release/support-dialer`
2017-09-25T13:37:28.335452+00:00 heroku[run.1246]: State changed from starting to up
2017-09-25T13:37:29.842073+00:00 heroku[run.1246]: Process exited with status 127
2017-09-25T13:37:29.779834+00:00 app[run.1246]: .build/release/support-dialer: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory
2017-09-25T13:37:29.856440+00:00 heroku[run.1246]: State changed from up to complete
所以我不知道我能做些什么来解决这个问题,因为它没有启动Slackbot,当我在Heroku
点击deploy link时它也说错了。