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 类一样简单

$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 https://127.0.0.1?type=webhook

扫描

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

curl --data "lat=53.3811&lon=-1.4701" https://127.0.0.1?type=scan

许可

Pokenotifier 是开源软件,受 MIT 许可 许可。