shanemcc / yasmin
Yasmin 是一个用于 PHP 的 Discord API 库。
Requires
- php: >=7.1
- ext-bcmath: *
- ext-date: *
- ext-filter: *
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- ext-pcre: *
- ext-zlib: *
- clue/buzz-react: ^2.6.0
- psr/http-message: ^1.0
- ratchet/pawl: ^0.3.1
- react/event-loop: ^1.0|^0.5|^0.4.3
- react/filesystem: ^0.1.1
- react/promise: ^2.7.0
- ringcentral/psr7: ^1.2
- valzargaming/collection: ^0.2.0
- valzargaming/eventemitter: ^0.1.5
- valzargaming/validator: ^0.3.0
Replaces
- charlottedunois/yasmin: v0.7.6
- valzargaming/yasmin: v0.7.6
This package is auto-updated.
Last update: 2024-09-20 09:41:53 UTC
README
注意: 这是一个对 CharlotteDunois/Yasmin 仓库的分支,包含其他分支的额外修复。
Yasmin
Yasmin 是一个用于 PHP 的 Discord API 库。Yasmin 连接到网关并交互 REST API。
此库仅适用于 PHP 7.1(及以上)版本,并在 CLI 中使用。Yasmin 仅支持机器人账号。
开始之前
在使用此库之前,您必须了解 PHP 的工作原理,您需要了解该语言以及您需要了解事件循环和承诺的工作方式。这是开始前的基本要求。如果没有这些知识,您只会遭受苦难。
有关资源,请参阅 https://github.com/elazar/asynchronous-php
入门
开始使用 Yasmin 非常简单。您只需要使用 composer 安装 Yasmin 及其依赖项。之后,您可以将 composer 的自动加载器包含到您的文件中,并开始与 Discord 和 Yasmin 交互!
composer require shanemcc/yasmin:"dev-master as 1.0.x-dev"
重要:请监听 error
事件。如果您没有附加 error
监听器,事件发射器将抛出异常。
请确保您还为所有承诺设置了拒绝处理程序,因为未处理的承诺拒绝会被吞掉,您将永远不会知道它们发生了什么。
重要信息: 类实例上所有使用魔术方法实现的属性(几乎意味着所有属性),如果属性不存在,则抛出异常。
有一个包含一些提示的 WIP Gitbook,您可以自由阅读:https://charlottedunois.gitbooks.io/yasmin-guide/content/
示例
这是一个使用 Yasmin 的简单示例。您应该将所有监听器代码放入 try-catch 块中,并相应地处理异常。
// Include composer autoloader $loop = \React\EventLoop\Factory::create(); $client = new \CharlotteDunois\Yasmin\Client(array(), $loop); $client->on('error', function ($error) { echo $error.PHP_EOL; }); $client->on('ready', function () use ($client) { echo 'Logged in as '.$client->user->tag.' created on '.$client->user->createdAt->format('d.m.Y H:i:s').PHP_EOL; }); $client->on('message', function ($message) { echo 'Received Message from '.$message->author->tag.' in '.($message->channel instanceof \CharlotteDunois\Yasmin\Interfaces\DMChannelInterface ? 'DM' : 'channel #'.$message->channel->name ).' with '.$message->attachments->count().' attachment(s) and '.\count($message->embeds).' embed(s)'.PHP_EOL; }); $client->login('YOUR_TOKEN')->done(); $loop->run();
语音支持
没有语音支持。
文档
https://shanemcc.github.io/Yasmin/
Windows 和 SSL
遗憾的是,Windows 上的 PHP 没有访问 Windows 证书存储的权限。这是一个问题,因为 TLS 被使用,因此证书验证被应用(关闭此选项 不是 一个选项)。
您会注意到这个问题,因为您的脚本在没有任何错误的情况下立即退出,而没有经过一轮循环。遗憾的是,出于某种原因,没有错误或异常。
因此,此库的用户需要从 cURL 网站下载一个 证书颁发机构提取。
必须将 caextract 的路径设置在 php.ini
的 openssl.cafile
中。
Linux 支持
使用 git 克隆此存储库。
Yasmin 需要运行 PHP 7.1+ 以及以下包。建议使用您存储库中可用的最新 PHP 版本。在提供的示例中,将使用 7.1。将 7.1 替换为您当前使用的版本。
Ubuntu
sudo apt install openssl php7.1 php7.1-bcmath php7.1-mbstring
注意:支持有限
我不能提供由于过时先决条件或实施SSL而引起的大多数问题的支持。如果您在Windows上托管并且需要 cacert.pem 文件但又不方便自己生成,那么我强烈推荐使用 WinNMP,因为它会在其 /data/ 目录中生成一个,您可以将 PHP.ini 指向它。
其他发行版
请参考您发行版的仓库以查找上述软件包。