Skip to content

Commit

Permalink
New feature: RAID_BOSS_LIST
Browse files Browse the repository at this point in the history
Adds a list of stored raid bosses to the overview message
  • Loading branch information
Ninjasoturi committed Oct 28, 2023
1 parent fd73aaa commit c71fe57
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/defaults-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"RAID_VIA_LOCATION_FUNCTION": "create",
"RAID_EGG_DURATION":"60",
"RAID_EGG_DURATION_ELITE":"1440",
"RAID_BOSS_LIST": false,
"RAID_BOSS_LIST_TITLE": "Raidbosses:",
"RAID_BOSS_LIST_RAID_LEVELS": [5,7,8,10],
"RAID_BOSS_LIST_ROW_LIMIT": "4",
"RAID_DURATION":"45",
"RAID_DURATION_ELITE":"30",
"RAID_DURATION_CLOCK_STYLE": true,
Expand Down
8 changes: 8 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,14 @@ Config reference
- Fully qualified HTTPS URL to ``raidpicture.php``\ , for example ``https://example.com/raidbot/raidpicture.php``
* - RAID_PIN_MESSAGE
- Custom message added to the bottom of the raid overview messages
* - RAID_BOSS_LIST"
- Bool, adds a list of saved raid bosses to overview message
* - RAID_BOSS_LIST_TITLE
- String, title of the list
* - RAID_BOSS_LIST_RAID_LEVELS
- Array, list of raid levels included in the list
* - RAID_BOSS_LIST_ROW_LIMIT
- Int, limit the list to set number of rows
* - RAID_POLL_HIDE_BUTTONS_POKEMON
- List of Pokemon dex IDs for which voting buttons are disabled
* - RAID_POLL_HIDE_BUTTONS_RAID_LEVEL
Expand Down
73 changes: 73 additions & 0 deletions logic/createRaidBossList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
require_once(LOGIC_PATH . '/get_raid_times.php');

/**
* Prints a list of saved raid bosses in this format
* - Darkrai 20.10. - 2.11.
* - Lugia 28.10. - 29.10.
* - Genesect Douse 2.11. - 9.11.
* - Virizion 9.11. - 16.11.
* - Cobalion, Terrakion 16.11. - 23.11.
*
* 28.10.
* - Mewtwo 10:00 - 10:00
* - Mewtwo 10:00 - 11:00
*
* 29.10.
* - Moltres, Lugia 20:00 - 21:00
* @return string
*/
function createRaidBossList() {
global $config;
$dateFormat = 'j.m.';
$timeFormat = 'H:i';
$levelList = '(' . implode(',', $config->RAID_BOSS_LIST_RAID_LEVELS). ')';
$q = my_query('SELECT pokedex_id,pokemon_form_id,date_start,date_end,concat(date_format(date_start,"%d%m%y%k"),date_format(date_end,"%d%m%y%k")) as arrkey,CASE WHEN date(date_start) = date(date_end) THEN 1 ELSE 0 END as sameDay FROM raid_bosses where raid_level in ' . $levelList . ' order by sameDay, date_start, date_end');
$list = '';
$prevStartDate = '';
$data[0] = $data[1] = [];
// Save the results in easy to process format
foreach($q->fetchAll() as $row) {
$data[$row['sameDay']][$row['arrkey']][] = $row;
}
if(count($row) == 0) return '';
$i = 1;
$list = $config->RAID_BOSS_LIST_TITLE;
// Print list of bosses that run for multiple days
foreach($data[0] as $tempRow) {
$list .= PHP_EOL . '- ';
foreach($tempRow as $num => $row) {
$pokemonName = get_local_pokemon_name($row['pokedex_id'], $row['pokemon_form_id']);
if($num != 0) $list .= ', ';
$list .= $pokemonName;
}
$dateStart = new dateTime($row['date_start']);
$dateEnd = new dateTime($row['date_end']);
$list .= ' ' . $dateStart->format($dateFormat) . ' - '. $dateEnd->format($dateFormat);
$i++;
if($i > $config->RAID_BOSS_LIST_ROW_LIMIT) break;
}

// Print list of one day bosses
foreach($data[1] as $arrkey => $tempRow) {
$startDate = substr($arrkey, 0, 6);
if($list != '' && $prevStartDate != $startDate) $list.= PHP_EOL . PHP_EOL;
foreach($tempRow as $num => $row) {
$dateStart = new dateTime($row['date_start']);
$dateEnd = new dateTime($row['date_end']);
if($num == 0){
if($prevStartDate != $startDate) {
$list .= $dateStart->format($dateFormat);
}
$list .= PHP_EOL . '- ';
}
$pokemonName = get_local_pokemon_name($row['pokedex_id'], $row['pokemon_form_id']);
if($num != 0) $list .= ', ';
$list .= $pokemonName;
$prevStartDate = $startDate;
}
$list .= ' ' . $dateStart->format($timeFormat) . ' - ' . $dateEnd->format($timeFormat);
}
return $list;
}
?>
7 changes: 7 additions & 0 deletions logic/get_overview.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
require_once(LOGIC_PATH . '/get_raid_times.php');
require_once(LOGIC_PATH . '/createRaidBossList.php');
/**
* Return the overview message for a specific chat.
* @param array $active_raids - Custom array of gym and raid info
Expand All @@ -15,6 +16,9 @@ function get_overview( $active_raids, $chat_title, $chat_username )

if(count($active_raids) == 0) {
$msg .= getPublicTranslation('no_active_raids') . CR . CR;
if($config->RAID_BOSS_LIST) {
$msg .= createRaidBossList() . CR . CR;
}
//Add custom message from the config.
if (!empty($config->RAID_PIN_MESSAGE)) {
$msg .= $config->RAID_PIN_MESSAGE;
Expand Down Expand Up @@ -105,6 +109,9 @@ function get_overview( $active_raids, $chat_title, $chat_username )
$msg .= (($att['count_want_invite'] > 0) ? EMOJI_WANT_INVITE . $att['count_want_invite'] : '');
$msg .= CR . CR;
}
if($config->RAID_BOSS_LIST) {
$msg .= createRaidBossList() . CR . CR;
}
//Add custom message from the config.
if (!empty($config->RAID_PIN_MESSAGE)) {
$msg .= $config->RAID_PIN_MESSAGE;
Expand Down

0 comments on commit c71fe57

Please sign in to comment.