exan / fenrir
Discord API & WS 包装器
0.13.5
2024-09-26 10:38 UTC
Requires
- discord-php/http: ^v10.3.0
- evenement/evenement: ^3.0.0
- exan/eventer: ^1.0.3
- exan/reactphp-retrier: ^1.0
- freezemage0/array_find: ^1.0
- nesbot/carbon: ^2.64 || ^3.0
- ralouphie/mimey: ^1.0
- ratchet/pawl: ^0.4.1
- react/async: ^4.0.0
- react/event-loop: ^1.3.0
- spatie/regex: ^3.1
Requires (Dev)
- cboden/ratchet: ^0.4.4
- friendsofphp/php-cs-fixer: ^3.20
- mockery/mockery: ^1.6
- monolog/monolog: ^3.2
- phpmd/phpmd: ^2.13
- phpunit/phpunit: ^9.5 || ^10.0
- symfony/var-dumper: ^6.2
- dev-master
- 0.13.5
- 0.13.4
- 0.13.3
- 0.13.2
- 0.13.1
- 0.12.6
- 0.12.5
- 0.12.4
- 0.12.3
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.3
- 0.11.2
- 0.11.1
- 0.11.0
- 0.10.5
- 0.10.4
- 0.10.3
- 0.10.2
- 0.10.1
- 0.9.14
- 0.9.13
- 0.9.12
- 0.9.11
- 0.9.10
- 0.9.9
- 0.9.8
- 0.9.7
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.0
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.4.2
- 0.4.1
- 0.3.1
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
- 0.0.2
- 0.0.1
- dev-updates/sep-26-2024
- dev-chore/sub-commands-test-case
- dev-chore/discord-api-updates
- dev-chore/php-version-pipelines
- dev-feature/start-thread-forum
- dev-tnapf-mapper
This package is auto-updated.
Last update: 2024-09-26 10:39:52 UTC
README
Fenrir
PHP Discord 接口。
关于
Fenrir 是 Discord APIs/gateway 的一种简单包装。没有内置缓存,这需要用户自行实现。
如果您正在寻找更易于使用的东西,具有开箱即用的缓存,您可以考虑 DiscordPHP。
Fenrir 严重依赖于 ReactPHP 进行异步操作。在深入研究之前,建议您了解异步 PHP 的基础知识。
示例机器人
use Ragnarok\Fenrir\Bitwise\Bitwise; use Ragnarok\Fenrir\Constants\Events; use Ragnarok\Fenrir\Discord; use Ragnarok\Fenrir\Enums\Intent; use Ragnarok\Fenrir\Gateway\Events\MessageCreate; use Ragnarok\Fenrir\Rest\Helpers\Channel\MessageBuilder; require './vendor/autoload.php'; $discord = new Discord('TOKEN'); $discord ->withGateway(Bitwise::from( Intent::GUILD_MESSAGES, Intent::DIRECT_MESSAGES, Intent::MESSAGE_CONTENT, )) ->withRest(); $discord->gateway->events->on(Events::MESSAGE_CREATE, function (MessageCreate $message) use ($discord) { if ($message->content === '!ping') { $discord->rest->channel->createMessage( $message->channel_id, (new MessageBuilder()) ->setContent('pong!') ); } }); $discord->gateway->open(); // Nothing after this line is executed
仅REST示例
use Ragnarok\Fenrir\Discord; use Ragnarok\Fenrir\Rest\Helpers\Channel\MessageBuilder; require './vendor/autoload.php'; $discord = new Discord('TOKEN'); $discord->withRest(); $discord->rest->channel->createMessage( 'channel-id', (new MessageBuilder()) ->setContent('Hi there!') );
(注意:仅使用REST意味着您将不会收到任何事件,并且您的机器人将显示为离线)
更多示例,请查看示例目录
支持
Fenrir 目前支持 PHP 8.1 到 8.3。测试应该可以通过每晚的 8.4 构建,但这不是一个支持的场景。
如果您在 Apache2/Nginx 等网络服务器环境中使用此软件,您可能需要仅使用 Fenrir 的 REST 功能。这些环境通常不允许长时间运行的过程。
不支持32位,尽管没有硬性限制。
贡献
欢迎贡献。您可以查找 @todo 以找到需要关注的内容。请确保尽可能编写测试,并确保您的代码符合 phpcs 配置。谢谢!
注意
当前底层的 HTTP 组件未来可能会发生变化。虽然可访问的 API 将保持相似,但在您的应用程序中应尽量避免手动使用它。