Skip to content

Commit

Permalink
Reduced unnecessary code execution and php notices
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjasoturi committed Jul 27, 2021
1 parent c85a8f1 commit 8476fb6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 95 deletions.
2 changes: 1 addition & 1 deletion logic/curl_json_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function curl_json_response($json_response, $json)
$response = json_decode($json_response, true);

// Validate response.
if ($response['ok'] != true || isset($response['update_id'])) {
if ((isset($response['ok']) && $response['ok'] != true) || isset($response['update_id'])) {
info_log("{$json} -> {$json_response}", 'ERROR:');
} else {
// Result seems ok, get message_id and chat_id if supergroup or channel message
Expand Down
10 changes: 7 additions & 3 deletions logic/get_pokemon_id_by_name.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ function get_pokemon_id_by_name($pokemon_name, $get_from_db = false)
");
$stmt->execute(['poke_name' => $poke_name, 'form_name' => $pokemon_form]);
$res = $stmt->fetch();
$pokemon_form_id = $res['pokemon_form_id'];
$pokemon_id = $res['pokedex_id'];
if($stmt->rowCount() > 0) {
$pokemon_form_id = $res['pokemon_form_id'];
$pokemon_id = $res['pokedex_id'];
}else {
$pokemon_form_id = 0;
}
}else {
// Get translation file
$str = file_get_contents(CORE_LANG_PATH . '/pokemon.json');
Expand Down Expand Up @@ -119,7 +123,7 @@ function get_pokemon_id_by_name($pokemon_name, $get_from_db = false)
");
$stmt->execute(['pokedex_id' => $pokemon_id, 'form_name' => $pokemon_form]);
$res = $stmt->fetch();
$pokemon_form_id = $res['pokemon_form_id'];
$pokemon_form_id = isset($res['pokemon_form_id']) ? $res['pokemon_form_id'] : '';
}

// Write to log.
Expand Down
62 changes: 34 additions & 28 deletions mods/vote_remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,48 @@

// Get remote value.
$remote = $rs->fetch();
$remote_status = $remote['remote'];
$remote_status = isset($remote['remote']) ? $remote['remote'] : 0;
$user_remote_count = isset($remote['user_count']) ? $remote['user_count'] : 0;

// Check if max remote users limit is already reached!
$remote_users = get_remote_users_count($data['id'], $update['callback_query']['from']['id']);

// Ignore max users reached when switching from remote to local otherwise check if max users reached?
if ($remote_users + $remote['user_count'] <= $config->RAID_REMOTEPASS_USERS_LIMIT || $remote_status == 1) {
// Update users table.
my_query(
"
UPDATE attendance
SET remote = CASE
WHEN remote = '0' THEN '1'
ELSE '0'
END,
want_invite = 0
WHERE raid_id = {$data['id']}
AND user_id = {$update['callback_query']['from']['id']}
"
);

if($remote_status == 0) {
alarm($data['id'],$update['callback_query']['from']['id'],'remote');
} else {
alarm($data['id'],$update['callback_query']['from']['id'],'no_remote');
}
if($rs->rowCount() > 0) {
// Ignore max users reached when switching from remote to local otherwise check if max users reached?
if ($remote_users + $user_remote_count <= $config->RAID_REMOTEPASS_USERS_LIMIT || $remote_status == 1) {
// Update users table.
my_query(
"
UPDATE attendance
SET remote = CASE
WHEN remote = '0' THEN '1'
ELSE '0'
END,
want_invite = 0
WHERE raid_id = {$data['id']}
AND user_id = {$update['callback_query']['from']['id']}
"
);

if($remote_status == 0) {
alarm($data['id'],$update['callback_query']['from']['id'],'remote');
} else {
alarm($data['id'],$update['callback_query']['from']['id'],'no_remote');
}

// Send vote response.
if($config->RAID_PICTURE) {
send_response_vote($update, $data,false,false);
// Send vote response.
if($config->RAID_PICTURE) {
send_response_vote($update, $data,false,false);
} else {
send_response_vote($update, $data);
}
} else {
send_response_vote($update, $data);
// Send max remote users reached.
send_vote_remote_users_limit_reached($update);
}
} else {
// Send max remote users reached.
send_vote_remote_users_limit_reached($update);
// Send vote time first.
send_vote_time_first($update);
}

exit();
2 changes: 1 addition & 1 deletion mods/vote_time.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
// Vote time in the future or Raid anytime?
if($now <= $attend_time || $vote_time == 0) {
// If user is attending remotely, get the number of remote users already attending
if (!in_array('remote', $answer) or $answer['remote'] == 0){
if (!is_array($answer) or !in_array('remote', $answer) or $answer['remote'] == 0){
$remote_users = 0;
} else {
$remote_users = get_remote_users_count($data['id'], $update['callback_query']['from']['id'], $attend_time);
Expand Down
63 changes: 1 addition & 62 deletions mods/vote_want_invite.php
Original file line number Diff line number Diff line change
@@ -1,62 +1 @@
<?php
// Write to log.
debug_log('vote_want_invite()');

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

try {
$query = "
UPDATE attendance
SET want_invite = CASE
WHEN want_invite = '0' THEN '1'
ELSE '0'
END,
late = 0,
arrived = 0,
remote = 0
WHERE raid_id = :raid_id
AND user_id = :user_id
";
$statement = $dbh->prepare( $query );
$statement->execute([
'raid_id' => $data['id'],
'user_id' => $update['callback_query']['from']['id']
]);
$query_select = "
SELECT want_invite
FROM attendance
WHERE raid_id = :raid_id
AND user_id = :user_id
LIMIT 1
";
$statement_select = $dbh->prepare( $query_select );
$statement_select->execute([
'raid_id' => $data['id'],
'user_id' => $update['callback_query']['from']['id']
]);
$res = $statement_select->fetch();
}
catch (PDOException $exception) {

error_log($exception->getMessage());
$dbh = null;
exit;
}
if($statement_select->rowCount() > 0) {
if($res['want_invite'] == 1) {
alarm($data['id'],$update['callback_query']['from']['id'],'want_invite');
} else {
alarm($data['id'],$update['callback_query']['from']['id'],'no_want_invite');
}
}

// Send vote response.
if($config->RAID_PICTURE) {
send_response_vote($update, $data,false,false);
} else {
send_response_vote($update, $data);
}

exit();
<?php// Write to log.debug_log('vote_want_invite()');// For debug.//debug_log($update);//debug_log($data);try { $query_select = " SELECT want_invite FROM attendance WHERE raid_id = :raid_id AND user_id = :user_id LIMIT 1 "; $statement_select = $dbh->prepare( $query_select ); $statement_select->execute([ 'raid_id' => $data['id'], 'user_id' => $update['callback_query']['from']['id'] ]); $res = $statement_select->fetch(); if($statement_select->rowCount() > 0) { $query = " UPDATE attendance SET want_invite = CASE WHEN want_invite = '0' THEN '1' ELSE '0' END, late = 0, arrived = 0, remote = 0 WHERE raid_id = :raid_id AND user_id = :user_id "; $statement = $dbh->prepare( $query ); $statement->execute([ 'raid_id' => $data['id'], 'user_id' => $update['callback_query']['from']['id'] ]); }}catch (PDOException $exception) { error_log($exception->getMessage()); $dbh = null; exit;}if($statement_select->rowCount() > 0) { if($res['want_invite'] == 0) { alarm($data['id'],$update['callback_query']['from']['id'],'want_invite'); } else { alarm($data['id'],$update['callback_query']['from']['id'],'no_want_invite'); } // Send vote response. if($config->RAID_PICTURE) { send_response_vote($update, $data,false,false); } else { send_response_vote($update, $data); } } else { // Send vote time first. send_vote_time_first($update);}exit();
Expand Down

0 comments on commit 8476fb6

Please sign in to comment.