Skip to content

Commit

Permalink
Pokedex fix (pokepark#205)
Browse files Browse the repository at this point in the history
* /pokedex fixes

* Pokedex update

Co-authored-by: Juho-Pekka Kuitunen <[email protected]>
  • Loading branch information
Ninjasoturi and jinnatar authored Dec 5, 2020
1 parent 5a55891 commit eb88fad
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 119 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -988,11 +988,15 @@ Show and update any pokemon raid boss. You can change the raid level (select rai

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`.

To quickly get to a specific pokemon raid boss, you can use the /pokedex command with the local name of the pokemon. A few examples:
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:

Your telegram is set to English and you like to change Deoxys in his Attack form: `/pokedex Deoxys Attack`
| Search term | Response |
|-----------------------|----------------------------------------------------------------------------------------------|
| `/pokedex Deoxys` | `Deoxys`<br/>`Deoxys Attack`<br/>`Deoxys Defense`<br/>`Deoxys Speed` |
| `/pokedex Charizard` | `Charizard`<br/>`Charizard Copy 2019` (clone)<br/>`Charizard Mega X`<br/>`Charizard Mega Y` |
| `/pokedex Knogga` | `Knogga`<br/>`Knogga Alola` |

Your telegram is set to German and you like to change Marowak (German: Knogga) in his Alolan (German: Alola) form: `/pokedex Knogga Alola`
User's local language is fetched from their Telegram settings.

Beside your local language the bot always is looking at the English language as a fallback.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.319.1
2.0.319.2
104 changes: 46 additions & 58 deletions commands/pokedex.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,83 +12,71 @@
// Get pokemon name or dex id.
$pokemon = trim(substr($update['message']['text'], 8));

// Init empty keys array.
$keys = [];

// Check if we recived pokemon name or dex id.
if(!empty($pokemon)) {
$forward = false;
// Pokedex_id received?
if(is_numeric($pokemon)) {
// Always normal form
$pokemon = $pokemon . '-0';
// Set forward to true
$forward = true;

$pokedex_id = $pokemon;
// Pokemon name received?
} else {
// Get pokemon id by name.
$pokemon = get_pokemon_id_by_name($pokemon);

// Set forward to true
if($pokemon != 0) {
$forward = true;
}
$pokemon_name_form = get_pokemon_id_by_name($pokemon);
$pokedex_id = explode("-", $pokemon_name_form)[0];
}

if($forward == true) {
// Reset data array
$data = [];
$data['id'] = $pokemon;
$data['action'] = 'pokedex_edit_pokemon';
$data['arg'] = 'id-or-name';

// Write to log.
debug_log($data, '* NEW DATA= ');

// Edit pokemon and exit.
include_once(ROOT_PATH . '/mods/pokedex_edit_pokemon.php');
exit();
$statement = $dbh->prepare("SELECT pokedex_id, pokemon_form_id FROM pokemon WHERE pokedex_id = :pokedex_id");
$statement->execute([":pokedex_id" => $pokedex_id]);
while ($pokemon = $statement->fetch()) {
$keys[] = [
[
'text' => get_local_pokemon_name($pokemon['pokedex_id'], $pokemon['pokemon_form_id']),
'callback_data' => $pokemon['pokedex_id'] . '-' . $pokemon['pokemon_form_id'] . ':pokedex_edit_pokemon:0'
]
];
}
// Set message.
$msg = '<b>' . getTranslation('pokedex_edit_pokemon') . '</b>';
}

// Init empty keys array.
$keys = [];

// Create keys array.
$keys = [
[
if(count($keys) == 0 ) {
// Create keys array.
$keys = [
[
'text' => getTranslation('pokedex_raid_pokemon'),
'callback_data' => '0:pokedex_list_raids:0'
]
],
[
[
'text' => getTranslation('pokedex_raid_pokemon'),
'callback_data' => '0:pokedex_list_raids:0'
]
],
[
'text' => getTranslation('edit_pokemon'),
'callback_data' => '0:pokedex:0'
]
],
[
[
'text' => getTranslation('edit_pokemon'),
'callback_data' => '0:pokedex:0'
]
],
[
'text' => getTranslation('disable_raid_level'),
'callback_data' => '0:pokedex_disable_raids:0'
]
],
[
[
'text' => getTranslation('disable_raid_level'),
'callback_data' => '0:pokedex_disable_raids:0'
]
],
[
'text' => getTranslation('import') . SP . '(Pokebattler)',
'callback_data' => '0:pokebattler:0'
[
'text' => getTranslation('import') . SP . '(Pokebattler)',
'callback_data' => '0:pokebattler:0'
]
]
],
];
// Set message.
$msg = '<b>' . getTranslation('pokedex_start') . ':</b>';
}
$keys[] = [
[
[
'text' => getTranslation('abort'),
'callback_data' => '0:exit:0'
]
'text' => getTranslation('abort'),
'callback_data' => '0:exit:0'
]
];

// Set message.
$msg = '<b>' . getTranslation('pokedex_start') . ':</b>';

// Send message.
send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]);

Expand Down
2 changes: 1 addition & 1 deletion config/config.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"VERSION":"2.0.319.1",
"VERSION":"2.0.319.2",
"DB_HOST":"localhost",
"DB_NAME":"your_database_name",
"DB_USER":"your_database_user",
Expand Down
2 changes: 1 addition & 1 deletion logic/get_pokemon_cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function get_pokemon_cp($pokemon_id, $pokemon_form_id)
SELECT min_cp, max_cp, min_weather_cp, max_weather_cp
FROM pokemon
WHERE pokedex_id = {$pokemon_id}
AND pokemon_form = '{$pokemon_form_id}'
AND pokemon_form_id = '{$pokemon_form_id}'
"
);

Expand Down
35 changes: 11 additions & 24 deletions mods/pokebattler.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,49 +327,36 @@
// Init empty keys array.
$keys = [];

// Add key for each raid level
$level_keys = $levels;
while ($pokemon = $rs->fetch()) {
$level_keys[$pokemon['pokedex_id'].'-'.$pokemon['pokemon_form_id']] = $pokemon['raid_level'];
}

// Init message and previous.
$msg = '<b>Pokebattler' . SP . '' . SP . getTranslation('import_done') . '</b>' . CR . CR;
$previous = 'FIRST_RUN';
$msg = '<b>Pokebattler' . SP . '' . SP . getTranslation('import_done') . '</b>' . CR;
$previous = '';

// Build the message
foreach ($level_keys as $pid => $lv) {
while ($pokemon = $rs->fetch()) {
// Set current level
$current = $lv;
$current = $pokemon['raid_level'];

// Add header for each raid level
if($previous != $current || $previous == 'FIRST_RUN') {
// Formatting.
if($previous != 'FIRST_RUN') {
$msg .= CR;
}
// Add header.
$msg .= '<b>' . getTranslation($lv . 'stars') . ':</b>' . CR ;
if($previous != $current) {
$msg .= CR . '<b>' . getTranslation($pokemon['raid_level'] . 'stars') . ':</b>' . CR ;
}
// Get just the dex id without the form.
$pokemon_id_form = explode('-',$pid,2);
$dex_id = $pokemon_id_form[0];
$pokemon_form_id = $pokemon_id_form[1];

// Add pokemon with id and name.
$dex_id = $pokemon['pokedex_id'];
$pokemon_form_id = $pokemon['pokemon_form_id'];
$poke_name = get_local_pokemon_name($dex_id, $pokemon_form_id);
$msg .= $poke_name . ' (#' . $dex_id . ')' . CR;

// Add button to edit pokemon.
if($id == RAID_LEVEL_ALL) {
$keys[] = array(
'text' => '[' . $lv . ']' . SP . $poke_name,
'callback_data' => $pid . ':pokedex_edit_pokemon:0'
'text' => '[' . $pokemon['raid_level'] . ']' . SP . $poke_name,
'callback_data' => $dex_id . "-" . $pokemon_form_id . ':pokedex_edit_pokemon:0'
);
} else {
$keys[] = array(
'text' => $poke_name,
'callback_data' => $pid . ':pokedex_edit_pokemon:0'
'callback_data' => $dex_id . "-" . $pokemon_form_id . ':pokedex_edit_pokemon:0'
);
}

Expand Down
29 changes: 9 additions & 20 deletions mods/pokedex_disable_raids.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
// Get all pokemon with raid levels from database.
$rs = my_query(
"
SELECT pokedex_id, pokemon_form_name, raid_level
SELECT pokedex_id, pokemon_form_name, pokemon_form_id, raid_level
FROM pokemon
WHERE raid_level IN ({$clear})
ORDER BY raid_level, pokedex_id, pokemon_form_name != 'normal', pokemon_form_name
Expand All @@ -73,34 +73,23 @@
// Init empty keys array.
$keys = [];

// Add key for each raid level
while ($pokemon = $rs->fetch()) {
$plevels[$pokemon['pokedex_id'].'-'.$pokemon['pokemon_form_name']] = $pokemon['raid_level'];
}

// Init message and previous.
$msg = '<b>' . getTranslation('disable_raid_level') . '?</b>' . CR . CR;
$previous = 'FIRST_RUN';
$msg = '<b>' . getTranslation('disable_raid_level') . '?</b>' . CR;
$previous = '';

// Build the message
foreach ($plevels as $pid => $lv) {
while ($pokemon = $rs->fetch()) {
// Set current level
$current = $lv;
$current = $pokemon['raid_level'];

// Add header for each raid level
if($previous != $current || $previous == 'FIRST_RUN') {
// Formatting.
if($previous != 'FIRST_RUN') {
$msg .= CR;
}
// Add header.
$msg .= '<b>' . getTranslation($lv . 'stars') . ':</b>' . CR ;
if($previous != $current) {
$msg .= CR . '<b>' . getTranslation($pokemon['raid_level'] . 'stars') . ':</b>' . CR ;
}
// Get just the dex id without the form.
$dex_id = explode('-',$pid)[0];

// Add pokemon with id and name.
$poke_name = get_local_pokemon_name($dex_id, explode('-',$pid)[1]);
$dex_id = $pokemon['pokedex_id'];
$poke_name = get_local_pokemon_name($dex_id, $pokemon['pokemon_form_id']);
$msg .= $poke_name . ' (#' . $dex_id . ')' . CR;

// Prepare next run.
Expand Down
2 changes: 1 addition & 1 deletion mods/pokedex_edit_pokemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// Set the id.
$poke_id_form = $data['id'];
$dex_id_form = explode('-',$data['id']);
$dex_id_form = explode('-',$data['id'],2);
$pokedex_id = $dex_id_form[0];
$pokemon_form = $dex_id_form[1];

Expand Down
2 changes: 1 addition & 1 deletion mods/pokedex_set_cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$pokedex_id = $data['id'];

// Split pokedex_id and form
$dex_id_form = explode('-',$pokedex_id);
$dex_id_form = explode('-',$pokedex_id,2);
$dex_id = $dex_id_form[0];
$dex_form = $dex_id_form[1];

Expand Down
2 changes: 1 addition & 1 deletion mods/pokedex_set_raid_level.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$arg = $data['arg'];

// Split pokedex_id and form
$dex_id_form = explode('-',$pokedex_id);
$dex_id_form = explode('-',$pokedex_id,2);
$dex_id = $dex_id_form[0];
$dex_form = $dex_id_form[1];

Expand Down
6 changes: 3 additions & 3 deletions mods/pokedex_set_weather.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
];

// Set the message.
$msg = getTranslation('raid_boss') . ': <b>' . get_local_pokemon_name($pokedex_id) . ' (#' . $dex_id . ')</b>' . CR;
$msg .= getTranslation('pokedex_current_weather') . get_weather_icons($dex_id, $dex_form) . CR . CR;
$msg .= '<b>' . getTranslation('pokedex_new_weather') . get_weather_icons($new_weather) . '</b>';
$msg = getTranslation('raid_boss') . ': <b>' . get_local_pokemon_name($dex_id, $dex_form) . ' (#' . $dex_id . ')</b>' . CR;
$msg .= getTranslation('pokedex_current_weather') . ' ' . get_weather_icons($old_weather) . CR . CR;
$msg .= '<b>' . getTranslation('pokedex_new_weather') . '</b> ' . get_weather_icons($new_weather);

// Save weather to database
} else if($action == 'save') {
Expand Down
7 changes: 2 additions & 5 deletions mods/raid_set_poke.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
// Get eggs.
$eggs = $GLOBALS['eggs'];

// Get pokedex_id.
$pokedex_id = explode('-', $data['arg'])[0];

// Do not update if pokedex_id is an egg.
if(!in_array($pokedex_id, $eggs)) {
if(!in_array($pokemon_id_form[0], $eggs)) {
// Update users in attendance table.
// Helps to proper sort users as they are ordered by pokemon.
my_query(
Expand Down Expand Up @@ -84,7 +81,7 @@
require_once(LOGIC_PATH . '/raid_picture.php');
while ($raidmsg = $rs->fetch()) {
$picture_url = raid_picture_url($raid);
$tg_json[] = editMessageMedia($raidmsg['message_id'], $updated_msg['short'], $updated_keys, $raidmsg['chat_id'], ['disable_web_page_preview' => 'true'], false, $picture_url);
$tg_json[] = editMessageMedia($raidmsg['message_id'], $updated_msg['short'], $updated_keys, $raidmsg['chat_id'], ['disable_web_page_preview' => 'true'], false, $picture_url);
}
} else {
while ($raidmsg = $rs->fetch()) {
Expand Down

0 comments on commit eb88fad

Please sign in to comment.