Skip to content

Commit

Permalink
Reworked +extra vote keys
Browse files Browse the repository at this point in the history
- Removed vote +extra players per team and repalced them with one key
- Added an optional key for announcing that a player is inviting someone from outside of the group (alien)
  • Loading branch information
Ninjasoturi committed Aug 12, 2021
1 parent dac2106 commit 9b53394
Show file tree
Hide file tree
Showing 22 changed files with 194 additions and 133 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.223.1
2.1.224.1
4 changes: 2 additions & 2 deletions commands/exreport.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
WHEN a.cancel = FALSE
OR a.raid_done = FALSE THEN
(
a.extra_mystic + a.extra_valor + a.extra_instinct + 1
a.extra_in_person + a.extra_alien + 1
)
ELSE
0
Expand All @@ -45,7 +45,7 @@
WHEN a.cancel = FALSE
OR a.raid_done = FALSE THEN
(
a.extra_mystic + a.extra_valor + a.extra_instinct + 1
a.extra_in_person + a.extra_alien + 1
)
ELSE
0
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.1.223.1",
"VERSION":"2.1.224.1",
"DB_HOST":"localhost",
"DB_NAME":"your_database_name",
"DB_USER":"your_database_user",
Expand Down
1 change: 1 addition & 0 deletions config/defaults-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"RAID_POLL_SHOW_CREATOR":true,
"RAID_POLL_ENABLE_HYPERLINKS_IN_NAMES":true,
"RAID_POLL_SHOW_NICK_OVER_NAME":false,
"RAID_POLL_VOTE_ALIEN":false,
"RAID_ENDED_HIDE_KEYS":false,
"MYSQL_SORT_COLLATE":"",
"RAID_EX_GYM_MARKER":"icon",
Expand Down
4 changes: 3 additions & 1 deletion constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
defined('EMOJI_NO_ALARM') or define('EMOJI_NO_ALARM',iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F515)));
defined('EMOJI_FRIEND') or define('EMOJI_FRIEND', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F91D)));
defined('EMOJI_WANT_INVITE')or define('EMOJI_WANT_INVITE', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F4E5)));

defined('EMOJI_IN_PERSON') or define('EMOJI_IN_PERSON', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F9E1)));
defined('EMOJI_ALIEN') or define('EMOJI_ALIEN', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F47D)));

// Weather Icons.
defined('EMOJI_W_SUNNY') or define('EMOJI_W_SUNNY', iconv('UCS-4LE', 'UTF-8', pack('V', 0x2600)));
defined('EMOJI_W_CLEAR') or define('EMOJI_W_CLEAR', iconv('UCS-4LE', 'UTF-8', pack('V', 0x2728)));
Expand Down
12 changes: 12 additions & 0 deletions lang/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -2903,6 +2903,18 @@
"PL": "TRANSLATE",
"FI": "Uusi osallistuja!"
},
"alert_add_alien_trainer": {
"NL": "TRANSLATE",
"DE": "TRANSLATE",
"EN": "User is inviting a player from outside the group!",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Pelaaja kutsuu kaverin ryhmän ulkopuolelta!"
},
"alert_later": {
"NL": "Late Speler!",
"DE": "Verspäteter Trainer!",
Expand Down
12 changes: 7 additions & 5 deletions logic/alarm.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ function alarm($raid_id_array, $user_id, $action, $info = '')
// Adding a guest
if($action == "extra") {
debug_log('Alarm additional trainer: ' . $info);
$color_old = array('mystic', 'valor', 'instinct');
$color_new = array (TEAM_B, TEAM_R, TEAM_Y);
$color = str_replace($color_old, $color_new, $info);
$icons = ['alien' => EMOJI_ALIEN, 'in_person' => EMOJI_IN_PERSON];

// Sending message
$msg_text = '<b>' . getTranslation('alert_add_trainer', true, $recipient_language) . '</b>' . CR;
if($info == 'alien') {
$msg_text = '<b>' . getTranslation('alert_add_alien_trainer', true, $recipient_language) . '</b>' . CR;
}else {
$msg_text = '<b>' . getTranslation('alert_add_trainer', true, $recipient_language) . '</b>' . CR;
}
$msg_text .= EMOJI_HERE . SP . $gymname . SP . '(' . $raidtimes . ')' . CR;
$msg_text .= EMOJI_SINGLE . SP . $username . SP . '+' . $color . CR;
$msg_text .= EMOJI_SINGLE . SP . $username . SP . '+' . $icons[$info] . CR;
$msg_text .= EMOJI_CLOCK . SP . check_time($attendtime);
$msg_text .= create_traincode_msg($trainercode);
$tg_json[] = sendMessage($answer['user_id'], $msg_text, true);
Expand Down
20 changes: 9 additions & 11 deletions logic/get_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ function get_overview( $active_raids, $chat_title, $chat_username )
$rs_att = my_query(
"
SELECT count(attend_time) AS count,
sum(team = 'mystic' && want_invite = 0) + sum(case when want_invite = 0 then attendance.extra_mystic else 0 end) AS count_mystic,
sum(team = 'valor' && want_invite = 0) + sum(case when want_invite = 0 then attendance.extra_valor else 0 end) AS count_valor,
sum(team = 'instinct' && want_invite = 0) + sum(case when want_invite = 0 then attendance.extra_instinct else 0 end) AS count_instinct,
sum(team IS NULL && want_invite = 0) AS count_no_team,
sum(case when want_invite = 1 then 1+attendance.extra_mystic+extra_instinct+extra_valor else 0 end) AS count_want_invite
sum(want_invite = 0 && remote = 0) + sum(case when want_invite = 0 && remote = 0 then attendance.extra_in_person else 0 end) AS count_in_person,
sum(want_invite = 0 && remote = 1) + sum(case when want_invite = 0 && remote = 1 then attendance.extra_in_person else 0 end) AS count_remote,
sum(case when want_invite = 0 then attendance.extra_alien else 0 end) AS extra_alien,
sum(case when want_invite = 1 then 1 + attendance.extra_in_person else 0 end) AS count_want_invite
FROM (
SELECT DISTINCT attend_time, user_id, extra_mystic, extra_valor, extra_instinct, want_invite
SELECT DISTINCT attend_time, user_id, extra_in_person, extra_alien, remote, want_invite
FROM attendance
WHERE raid_id = {$raid_id}
AND attend_time IS NOT NULL
Expand All @@ -88,11 +87,10 @@ function get_overview( $active_raids, $chat_title, $chat_username )

// Add to message.
if ($att['count'] > 0) {
$msg .= EMOJI_GROUP . '<b> ' . ($att['count_mystic'] + $att['count_valor'] + $att['count_instinct'] + $att['count_no_team'] + $att['count_want_invite']) . '</b> — ';
$msg .= ((($att['count_mystic']) > 0) ? TEAM_B . ($att['count_mystic']) . ' ' : '');
$msg .= ((($att['count_valor']) > 0) ? TEAM_R . ($att['count_valor']) . ' ' : '');
$msg .= ((($att['count_instinct']) > 0) ? TEAM_Y . ($att['count_instinct']) . ' ' : '');
$msg .= (($att['count_no_team'] > 0) ? TEAM_UNKNOWN . $att['count_no_team'] : '');
$msg .= EMOJI_GROUP . '<b> ' . ($att['count_in_person'] + $att['count_remote'] + $att['extra_remote'] + $att['count_want_invite']) . '</b> — ';
$msg .= ((($att['count_in_person']) > 0) ? EMOJI_IN_PERSON . ($att['count_in_person']) . ' ' : '');
$msg .= ((($att['count_remote']) > 0) ? EMOJI_REMOTE . ($att['count_remote']) . ' ' : '');
$msg .= ((($att['extra_alien']) > 0) ? EMOJI_ALIEN . ($att['extra_alien']) . ' ' : '');
$msg .= (($att['count_want_invite'] > 0) ? EMOJI_WANT_INVITE . $att['count_want_invite'] : '');
$msg .= CR;
}
Expand Down
16 changes: 8 additions & 8 deletions logic/get_remote_users_count.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ function get_remote_users_count($raid_id, $user_id, $attend_time = false)
if(!$attend_time) {
// If attend time is not given, get the one user has already voted for from database
$att_sql = "(
SELECT attend_time
FROM attendance
WHERE raid_id = {$raid_id}
AND user_id = {$user_id}
LIMIT 1
)";
SELECT attend_time
FROM attendance
WHERE raid_id = {$raid_id}
AND user_id = {$user_id}
LIMIT 1
)";
}else {
// Use given attend time (needed when voting for new time)
$att_sql = "'{$attend_time}'";
Expand All @@ -28,8 +28,8 @@ function get_remote_users_count($raid_id, $user_id, $attend_time = false)
// Ignore max limit if attend time is 'Anytime'
$rs = my_query(
"
SELECT IF(attend_time = '" . ANYTIME . "', 0, sum(1 + extra_mystic + extra_valor + extra_instinct)) AS remote_users
FROM (SELECT DISTINCT user_id, extra_mystic, extra_valor, extra_instinct, remote, attend_time FROM attendance WHERE remote = 1 AND cancel = 0 AND raid_done = 0) as T
SELECT IF(attend_time = '" . ANYTIME . "', 0, sum(1 + extra_in_person)) AS remote_users
FROM (SELECT DISTINCT user_id, extra_in_person, attend_time FROM attendance WHERE remote = 1 AND cancel = 0 AND raid_done = 0) as T
WHERE attend_time = {$att_sql}
GROUP BY attend_time
"
Expand Down
44 changes: 13 additions & 31 deletions logic/keys_vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,30 @@ function keys_vote($raid)
'callback_data' => $raid['id'] . ':vote_extra:0'
],
[
'text' => '+ ' . TEAM_B,
'callback_data' => $raid['id'] . ':vote_extra:mystic'
'text' => '+ ' . EMOJI_IN_PERSON,
'callback_data' => $raid['id'] . ':vote_extra:in_person'
],
[
'text' => '+ ' . TEAM_R,
'callback_data' => $raid['id'] . ':vote_extra:valor'
],
[
'text' => '+ ' . TEAM_Y,
'callback_data' => $raid['id'] . ':vote_extra:instinct'
'text' => '+ ' . EMOJI_ALIEN,
'callback_data' => $raid['id'] . ':vote_extra:alien'
]
]
];

// Remote Raid Pass key
$button_remote = [
[
[
'text' => EMOJI_REMOTE,
'callback_data' => $raid['id'] . ':vote_remote:0'
]
]
];


if($config->RAID_REMOTEPASS_USERS && ($raid['event_allow_remote'] == null or $raid['event_allow_remote'] != 0)) {
$buttons_extra[0] = array_merge($buttons_extra[0], $button_remote[0]);
$buttons_extra[0][] = [
'text' => EMOJI_REMOTE,
'callback_data' => $raid['id'] . ':vote_remote:0'
];
}

// Want invite key
$button_want_invite = [
[
[
'text' => EMOJI_WANT_INVITE,
'callback_data' => $raid['id'] . ':vote_want_invite:0'
]
]
];

if($config->RAID_WANT_INVITE && ($raid['event_allow_invite'] == null or $raid['event_allow_invite'] != 0)) {
$buttons_extra[0] = array_merge($buttons_extra[0], $button_want_invite[0]);
$buttons_extra[0][] = [
'text' => EMOJI_WANT_INVITE,
'callback_data' => $raid['id'] . ':vote_want_invite:0'
];
}

// Team and level keys.
Expand Down Expand Up @@ -176,7 +159,6 @@ function keys_vote($raid)
];
$buttons_status[0] = array_merge($buttons_refresh[0], $buttons_status[0]);
}

// Get current pokemon
$raid_pokemon_id = $raid['pokemon'];
$raid_pokemon_form_id = $raid['pokemon_form'];
Expand Down Expand Up @@ -587,7 +569,7 @@ function keys_vote($raid)
//debug_log($keys_default);

// Add Ex-Raid Invite button for raid level X
if ($raid_level == 'X') {
if ($raid['event'] == EVENT_ID_EX) {
if($config->RAID_POLL_HIDE_BUTTONS_TEAM_LVL) {
$buttons_extra[0] = array_merge($buttons_extra[0], $button_invite[0]);
} else {
Expand Down
3 changes: 0 additions & 3 deletions logic/raid_edit_raidlevel_keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ function raid_edit_raidlevel_keys($gym_id, $gym_first_letter, $admin_access = [f
// Raid level and action
$raid_level = $level['raid_level'];

// Continue if user doesn't have permission to create ex-raid and raid_level is X
if($raid_level == 'X' && $admin_access[0] === false) continue;

// Add key for pokemon if we have just 1 pokemon for a level
if($level['raid_level_count'] == 1) {
$query_mon = my_query('
Expand Down
2 changes: 1 addition & 1 deletion logic/send_vote_remote_users_limit_reached.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
function send_vote_remote_users_limit_reached($update)
{
// Set the message.
$msg = getPublicTranslation('vote_remote_users_limit_reached');
$msg = getTranslation('vote_remote_users_limit_reached');

// Answer the callback.
answerCallbackQuery($update['callback_query']['id'], $msg);
Expand Down
Loading

0 comments on commit 9b53394

Please sign in to comment.