Skip to content

Commit

Permalink
Add /gymgps command to change gps coordinates of a gym in case it was…
Browse files Browse the repository at this point in the history
… moved.
  • Loading branch information
Chefkeks committed Sep 12, 2019
1 parent 978d0a1 commit dd229f6
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ A few examples for access files can be found below the permission overview table
| | Edit extended gym details `/gym` | `gym-edit` |
| | Edit gym name `/gymname` | `gym-name` |
| | Edit gym address `/gymaddress` | `gym-address` |
| | Edit gym gps coordinates `/gymgps` | `gym-gps` |
| | Edit gym note `/gymnote` | `gym-note` |
| | Add a gym `/addgym` | `gym-add` |
| | Delete a gym `/deletegym` | `gym-delete` |
Expand Down Expand Up @@ -667,6 +668,13 @@ Example input: `/gymaddress 34, Großer Stern, 10557 Berlin`
Example input to delete the gym address: `/gymaddress 34, reset`


### Command: /gymgps

The bot will set the gps coordinates of gym to your input. The id of the gym is required.

Example input: `/gymgps 34, 52.5145434,13.3501189`


### Command: /gymnote

The bot will set the note for gym to your input. The id of the gym is required. You can delete the gym note using the keyword 'reset'.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.254.2
1.9.255.1
101 changes: 101 additions & 0 deletions commands/gymgps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
// Write to log.
debug_log('GYMGPS()');

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

// Check access.
bot_access_check($update, 'gym-gps');

// Get gym by name.
// Trim away everything before "/gymgps "
$id_info = $update['message']['text'];
$id_info = substr($id_info, 8);
$id_info = trim($id_info);

// Display keys to get gym ids.
if(empty($id_info)) {
debug_log('Missing gym coordinates!');
// Set message.
$msg = CR . '<b>' . getTranslation('gym_id_gps_missing') . '</b>';
$msg .= CR . CR . getTranslation('gym_gps_instructions');
$msg .= CR . getTranslation('gym_gps_example');

// Set keys.
$keys = [];
} else {
// Set keys.
$keys = [];

// Get gym id.
$split_id_info = explode(',', $id_info,2);
$id = $split_id_info[0];
$info = $split_id_info[1];
$info = trim($info);

// Count commas given in info.
$count = substr_count($info, ",");

// 1 comma as it should be?
// E.g. 52.5145434,13.3501189
if($count == 1) {
$lat_lon = explode(',', $info);
$lat = $lat_lon[0];
$lon = $lat_lon[1];

// Lat and lon with comma instead of dot?
// E.g. 52,5145434,13,3501189
} else if($count == 3) {
$lat_lon = explode(',', $info);
$lat = $lat_lon[0] . '.' . $lat_lon[1];
$lon = $lat_lon[2] . '.' . $lat_lon[3];
} else {
// Invalid input - send the message and exit.
$msg = '<b>' . getTranslation('invalid_input') . '</b>' . CR . CR;
$msg .= getTranslation('gym_gps_coordinates_format_error') . CR;
$msg .= getTranslation('gym_gps_example');
sendMessage($update['message']['chat']['id'], $msg);
exit();
}

// Make sure we have a valid gym id.
$gym = false;
if(is_numeric($id)) {
$gym = get_gym($id);
}

if($gym && !empty($info)) {
debug_log('Updating gps coordinates for gym with ID: ' . $id);
debug_log('Gym latitude: ' . $lat);
debug_log('Gym longitude: ' . $lon);
my_query(
"
UPDATE gyms
SET lat = {$lat},
lon = {$lon}
WHERE id = {$id}
"
);

// Set message.
$msg = get_gym_details($gym);
$msg .= EMOJI_NEW . SP . $info;
$msg .= CR . CR . '<b>' . getTranslation('gym_gps_added') . '</b>';
} else if($gym && empty($info)) {
debug_log('Missing gym coordinates!');
// Set message.
$msg .= CR . '<b>' . getTranslation('gym_id_gps_missing') . '</b>';
$msg .= CR . CR . getTranslation('gym_gps_instructions');
$msg .= CR . getTranslation('gym_gps_example');
} else {
// Set message.
$msg .= getTranslation('invalid_input');
}
}

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

?>
55 changes: 55 additions & 0 deletions lang/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,61 @@
"FR":"TRANSLATE",
"PL":"TRANSLATE"
},
"gym_gps_coordinates_format_error":{
"NL":"Error! Stuur de coordinaten in het volgende formaat: <code>Latitude,Longitude</code>",
"DE":"Fehler! Bitte übermittle die Koordinaten im folgenden Format: <code>Breitengrad,Längengrad</code>",
"EN":"Error! Please submit the coordinates in the following format: <code>Latitude,Longitude</code>",
"IT":"TRANSLATE",
"PT-BR":"TRANSLATE",
"RU":"TRANSLATE",
"NO":"TRANSLATE",
"FR":"TRANSLATE",
"PL":"TRANSLATE"
},
"gym_gps_instructions":{
"NL":"Om de gym coordinaten te veranderen stuur /gymgps <code>gym id, nieuwe gym coordinaten</code>!",
"DE":"Zum Ändern der Arena-Koordinaten bitte /gymgps <code>Arena-ID, neue Arena-Koordinaten</code> eingeben!",
"EN":"To change the coordinates of a gym please enter /gymgps <code>gym id, new gym coordinates</code>!",
"IT":"TRANSLATE",
"PT-BR":"TRANSLATE",
"RU":"TRANSLATE",
"NO":"TRANSLATE",
"FR":"TRANSLATE",
"PL":"TRANSLATE"
},
"gym_gps_example":{
"NL":"Als voorbeeld: <code>/gymgps 34, 51.516263,4.377755</code>",
"DE":"Zum Beispiel: <code>/gymgps 34, 52.516263,13.377755</code>",
"EN":"For example: <code>/gymgps 34, 52.516263,13.377755</code>",
"IT":"TRANSLATE",
"PT-BR":"TRANSLATE",
"RU":"TRANSLATE",
"NO":"TRANSLATE",
"FR":"TRANSLATE",
"PL":"TRANSLATE"
},
"gym_gps_added":{
"NL":"Gym coordinaten succesvol toegevoegd!",
"DE":"Arena-Koordinaten erfolgreich hinzugefügt!",
"EN":"Gym coordinates successfully added!",
"IT":"TRANSLATE",
"PT-BR":"TRANSLATE",
"RU":"TRANSLATE",
"NO":"TRANSLATE",
"FR":"TRANSLATE",
"PL":"TRANSLATE"
},
"gym_id_gps_missing":{
"NL":"Error! gym id of coordinaten mist!",
"DE":"Fehler! Arena-ID oder Koordinaten fehlen!",
"EN":"Error! Gym id or coordinates are missing!",
"IT":"TRANSLATE",
"PT-BR":"TRANSLATE",
"RU":"TRANSLATE",
"NO":"TRANSLATE",
"FR":"TRANSLATE",
"PL":"TRANSLATE"
},
"gymname_then_location":{
"NL":"Gebruik het commando /gymname <code>Naam van de gym</code> om deze aan de coordinaten vast te zetten. Daarna kan je weer een locatie delen!",
"DE":"Bitte nutze den Befehl /gymname <code>Name der Arena</code>, um einen Arena-Namen für die zuletzt übermittelten Koordinaten festzulegen. Erst dann kann wieder ein Standort übermittelt werden!",
Expand Down

0 comments on commit dd229f6

Please sign in to comment.