nopolabs / yabot-template
yabot项目的模板。
dev-master
2017-11-12 23:11 UTC
Requires
- php: >=7.0
- nopolabs/yabot: dev-master
Requires (Dev)
- nopolabs/mock-with-expectations: dev-master
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2024-09-14 18:42:18 UTC
README
使用nopolabs/yabot构建的Slack机器人的项目模板
入门
您需要php 7.*和composer。
- 使用composer根据yabot-template创建一个新项目。
- 将config.example.php复制到config.php
- 按照Slack的说明获取Slack令牌。
- 在config.php中将"SLACK-TOKEN-GOES-HERE"替换为您的Slack令牌。
- 不要 将您的Slack令牌检查到公共源代码控制仓库中。
(Slack会撤销它发现的公开共享的令牌)。 - 运行Yabot: 'php yabot.php'
composer create-project --stability dev nopolabs/yabot-template my-bot # allow composer to remove existing .git history cd my-bot # create your own git repository for your bot cp config.example.php config.php cp .env.example .env vi .env # replace SLACK-TOKEN-GOES-HERE with your slack token php yabot.php # ... profit
注意:yabot使用nopolabs仓库中的slack-client和phpws,因为它依赖于尚未从这些包中提供的coderstephen/slack-client和devristo/phpws的更新。
添加插件
访问yabot-plugins以找到不同复杂度和实用性的多个示例插件。以下是如何将其中一个插件(GiphyPlugin)添加到本项目中的方法。
- 使用composer require nopolabs/yabot-plugins
- 在config/plugins.yml中导入plugin.giphy.yml
- 启动yabot
composer require nopolabs/yabot-plugins
vi config/plugins.yml
# add: "- { resource: '../vendor/nopolabs/yabot-plugins/config/plugin.giphy.yml' }" to the imports section.
php yabot.php
编写您自己的插件
yabot-template包含一个插件(HelloPlugin)作为占位符,以显示插件源代码、测试和配置的位置。具体来说
- 源代码位于src/目录中
- 测试位于tests/目录中
- 配置位于config/plugins.yml和config.php中
- src/和tests/的包命名空间和自动加载在composer.json中设置
日志记录
Yabot使用monolog来记录日志。默认情况下,日志记录在config.php中配置为输出到logs/bot.log。
设置'log.file' => 'php://stdout'
在开发期间非常有用,可以将日志信息直接定向到您启动yabot的终端。