This repository has been archived by the owner on Sep 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rocket-webhook.php
79 lines (67 loc) · 2.52 KB
/
rocket-webhook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
require 'config.php';
require 'config-rocket.php';
require 'libs/Telegram-PHP/src/Autoloader.php';
require 'libs/RocketMap/src/RocketMap.php';
$content = file_get_contents("php://input");
$json = json_decode($content, TRUE);
if(empty($json)){ die(); }
$bot = new Telegram\Bot($config['telegram']);
$telegram = new Telegram\Sender($bot);
$telegram->convert_emoji = FALSE;
$gyms = array();
$color = ['Neutro', 'Azul', 'Rojo', 'Amarillo'];
$pokedex = require 'libs/RocketMap/src/Pokedex.php';
foreach($json as $message){
if(!in_array($message['type'], $rocket['parse_types'])){ continue; }
if($message['type'] == "gym"){
$gym = new \RocketMap\Gym($message['message']);
$title = "Gimnasio de color " .$color[$gym->team_id] ."!";
$sub = $gym->slots_available ." huecos";
$telegram
->chats($rocket['parse_chats'])
->location($gym->latitude, $gym->longitude)
->venue($title, $sub)
->send();
}elseif($message['type'] == "raid"){
$raid = new \RocketMap\Raid($message['message']);
$title = "¡Raid " .$pokedex[$raid->pokemon_id][0] ."! " .$raid->cp ." PC.";
$sub = "Termina a " .date("H:i:s", $raid->end);
$telegram
->chats($rocket['parse_chats'])
->location($raid->latitude, $raid->longitude)
->venue($title, $sub)
->send();
}elseif($message['type'] == "gym_details"){
$gym = new \RocketMap\Gym($message['message']);
$details = new \RocketMap\GymDetails($message['message']);
$pokemon = array();
if(!empty($message['message']['pokemon'])){
foreach($message['message']['pokemon'] as $pk){
$pokemon[] = new \RocketMap\GymPokemon($pk);
}
}
$str = "¡Nuevo gym " .$color[$gym->team_id] ."! " .$details->name ."\n"
."Hay " .count($pokemon) ." Pokémon.\n";
foreach($pokemon as $pk){
$iv = number_format(($pk->iv_defense + $pk->iv_attack + $pk->iv_stamina) / 45 * 100, 1);
$str .= $pokedex[$pk->pokemon_id][0] ." " .$pk->cp ." PC - $iv %\n";
}
$telegram->chats($rocket['parse_chats'])->file('photo', $details->url);
$telegram
->chats($rocket['parse_chats'])
->text($str)
->send();
}elseif($message['type'] == "pokemon"){
$pokemon = new \RocketMap\Pokemon($message['message']);
$iv = number_format(($pokemon->individual_defense + $pokemon->individual_attack + $pokemon->individual_stamina) / 45 * 100, 1);
$title = "¡Un " .$pokedex[$pokemon->pokemon_id][0] ."! ";
$sub = "Se va a las " .date("H:i:s", $pokemon->disappear_time) .".";
$telegram
->chats($rocket['parse_chats'])
->location($pokemon->latitude, $pokemon->longitude)
->venue($title, $sub)
->send();
}
}
?>