cornford/pokenotifier

轻松地向 Slack 发送附近的宝可梦通知。

v1.0.0 2016-08-02 10:30 UTC

This package is auto-updated.

Last update: 2024-09-07 06:43:03 UTC


README

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality

将 Pokenotifier 视为使用 PokemonGo-Map 生成 Slack 附近宝可梦通知的简单方法。这些包括

  • processScanRequest
  • processWebhookRequest
  • requestPokemonGoMapScan
  • requestPokemonGoMapData
  • expireCachedItems
  • sendSlackNotification
  • processPokemon
  • loadApplicationConfiguration
  • getApplicationConfiguration
  • loadPokemonConfiguration
  • getPokemonConfiguration
  • createGuzzleClient
  • getGuzzleClient
  • setGuzzleClient
  • createSlackClient
  • getSlackClient
  • setSlackClient
  • createDirectoryIteratorInstance
  • getDirectoryIteratorInstance
  • setDirectoryIteratorInstance

安装

首先,通过 Composer 安装此包。编辑您的项目 composer.json 文件以添加 cornford/pokenotifier 作为依赖项。

"require": {
	"cornford/pokenotifier": "1.*"
}

接下来,在终端中更新 Composer

composer update

最后,我们需要将配置文件引入到您的应用程序/目录中

cp src/config/{example.,}application.php

就这样!您已经准备就绪。

配置

您现在可以按照几个简单的步骤配置 Pokenotifier。打开 src/config/application.php 并根据需要更新选项。

  • default-latitude - 用于扫描的默认纬度。
  • default-longitude - 用于扫描的默认经度。
  • cache-directory - 缓存目录位置。
  • pokemongo-protocol - PokemonGo-Map 服务器的协议。
  • pokemongo-ip - PokemonGo-Map 服务器的 IP 地址。
  • pokemongo-port - PokemonGo-Map 服务器的端口号。
  • pokemon-rarity - 要通知的宝可梦稀有度等级(1-5)。
  • slack-webhook - Slack 服务器 webhook 的 URL。
  • slack-channel - Slack 服务器的频道。

使用方法

使用 Pokenotifier 类的方式非常简单,您可以在任何适合的 Controller / Model / 文件中使用

$notifier = new Cornford\Pokenotifier\Notifier();

这将为您提供以下访问权限

处理扫描请求

processScanRequest 方法允许您使用位置对象作为参数处理扫描请求。

$notifier->processScanRequest(new Cornford\Pokenotifier\Models\Position(0, 0));

处理扫描请求

processWebhookRequest 方法允许您使用位置对象和请求数据作为参数处理 webhook 请求。

$notifier->processWebhookRequest(new Cornford\Pokenotifier\Models\Position(0, 0), ['pokemons'=> []]);

请求 Pokemon Go Map 扫描

requestPokemonGoMapScan 方法允许您使用位置对象作为参数向 PokemonGo-Map 发送扫描请求。

$notifier->requestPokemonGoMapScan(new Cornford\Pokenotifier\Models\Position(0, 0));

请求 Pokemon Go Map 数据

requestPokemonGoMapData 方法允许您向 PokemonGo-Map 发送数据请求。

$notifier->requestPokemonGoMapData();

使缓存项过期

expireCachedItems 方法允许您使用字符串作为参数使未修改的指定超时时间的缓存项过期。

$notifier->expireCachedItems('-1 day');

发送 Slack 通知

sendSlackNotification 方法允许您使用宝可梦数据数组和位置对象作为参数发送 Slack 通知。

$notifier->sendSlackNotification(['pokemon_id' => '', 'pokemon_name' => '', 'latitude' => '', 'longitude' => '', 'disappear_time' => ''], new Cornford\Pokenotifier\Models\Position(0, 0));

处理宝可梦

processPokemon 方法允许您处理宝可梦数组,并可选择使用宝可梦数据数组、位置对象和通知布尔值作为参数发送 Slack 通知。

$notifier->processPokemon(['pokemons'=> []], new Cornford\Pokenotifier\Models\Position(0, 0), true);

加载应用程序配置

loadApplicationConfiguration 方法允许您加载当前应用程序配置文件。

$notifier->loadApplicationConfiguration();

获取应用程序配置

getApplicationConfiguration 方法允许您获取当前存储的应用配置。

$notifier->getApplicationConfiguration();

加载宝可梦配置

loadPokemonConfiguration 方法允许您加载当前的宝可梦配置文件。

$notifier->loadPokemonConfiguration();

获取宝可梦配置

getPokemonConfiguration 方法允许您获取当前存储的宝可梦配置。

$notifier->getPokemonConfiguration();

创建 Guzzle 客户端

createGuzzleClient 方法允许您实例化一个新的 Guzzle 客户端。

$notifier->createGuzzleClient();

获取 Guzzle 客户端

getGuzzleClient 方法允许您获取当前已实例化的 Guzzle 客户端。

$notifier->getGuzzleClient();

设置 Guzzle 客户端

setGuzzleClient 方法允许您通过客户端对象作为参数存储新的 Guzzle 客户端实例。

$notifier->setGuzzleClient(new GuzzleClient(['base_url' => 'http://www.google.com']));

创建 Slack 客户端

createSlackClient 方法允许您实例化一个新的 Slack 客户端。

$notifier->createSlackClient();

获取 Slack 客户端

getSlackClient 方法允许您获取当前已实例化的 Slack 客户端。

$notifier->getSlackClient();

设置 Slack 客户端

setSlackClient 方法允许您通过客户端对象作为参数存储新的 Slack 客户端实例。

$notifier->setSlackClient(new SlackClient('https://hooks.slack.com/services/', [], $notifier->getGuzzleClient()));

创建目录迭代器

createDirectoryIterator 方法允许您实例化一个新的目录迭代器。

$notifier->createDirectoryIterator();

获取目录迭代器

getDirectoryIterator 方法允许您获取当前已实例化的目录迭代器。

$notifier->getDirectoryIterator();

设置目录迭代器

setDirectoryIterator 方法允许您通过迭代器对象作为参数存储新的目录迭代器实例。

$notifier->setDirectoryIterator('./cache');

示例

有关示例用法,请参阅 index.php

Webhook

您可以使用以下命令在 PokemonGo-Map 中运行 webhook,其中 -wh 参数是脚本所在的位置。您可以在本地运行一个 Web 服务器,监听本地响应 webhook 请求。

sudo python /var/www/PokemonGo-Map/runserver.py -wh http://localhost?type=webhook

扫描

您可以使用以下命令在 PokemonGo-Map 中运行扫描,其中 post 数据包含 latlon 参数。您可以使用像 Traccar Client 这样的应用程序,向您的 Web 服务器发送扫描请求。

curl --data "lat=53.3811&lon=-1.4701" http://localhost?type=scan

许可

Pokenotifier 是一个开源软件,根据 MIT 许可证 发布。