Skip to content

Commit 369d1d8

Browse files
committed
Another vote key refactor
Brought back the old vote key logic, but more compact.
1 parent 8caa37c commit 369d1d8

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

logic/keys_vote.php

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -255,46 +255,39 @@ function generateTimeslotKeys($RAID_SLOTS, $raid) {
255255
$directStartMinutes = $direct_slot->format('i');
256256

257257
// Get first raidslot rounded up to the next 5 minutes
258-
$five_slot = new DateTimeImmutable($raid['start_time'], new DateTimeZone('UTC'));
259258
$minute = $directStartMinutes % 5;
260-
$diff = ($minute != 0) ? 5 - $minute : 5;
261-
$five_slot = $five_slot->add(new DateInterval('PT'.$diff.'M'));
259+
$diff = ($minute != 0) ? 5 - $minute : 0;
260+
$five_slot = $direct_slot->add(new DateInterval('PT'.$diff.'M'));
261+
262+
// Add $config->RAID_FIRST_START minutes to five minutes slot
263+
$five_plus_slot = $five_slot;
264+
$five_plus_slot = $five_plus_slot->add(new DateInterval("PT".$config->RAID_FIRST_START."M"));
262265

263266
// Get first regular raidslot
264-
$first_slot =
265-
($minute == 0) ?
266-
$direct_slot->add(new DateInterval('PT'.$RAID_SLOTS.'M')) :
267-
$five_slot->add(new DateInterval('PT'.$RAID_SLOTS.'M')
268-
);
267+
$firstSlotMinute = $directStartMinutes % $RAID_SLOTS;
268+
$firstSlotDiff = ($firstSlotMinute != 0) ? $RAID_SLOTS - ($firstSlotMinute) : 0;
269+
$first_slot = $direct_slot->add(new DateInterval('PT'.$firstSlotDiff.'M'));
269270

270271
// Write slots to log.
271272
debug_log($direct_slot, 'Direct start slot:');
272273
debug_log($five_slot, 'Next 5 Minute slot:');
273274
debug_log($first_slot, 'First regular slot:');
274275
$keys_time = [];
275-
// Add button for when raid starts time
276-
if($config->RAID_DIRECT_START && $direct_slot >= $dt_now) {
276+
277+
// Add button for direct start if needed
278+
if($config->RAID_DIRECT_START && $direct_slot != $five_slot && $direct_slot >= $dt_now) {
277279
$keys_time[] = button(dt2time($direct_slot->format('Y-m-d H:i:s')), ['vote_time', 'r' => $raid['id'], 't' => $direct_slot->format('YmdHis')]);
278-
$last_slot = $direct_slot;
279280
}
280-
// Add five minutes slot
281-
if($five_slot >= $dt_now &&
282-
(empty($keys_time) || (!empty($keys_time) && $direct_slot != $five_slot)) &&
283-
$raid['event_vote_key_mode'] !== 0
284-
) {
281+
282+
// Add button for first five minutes if needed
283+
if($five_slot < $first_slot && $five_plus_slot <= $first_slot && $five_slot >= $dt_now) {
285284
$keys_time[] = button(dt2time($five_slot->format('Y-m-d H:i:s')), ['vote_time', 'r' => $raid['id'], 't' => $five_slot->format('YmdHis')]);
286-
$last_slot = $five_slot;
287-
}
288-
// Add the first normal slot
289-
if($first_slot >= $dt_now && $first_slot != $five_slot) {
290-
$keys_time[] = button(dt2time($first_slot->format('Y-m-d H:i:s')), ['vote_time', 'r' => $raid['id'], 't' => $first_slot->format('YmdHis')]);
291-
$last_slot = $first_slot;
292285
}
293286

294287
// Get regular slots
295288
// Start with second slot as first slot is already added to keys.
296289
$dt_end = new DateTimeImmutable($raid['end_time'], new DateTimeZone('UTC'));
297-
$regular_slots = new DatePeriod($first_slot, new DateInterval('PT'.$RAID_SLOTS.'M'), $dt_end->sub(new DateInterval('PT'.$config->RAID_LAST_START.'M')), DatePeriod::EXCLUDE_START_DATE);
290+
$regular_slots = new DatePeriod($first_slot, new DateInterval('PT'.$RAID_SLOTS.'M'), $dt_end->sub(new DateInterval('PT'.$config->RAID_LAST_START.'M')));
298291

299292
// Add regular slots.
300293
foreach($regular_slots as $slot){
@@ -309,8 +302,7 @@ function generateTimeslotKeys($RAID_SLOTS, $raid) {
309302

310303
// Add raid last start slot
311304
// Set end_time to last extra slot, subtract $config->RAID_LAST_START minutes and round down to earlier 5 minutes.
312-
$last_extra_slot = $dt_end;
313-
$last_extra_slot = $last_extra_slot->sub(new DateInterval('PT'.$config->RAID_LAST_START.'M'));
305+
$last_extra_slot = $dt_end->sub(new DateInterval('PT'.$config->RAID_LAST_START.'M'));
314306
$s = 5 * 60;
315307
$last_extra_slot = $last_extra_slot->setTimestamp($s * floor($last_extra_slot->getTimestamp() / $s));
316308

@@ -319,8 +311,9 @@ function generateTimeslotKeys($RAID_SLOTS, $raid) {
319311
debug_log($last_extra_slot, 'Last extra slot:');
320312

321313
// Last extra slot not conflicting with last slot
322-
if((isset($last_slot) && $last_extra_slot > $last_slot && $last_extra_slot != $last_slot && $last_extra_slot >= $dt_now) ||
323-
(!isset($last_slot) && $last_extra_slot >= $dt_now)) {
314+
if($last_extra_slot >= $dt_now &&
315+
((isset($last_slot) && $last_extra_slot > $last_slot && $last_extra_slot != $last_slot) ||
316+
!isset($last_slot))) {
324317
// Add last extra slot
325318
$keys_time[] = button(dt2time($last_extra_slot->format('Y-m-d H:i:s')), ['vote_time', 'r' => $raid['id'], 't' => $last_extra_slot->format('YmdHis')]);
326319
}

0 commit comments

Comments
 (0)