yomo/redditbot

此包已被废弃,不再维护。未建议替代包。

用于开发Reddit机器人的Laravel包

v1.0.3 2019-01-27 14:28 UTC

This package is auto-updated.

Last update: 2022-06-04 11:35:36 UTC


README

RedditBot是一个简单易用的Laravel 5.x库,它封装了Reddit API,使得阅读、发布和评论Reddit帖子变得非常容易!

这个库部分受到Decronym的启发。

安装

使用以下命令通过composer安装此包

composer require yomo/redditbot

Laravel 5.5或更高版本

执行

php artisan vendor:publish --tag=redditbot

Laravel 5.4或更低版本

如果您正在运行Laravel 5.4及以下版本,需要在config/app.php中的providers数组中添加服务提供者

Redditbot\Providers\RedditbotServiceProvider::class

然后执行

php artisan vendor:publish --tag=redditbot

用法

此库假定您的机器人已经通过Reddit应用面板创建,您需要注册一个“个人用途脚本”应用。
有关如何配置机器人的更多详细信息,请参阅Reddit的快速入门指南

您的.env文件需要以下设置

REDDIT_USERNAME
REDDIT_PASSWORD
REDDIT_APP_ID
REDDIT_APP_SECRET

从子版块检索评论并回复

配置完成后,您可以使用以下方式创建Reddit类的实例

$reddit = new Reddit();
$comments = $reddit->fetchComments('sheiseverywhere');

评论以集合的形式返回,您可以使用foreach->each轻松遍历。以下示例展示了机器人如何使用“sinceLastCheck”函数回复特定短语的所有实例

$reddit = new Reddit();
$comments = $reddit->fetchComments('jimny');

$comments->sinceLastCheck()->each(function($comment){

   if (strpos($comment->body, 'Suzuki Jimny') !== false) {
     $comment->reply('The Suzuki Jimny is the best off-roader ever built');   # This replies to the specific comment
     $comment->comment('Visit /r/jimny for more information'); # This submits a top-level post to the main thread
   }

});

还有一个可用的门面,以下是一个示例

   $firstNewComment = Reddit::fetchComments('jimny')->sinceLastCheck()->first();

关于作者

Stuart SteedmanYonder Media的开发主管,Yonder Media是一家位于比勒陀利亚的南非数字媒体代理机构。他专注于PHP和Laravel开发,并在技术和开发相关会议上发表演讲。