Skip to content

Commit

Permalink
Fix raid event limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Chefkeks committed Jan 7, 2021
1 parent ecd9061 commit b316897
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.359.2
2.1.007.1
53 changes: 37 additions & 16 deletions commands/start.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
} else {
$access = bot_access_check($update, 'create', false, true);
}


// Raid event?
if($config->RAID_HOUR || $config->RAID_DAY) {
// Always allow for Admins.
if($access && $access == 'BOT_ADMINS') {
debug_log('Bot Admin detected. Allowing further raid creation during the raid hour');
debug_log('Bot Admin detected. Allowing further raid creation during the raid event');
} else {
debug_log('Checking further raid creation during the raid event');

// Get number of raids for the current user.
$rs = my_query(
"
Expand All @@ -47,36 +51,53 @@

$info = $rs->fetch();

// Set message and keys.
// Init message and keys.
$msg = getTranslation('not_supported');
$keys = [];

if($config->RAID_HOUR) {
// Limits
$creation_limit = $config->RAID_HOUR_CREATION_LIMIT;
debug_log('Event: Raid hour');
debug_log($info['created_raids_count'],'Raids created from user:');
debug_log($creation_limit,'Max raids user can create during event:');

// Check raid count
$creation_limit = $config->RAID_HOUR_CREATION_LIMIT - 1;
if($info['created_raids_count'] > $creation_limit) {
if($info['created_raids_count'] == $creation_limit) {
if($config->RAID_HOUR_CREATION_LIMIT == 1) {
$msg = '<b>' . getTranslation('raid_hour_creation_limit_one') . '</b>';
} else {
$msg = '<b>' . str_replace('RAID_HOUR_CREATION_LIMIT', $config->RAID_HOUR_CREATION_LIMIT, getPublicTranslation('raid_hour_creation_limit')) . '</b>';
$msg = '<b>' . str_replace('RAID_HOUR_CREATION_LIMIT', $config->RAID_HOUR_CREATION_LIMIT, getTranslation('raid_hour_creation_limit')) . '</b>';
}

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

// Exit.
exit();
}
} elseif($config->RAID_DAY) {
// Limits
$creation_limit = $config->RAID_DAY_CREATION_LIMIT;
debug_log('Event: Raid day');
debug_log($info['created_raids_count'],'Raids created from user:');
debug_log($creation_limit,'Max raids user can create during event:');

// Check raid count
$creation_limit = $config->RAID_DAY_CREATION_LIMIT - 1;
if($info['created_raids_count'] > $creation_limit) {
if($info['created_raids_count'] == $creation_limit) {
if($config->RAID_DAY_CREATION_LIMIT == 1) {
$msg = '<b>' . getTranslation('raid_day_creation_limit_one') . '</b>';
} else {
$msg = '<b>' . str_replace('RAID_DAY_CREATION_LIMIT', $config->RAID_DAY_CREATION_LIMIT, getPublicTranslation('raid_day_creation_limit')) . '</b>';
$msg = '<b>' . str_replace('RAID_DAY_CREATION_LIMIT', $config->RAID_DAY_CREATION_LIMIT, getTranslation('raid_day_creation_limit')) . '</b>';
}
}
}

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

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

// Exit.
exit();
// Exit.
exit();
}
}
}
}

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.359.2",
"VERSION":"2.1.007.1",
"DB_HOST":"localhost",
"DB_NAME":"your_database_name",
"DB_USER":"your_database_user",
Expand Down

0 comments on commit b316897

Please sign in to comment.