Skip to content

Commit

Permalink
New method for storing raid boss info
Browse files Browse the repository at this point in the history
Info of raid bosses is now stored in separate table in mysql. This brings much more versatility to maintaining the bot and adds user friendliness when we can provide more exact polls.

There is currently no method of scheduling boss times via Telegram, you have to do that manually straight to database.
  • Loading branch information
Ninjasoturi committed Jul 11, 2021
1 parent 49fa3ae commit ec09215
Show file tree
Hide file tree
Showing 28 changed files with 264 additions and 516 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ Based on your access to the bot, you may can only change the pokemon raid boss o

Show and update any pokemon raid boss. You can change the raid level (select raid level 0 to disable a raid boss), pokemon CP values and weather information of any pokemon raid boss.

There is also a possibility to import the raids bosses from Pokebattler and disable all raid bosses for all or just a specific raid level which makes raid boss management pretty easy. By default the import will disable eggs for levels that only contain 1 raid boss. To disable this set `POKEBATTLER_IMPORT_DISABLE_REDUNDANT_EGGS` to `false`.
There is also a possibility to import the raids bosses from Pokebattler and disable all raid bosses for all or just a specific raid level which makes raid boss management pretty easy.

To quickly get to a specific pokemon raid boss, you can use the /pokedex command with the local name of the pokemon to get a list of it's all formes. A few examples:

Expand Down Expand Up @@ -1242,7 +1242,6 @@ Updates to the config file are NOT checked automatically. Therefore always check
| MAPS_API_KEY| Google Maps API key for `MAPS_LOOKUP` |
| MAPS_LOOKUP| Boolean, resolve missing gym addresses via Google Maps |
| MAP_URL| ? |
| POKEBATTLER_IMPORT_DISABLE_REDUNDANT_EGGS| Boolean, when importing Pokedex from Pokebattler, disable creating an Egg raid for any level that only has one boss available. |
| PORTAL_IMPORT| Bool, allow importing gyms via portal import Telegram bots |
| RAID_ANYTIME| Bool, enable a final timeslot for attending at any given time. |
| RAID_AUTOMATIC_ALARM | Bool, sign up every attendee to the raid alarm automatically. They will get private messages of new participants as if they had enabled it themselves on the poll. |
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.189.1
2.1.192.1
261 changes: 0 additions & 261 deletions commands/raid.php

This file was deleted.

59 changes: 14 additions & 45 deletions commands/raid_from_webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,46 +108,13 @@ function isPointInsidePolygon($point, $vertices) {
}

// Create raid if not exists otherwise update if changes are detected
$form = 0;
$form_lookup = false;
$form_query = ':pokemon_form';
if ($pokemon == 0) {
// Just an egg
$query = '
SELECT pokemon_form_id,
pokedex_id
FROM pokemon
WHERE raid_level = :raid_level
';
$statement = $dbh->prepare( $query );
$statement->execute([
':raid_level' => $level
]);
if($statement->rowCount() == 1) {
$result = $statement->fetch();
$pokemon = $result['pokedex_id'];
$form = $result['pokemon_form_id'];
}else {
$pokemon = '999' . $level;
}

// Raid pokemon form
// Use negated evolution id instead of form id if present
if(isset($raid['message']['evolution']) && $raid['message']['evolution'] > 0) {
$form = 0 - $raid['message']['evolution'];
}else {
// Use negated evolution id instead of form id if present
if(isset($raid['message']['evolution']) && $raid['message']['evolution'] > 0) {
$form = 0 - $raid['message']['evolution'];
}else {
if ( isset($raid['message']['form']) && $raid['message']['form'] != '0') {
// Use the form provided in webhook if it's valid
$form = $raid['message']['form'];
}elseif($pokemon != 0) {
// Else look up the normal form's id from pokemon table unless it's an egg
$form_query = '(SELECT pokemon_form_id FROM pokemon
WHERE
pokedex_id = :pokemon AND
pokemon_form_name = \'normal\'
LIMIT 1)';
$form_lookup = true;
}
}
$form = $raid['message']['form'] ?? 0;
}

// Raid pokemon gender
Expand All @@ -165,6 +132,7 @@ function isPointInsidePolygon($point, $vertices) {
}

// Raid start and endtimes
$spawn = gmdate('Y-m-d H:i:s',$raid['message']['spawn']);
$start = gmdate('Y-m-d H:i:s',$raid['message']['start']);
$end = gmdate('Y-m-d H:i:s',$raid['message']['end']);

Expand Down Expand Up @@ -197,7 +165,7 @@ function isPointInsidePolygon($point, $vertices) {
UPDATE raids
SET
pokemon = :pokemon,
pokemon_form = '.$form_query.',
pokemon_form = :form,
gym_team = :gym_team,
move1 = :move1,
move2 = :move2,
Expand All @@ -207,13 +175,13 @@ function isPointInsidePolygon($point, $vertices) {
';
$execute_array = [
'pokemon' => $pokemon,
'pokemon_form' => $form,
'gym_team' => $team,
'move1' => $move_1,
'move2' => $move_2,
'gender' => $gender,
'id' => $raid_id
];
if(!$form_lookup) $execute_array['pokemon_form'] = $form;
$statement = $dbh->prepare( $query );
$statement->execute($execute_array);
}
Expand All @@ -234,22 +202,23 @@ function isPointInsidePolygon($point, $vertices) {
// Create Raid and send messages
try {
$query = '
INSERT INTO raids (pokemon, pokemon_form, user_id, first_seen, start_time, end_time, gym_team, gym_id, move1, move2, gender)
VALUES (:pokemon, '.$form_query.', :user_id, :first_seen, :start_time, :end_time, :gym_team, :gym_id, :move1, :move2, :gender)
INSERT INTO raids (pokemon, pokemon_form, user_id, spawn, start_time, end_time, gym_team, gym_id, level, move1, move2, gender)
VALUES (:pokemon, :pokemon_form, :user_id, :spawn, :start_time, :end_time, :gym_team, :gym_id, :level, :move1, :move2, :gender)
';
$execute_array = [
'pokemon' => $pokemon,
'pokemon_form' => $form,
'user_id' => $config->WEBHOOK_CREATOR,
'first_seen' => gmdate('Y-m-d H:i:s'),
'spawn' => $spawn,
'start_time' => $start,
'end_time' => $end,
'gym_team' => $team,
'gym_id' => $gym_internal_id,
'level' => $level,
'move1' => $move_1,
'move2' => $move_2,
'gender' => $gender
];
if(!$form_lookup) $execute_array['pokemon_form'] = $form;
$statement = $dbh->prepare( $query );
$statement->execute($execute_array);
$raid_id = $dbh->lastInsertId();
Expand Down
Loading

0 comments on commit ec09215

Please sign in to comment.