Skip to content

Commit

Permalink
NEW: Set shiny (or not shiny) via /pokedex :)
Browse files Browse the repository at this point in the history
🎁 Merry X-MAS everyone! 🎁
  • Loading branch information
Chefkeks committed Dec 24, 2020
1 parent 8c9791c commit ecd9061
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.357.4
2.0.359.2
2 changes: 1 addition & 1 deletion commands/pokedex.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
],
[
[
'text' => getTranslation('import') . SP . '(pogoinfo)',
'text' => getTranslation('import') . SP . '(ccev pogoinfo)',
'callback_data' => '0:pogoinfo:0'
]
]
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.357.4",
"VERSION":"2.0.359.2",
"DB_HOST":"localhost",
"DB_NAME":"your_database_name",
"DB_USER":"your_database_user",
Expand Down
48 changes: 48 additions & 0 deletions lang/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,30 @@
"PL": "Jajo",
"FI": "Raid-muna"
},
"shiny": {
"NL": "Shiny",
"DE": "Schillernd",
"EN": "Shiny",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "TRANSLATE"
},
"not_shiny": {
"NL": "TRANSLATE",
"DE": "Nicht schillernd",
"EN": "Not shiny",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "TRANSLATE"
},
"alone": {
"NL": "Alleen",
"DE": "Alleine",
Expand Down Expand Up @@ -2075,6 +2099,30 @@
"PL": "Aktualny poziom Rajdu:",
"FI": "Nykyinen raiditaso:"
},
"pokedex_new_status": {
"NL": "TRANSLATE",
"DE": "Neuer Status",
"EN": "New status",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "TRANSLATE"
},
"pokedex_current_status": {
"NL": "TRANSLATE:",
"DE": "Aktueller Status:",
"EN": "Current status:",
"IT": "TRANSLATE:",
"PT-BR": "TRANSLATE:",
"RU": "TRANSLATE:",
"NO": "TRANSLATE:",
"FR": "TRANSLATE:",
"PL": "TRANSLATE:",
"FI": "TRANSLATE:"
},
"pokedex_select_action": {
"NL": "Selecteer een eigenschap om deze aan te passen:",
"DE": "Eigenschaft zum Ändern auswählen:",
Expand Down
1 change: 1 addition & 0 deletions logic.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
include('logic/get_pokemon_id_by_name.php');
include('logic/get_pokemon_info.php');
include('logic/get_pokemon_weather.php');
include('logic/get_pokemon_shiny_status.php');
include('logic/get_raid_level.php');
include('logic/get_raid.php');
include('logic/get_raid_times.php');
Expand Down
5 changes: 4 additions & 1 deletion logic/get_pokemon_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ function get_pokemon_info($pokemon_id, $pokemon_form_id)
* Raid boss: Mewtwo (#ID)
* Weather: Icons
* CP: CP values (Boosted CP values)
* Shiny: Shiny
*/
$info = '';
$info .= getTranslation('raid_boss') . ': <b>' . get_local_pokemon_name($pokemon_id, $pokemon_form_id) . ' (#' . $pokemon_id . ')</b>' . CR . CR;
$poke_raid_level = get_raid_level($pokemon_id, $pokemon_form_id);
$poke_cp = get_formatted_pokemon_cp($pokemon_id, $pokemon_form_id);
$poke_weather = get_pokemon_weather($pokemon_id, $pokemon_form_id);
$poke_shiny = get_pokemon_shiny_status($pokemon_id, $pokemon_form_id);
$info .= getTranslation('pokedex_raid_level') . ': ' . getTranslation($poke_raid_level . 'stars') . CR;
$info .= (empty($poke_cp)) ? (getTranslation('pokedex_cp') . CR) : $poke_cp . CR;
$info .= getTranslation('pokedex_weather') . ': ' . get_weather_icons($poke_weather) . CR . CR;
$info .= getTranslation('pokedex_weather') . ': ' . get_weather_icons($poke_weather) . CR;
$info .= (($poke_shiny == 1) ? (getTranslation('shiny')) : (getTranslation('not_shiny'))) . CR . CR;

return $info;
}
Expand Down
31 changes: 31 additions & 0 deletions logic/get_pokemon_shiny_status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Get pokemon shiny status.
* @param $pokemon_id
* @param $pokemon_form_id
* @return string
*/
function get_pokemon_shiny_status($pokemon_id, $pokemon_form_id)
{
if($pokemon_id !== "NULL" && $pokemon_id != 0) {
// Get pokemon shiny status from database
$rs = my_query(
"
SELECT shiny
FROM pokemon
WHERE pokedex_id = {$pokemon_id}
AND pokemon_form_id = '{$pokemon_form_id}'
"
);

// Fetch the row.
$shiny = $rs->fetch();
debug_log($shiny, 'Per db, shiny status is:');

return $shiny['shiny'];
} else {
return 0;
}
}

?>
6 changes: 3 additions & 3 deletions mods/pogoinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// Raid level selection
if($id == 0) {
// Set message.
$msg = '<b>' . getTranslation('import') . SP . '(pogoinfo)' . '</b>' . CR . CR;
$msg = '<b>' . getTranslation('import') . SP . '(ccev pogoinfo)' . '</b>' . CR . CR;
$msg .= '<b>' . getTranslation('select_raid_level') . ':</b>';

// Init empty keys array.
Expand Down Expand Up @@ -51,7 +51,7 @@
$keys = inline_key_array($keys, 1);
} else if($id > 0) {
// Set message and init message to exclude raid bosses.
$msg = '<b>' . getTranslation('import') . SP . '(pogoinfo)' . '</b>' . CR . CR;
$msg = '<b>' . getTranslation('import') . SP . '(ccev pogoinfo)' . '</b>' . CR . CR;
$ex_msg = '';

// Get pogoinfo data.
Expand Down Expand Up @@ -104,7 +104,7 @@
debug_log($get_levels);

// Process raid tier(s)
debug_log('Processing received pogoinfo raid bosses for each raid level');
debug_log('Processing received ccev pogoinfo raid bosses for each raid level');
foreach($data as $tier => $tier_pokemon) {
// Process raid level?
if(!in_array($tier,$get_levels)) {
Expand Down
6 changes: 6 additions & 0 deletions mods/pokedex_edit_pokemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
'text' => getTranslation('pokedex_weather'),
'callback_data' => $poke_id_form . ':pokedex_set_weather:add-0'
]
],
[
[
'text' => getTranslation('shiny'),
'callback_data' => $poke_id_form . ':pokedex_set_shiny:setshiny'
]
]
];

Expand Down
123 changes: 123 additions & 0 deletions mods/pokedex_set_shiny.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
// Write to log.
debug_log('pokedex_set_shiny()');

// For debug.
//debug_log($update);
//debug_log($data);

// Check access.
bot_access_check($update, 'pokedex');

// Set the id.
$pokedex_id = $data['id'];

// Get the shiny status.
$arg = $data['arg'];

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

// Set shiny or ask to set?
if($data['arg'] == "setshiny") {
// Get current shiny status from database.
$shiny = get_pokemon_shiny_status($dex_id, $dex_form);

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

// Create keys array.
if($shiny == 0) {
// Enable shiny.
$old_shiny_status = getTranslation('not_shiny');
$keys[] = [
array(
'text' => getTranslation('shiny'),
'callback_data' => $pokedex_id . ':pokedex_set_shiny:1'
)
];

} else {
// Disable shiny.
$old_shiny_status = getTranslation('shiny');
$keys[] = [
array(
'text' => getTranslation('not_shiny'),
'callback_data' => $pokedex_id . ':pokedex_set_shiny:0'
)
];
}

// Back and abort.
$keys[] = [
[
'text' => getTranslation('back'),
'callback_data' => $pokedex_id . ':pokedex_edit_pokemon:0'
],
[
'text' => getTranslation('abort'),
'callback_data' => '0:exit:0'
]
];

// Build callback message string.
$callback_response = getTranslation('select_shiny_status');

// Set the message.
$msg = getTranslation('raid_boss') . ': <b>' . get_local_pokemon_name($dex_id, $dex_form) . ' (#' . $dex_id . ')</b>' . CR;
$msg .= getTranslation('pokedex_current_status') . SP . $old_shiny_status . CR . CR;
$msg .= '<b>' . getTranslation('pokedex_new_status') . ':</b>';
} else {
// Update shiny status of pokemon.
$rs = my_query(
"
UPDATE pokemon
SET shiny = '{$arg}'
WHERE pokedex_id = {$dex_id}
AND pokemon_form_id = '{$dex_form}'
"
);

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

// Back to pokemon and done keys.
$keys = [
[
[
'text' => getTranslation('back') . ' (' . get_local_pokemon_name($dex_id, $dex_form) . ')',
'callback_data' => $pokedex_id . ':pokedex_edit_pokemon:0'
],
[
'text' => getTranslation('done'),
'callback_data' => '0:exit:1'
]
]
];

// Build callback message string.
$callback_response = getTranslation('pokemon_saved') . ' ' . get_local_pokemon_name($dex_id, $dex_form);

// Set the message.
$msg = getTranslation('pokemon_saved') . CR;
$msg .= '<b>' . get_local_pokemon_name($dex_id, $dex_form) . ' (#' . $dex_id . ')</b>' . CR . CR;
$msg .= getTranslation('pokedex_new_status') . ':' . CR;
$msg .= '<b>' . (($arg == 1) ? (getTranslation('shiny')) : (getTranslation('not_shiny'))) . '</b>';
}

// Telegram JSON array.
$tg_json = array();

// Answer callback.
$tg_json[] = answerCallbackQuery($update['callback_query']['id'], $callback_response, true);

// Edit message.
$tg_json[] = edit_message($update, $msg, $keys, false, true);

// Telegram multicurl request.
curl_json_multi_request($tg_json);

// Exit.
exit();

0 comments on commit ecd9061

Please sign in to comment.