Skip to content

Commit

Permalink
Alarm fixes and curl optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjasoturi committed Aug 19, 2021
1 parent 1773f9e commit d26deb9
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 36 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.231.6
2.1.231.7
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.1.231.6",
"VERSION":"2.1.231.7",
"DB_HOST":"localhost",
"DB_NAME":"your_database_name",
"DB_USER":"your_database_user",
Expand Down
16 changes: 9 additions & 7 deletions logic/alarm.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
/**
* Send raid alerts to user.
* @param $raid_id_array - raid id or the result of get_raid()
* @param $user_id - ID of the user that executed the call
* @param $action - which alarm action to perform
* @param $info - additional info for the action if required
* @param array $raid_id_array raid id or the result of get_raid()
* @param int $user_id ID of the user that executed the call
* @param string $action which alarm action to perform
* @param string $info additional info for the action if required
* @param array $tg_json multicurl array
* @return array multicurl array
*/
function alarm($raid_id_array, $user_id, $action, $info = '')
function alarm($raid_id_array, $user_id, $action, $info = '', $tg_json = [])
{
// Get config
global $config;
Expand Down Expand Up @@ -65,7 +67,7 @@ function alarm($raid_id_array, $user_id, $action, $info = '')
AND alarm = 1
");
}
$tg_json = [];

while($answer = $request->fetch())
{
if(!isset($answer['lang']) or empty($answer['lang'])) $recipient_language = $config->LANGUAGE_PUBLIC;
Expand Down Expand Up @@ -255,7 +257,7 @@ function alarm($raid_id_array, $user_id, $action, $info = '')
}
$tg_json[] = send_message($answer['user_id'], $msg_text, false, false, true);
}
if(count($tg_json) > 0) curl_json_multi_request($tg_json);
return $tg_json;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions mods/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
// Set the arg.
$arg = $data['arg'];

// Telegram JSON array.
$tg_json = array();

// Get raid info.
$raid = get_raid($raid_id);
$gym_name = $raid['gym_name'];
Expand All @@ -39,7 +42,7 @@
$group_code = getTranslation('start_raid_public') . SP . getTranslation('no_group_code');

// Send code via alarm function
alarm($raid_id,$update['callback_query']['from']['id'],'group_code_public',$group_code);
$tg_json = alarm($raid_id,$update['callback_query']['from']['id'],'group_code_public',$group_code, $tg_json);

// Init empty keys array.
$keys = [];
Expand Down Expand Up @@ -127,7 +130,7 @@
$group_code .= $p3 . CR;

// Send code via alarm function
alarm($raid_id,$update['callback_query']['from']['id'],'group_code_private',$group_code);
$tg_json = alarm($raid_id,$update['callback_query']['from']['id'],'group_code_private',$group_code, $tg_json);

// Init empty keys array.
$keys = [];
Expand All @@ -142,9 +145,6 @@
}
}

// Telegram JSON array.
$tg_json = array();

// Answer callback.
$tg_json[] = answerCallbackQuery($update['callback_query']['id'], $callback_response, true);

Expand Down
6 changes: 3 additions & 3 deletions mods/raid_set_poke.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
require_once(LOGIC_PATH .'/update_raid_poll.php');
$tg_json = update_raid_poll($raid_id, $raid, false, $tg_json, false);

// Alert users.
$tg_json = alarm($raid, $update['callback_query']['from']['id'], 'new_boss', '', $tg_json);

// Telegram multicurl request.
curl_json_multi_request($tg_json);

// Alert users.
alarm($raid, $update['callback_query']['from']['id'], 'new_boss');

// Exit.
exit();
6 changes: 4 additions & 2 deletions mods/vote_can_invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@
}
if($statement_select->rowCount() > 0) {
if($res['can_invite'] == 0) {
alarm($data['id'],$update['callback_query']['from']['id'],'can_invite');
$alarm_action = 'can_invite';
} else {
alarm($data['id'],$update['callback_query']['from']['id'],'no_can_invite');
$alarm_action = 'no_can_invite';
}
// Send vote response.
require_once(LOGIC_PATH . '/update_raid_poll.php');

$tg_json = update_raid_poll($data['id'], false, $update);

$tg_json = alarm($data['id'],$update['callback_query']['from']['id'], $alarm_action, '', $tg_json);

$tg_json[] = answerCallbackQuery($update['callback_query']['id'], getTranslation('vote_updated'), true);

curl_json_multi_request($tg_json);
Expand Down
9 changes: 6 additions & 3 deletions mods/vote_extra.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
// Get the answer.
$answer = $rs->fetch();

// Telegram JSON array.
$tg_json = array();

// Write to log.
debug_log($answer);

Expand All @@ -36,7 +39,7 @@
AND user_id = {$update['callback_query']['from']['id']}
"
);
alarm($data['id'],$update['callback_query']['from']['id'],'extra_alone',$data['arg']);
$tg_json = alarm($data['id'],$update['callback_query']['from']['id'],'extra_alone',$data['arg'], $tg_json);
} else if($answer['can_invite'] == 1 ) {
// People who are only inviting others can't add extras
$msg = getTranslation('vote_status_not_allowed');
Expand Down Expand Up @@ -68,7 +71,7 @@
AND {$team} < 5
"
);
alarm($data['id'],$update['callback_query']['from']['id'],'extra',$data['arg']);
$tg_json = alarm($data['id'],$update['callback_query']['from']['id'],'extra',$data['arg'], $tg_json);
} else {
// Send max remote users reached.
send_vote_remote_users_limit_reached($update);
Expand All @@ -80,7 +83,7 @@
// Send vote response.
require_once(LOGIC_PATH . '/update_raid_poll.php');

$tg_json = update_raid_poll($data['id'], false, $update);
$tg_json = update_raid_poll($data['id'], false, $update, $tg_json);

$tg_json[] = answerCallbackQuery($update['callback_query']['id'], getTranslation('vote_updated'), true);

Expand Down
8 changes: 4 additions & 4 deletions mods/vote_pokemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
);

// Send alarm
alarm($data['id'],$update['callback_query']['from']['id'],'pok_individual',$data['arg']);
$tg_json = alarm($data['id'],$update['callback_query']['from']['id'],'pok_individual',$data['arg']);
} else {
// Init found and count.
$found = false;
Expand Down Expand Up @@ -92,7 +92,7 @@
);
}
// Send alarm
alarm($data['id'],$update['callback_query']['from']['id'],'pok_cancel_individual',$data['arg']);
$tg_json = alarm($data['id'],$update['callback_query']['from']['id'],'pok_cancel_individual',$data['arg']);

// Update count.
$count = $count - 1;
Expand All @@ -106,7 +106,7 @@
// Not found? Insert!
if(!$found) {
// Send alarm
alarm($data['id'],$update['callback_query']['from']['id'],'pok_individual',$data['arg']);
$tg_json = alarm($data['id'],$update['callback_query']['from']['id'],'pok_individual',$data['arg']);

// Insert vote.
my_query(
Expand Down Expand Up @@ -168,7 +168,7 @@

require_once(LOGIC_PATH . '/update_raid_poll.php');

$tg_json = update_raid_poll($data['id'], false, $update);
$tg_json = update_raid_poll($data['id'], false, $update, $tg_json);

$tg_json[] = answerCallbackQuery($update['callback_query']['id'], getTranslation('vote_updated'), true);

Expand Down
6 changes: 3 additions & 3 deletions mods/vote_remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
);

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

// Send vote response.
require_once(LOGIC_PATH . '/update_raid_poll.php');

$tg_json = update_raid_poll($data['id'], false, $update);
$tg_json = update_raid_poll($data['id'], false, $update, $tg_json);

$tg_json[] = answerCallbackQuery($update['callback_query']['id'], getTranslation('vote_updated'), true);

Expand Down
9 changes: 6 additions & 3 deletions mods/vote_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// Write to log.
debug_log($answer);

// Telegram JSON array.
$tg_json = array();

// Get status to update
$status = $data['arg'];

Expand Down Expand Up @@ -82,15 +85,15 @@
]];
send_message($update['callback_query']['from']['id'], getTranslation("delete_remote_raid"), $keys);
}
}else {
alarm($data['id'],$update['callback_query']['from']['id'],'status',$status);
}elseif($status != 'arrived') {
$tg_json = alarm($data['id'],$update['callback_query']['from']['id'],'status',$status, $tg_json);
}
}

// Send vote response.
require_once(LOGIC_PATH . '/update_raid_poll.php');

$tg_json = update_raid_poll($data['id'], false, $update);
$tg_json = update_raid_poll($data['id'], false, $update, $tg_json);

$tg_json[] = answerCallbackQuery($update['callback_query']['id'], getTranslation('vote_updated'), true);

Expand Down
4 changes: 2 additions & 2 deletions mods/vote_time.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
AND user_id = {$update['callback_query']['from']['id']}
"
);
alarm($data['id'],$update['callback_query']['from']['id'],'change_time', $attend_time);
$tg_json = alarm($data['id'],$update['callback_query']['from']['id'],'change_time', $attend_time, $tg_json);

// User has not voted before.
} else {
Expand All @@ -122,7 +122,7 @@
'alarm' => ($config->RAID_AUTOMATIC_ALARM ? 1 : 0)
]);
// Send Alarm.
alarm($data['id'],$update['callback_query']['from']['id'],'new_att', $attend_time);
$tg_json = alarm($data['id'],$update['callback_query']['from']['id'],'new_att', $attend_time, $tg_json);

// Enable alerts message. -> only if alert is on
if($config->RAID_AUTOMATIC_ALARM) {
Expand Down
6 changes: 4 additions & 2 deletions mods/vote_want_invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@
}
if($statement_select->rowCount() > 0) {
if($res['want_invite'] == 0) {
alarm($data['id'],$update['callback_query']['from']['id'],'want_invite');
$alarm_action = 'want_invite';
} else {
alarm($data['id'],$update['callback_query']['from']['id'],'no_want_invite');
$alarm_action = 'no_want_invite';
}
// Send vote response.
require_once(LOGIC_PATH . '/update_raid_poll.php');

$tg_json = update_raid_poll($data['id'], false, $update);

$tg_json = alarm($data['id'],$update['callback_query']['from']['id'],$alarm_action, '', $tg_json);

$tg_json[] = answerCallbackQuery($update['callback_query']['id'], getTranslation('vote_updated'), true);

curl_json_multi_request($tg_json);
Expand Down

0 comments on commit d26deb9

Please sign in to comment.