只要你安装了 homebrew,在 Mac 上安装 libsodium 非常简单。安装后,你只需要执行 brew install libsodium
。 就这样!
这取决于你运行的 Ubuntu 版本,所以我在这里制作了一个表格
Ubuntu 14.04 | Ubuntu 16.04 |
---|---|
sudo -E add-apt-repository -y ppa:chris-lea/libsodium && sudo apt-get update && sudo apt-get install -y libsodium-dev |
sudo apt-get update && sudo apt-get install -y libsodium-dev |
最好直接将该命令复制并粘贴到 shell 中,并根据需要在屏幕上显示的说明进行操作。
要将 Sword 添加为依赖项,你必须首先在指定文件夹中创建一个 Swift 可执行文件,例如 swift package init --type executable
。 然后在新创建的 Package.swift 中,打开它并将 Sword 添加为依赖项
// swift-tools-version: 4.0
import PackageDescription
let package = Package(
name: "yourswiftexecutablehere",
dependencies: [
.package(url: "https://github.com/Azoy/Sword", .branch("master"))
],
targets: [
.target(
name: "yourswiftexecutablehere",
dependencies: ["Sword"]
)
]
)
之后,打开 Sources/main.swift 并删除所有内容,并将其替换为下面的示例。
import Sword
let bot = Sword(token: "Your bot token here")
bot.editStatus(to: "online", playing: "with Sword!")
bot.on(.messageCreate) { data in
let msg = data as! Message
if msg.content == "!ping" {
msg.reply(with: "Pong!")
}
}
bot.connect()
使用 CocoaPods 将 Sword 添加到你的 iOS、watchOS 或 tvOS 应用程序比以往任何时候都容易。 你所要做的就是将 Sword 添加为 Podfile 的依赖项,类似于这样
target 'yourappnamehere' do
use_frameworks!
pod 'Sword'
end
然后你所要做的就是 pod install
,你就可以开始使用了。
使用 swift build
构建库,然后键入 swift run
要在 Xcode 中运行机器人,你首先必须使用 swift build
编译库。 然后要构建 xcode 项目,请键入 swift package generate-xcodeproj
。 最后,键入 open yourswiftexecutablehere.xcodeproj
,查看顶部并按照以下步骤操作
然后点击播放按钮!
加入 API 频道 提问!