Skip to content

Commit

Permalink
Initial commit for event feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjasoturi committed Oct 18, 2020
1 parent 25a642e commit e678e59
Show file tree
Hide file tree
Showing 28 changed files with 851 additions and 449 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ A few examples for access files can be found below the permission overview table
| Raid poll | Vote on shared raid poll | Not required! |
| | Create raids `/start`, `/raid` | `create` |
| | Create ex-raids `/start` | `ex-raids` |
| | Create event raids `/start` | `event-raids` |
| | Change raid duration `/start` | `raid-duration` |
| | List all raids `/list` | `list` |
| | Manage overview `/overview` | `overview` |
Expand Down
3 changes: 2 additions & 1 deletion config/defaults-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"RAID_EVENT_CREATION_LIMIT":"1",
"RAID_DURATION_CLOCK_STYLE": true,
"RAID_CUSTOM_GYM_LETTERS":"",
"RAID_EXCLUDE_EXRAID_DUPLICATION": false,
"RAID_EXCLUDE_EXRAID_DUPLICATION": true,
"RAID_EXCLUDE_EVENT_DUPLICATION": true,
"RAID_LOCATION": false,
"RAID_SLOTS":"15",
"RAID_DIRECT_START": false,
Expand Down
3 changes: 3 additions & 0 deletions constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
define('ANYTIME', '1970-01-01 00:00:00');
define('ANYTIME_TS', preg_replace("/[^0-9]/", "", ANYTIME));

// Ex-raid event ID
defined('EVENT_ID_EX') or define('EVENT_ID_EX', '999');

// Icons.
defined('TEAM_B') or define('TEAM_B', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F499)));
defined('TEAM_R') or define('TEAM_R', iconv('UCS-4LE', 'UTF-8', pack('V', 0x2764)));
Expand Down
39 changes: 37 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,43 @@
// Import portal.
include_once(ROOT_PATH . '/mods/importal.php');
} else {
// Logic to get the command
include_once(CORE_BOT_PATH . '/commands.php');
// Check if user is expected to be posting something we want to save to db
$q = my_query("SELECT id FROM raids WHERE event_note='{$update['message']['from']['id']}' LIMIT 1");
if( $q->rowCount() > 0 ) {
debug_log("Found user from raids table: " . $update['message']['from']['id']);
$res = $q->fetch();

$query = $dbh->prepare("UPDATE raids SET event_note=:text WHERE id = :id");
$query->execute([':text' => $update['message']['text'], ':id' => $res['id']]);

$msg = '';
$msg .= getTranslation('raid_saved') . CR;
$msg .= CR.getTranslation('event_note').': '.$update['message']['text'].CR2;
$msg .= show_raid_poll_small(get_raid($res['id'])) . CR;
debug_log($msg);
$keys = [
[
[
'text' => getTranslation('event_note_edit'),
'callback_data' => $res['id'] . ':edit_event_note:edit'
]
],
[
[
'text' => getTranslation('delete'),
'callback_data' => $res['id'] . ':raids_delete:0'
]
]
];
$keys_share = share_keys($res['id'], 'raid_share', $update, $chats);
$keys = array_merge($keys, $keys_share);

debug_log($keys);
send_message($update['message']['from']['id'],$msg,$keys,[]);
}else {
// Logic to get the command
include_once(CORE_BOT_PATH . '/commands.php');
}
}
}

Expand Down
72 changes: 72 additions & 0 deletions lang/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -2962,5 +2962,77 @@
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Ei ylimääräisiä kouluttajia!"
},
"event": {
"NL": "TRANSLATE",
"DE": "TRANSLATE",
"EN": "Event",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Tapahtuman"
},
"event_note": {
"NL": "TRANSLATE",
"DE": "TRANSLATE",
"EN": "Event note",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Tapahtuman lisätiedot"
},
"event_note_add": {
"NL": "TRANSLATE",
"DE": "TRANSLATE",
"EN": "Add event note",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Lisää raiditapahtumaan lisätietoja"
},
"event_note_edit": {
"NL": "TRANSLATE",
"DE": "TRANSLATE",
"EN": "Edit event note",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Muokkaa raiditapahtuman lisätietoja"
},
"event_add_note_description": {
"NL": "TRANSLATE",
"DE": "TRANSLATE",
"EN": "Add more info for this specific poll regarding the event. (e.g. route)",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Lisää ilmoituskohtaisia lisätietoja tapahtumaan liittyen. (esim. reitti)"
},
"Participate": {
"NL": "TRANSLATE",
"DE": "TRANSLATE",
"EN": "Participate",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Osallistu"
}
}
2 changes: 2 additions & 0 deletions logic.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
include('logic/get_gym.php');
include('logic/get_local_pokemon_name.php');
include('logic/get_overview.php');
include('logic/get_pokemon_by_table_id.php');
include('logic/get_pokemon_cp.php');
include('logic/get_pokemon_form_name.php');
include('logic/get_pokemon_id_by_name.php');
Expand All @@ -40,6 +41,7 @@
include('logic/insert_gym.php');
include('logic/insert_overview.php');
include('logic/insert_trainerinfo.php');
include('logic/keys_event.php');
include('logic/keys_trainerinfo.php');
include('logic/keys_vote.php');
include('logic/mapslink.php');
Expand Down
48 changes: 12 additions & 36 deletions logic/active_raid_duplication_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,25 @@ function active_raid_duplication_check($gym_id)
// Build query.
$rs = my_query(
"
SELECT id, pokemon, pokemon_form, count(gym_id) AS active_raid
SELECT id, event
FROM raids
WHERE end_time > (UTC_TIMESTAMP() - INTERVAL 10 MINUTE)
AND gym_id = {$gym_id}
GROUP BY id, pokemon, pokemon_form
ORDER BY event IS NOT NULL
"
);

// Init counter and raid id.
$active_counter = 0;
$active_raid_id = 0;

// Get row - allow normal and ex-raid at the gym.
if($config->RAID_EXCLUDE_EXRAID_DUPLICATION) {
while ($raid = $rs->fetch()) {
$active = $raid['active_raid'];
if ($active > 0) {
// Exclude ex-raid pokemon.
$raid_level = get_raid_level($raid['pokemon'], $raid['pokemon_form']);
if($raid_level == 'X') {
continue;
} else {
$active_raid_id = $raid['id'];
$active_counter = $active_counter + 1;
break;
}
// No active raids.
} else {
break;
}
$active = 0;
while($raid = $rs->fetch()) {
if($config->RAID_EXCLUDE_EXRAID_DUPLICATION && $raid['event'] == EVENT_ID_EX) {
continue;
}
} else {
$raid = $rs->fetch();
$active_counter = $raid['active_raid'];
$active_raid_id = $raid['id'];
}

// Return 0 or raid id
if ($active_counter > 0) {
return $active_raid_id;
} else {
return 0;
if($config->RAID_EXCLUDE_EVENT_DUPLICATION && $raid['event'] !== NULL && $raid['event'] != EVENT_ID_EX) {
continue;
}
$active = $raid['id'];
break;
}
return $active;
}

?>
17 changes: 17 additions & 0 deletions logic/get_pokemon_by_table_id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Get pokedex_id and pokemon_form_id with id from database.
* @param $pokemon_table_id
* @return array
*/
function get_pokemon_by_table_id($pokemon_table_id) {
$q = my_query("
SELECT pokedex_id,
pokemon_form_id
FROM pokemon
WHERE id = {$pokemon_table_id}
LIMIT 1
");
$return = $q->fetch();
return $return;
}
3 changes: 3 additions & 0 deletions logic/get_raid.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ function get_raid($raid_id)
SELECT raids.*,
gyms.lat, gyms.lon, gyms.address, gyms.gym_name, gyms.ex_gym, gyms.gym_note,
users.name, users.trainername, users.nick,
events.name as event_name, events.description as event_description, events.vote_key_mode as event_vote_key_mode, events.time_slots as event_time_slots, events.raid_duration as event_raid_duration, events.hide_raid_picture as event_hide_raid_picture,
TIME_FORMAT(TIMEDIFF(end_time, UTC_TIMESTAMP()) + INTERVAL 1 MINUTE, '%k:%i') AS t_left,
TIMESTAMPDIFF(MINUTE,raids.start_time,raids.end_time) as t_duration
FROM raids
LEFT JOIN gyms
ON raids.gym_id = gyms.id
LEFT JOIN users
ON raids.user_id = users.user_id
LEFT JOIN events
ON events.id = raids.event
WHERE raids.id = {$raid_id}
"
);
Expand Down
30 changes: 30 additions & 0 deletions logic/keys_event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Event keys.
* @param $gym_id_plus_letter
* @param $action
* @return array
*/
function event_keys($gym_id_plus_letter, $action) {
$q = my_query("
SELECT id,
name
FROM
events
");
while($event = $q->fetch()) {
$keys[] = array(
'text' => $event['name'],
'callback_data' => $gym_id_plus_letter . ':' . $action . ':' . $event['id']
);
}
$keys[] = array(
'text' => getTranslation("Xstars"),
'callback_data' => $gym_id_plus_letter . ':' . $action . ':X'
);
// Get the inline key array.
$keys = inline_key_array($keys, 1);

return $keys;
}
?>
Loading

0 comments on commit e678e59

Please sign in to comment.