From 7260075c15ddb236c4cbd5863376b32838c3815f Mon Sep 17 00:00:00 2001 From: d4NY0 Date: Tue, 15 Aug 2017 19:31:39 +0200 Subject: [PATCH 001/225] first cleanup (unfinished) --- .gitignore | 2 + commands/gym.php | 95 ++++--- commands/help.php | 18 +- commands/list.php | 4 +- commands/raid.php | 24 +- commands/sethelp.php | 25 -- commands/start.php | 2 +- commands/team.php | 4 +- config.php.example | 9 + config.php.php.example | 11 - constants.php | 55 ++-- create_diff | 9 - debug.php | 43 ++- functions.php | 529 +++++++++++++++++------------------ geo_api.php | 125 +++++---- index.php | 226 +++++++++------ logic.php | 578 +++++++++++++++++++++++++++------------ modules/join.php | 10 - modules/raid_create.php | 5 +- modules/vote_arrived.php | 10 +- modules/vote_cancel.php | 4 +- modules/vote_done.php | 2 +- raid-pokemon-bot.sql | 6 - webhook.html | 38 +++ 24 files changed, 1062 insertions(+), 772 deletions(-) create mode 100644 .gitignore delete mode 100644 commands/sethelp.php create mode 100644 config.php.example delete mode 100644 config.php.php.example delete mode 100755 create_diff delete mode 100644 modules/join.php create mode 100644 webhook.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..094695b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.idea +config.php diff --git a/commands/gym.php b/commands/gym.php index a17ae23..10d5fbd 100644 --- a/commands/gym.php +++ b/commands/gym.php @@ -1,44 +1,55 @@ real_escape_string($gym_name).'" WHERE user_id='.$update['message']['from']['id'].' ORDER BY id DESC LIMIT 1'; - my_query($query); - - sendMessage('none',$update['message']['chat']['id'],'Gym name updated'); - - } else { - if ($update['message']['reply_to_message']['text']) { - $lines = explode(CR,$update['message']['reply_to_message']['text']); - $last_line = array_pop($lines); - $pos = strpos($last_line, 'ID = '); - $id = intval(trim(substr($last_line,$pos+5))); - debug_log('Gym ID='.$id.' name='.$gym_name); - - $query = 'SELECT COUNT(*) FROM users WHERE user_id='.$update['message']['from']['id'].' AND moderator=1'; - $rs = my_query($query); - $row = $rs->fetch_row(); - $q = ' AND user_id='.$update['message']['from']['id']; - if ($row[0]) $q = ''; - - $query = 'UPDATE raids SET gym_name="'.$db->real_escape_string($gym_name).'" WHERE id='.$id.' '.$q; - my_query($query); - - $rs = my_query('SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) as ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE id='.$id.''); - $raid = $rs->fetch_assoc(); - - $text = show_raid_poll($raid); - $keys = keys_vote($raid); - - editMessageText($update['message']['reply_to_message']['message_id'], $text, $keys, $update['message']['chat']['id']); - } - } - - exit; +$gym_name = trim(substr($update['message']['text'], 4)); + +// Write to log. +debug_log('SET gym name to ' . $gym_name); + +if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { + + $query = 'UPDATE raids SET gym_name="' . $db->real_escape_string($gym_name) . '" WHERE user_id=' . $update['message']['from']['id'] . ' ORDER BY id DESC LIMIT 1'; + my_query($query); + + sendMessage($update['message']['chat']['id'],'Gym name updated'); + +} else { + if ($update['message']['reply_to_message']['text']) { + $lines = explode(CR, $update['message']['reply_to_message']['text']); + $last_line = array_pop($lines); + $pos = strpos($last_line, 'ID = '); + $id = intval(trim(substr($last_line, $pos+5))); + debug_log('Gym ID=' . $id . ' name=' . $gym_name); + + $query = 'SELECT COUNT(*) FROM users WHERE user_id=' . $update['message']['from']['id'] . ' AND moderator=1'; + $rs = my_query($query); + + $row = $rs->fetch_row(); + $q = ' AND user_id=' . $update['message']['from']['id']; + if ($row[0]) { + $q = ''; + } + + $query = 'UPDATE raids SET gym_name="' . $db->real_escape_string($gym_name) . '" WHERE id=' . $id . ' ' . $q; + my_query($query); + + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$id} + " + ); + + $raid = $rs->fetch_assoc(); + + $text = show_raid_poll($raid); + $keys = keys_vote($raid); + + editMessageText($update['message']['reply_to_message']['message_id'], $text, $keys, $update['message']['chat']['id']); + } +} + +exit; diff --git a/commands/help.php b/commands/help.php index edc3cb3..d9867fc 100644 --- a/commands/help.php +++ b/commands/help.php @@ -1,8 +1,16 @@ fetch_assoc(); - if (!$row) exit; - - sendMessage('none',$update['message']['from']['id'],$row['message']); + $msg = ' +EN Guide on how to create a raid poll raid bot +1) make sure the raid hasn\'t been posted yet in the chat +2) check how much time is left for the raid +3) open new PM with @RaidPokemonBot +4) send your location to the bot (make sure you send the location of where the gym is located) +5) choose the type of raid boss and the time left +6) to ensure an easier way to locate the gym in game/chat, it\'s recommended to use the bot function /gym (name of the gym and/or description of it) +7) press share and choose yourRaid channel +8) wait until the option with the boss name appears and select it +'; + $msg = 'This is a private bot.'; + sendMessage($update['message']['from']['id'], $msg); \ No newline at end of file diff --git a/commands/list.php b/commands/list.php index 3257f40..cecb331 100644 --- a/commands/list.php +++ b/commands/list.php @@ -6,7 +6,7 @@ $rs = my_query($q); $row = $rs->fetch_assoc(); if (!$row) { - sendMessage('none',$update['message']['from']['id'],'Can\'t determine your location, please participate in at least 1 raid'); + sendMessage($update['message']['from']['id'],'Can\'t determine your location, please participate in at least 1 raid'); exit; } @@ -23,7 +23,7 @@ 'text' => 'Expand', 'callback_data' => $raid['id'].':vote_refresh:0', ]]]; $msg = show_raid_poll_small($raid); - send_message('none',$update['message']['from']['id'],$msg, $keys, + send_message($update['message']['from']['id'],$msg, $keys, ['reply_markup' => ['selective'=>true, 'one_time_keyboard'=>true]] ); } diff --git a/commands/raid.php b/commands/raid.php index 72dc6e4..6b180d7 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -2,13 +2,13 @@ $gym_data = trim(substr($update['message']['text'],5)); - $data = explode(',',$gym_data,5); + $data = explode(',',$gym_data,6); - if (count($data)<5) { - send_message('none',$update['message']['chat']['id'],'Invalid input',[]); + if (count($data)<6) { + send_message($update['message']['chat']['id'],'Invalid input',[]); exit; } - + $query = 'UPDATE raids SET gym_name="'.$db->real_escape_string($gym_name).'" WHERE user_id='.$update['message']['from']['id'].' ORDER BY id DESC LIMIT 1'; $lat = floatval($data[1]); $lon = floatval($data[2]); @@ -18,21 +18,15 @@ $tz = get_timezone($lat, $lon); $addr = get_address($lat, $lon); - $end_time = 'DATE_ADD(first_seen, INTERVAL '.$data[3].' MINUTE)'; - if (strpos($data[3],':')) { - $dt = new DateTime($data[3]); - $dt->setTimeZone(new DateTimeZone($tz)); - $end_time = '"'.$dt->format('Y-m-d H:i:s').'"'; - } - $q = 'INSERT INTO raids SET pokemon="'.$db->real_escape_string($data[0]).'", user_id='.$update['message']['from']['id'].', lat="'.$lat.'", lon="'.$lon.'", first_seen=NOW(), - end_time='.$end_time.', - gym_name="'.$db->real_escape_string($data[4]).'" + end_time=DATE_ADD(first_seen, INTERVAL '.$data[3].' MINUTE), + gym_team="'.$db->real_escape_string($data[4]).'", + gym_name="'.$db->real_escape_string($data[5]).'" '; if ($tz!==false) { @@ -64,13 +58,13 @@ 'text'=>'Share','switch_inline_query'=>strval($id), ]]]; - send_message('none',$update['message']['chat']['id'],$text, $keys); + send_message($update['message']['chat']['id'],$text, $keys); } else { $reply_to = $update['message']['chat']['id']; if ($update['message']['reply_to_message']['message_id']) $reply_to = $update['message']['reply_to_message']['message_id']; - send_message('none',$update['message']['chat']['id'],$text, $keys, + send_message($update['message']['chat']['id'],$text, $keys, ['reply_to_message_id'=>$reply_to, 'reply_markup' => ['selective'=>true, 'one_time_keyboard'=>true]] ); } diff --git a/commands/sethelp.php b/commands/sethelp.php deleted file mode 100644 index 831bc93..0000000 --- a/commands/sethelp.php +++ /dev/null @@ -1,25 +0,0 @@ -fetch_row(); - if (!$row[0]) { - $msg = 'Not allowed'; - sendMessage('none',$update['message']['from']['id'],$msg); - exit; - } - - - if (!$update['message']['reply_to_message']['text']) { - $msg = 'Please reply-to message that you want to set as help text'; - sendMessage('none',$update['message']['from']['id'],$msg); - exit; - } - - $help = $db->real_escape_string($update['message']['reply_to_message']['text']); - - my_query('INSERT INTO help SET id='.$update['message']['chat']['id'].', message="'.$help.'" ON DUPLICATE KEY update message="'.$help.'"'); - - $msg = 'Help text set'; - sendMessage('none',$update['message']['chat']['id'],$msg); - exit; diff --git a/commands/start.php b/commands/start.php index 041bbb0..db5d1dc 100644 --- a/commands/start.php +++ b/commands/start.php @@ -1,3 +1,3 @@ Please send location to start Raid announce '); + sendMessage($update['message']['chat']['id'],'Please send location to start Raid announce '); diff --git a/commands/team.php b/commands/team.php index 40af24a..585a0eb 100644 --- a/commands/team.php +++ b/commands/team.php @@ -18,9 +18,9 @@ $query = 'UPDATE raids SET gym_team="'.$teams[$gym_team].'" WHERE user_id='.$update['message']['from']['id'].' ORDER BY id DESC LIMIT 1'; my_query($query); - sendMessage('none',$update['message']['chat']['id'],'Gym team set to '.ucfirst($teams[$gym_team])); + sendMessage($update['message']['chat']['id'],'Gym team set to '.ucfirst($teams[$gym_team])); } else { - sendMessage('none',$update['message']['chat']['id'],'Invalid team name - type Mystic, Valor, Instinct or Blue, Red, Yellow'); + sendMessage($update['message']['chat']['id'],'Invalid team name - type Mystic, Valor, Instinct or Blue, Red, Yellow'); } \ No newline at end of file diff --git a/config.php.example b/config.php.example new file mode 100644 index 0000000..01ff278 --- /dev/null +++ b/config.php.example @@ -0,0 +1,9 @@ + TEAM_B, - 'valor' => TEAM_R, - 'instinct' => TEAM_Y, - 'unknown' => TEAM_UNKNOWN, - 'cancel' => TEAM_CANCEL, + 'mystic' => TEAM_B, + 'valor' => TEAM_R, + 'instinct' => TEAM_Y, + 'unknown' => TEAM_UNKNOWN, + 'cancel' => TEAM_CANCEL ); $pokemon = array( '5' => array( - 'Articuno', + 'Arktos', 'Lugia', - 'Moltres', + 'Lavados', 'Zapdos', ), '4' => array( - 'Tyranitar', - 'Snorlax', + 'Despotar', + 'Relaxo', 'Lapras', - 'Rhydon', - 'Charizard', - 'Venusaur', - 'Blastoise', + 'Rizeros', + 'Glurak', + 'Bisasflor', + 'Turtok', ), '3' => array( 'Machamp', @@ -53,7 +44,7 @@ 'Alakazam', 'Arcanine', 'Gengar', - ), + ) ); diff --git a/create_diff b/create_diff deleted file mode 100755 index 87cf318..0000000 --- a/create_diff +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -PROJ=_pogo-raid-bot - -git diff --ignore-space-change -U10 --no-prefix > $PROJ.diff -git status > $PROJ.files.diff -chmod 0666 $PROJ.diff -chmod 0666 $PROJ.files.diff -/usr/bin/mcedit $PROJ.diff diff --git a/debug.php b/debug.php index 365a4b9..1a320bf 100644 --- a/debug.php +++ b/debug.php @@ -1,42 +1,55 @@ insert_id; } +/** + * Get db query. + * @param $query + * @return bool|mysqli_result + */ function my_query($query) { global $db; + debug_log($query, '?'); + $res = $db->query($query); + if ($db->error) { - debug_log($db->error,'!'); + debug_log($db->error, '!'); } + return $res; } +/** + * Write debug log. + * @param $val + * @param string $type + */ function debug_log($val, $type = '*') { $date = @date('Y-m-d H:i:s'); $usec = microtime(true); - $date = $date.'.'.str_pad(substr($usec,11,4),4,'0',STR_PAD_RIGHT); + $date = $date . '.' . str_pad(substr($usec, 11, 4), 4, '0', STR_PAD_RIGHT); $bt = debug_backtrace(); $bl = ''; - while($btl=array_shift($bt)) { - if ($btl['function']==__FUNCTION__) continue; - $bl = '['.basename($btl['file']).':'.$btl['line'].'] '; + + while($btl = array_shift($bt)) { + if ($btl['function'] == __FUNCTION__) continue; + $bl = '[' . basename($btl['file']) . ':' . $btl['line'] . '] '; break; } - - - - if (gettype($val)!='string') $val = var_export($val,1); + + if (gettype($val) != 'string') $val = var_export($val, 1); $rows = explode("\n", $val); foreach ($rows as $v) { - error_log('['.$date.']['.getmypid().'] '.$bl.$type.' '.$v."\n",3,CONFIG_LOGFILE); + error_log('[' . $date . '][' . getmypid() . '] ' . $bl . $type . ' ' . $v . "\n", 3, CONFIG_LOGFILE); } -} - - - +} \ No newline at end of file diff --git a/functions.php b/functions.php index 56623d0..8f7a9ff 100644 --- a/functions.php +++ b/functions.php @@ -1,142 +1,55 @@ $value) { - $user_count = count($value); - if($user_count>1000000000000) $current_number = round(($user_count/1000000000000),1).' T'; - else if($user_count>1000000000) $current_number = round(($user_count/1000000000),1).' B'; - else if($user_count>1000000) $current_number = round(($user_count/1000000),1).' M'; - else if($user_count>1000) $current_number = round(($user_count/1000),1).' K'; - else $current_number = $user_count; - $inline_keyboard[][] = [ - 'text' => $key.' - '.$current_number, - 'callback_data' => $val['chat_id'].':'.$val['id'].':'.$key, - ]; - - $text .= "\n$key [$current_number]\n"; - foreach ($value as $id => $name) $text .= '└ '.$name."\n"; - } - } else if ($anony == 'y') { - $text .= "\n"; - foreach ($poll_votes[$type] as $key => $value) { - $user_count = count($value); - if($user_count>1000000000000) $current_number = round(($user_count/1000000000000),1).' T'; - else if($user_count>1000000000) $current_number = round(($user_count/1000000000),1).' B'; - else if($user_count>1000000) $current_number = round(($user_count/1000000),1).' M'; - else if($user_count>1000) $current_number = round(($user_count/1000),1).' K'; - else $current_number = $user_count; - $inline_keyboard[][] = [ - 'text' => $key.' - '.$current_number, - 'callback_data' => $val['chat_id'].':'.$val['id'].':'.$key, - ]; - - $text .= "\n$key [$current_number]\n"; - } - } - return ['text' => $text,'inline_keyboard' => $inline_keyboard]; -} - -function generate_markup($type,$anony) { - debug_log('Type='.$type); - debug_log('anony='.$anony); - $inline_keyboard = [ - [ - [ - 'text' => 'Vote'.($type == 'vote' ? ' ✅':''), - 'callback_data' => 'comm:vote', - ], - [ - 'text' => 'Doodle'.($type == 'doodle' ? ' ✅':''), - 'callback_data' => 'comm:doodle', - ], - ], - [ - [ - 'text' => 'Anonymous'.($anony == 'y' ? ' ✅':''), - 'callback_data' => 'comm:anony', - ], - [ - 'text' => 'Identified Users'.($anony == 'n' ? ' ✅':''), - 'callback_data' => 'comm:noanony', - ] - ], - ]; - return $inline_keyboard; -} - -function sendMessage($sampletext,$chat_id,$val = array()) { - switch ($sampletext) { - case 'start': - debug_log($val); - $text = "Hello\nI can help you organize stuff in group chats\nFirst, send me the question and select the poll type with the buttons below.\n"; - $inline_keyboard = generate_markup($val['type'],$val['anony']); - debug_log($inline_keyboard); - break; - case 'enter_first': - $text = "Okay\nNow send me the first vote option"; - break; - case 'enter_more': - $text = "Got it\nKeep sending more vote options or hit /done to publish the poll"; - break; - case 'done': - $message = generate_poll_message($val,false); - $text = $message['text']; - $inline_keyboard = $message['inline_keyboard']; - break; - case 'wrong': - $text = "Unrecognized command\nYou may now correct that or make a new poll using /start ..."; - case 'none': - $text = $val; - break; - } +/** + * Send message. + * @param $chat_id + * @param array $text + */ +function sendMessage($chat_id, $text = array()) { + // Create response content array. $reply_content = [ - 'method' => 'sendMessage', - 'chat_id' => $chat_id, - 'parse_mode' => 'HTML', - 'text' => $text, + 'method' => 'sendMessage', + 'chat_id' => $chat_id, + 'parse_mode' => 'HTML', + 'text' => $text ]; if (isset($inline_keyboard)) { $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; } + // Encode data to json. $reply_json = json_encode($reply_content); + // Set header to json. header('Content-Type: application/json'); + + // Write to log. debug_log($reply_json,'>'); + + // Send request to telegram api. curl_json_request($reply_json); } -function send_message($sampletext, $chat_id, $val = array(), $inline_keyboard = false, $merge_args = []) { - switch ($sampletext) { - case 'none': - $text = $val; - break; - } +/** + * Send message. + * @param $chat_id + * @param array $text + * @param mixed $inline_keyboard + * @param array $merge_args + */ +function send_message($chat_id, $text = array(), $inline_keyboard = false, $merge_args = []) { + // Create response content array. $reply_content = [ - 'method' => 'sendMessage', - 'chat_id' => $chat_id, + 'method' => 'sendMessage', + 'chat_id' => $chat_id, 'parse_mode' => 'HTML', - 'text' => $text, + 'text' => $text ]; - + + // Write to log. debug_log('KEYS'); debug_log($inline_keyboard); + if (isset($inline_keyboard)) { $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; } @@ -144,262 +57,330 @@ function send_message($sampletext, $chat_id, $val = array(), $inline_keyboard = if (is_array($merge_args) && count($merge_args)) { $reply_content = array_merge_recursive($reply_content, $merge_args); } - + // Encode data to json. $reply_json = json_encode($reply_content); + // Set header to json. header('Content-Type: application/json'); + + // Write to log. debug_log($reply_json,'>'); + + // Send request to telegram api. curl_json_request($reply_json); } -function send_location($sampletext, $chat_id, $lat, $lon, $inline_keyboard = false) { - switch ($sampletext) { - case 'none': - $text = $val; - break; - } +/** + * Send location. + * @param $chat_id + * @param $lat + * @param $lon + * @param bool $inline_keyboard + * @return mixed + */ +function send_location($chat_id, $lat, $lon, $inline_keyboard = false) { + // Create reply content array. $reply_content = [ - 'method' => 'sendLocation', - 'chat_id' => $chat_id, - 'latitude' => $lat, - 'longitude' => $lon, + 'method' => 'sendLocation', + 'chat_id' => $chat_id, + 'latitude' => $lat, + 'longitude' => $lon ]; - + + // Write to log. debug_log('KEYS'); debug_log($inline_keyboard); + if (is_array($inline_keyboard)) { $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; } + // Encode data to json. $reply_json = json_encode($reply_content); + // Set header to json. header('Content-Type: application/json'); - debug_log($reply_json,'>'); - $resp = curl_json_request($reply_json); - return $resp; -} + // Write to log. + debug_log($reply_json, '>'); -function sendMessageEcho($sampletext,$chat_id,$val) { - $text = $val; - + // Send request to telegram api and return response. + return curl_json_request($reply_json); +} + +/** + * Echo message. + * @param $chat_id + * @param $text + */ +function sendMessageEcho($chat_id, $text) { + // Create reply content array. $reply_content = [ - 'method' => 'sendMessage', - 'chat_id' => $chat_id, - 'parse_mode' => 'HTML', - 'text' => $text, + 'method' => 'sendMessage', + 'chat_id' => $chat_id, + 'parse_mode' => 'HTML', + 'text' => $text ]; + // Encode data to json. $reply_json = json_encode($reply_content); + + // Set header to json. header('Content-Type: application/json'); - debug_log($reply_json,'>'); - echo($reply_json); -} + // Write to log. + debug_log($reply_json, '>'); + // Echo json. + echo($reply_json); +} -function answerCallbackQuery($query_id,$val) { - $text = $val; - $response = [ - 'method' => 'answerCallbackQuery', +/** + * Answer callback query. + * @param $query_id + * @param $text + */ +function answerCallbackQuery($query_id, $text) { + // Create response array. + $response = [ + 'method' => 'answerCallbackQuery', 'callback_query_id' => $query_id, - 'text' => $text, + 'text' => $text ]; - $json_response = json_encode($response); - header('Content-Type: application/json'); - debug_log($json_response,'>'); - curl_json_request($json_response); -} -function answerInlineQuery($query_id,$contents) { - $results = array(); - foreach ($contents as $key => $row) { - //$message = generate_poll_message($row,true); - //$poll = json_decode($row['poll_votes'],true); - //$desc = array_keys($poll)[0].' '.$row['anony'] == 'y' ? 'Anonymous ' : 'Personal '; - //foreach ($poll[array_keys($poll)[0]] as $name => $users) $desc.=$name.', '; - $text = ucfirst($row['pokemon']).' '.substr($row['end_time'],11,5); - $inline_keyboard = [[[]]]; - $input_message_content = [ - 'parse_mode' => 'HTML', - 'message_text' => $text, - 'disable_web_page_preview' => true, - ]; - $results[] = [ - 'type' => 'article', - 'id' => $query_id.$key, - 'title' => ucfirst($row['pokemon']), - 'description' => strval(substr($row['end_time'],11,5)), - 'input_message_content' => $input_message_content, - 'reply_markup' => ['inline_keyboard' => $inline_keyboard], - ]; - } - - - $reply_content = [ - 'method' => 'answerInlineQuery', - 'inline_query_id' => $query_id, - 'results' => $results, - ]; - - debug_log($reply_content,'>'); - curl_json_request(json_encode($reply_content)); + // Encode response to json format. + $json_response = json_encode($response); + + // Set header to json. + header('Content-Type: application/json'); + + // Write to log. + debug_log($json_response, '>'); + + // Send request to telegram api. + curl_json_request($json_response); } +/** + * Answer inline query. + * @param $query_id + * @param $contents + */ +function answerInlineQuery($query_id, $contents) { + // Init empty result array. + $results = array(); -function answer_inline_query($query_id,$contents) { - $results = array(); + // For each content. foreach ($contents as $key => $row) { + // Get raid poll. $text = show_raid_poll($row); - - - //$inline_keyboard = [keys_raid_people($row['id'])]; - $inline_keyboard = keys_vote($row); - $input_message_content = [ - 'parse_mode' => 'HTML', - 'message_text' => $text, - 'disable_web_page_preview' => true, + + // Get inline keyboard. + $inline_keyboard = keys_vote($row); + + // Create input message content array. + $input_message_content = [ + 'parse_mode' => 'HTML', + 'message_text' => $text, + 'disable_web_page_preview' => true ]; + // Fill results array. $results[] = [ - 'type' => 'article', - 'id' => $query_id.$key, - 'title' => ucfirst($row['pokemon']).' '.unix2tz($row['ts_end'], $row['timezone']), - 'description' => strval($row['gym_name']), + 'type' => 'article', + 'id' => $query_id . $key, + 'title' => ucfirst($row['pokemon']) . ' ' . unix2tz($row['ts_end'], $row['timezone']), + 'description' => strval($row['gym_name']), 'input_message_content' => $input_message_content, - 'reply_markup' => ['inline_keyboard' => $inline_keyboard], - ]; - -/* - $results[] = [ - 'id' => $row['id'], - 'type' => 'location', - 'latitude' => floatval($row['lat']), - 'longitude' => floatval($row['lon']), - 'title' => $input_message_content['message_text'], - 'reply_markup' => ['inline_keyboard' => $inline_keyboard], + 'reply_markup' => [ + 'inline_keyboard' => $inline_keyboard + ] ]; -*/ } - - + + // Create reply content array. $reply_content = [ - 'method' => 'answerInlineQuery', + 'method' => 'answerInlineQuery', 'inline_query_id' => $query_id, - 'is_personal' => true, - 'cache_time' => 10, - 'results' => $results, + 'is_personal' => true, + 'cache_time' => 10, + 'results' => $results ]; - - $ret = curl_json_request(json_encode($reply_content)); -} + // Encode to json and send request to telegram api. + curl_json_request(json_encode($reply_content)); +} -function editMessageText($id_val,$text_val,$markup_val,$chat_id = NULL, $merge_args = false) { - $response = [ - 'method' => 'editMessageText', - 'text' => $text_val, - 'parse_mode' => 'HTML', - 'reply_markup' => ['inline_keyboard' => $markup_val], +/** + * Edit message text. + * @param $id_val + * @param $text_val + * @param $markup_val + * @param null $chat_id + * @param bool $merge_args + */ +function editMessageText($id_val, $text_val, $markup_val, $chat_id = NULL, $merge_args = false) { + // Create response array. + $response = [ + 'method' => 'editMessageText', + 'text' => $text_val, + 'parse_mode' => 'HTML', + 'reply_markup' => [ + 'inline_keyboard' => $markup_val + ] ]; - if ($markup_val==false) { + if ($markup_val == false) { unset($response['reply_markup']); $response['remove_keyboard'] = true; } - + + // Valid chat id. if ($chat_id != null) { - $response['chat_id'] = $chat_id; + $response['chat_id'] = $chat_id; $response['message_id'] = $id_val; } else { $response['inline_message_id'] = $id_val; } - - debug_log($merge_args,'K'); - debug_log($response,'K'); + + // Write to log. + debug_log($merge_args, 'K'); + debug_log($response, 'K'); + if (is_array($merge_args) && count($merge_args)) { $response = array_merge_recursive($response, $merge_args); } + // Write to log. debug_log($response,'K'); - + + // Encode response to json format. $json_response = json_encode($response); - debug_log($response,'->'); + + // Write to log. + debug_log($response,'<-'); + + // Send request to telegram api. curl_json_request($json_response); } -function editMessageReplyMarkup($id_val,$markup_val,$chat_id) { - $response = [ - 'method' => 'editMessageReplyMarkup', - 'reply_markup' => ['inline_keyboard' => $markup_val], +/** + * Edit message reply markup. + * @param $id_val + * @param $markup_val + * @param $chat_id + */ +function editMessageReplyMarkup($id_val, $markup_val, $chat_id) { + // Create response array. + $response = [ + 'method' => 'editMessageReplyMarkup', + 'reply_markup' => [ + 'inline_keyboard' => $markup_val + ] ]; - + + // Valid chat id. if ($chat_id != null) { $response['chat_id'] = $chat_id; $response['message_id'] = $id_val; + } else { $response['inline_message_id'] = $id_val; } - + + // Encode response to json format. $json_response = json_encode($response); + + // Write to log. debug_log($response,'->'); - curl_json_request($json_response); + + // Send request to telegram api. + curl_json_request($json_response); } -function edit_message_keyboard($id_val,$markup_val,$chat_id) { - $response = [ - 'method' => 'editMessageReplyMarkup', - 'reply_markup' => ['inline_keyboard' => $markup_val], +/** + * Edit message keyboard. + * @param $id_val + * @param $markup_val + * @param $chat_id + */ +function edit_message_keyboard($id_val, $markup_val, $chat_id) { + // Create response array. + $response = [ + 'method' => 'editMessageReplyMarkup', + 'reply_markup' => [ + 'inline_keyboard' => $markup_val + ] ]; - if ($chat_id != null) { - $response['chat_id'] = $chat_id; + // Valid chat id. + if ($chat_id != null) { + $response['chat_id'] = $chat_id; $response['message_id'] = $id_val; + } else { $response['inline_message_id'] = $id_val; } - + + // Encode response to json format. $json_response = json_encode($response); + + // Write to log. debug_log($response,'->'); + + // Send request to telegram api. curl_json_request($json_response); } +/** + * Edit message. + * @param $update + * @param $message + * @param $keys + * @param bool $merge_args + */ function edit_message($update, $message, $keys, $merge_args = false) { - if (isset($update['callback_query']['inline_message_id'])) { - editMessageText($update['callback_query']['inline_message_id'],$message, $keys, NULL, $merge_args); + if (isset($update['callback_query']['inline_message_id'])) { + editMessageText($update['callback_query']['inline_message_id'], $message, $keys, NULL, $merge_args); } else { - editMessageText($update['callback_query']['message']['message_id'],$message,$keys,$update['callback_query']['message']['chat']['id'], $merge_args); + editMessageText($update['callback_query']['message']['message_id'], $message, $keys, $update['callback_query']['message']['chat']['id'], $merge_args); } } - -function typing($chat_id) { - $response = [ - 'method' => 'sendChatAction', - 'chat_id' => $chat_id, - 'action' => 'typing', - ]; - $json_response = json_encode($response); - debug_log($response,'->'); - curl_json_request($json_response); -} - +/** + * Send request to telegram api. + * @param $json + * @return mixed + */ function curl_json_request($json) { - $curl = curl_init('https://api.telegram.org/bot'.API_KEY.'/'); + + $curl = curl_init('https://api.telegram.org/bot' . API_KEY . '/'); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, - array("Content-type: application/json")); + curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json")); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); - debug_log($json,'->'); + // Write to log. + debug_log($json, '->'); + + // Execute curl request. $json_response = curl_exec($curl); - debug_log($json_response,'<-'); - $response = json_decode($json_response,true); - if ($response['ok']!=true || isset($response['update_id'])) debug_log('ERROR: '.$json."\n\n".$json_response."\n\n"); + + // Write to log. + debug_log($json_response, '<-'); + + // Decode json response. + $response = json_decode($json_response, true); + + // Validate response. + if ($response['ok'] != true || isset($response['update_id'])) { + // Write error to log. + debug_log('ERROR: ' . $json . "\n\n" . $json_response . "\n\n"); + } + + // Return response. return $response; } - diff --git a/geo_api.php b/geo_api.php index f735f49..f6221f6 100644 --- a/geo_api.php +++ b/geo_api.php @@ -1,55 +1,80 @@ '); - $json_response = curl_exec($curl); - debug_log($json_response,''); - $json_response = curl_exec($curl); - debug_log($json_response,''); + $json_response = curl_exec($curl); + debug_log($json_response,''); + + $json_response = curl_exec($curl); + + debug_log($json_response, 'connect_errno) { - debug_log("Failed to connect to Database!".$db->connect_error(), '!'); - sendMessage('none',$update['message']['chat']['id'],"Failed to connect to Database!\nPlease contact ".MAINTAINER." and forward this message...\n"); - } - - update_user($update); - if (isset($update['callback_query'])) { - if ($update['callback_query']['data']) { - $d = explode(':', $update['callback_query']['data']); - $data['id'] = $d[0]; - $data['action'] = $d[1]; - $data['arg'] = $d[2]; - } - debug_log('DATA='); - debug_log($data); - - $module = 'modules/'.basename($data['action']).'.php'; - debug_log($module); - if (file_exists($module)) { - include_once($module); - exit; - } else { - debug_log('No action'); - } - - - } else if (isset($update['inline_query'])){ - /* INLINE - LIST POLLS */ - raid_list($update); - exit; - } else if (isset($update['message']['location'])) { - include_once('modules/raid_create.php'); - exit(); - - } else if (isset($update['message']['new_chat_member'])) { - include_once('modules/join.php'); - exit(); - - } else if (isset($update['message'])) { - if (substr($update['message']['text'],0,1) == '/') { - $command = strtolower(str_replace('/','',str_replace(BOT_NAME,'',explode(' ',$update['message']['text'])[0]))); - $module = 'commands/'.basename($command).'.php'; - debug_log($module); - - if (file_exists($module)) { - include_once($module); - exit; - } - - sendMessage('none',$update['message']['chat']['id'],'Please send location to start Raid announce '); - } - } +// Get current unix timestamp as float. +$start = microtime(true); + +// Include files. +require_once('config.php'); +require_once('debug.php'); +require_once('constants.php'); +require_once('functions.php'); +require_once('logic.php'); +require_once('geo_api.php'); + +// Get api key from get parameters. +$apiKey = $_GET['apikey']; + +// Check if hashed api key is matching config. +if (hash('sha512', $apiKey) == CONFIG_HASH) { + // Split the api key. + $splitKey = explode(':', $apiKey); + + // Set constants. + define('API_KEY', $apiKey); + define('BOT_ID', $splitKey[0]); + define('BOT_KEY', $splitKey[1]); + +// Api key is wrong! +} else { + // Echo data. + sendMessageEcho(MAINTAINER_ID, $_SERVER['REMOTE_ADDR'] . ' ' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ' ' . $apiKey); + // And exit script. + exit(); +} + +// Get content from POST data. +$content = file_get_contents('php://input'); + +// Decode the json string. +$update = json_decode($content, true); + +// Update var is false. +if (!$update) { + // Write to log. + debug_log($content, '!'); + +} else { + // Write to log. + debug_log($update,'<'); +} + +// Init command. +$command = NULL; + +// Establish mysql connection. +$db = new mysqli('localhost', BOT_ID, BOT_KEY, BOT_ID); + +// Error connecting to db. +if ($db->connect_errno) { + // Write connection error to log. + debug_log("Failed to connect to Database!" . $db->connect_error(), '!'); + // Echo data. + sendMessage($update['message']['chat']['id'], "Failed to connect to Database!\nPlease contact " . MAINTAINER . " and forward this message...\n"); +} + +// Update the user. +update_user($update); + +// Callback query received. +if (isset($update['callback_query'])) { + // Init empty data array. + $data = array(); + + // Callback data found. + if ($update['callback_query']['data']) { + // Split callback data and assign to data array. + $splitData = explode(':', $update['callback_query']['data']); + $data['id'] = $splitData[0]; + $data['action'] = $splitData[1]; + $data['arg'] = $splitData[2]; + } + + // Write data to log. + debug_log('DATA='); + debug_log($data); + + // Set module path by sent action name. + $module = 'modules/' . basename($data['action']) . '.php'; + + // Write module to log. + debug_log($module); + + // Check if the module file exists. + if (file_exists($module)) { + // Dynamically include module file and exit. + include_once($module); + exit(); + + // Module file is missing. + } else { + // Write to log. + debug_log('No action'); + } + +// Inline query received. +} else if (isset($update['inline_query'])) { + // List polls and exit. + raid_list($update); + exit(); + +// Location received. +} else if (isset($update['message']['location'])) { + // Create raid and exit. + include_once('modules/raid_create.php'); + exit(); + +// Message is required to check for commands. +} else if (isset($update['message'])) { + // Check message text for a leading slash. + if (substr($update['message']['text'], 0, 1) == '/') { + // Get command name. + $com = strtolower(str_replace('/', '', str_replace(BOT_NAME, '', explode(' ', $update['message']['text'])[0]))); + + // Set command path. + $command = 'commands/' . basename($com) . '.php'; + + // Write to log. + debug_log($command); + + // Check if command file exits. + if (file_exists($command)) { + // Dynamically include command file and exit. + include_once($command); + exit(); + } + + // Echo bot response. + sendMessage($update['message']['chat']['id'], 'Please send location to start Raid announce'); + } +} diff --git a/logic.php b/logic.php index 341bfe7..bf95ff5 100644 --- a/logic.php +++ b/logic.php @@ -1,29 +1,43 @@ -fetch_assoc(); - if ($update['callback_query']['from']['id']!=$raid['user_id']) { - $query = 'SELECT COUNT(*) FROM users WHERE user_id='.$update['callback_query']['from']['id'].' AND moderator=1'; + + if ($update['callback_query']['from']['id'] != $raid['user_id']) { + $query = "SELECT COUNT(*) FROM users WHERE user_id={$update['callback_query']['from']['id']} AND moderator=1"; $rs = my_query($query); $row = $rs->fetch_row(); - if ($row['0']) return true; - $callback_response = 'You are not allowed to edit this raid'; - answerCallbackQuery($update['callback_query']['id'],$callback_response); - exit; + if (empty($row['0'])) { + $callback_response = 'You are not allowed to edit this raid'; + answerCallbackQuery($update['callback_query']['id'], $callback_response); + exit; + } } } - +/** + * Inline key array. + * @param $buttons + * @param $columns + * @return array + */ function inline_key_array($buttons, $columns) { $result = array(); $col = 0; $row = 0; + foreach ($buttons as $v) { $result[$row][$col] = $v; $col++; - if ($col>=$columns) { + + if ($col >= $columns) { $row++; $col=0; } @@ -31,198 +45,357 @@ function inline_key_array($buttons, $columns) { return $result; } +/** + * Raid edit start keys. + * @param $id + * @return array + */ function raid_edit_start_keys($id) { - $keys = - [[[ - 'text' => 'Legendary Raid *****','callback_data' => $id.':edit:type_5', - ]],[[ - 'text' => '4 Star Raid ****', 'callback_data' => $id.':edit:type_4', - ],[ - 'text' => '3 Star Raid ***', 'callback_data' => $id.':edit:type_3', - ]],[[ - 'text' => '2 Star Raid **', 'callback_data' => $id.':edit:type_2', - ],[ - 'text' => '1 Star Raid *', 'callback_data' => $id.':edit:type_1', - ]]]; + $keys = [ + [ + [ + 'text' => 'Legendary Raid *****', + 'callback_data' => $id . ':edit:type_5' + ] + ], + [ + [ + 'text' => '4 Star Raid ****', + 'callback_data' => $id . ':edit:type_4' + ], + [ + 'text' => '3 Star Raid ***', + 'callback_data' => $id . ':edit:type_3' + ] + ], + [ + [ + 'text' => '2 Star Raid **', + 'callback_data' => $id . ':edit:type_2' + ], + [ + 'text' => '1 Star Raid *', + 'callback_data' => $id . ':edit:type_1' + ] + ] + ]; + return $keys; } +/** + * Keys raid people. + * @param $data + * @return array + */ function keys_raid_people($data) { - if (!is_array($data)) $data=array('id'=>$data); - - $keys = [[ - 'text' => '+1', 'callback_data' => $data['id'].':vote:1', - ],[ - 'text' => '+2', 'callback_data' => $data['id'].':vote:2' - ],[ - 'text' => '+3', 'callback_data' => $data['id'].':vote:3' - ],[ - 'text' => '+4', 'callback_data' => $data['id'].':vote:4' - ],[ - 'text' => '+5', 'callback_data' => $data['id'].':vote:5' - ]]; - return $keys; + + if (!is_array($data)) { + $data = array('id' => $data); + } + + $keys = [ + [ + 'text' => '+1', + 'callback_data' => $data['id'] . ':vote:1' + ], + [ + 'text' => '+2', + 'callback_data' => $data['id'] . ':vote:2' + ], + [ + 'text' => '+3', + 'callback_data' => $data['id'] . ':vote:3' + ], + [ + 'text' => '+4', + 'callback_data' => $data['id'] . ':vote:4' + ], + [ + 'text' => '+5', + 'callback_data' => $data['id'] . ':vote:5' + ] + ]; + + return $keys; } +/** + * Keys vote. + * @param $raid + * @return array + */ function keys_vote($raid) { - $keys_team = []; - $keys_time = []; - - $end_time = $raid['ts_end']; - $now = $raid['ts_now']; - - $keys = [[[ - 'text' => '+1', 'callback_data' => $raid['id'].':vote:1', - ],[ - 'text' => '+2', 'callback_data' => $raid['id'].':vote:2' - ],[ - 'text' => '+3', 'callback_data' => $raid['id'].':vote:3' - ],[ - 'text' => '+4', 'callback_data' => $raid['id'].':vote:4' - ],[ - 'text' => '+5', 'callback_data' => $raid['id'].':vote:5' - ]],[[ - 'text' => TEAM_B.' Mystic', 'callback_data' => $raid['id'].':vote_team:mystic', - ],[ - 'text' => TEAM_R.' Valor', 'callback_data' => $raid['id'].':vote_team:valor', - ],[ - 'text' => TEAM_Y.' Instinct', 'callback_data' => $raid['id'].':vote_team:instinct', - ]]]; - - if ($end_time<$now) { - $keys[] = [array('text'=>'Raid Finished','callback_data'=>$raid['id'].':vote_time:'.(ceil(time()/300)*300))]; + // Init keys time array. + $keys_time = []; + + $end_time = $raid['ts_end']; + $now = $raid['ts_now']; + + $keys = [ + [ + [ + 'text' => 'alleine', + 'callback_data' => $raid['id'] . ':vote:1' + ], + [ + 'text' => '+1', + 'callback_data' => $raid['id'] . ':vote:2' + ], + [ + 'text' => '+2', + 'callback_data' => $raid['id'] . ':vote:3' + ], + [ + 'text' => '+3', + 'callback_data' => $raid['id'] . ':vote:4' + ], + [ + 'text' => '+4', + 'callback_data' => $raid['id'] . ':vote:5' + ] + ], + [ + [ + 'text' => TEAM_B . ' Mystic', + 'callback_data' => $raid['id'] . ':vote_team:mystic' + ], + [ + 'text' => TEAM_R . ' Valor', + 'callback_data' => $raid['id'] . ':vote_team:valor' + ], + [ + 'text' => TEAM_Y . ' Instinct', + 'callback_data' => $raid['id'] . ':vote_team:instinct' + ] + ] + ]; + + if ($end_time < $now) { + $keys[] = [ + array( + 'text' =>'Raid beendet.', + 'callback_data' => $raid['id'] . ':vote_time:' . (ceil(time()/900)*900) + ) + ]; + } else { $col = 1; - for ($i=ceil($now/300)*300; $i<=($end_time-300); $i=$i+300) { - if ($col++>=5) { + for ($i=ceil($now/900)*900; $i<=($end_time-900); $i=$i+900) { + + if ($col++ >= 4) { $keys[] = $keys_time; $keys_time = []; $col = 1; } - $keys_time[] = array('text' => unix2tz($i,$raid['timezone']), 'callback_data' => $raid['id'].':vote_time:'.$i); + + $keys_time[] = array( + 'text' => unix2tz($i, $raid['timezone']), + 'callback_data' => $raid['id'] . ':vote_time:' . $i + ); } + $keys[] = $keys_time; } $keys[] = [ - ['text' => EMOJI_REFRESH, 'callback_data' => $raid['id'].':vote_refresh:0'], - ['text' => 'Arrived', 'callback_data' => $raid['id'].':vote_arrived:0'], - ['text' => 'Done', 'callback_data' => $raid['id'].':vote_done:0'], - ['text' => 'Won\'t come', 'callback_data' => $raid['id'].':vote_cancel:0'], + [ + 'text' => EMOJI_REFRESH, + 'callback_data' => $raid['id'] . ':vote_refresh:0' + ], + [ + 'text' => 'Bin da', + 'callback_data' => $raid['id'] . ':vote_arrived:0' + ], + [ + 'text' => 'Fertig', + 'callback_data' => $raid['id'] . ':vote_done:0' + ], + [ + 'text' => 'Absage', + 'callback_data' => $raid['id'] . ':vote_cancel:0' + ], ]; - if ($end_time<$now) { - $keys = [[['text'=>'Raid Finished','callback_data'=>$raid['id'].':vote_refresh:0']]]; + + if ($end_time < $now) { + $keys = [ + [ + [ + 'text' => 'Raid beendet', + 'callback_data' => $raid['id'] . ':vote_refresh:0' + ] + ] + ]; } return $keys; } - +/** + * Update user. + * @param $update + * @return bool|mysqli_result + */ function update_user($update) { - global $db; - - $name = ''; - $sep = ''; - - if ($update['message']) { - $msg = $update['message']['from']; - } - - if ($update['callback_query']) { - $msg = $update['callback_query']['from']; - } - - if ($update['inline_query']) { - $msg = $update['inline_query']['from']; - } - - $id = $msg['id']; - if (!$id) { - debug_log('No id','!'); - debug_log($update,'!'); - return false; - } - - - if ($msg['first_name']) { - $name = $msg['first_name']; - $sep = ' '; - } - if ($msg['last_name']) $name .= $sep.$msg['last_name']; - - - $request = my_query('INSERT INTO users SET - user_id='.$id.', - nick="'.$db->real_escape_string($msg['username']).'", - name="'.$db->real_escape_string($name).'" - ON DUPLICATE KEY UPDATE - nick="'.$db->real_escape_string($msg['username']).'", - name="'.$db->real_escape_string($name).'" - '); - return $request; + global $db; + + $name = ''; + $sep = ''; + + if ($update['message']) { + $msg = $update['message']['from']; + } + + if ($update['callback_query']) { + $msg = $update['callback_query']['from']; + } + + if ($update['inline_query']) { + $msg = $update['inline_query']['from']; + } + + if (!empty($msg['id'])) { + $id = $msg['id']; + + } else { + debug_log('No id', '!'); + debug_log($update, '!'); + return false; + } + + if ($msg['first_name']) { + $name = $msg['first_name']; + $sep = ' '; + } + + if ($msg['last_name']) { + $name .= $sep . $msg['last_name']; + } + + $request = my_query( + " + INSERT INTO users + SET user_id = {$id}, + nick = '{$db->real_escape_string($msg['username'])}', + name = '{$db->real_escape_string($name)}' + ON DUPLICATE KEY + UPDATE nick = '{$db->real_escape_string($msg['username'])}', + name = '{$db->real_escape_string($name)}' + " + ); + + return $request; } -function send_response_vote($update, $data, $new=false) { - $rs = my_query('SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) as ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE id='.$data['id'].''); - $raid = $rs->fetch_assoc(); - - $msg = show_raid_poll($raid); - $keys = keys_vote($raid); - - if ($new) { - $loc = send_location('none',$update['callback_query']['message']['chat']['id'],$raid['lat'], $raid['lon']); - debug_log('location:'); - debug_log($loc); - $msg = send_message('none',$update['callback_query']['message']['chat']['id'],$msg."\n", $keys, ['reply_to_message_id'=>$loc['result']['message_id']]); - answerCallbackQuery($update['callback_query']['id'],$msg); - } else { - edit_message($update, $msg, $keys); - $msg = 'Raid attendance updated'; - answerCallbackQuery($update['callback_query']['id'],$msg); - } - exit; +/** + * Send response vote. + * @param $update + * @param $data + * @param bool $new + */ +function send_response_vote($update, $data, $new = false) { + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$data['id']} + " + ); + + $raid = $rs->fetch_assoc(); + + $msg = show_raid_poll($raid); + $keys = keys_vote($raid); + + // Write to log. + debug_log($keys); + + if ($new) { + $loc = send_location($update['callback_query']['message']['chat']['id'], $raid['lat'], $raid['lon']); + + debug_log('location:'); + debug_log($loc); + + send_message($update['callback_query']['message']['chat']['id'], $msg . "\n", $keys, ['reply_to_message_id' => $loc['result']['message_id']]); + answerCallbackQuery($update['callback_query']['id'],$msg); + + } else { + edit_message($update, $msg, $keys); + $msg = 'Abstimmung aktualisiert'; + answerCallbackQuery($update['callback_query']['id'], $msg); + } + + exit; } - +/** + * @param $unix + * @param $tz + * @param string $format + * @return bool|string + */ function unix2tz($unix, $tz, $format = 'H:i') { - if (!$unix) return false; - $dt = new DateTime('@'.$unix); + if (!$unix) { + return false; + } + + $dt = new DateTime('@' . $unix); $dt->setTimeZone(new DateTimeZone($tz)); return $dt->format($format); } +/** + * Show raid poll. + * @param $raid + * @return string + */ function show_raid_poll($raid) { $time_left = floor($raid['t_left']/60); - $time_left = floor($time_left/60).':'.str_pad($time_left%60,2,'0',STR_PAD_LEFT).' left'; + $time_left = floor($time_left/60) . ':' . str_pad($time_left%60,2, '0', STR_PAD_LEFT) . 'h übrig '; + // Init empty message string. $msg = ''; + if ($raid['gym_name'] || $raid['gym_team']) { - $msg .= 'Gym: '.$raid['gym_name'].''; - if ($raid['gym_team']) $msg .= ' '.$GLOBALS['teams'][$raid['gym_team']].' '.ucfirst($raid['gym_team']); + $msg .= 'Arena: ' . $raid['gym_name'] . ''; + if ($raid['gym_team']) { + $msg .= ' ' . $GLOBALS['teams'][$raid['gym_team']] . ' ' . ucfirst($raid['gym_team']); + } $msg .= CR; } + if ($raid['address']) { - $addr = explode(',',$raid['address'],4); + $addr = explode(',', $raid['address'], 4); array_pop($addr); - $addr = implode(',',$addr); - $msg .= ''.$addr.''.CR2; + $addr = implode(',', $addr); + $msg .= 'Adresse: ' . $addr . '' . CR2; } - $msg .= '#Raid '.ucfirst($raid['pokemon']).''.CR2; - //$msg .= CR; - if ($time_left<0) { - $msg .= 'Raid Finished'.CR2; + $msg .= 'Raid Boss: ' . ucfirst($raid['pokemon']) . '' . CR2; + + if ($time_left < 0) { + $msg .= 'Raid beendet.' . CR2; + } else { - //$msg .= ''.$time_left.' until '.substr($raid['end_time'],11,5)."\n\n"; - $msg .= ''.$time_left.' until '.unix2tz($raid['ts_end'],$raid['timezone'])."\n\n"; + $msg .= ''.$time_left.' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . CR; } - $msg .= 'Location: https://maps.google.com/?q='.$raid['lat'].','.$raid['lon'].CR; - - $query = 'SELECT *, UNIX_TIMESTAMP(attend_time) AS ts_att FROM attendance WHERE raid_id='.$raid['id'].' ORDER BY cancel ASC, raid_done DESC, team ASC, arrived DESC, attend_time ASC'; - $rs = my_query($query); + + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(attend_time) AS ts_att + FROM attendance + WHERE raid_id={$raid['id']} + ORDER BY cancel ASC, + raid_done DESC, + team ASC, + arrived DESC, + attend_time ASC + " + ); + $data = array(); while ($row = $rs->fetch_assoc()) { @@ -240,41 +413,94 @@ function show_raid_poll($raid) { debug_log($data); if (count($data)==0) { - $msg .= CR.'No participants yet.'.CR; + $msg .= CR.'Noch keine Teilnehmer.'.CR; + + } + $query = 'SELECT distinct UNIX_TIMESTAMP(attend_time) AS ts_att, count(attend_time) as count, sum(extra_people) as extra FROM attendance WHERE raid_id='.$raid['id'].' AND attend_time IS NOT NULL and raid_done !=1 and cancel!=1 group by attend_time ORDER BY attend_time ASC'; + $rs = my_query($query); + $timeslots = array(); + while ($row = $rs->fetch_assoc()) { + $timeslots[]=$row; } + debug_log($timeslots); + + foreach ($timeslots as $ts) { + $msg .=CR.''.unix2tz($ts['ts_att'],$raid['timezone']).''.' ['.($ts['count']+$ts['extra']).']'.CR; + + $attend_query = 'select * from attendance where UNIX_TIMESTAMP(attend_time)='.$ts['ts_att'].' AND raid_done != 1 AND cancel != 1 AND raid_id='.$raid['id'].' ORDER BY team ASC'; + $user_rs = my_query($attend_query); + $att_users = array(); + while ($rowusers = $user_rs->fetch_assoc()) { + $att_users[]=$rowusers; + } + debug_log($att_users); - foreach ($GLOBALS['teams'] as $k=>$v) { - if (!count($data[$k])) continue; - $msg .= CR.$v.' '.ucfirst($k).': '.count($data[$k]).''."\n"; - foreach ($data[$k] as $vv) { - if ($vv===false) continue; - if ($vv['raid_done']) continue; + foreach ($att_users as $vv) { + debug_log($vv['user_id']); $query = 'SELECT * FROM users WHERE user_id='.$vv['user_id']; $rs = my_query($query); $row = $rs->fetch_assoc(); - $name = '@'.$row['nick']; - if ($name=='@') $name = $row['name']; - if ($name=='') $name = $vv['user_id']; - $msg .= ' - '.$name.' '; + // always use name + $name = htmlspecialchars($row['name']); + if ($row['team']===NULL) + { + $msg .= ' └ '.$GLOBALS['teams']['unknown'].' '.$name.' '; + } else + { + $msg .= ' └ '.$GLOBALS['teams'][$row['team']].' '.$name.' '; + } if ($vv['arrived']) { - $msg .= '[arrived '.unix2tz($vv['ts_att'],$raid['timezone']).'] '; + $msg .= '[Bin da'.unix2tz($vv['ts_att'],$raid['timezone']).'] '; } else if ($vv['cancel']) { - $msg .= '[cancel] '; + $msg .= '[abgesagt] '; } else { -// $msg .= '['.substr($vv['attend_time'],11,5).'] '; - $msg .= '['.unix2tz($vv['ts_att'],$raid['timezone']).'] '; + //$msg .= '['.unix2tz($vv['ts_att'],$raid['timezone']).'] '; } if ($vv['extra_people']) $msg .= '+'.$vv['extra_people']; $msg .= CR; } } + + if (count($data['done'])) { - $msg .= CR.' Done: '.count($data['done']).''.CR; + $msg .= CR.TEAM_DONE.' Fertig: '.' ['.count($data['done']).']'.CR; + foreach ($data['done'] as $vv) { + + if (!$vv['raid_done']) continue; + $query = 'SELECT * FROM users WHERe user_id='.$vv['user_id']; + $rs = my_query($query); + $row = $rs->fetch_assoc(); + $name = htmlspecialchars($row['name']); + $msg .= ' └ '.$GLOBALS['teams'][$row['team']].' '.$name.' '; + if ($vv['raid_done']) { + $msg .= '[Fertig '.unix2tz($vv['ts_att'],$raid['timezone']).'] '; + } + if ($vv['extra_people']) $msg .= '+'.$vv['extra_people']; + $msg .= CR; + } } + + if (count($data['cancel'])) { + $msg .= CR.TEAM_CANCEL.' Abgesagt: '.' ['.count($data['cancel']).']'.CR; + foreach ($data['cancel'] as $vv) { + + if (!$vv['cancel']) continue; + $query = 'SELECT * FROM users WHERe user_id='.$vv['user_id']; + $rs = my_query($query); + $row = $rs->fetch_assoc(); + $name = htmlspecialchars($row['name']); + $msg .= ' └ '.$GLOBALS['teams'][$row['team']].' '.$name.' '; + if ($vv['cancel']) { + $msg .= '[Abgesagt '.unix2tz($vv['ts_att'],$raid['timezone']).'] '; + } + if ($vv['extra_people']) $msg .= '+'.$vv['extra_people']; + $msg .= CR; + } + } - $msg .= CR.'Updated: '.unix2tz(time(), $raid['timezone'], 'H:i:s').' ID = '.$raid['id']; + $msg .= CR.'Aktualisiert: '.unix2tz(time(), $raid['timezone'], 'H:i:s').' ID = '.$raid['id']; return $msg; } @@ -305,7 +531,7 @@ function show_raid_poll_small($raid) { $total += $sum; } if (!$total) { - $msg .= ' No participants'.CR; + $msg .= ' Keine Teilnehmer'.CR; } else { $msg .= ' = '.$total.''.CR; } @@ -328,7 +554,7 @@ function raid_list($update) { $rows[] = $answer; } debug_log($rows); - answer_inline_query($update['inline_query']['id'], $rows); + answerInlineQuery($update['inline_query']['id'], $rows); } else { /* By user */ $request = my_query('SELECT *, @@ -342,6 +568,6 @@ function raid_list($update) { } debug_log($rows); - answer_inline_query($update['inline_query']['id'], $rows); + answerInlineQuery($update['inline_query']['id'], $rows); } } diff --git a/modules/join.php b/modules/join.php deleted file mode 100644 index d6b7f11..0000000 --- a/modules/join.php +++ /dev/null @@ -1,10 +0,0 @@ -fetch_assoc(); - if (!$row) exit; - - foreach ($update['message']['new_chat_members'] as $v) { - sendMessage('none',$v['id'],$row['message']); - } - diff --git a/modules/raid_create.php b/modules/raid_create.php index a0a0fb5..3178f16 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -1,4 +1,5 @@ '.$addr.''; if ($update['message']['chat']['type']=='private') { - send_message('none',$update['message']['chat']['id'],$msg.CR.'Choose Raid level:', $keys); + send_message($update['message']['chat']['id'],$msg.CR.'Choose Raid level:', $keys); } else { $reply_to = $update['message']['chat']['id']; if ($update['message']['reply_to_message']['message_id']) $reply_to = $update['message']['reply_to_message']['message_id']; - send_message('none',$update['message']['chat']['id'],$msg.CR.'Choose Raid level:', $keys, + send_message($update['message']['chat']['id'],$msg.CR.'Choose Raid level:', $keys, ['reply_to_message_id'=>$reply_to, 'reply_markup' => ['selective'=>true, 'one_time_keyboard'=>true]] ); } diff --git a/modules/vote_arrived.php b/modules/vote_arrived.php index d4d772f..b27fa78 100644 --- a/modules/vote_arrived.php +++ b/modules/vote_arrived.php @@ -5,13 +5,13 @@ debug_log($answer); if (!$answer) { - $query = 'SELECT * FROM users WHERE user_id='.$update['callback_query']['from']['id']; - $rs = my_query($query); - $row = $rs->fetch_assoc(); + //$query = 'SELECT * FROM users WHERE user_id='.$update['callback_query']['from']['id']; + //$rs = my_query($query); + //$row = $rs->fetch_assoc(); - my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', arrived=1, team="'.$row['team'].'", attend_time=NOW()'); + //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', arrived=1, team="'.$row['team'].'", attend_time=NOW()'); } else { - my_query('UPDATE attendance SET arrived=1,raid_done=0,cancel=0,attend_time=NOW() WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); + my_query('UPDATE attendance SET arrived=1,raid_done=0,cancel=0 WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); } send_response_vote($update, $data); diff --git a/modules/vote_cancel.php b/modules/vote_cancel.php index ea0c33f..d0e140c 100644 --- a/modules/vote_cancel.php +++ b/modules/vote_cancel.php @@ -4,9 +4,9 @@ debug_log($answer); if (!$answer) { - my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', cancel=1, attend_time=NULL'); + //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', cancel=1, attend_time=NULL'); } else { - my_query('UPDATE attendance SET cancel=1, raid_done=0, arrived=0, attend_time=NULL WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); + my_query('UPDATE attendance SET cancel=1, raid_done=0, arrived=0 WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); } send_response_vote($update, $data); diff --git a/modules/vote_done.php b/modules/vote_done.php index a8e975f..e38bc42 100644 --- a/modules/vote_done.php +++ b/modules/vote_done.php @@ -5,7 +5,7 @@ debug_log($answer); if (!$answer) { - my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', raid_done=1'); + //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', raid_done=1'); } else { my_query('UPDATE attendance SET raid_done=1 WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); } diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index 1a53b38..a471dd8 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -65,12 +65,6 @@ CREATE TABLE `users` ( UNIQUE KEY `i_userid` (`user_id`) ) ENGINE=InnoDB AUTO_INCREMENT=12891 DEFAULT CHARSET=utf8; -CREATE TABLE `help` ( - `id` bigint(20) NOT NULL, - `message` text, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 - /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; diff --git a/webhook.html b/webhook.html new file mode 100644 index 0000000..a3f3943 --- /dev/null +++ b/webhook.html @@ -0,0 +1,38 @@ + + +Set Webhooks + + + + +
+
+ Enter your Bot Token:
+ Enter your Bot Url:
+ MAX Connections?:
+ Enter your Certificate:
+
+ +
+
+ + + From e680e00626fdf8cf9511e9f8603d55496ec63204 Mon Sep 17 00:00:00 2001 From: d4NY0H Date: Wed, 16 Aug 2017 10:03:57 +0200 Subject: [PATCH 002/225] cleanup --- logic.php | 337 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 235 insertions(+), 102 deletions(-) diff --git a/logic.php b/logic.php index bf95ff5..a1bc224 100644 --- a/logic.php +++ b/logic.php @@ -387,7 +387,7 @@ function show_raid_poll($raid) { SELECT *, UNIX_TIMESTAMP(attend_time) AS ts_att FROM attendance - WHERE raid_id={$raid['id']} + WHERE raid_id = {$raid['id']} ORDER BY cancel ASC, raid_done DESC, team ASC, @@ -399,12 +399,20 @@ function show_raid_poll($raid) { $data = array(); while ($row = $rs->fetch_assoc()) { - if ($row['cancel']) $row['team']='cancel'; - if ($row['raid_done']) $row['team']='done'; - if (!$row['team']) $row['team']='unknown'; - $data[$row['team']][] = $row; - if ($row['extra_people']) { - for ($i=1; $i<=$row['extra_people']; $i++) { + if ($row['cancel']) { + $row['team'] = 'cancel'; + } + if ($row['raid_done']) { + $row['team'] = 'done'; + } + if (!$row['team']) { + $row['team'] = 'unknown'; + } + + $data[$row['team']][] = $row; + + if ($row['extra_people']) { + for ($i = 1; $i <= $row['extra_people']; $i++) { $data[$row['team']][] = false; } } @@ -412,162 +420,287 @@ function show_raid_poll($raid) { debug_log($data); - if (count($data)==0) { - $msg .= CR.'Noch keine Teilnehmer.'.CR; - + if (count($data) == 0) { + $msg .= CR . 'Noch keine Teilnehmer.' . CR; } - - $query = 'SELECT distinct UNIX_TIMESTAMP(attend_time) AS ts_att, count(attend_time) as count, sum(extra_people) as extra FROM attendance WHERE raid_id='.$raid['id'].' AND attend_time IS NOT NULL and raid_done !=1 and cancel!=1 group by attend_time ORDER BY attend_time ASC'; - $rs = my_query($query); - $timeslots = array(); + + $rs = my_query( + " + SELECT DISTINCT UNIX_TIMESTAMP(attend_time) AS ts_att, + count(attend_time) AS count, + sum(extra_people) AS extra + FROM attendance + WHERE raid_id = {$raid['id']} + AND attend_time IS NOT NULL + AND raid_done != 1 + AND cancel != 1 + GROUP BY attend_time + ORDER BY attend_time ASC + " + ); + + // Init empty time slots array. + $timeSlots = array(); + while ($row = $rs->fetch_assoc()) { - $timeslots[]=$row; + $timeSlots[] = $row; } - debug_log($timeslots); + + // Write to log. + debug_log($timeSlots); - foreach ($timeslots as $ts) { - $msg .=CR.''.unix2tz($ts['ts_att'],$raid['timezone']).''.' ['.($ts['count']+$ts['extra']).']'.CR; - - $attend_query = 'select * from attendance where UNIX_TIMESTAMP(attend_time)='.$ts['ts_att'].' AND raid_done != 1 AND cancel != 1 AND raid_id='.$raid['id'].' ORDER BY team ASC'; - $user_rs = my_query($attend_query); - $att_users = array(); - while ($rowusers = $user_rs->fetch_assoc()) { - $att_users[]=$rowusers; + foreach ($timeSlots as $ts) { + // Add to message. + $msg .= CR . '' . unix2tz($ts['ts_att'], $raid['timezone']) . '' . ' [' . ($ts['count']+$ts['extra']) . ']' . CR; + + $user_rs = my_query( + " + SELECT * + FROM attendance + WHERE UNIX_TIMESTAMP(attend_time) = {$ts['ts_att']} + AND raid_done != 1 + AND cancel != 1 + AND raid_id = {$raid['id']} + ORDER BY team ASC + " + ); + + // Init empty attend users array. + $att_users = array(); + + + while ($rowusers = $user_rs->fetch_assoc()) { + $att_users[] = $rowusers; } + + // Write to log. debug_log($att_users); foreach ($att_users as $vv) { - debug_log($vv['user_id']); - $query = 'SELECT * FROM users WHERE user_id='.$vv['user_id']; - $rs = my_query($query); + // Write to log. + debug_log($vv['user_id']); + + $rs = my_query( + " + SELECT * + FROM users + WHERE user_id = {$vv['user_id']} + " + ); + $row = $rs->fetch_assoc(); - // always use name + + // Always use name. $name = htmlspecialchars($row['name']); - if ($row['team']===NULL) - { - $msg .= ' └ '.$GLOBALS['teams']['unknown'].' '.$name.' '; - } else - { - $msg .= ' └ '.$GLOBALS['teams'][$row['team']].' '.$name.' '; + + // Unknown team. + if ($row['team'] === NULL) { + $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' ' . $name . ' '; + + // Known team. + } else { + $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name . ' '; } + + // Arrived. if ($vv['arrived']) { - $msg .= '[Bin da'.unix2tz($vv['ts_att'],$raid['timezone']).'] '; + $msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + + // Cancelled. } else if ($vv['cancel']) { $msg .= '[abgesagt] '; - } else { - //$msg .= '['.unix2tz($vv['ts_att'],$raid['timezone']).'] '; } - if ($vv['extra_people']) $msg .= '+'.$vv['extra_people']; + + // Add extra people. + if ($vv['extra_people']) { + $msg .= '+' . $vv['extra_people']; + } $msg .= CR; } } - + // DONE if (count($data['done'])) { - $msg .= CR.TEAM_DONE.' Fertig: '.' ['.count($data['done']).']'.CR; - foreach ($data['done'] as $vv) { + // Add to message. + $msg .= CR . TEAM_DONE . ' Fertig: ' . ' [' . count($data['done']) . ']' . CR; + + foreach ($data['done'] as $vv) { if (!$vv['raid_done']) continue; - $query = 'SELECT * FROM users WHERe user_id='.$vv['user_id']; - $rs = my_query($query); - $row = $rs->fetch_assoc(); - $name = htmlspecialchars($row['name']); - $msg .= ' └ '.$GLOBALS['teams'][$row['team']].' '.$name.' '; + + $rs = my_query( + " + SELECT * + FROM users + WHERE user_id = {$vv['user_id']} + " + ); + + $row = $rs->fetch_assoc(); + + $name = htmlspecialchars($row['name']); + + // Add to message. + $msg .= ' └ '.$GLOBALS['teams'][$row['team']].' '.$name.' '; + + // Done. if ($vv['raid_done']) { $msg .= '[Fertig '.unix2tz($vv['ts_att'],$raid['timezone']).'] '; - } - if ($vv['extra_people']) $msg .= '+'.$vv['extra_people']; + } + // Add extra people. + if ($vv['extra_people']) { + $msg .= '+' . $vv['extra_people']; + } + $msg .= CR; } } - + + // CANCEL if (count($data['cancel'])) { - $msg .= CR.TEAM_CANCEL.' Abgesagt: '.' ['.count($data['cancel']).']'.CR; - foreach ($data['cancel'] as $vv) { + // Add to message. + $msg .= CR . TEAM_CANCEL . ' Abgesagt: ' . ' [' . count($data['cancel']) . ']' . CR; + + foreach ($data['cancel'] as $vv) { if (!$vv['cancel']) continue; - $query = 'SELECT * FROM users WHERe user_id='.$vv['user_id']; - $rs = my_query($query); - $row = $rs->fetch_assoc(); - $name = htmlspecialchars($row['name']); - $msg .= ' └ '.$GLOBALS['teams'][$row['team']].' '.$name.' '; - if ($vv['cancel']) { + + $rs = my_query( + " + SELECT * + FROM users + WHERE user_id = {$vv['user_id']} + " + ); + + $row = $rs->fetch_assoc(); + + $name = htmlspecialchars($row['name']); + + $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name . ' '; + + // Cancel. + if ($vv['cancel']) { $msg .= '[Abgesagt '.unix2tz($vv['ts_att'],$raid['timezone']).'] '; - } - if ($vv['extra_people']) $msg .= '+'.$vv['extra_people']; + } + // Add extra people. + if ($vv['extra_people']) { + $msg .= '+' . $vv['extra_people']; + } + $msg .= CR; } } - $msg .= CR.'Aktualisiert: '.unix2tz(time(), $raid['timezone'], 'H:i:s').' ID = '.$raid['id']; + // Add update time and raid id to message. + $msg .= CR . 'Aktualisiert: ' . unix2tz(time(), $raid['timezone'], 'H:i:s') . ' ID = ' . $raid['id']; + // Return the message. return $msg; } +/** + * Show small raid poll. + * @param $raid + * @return string + */ function show_raid_poll_small($raid) { $time_left = floor($raid['t_left']/60); - $time_left = floor($time_left/60).':'.str_pad($time_left%60,2,'0',STR_PAD_LEFT).' left'; + $time_left = floor($time_left/60) . ':' . str_pad($time_left%60, 2, '0', STR_PAD_LEFT) . ' left'; - $msg = ''.ucfirst($raid['pokemon']).' '.$time_left.' '.$raid['gym_name'].''.CR; - if ($raid['address']) { - $addr = explode(',',$raid['address'],4); + $msg = '' . ucfirst($raid['pokemon']) . ' ' . $time_left . ' ' . $raid['gym_name'] . '' . CR; + + // Address found. + if ($raid['address']) { + $addr = explode(',', $raid['address'], 4); array_pop($addr); - $addr = implode(',',$addr); - $msg .= ''.$addr.''.CR2; + $addr = implode(',', $addr); + // Add to message. + $msg .= '' . $addr . '' . CR2; } - - $query = 'SELECT team, COUNT(*) AS cnt, SUM(extra_people) AS extra FROM attendance WHERE raid_id='.$raid['id'].' AND (cancel=0 OR cancel IS NULL) AND (raid_done=0 OR raid_done IS NULL) GROUP BY team'; - $rs = my_query($query); - $data = array(); + + // Build query. + $rs = my_query( + " + SELECT team, + COUNT(*) AS cnt, + SUM(extra_people) AS extra + FROM attendance + WHERE raid_id = {$raid['id']} + AND (cancel = 0 OR cancel IS NULL) + AND (raid_done = 0 OR raid_done IS NULL) + GROUP BY team + " + ); $total = 0; $sep = ''; - while ($row = $rs->fetch_assoc()) { + + while ($row = $rs->fetch_assoc()) { $sum = $row['cnt']+$row['extra']; - if ($sum==0) continue; - $msg .= $sep.$GLOBALS['teams'][$row['team']].' '.$sum; + + if ($sum==0) continue; + + // Add to message. + $msg .= $sep . $GLOBALS['teams'][$row['team']] . ' ' . $sum; $sep = ' | '; $total += $sum; } + if (!$total) { - $msg .= ' Keine Teilnehmer'.CR; + $msg .= ' Keine Teilnehmer' . CR; } else { - $msg .= ' = '.$total.''.CR; + $msg .= ' = ' . $total . '' . CR; } return $msg; } +/** + * Raid list. + * @param $update + */ function raid_list($update) { - /* INLINE - LIST POLLS */ + // Init empty rows array. + $rows = array(); + // Inline list polls. if ($update['inline_query']['query']) { - /* By ID */ - $request = my_query('SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) as ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE id='.intval($update['inline_query']['query'])); - $rows = array(); - while($answer = $request->fetch_assoc()) { - $rows[] = $answer; - } - debug_log($rows); - answerInlineQuery($update['inline_query']['id'], $rows); - } else { - /* By user */ - $request = my_query('SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) as ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE user_id = '.$update['inline_query']['from']['id'].' ORDER BY id DESC LIMIT 3;'); - $rows = array(); - while($answer = $request->fetch_assoc()) { - $rows[] = $answer; - } - - debug_log($rows); - answerInlineQuery($update['inline_query']['id'], $rows); + + $iqq = intval($update['inline_query']['query']); + + // By ID. + $request = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$iqq} + " + ); + + } else { + // By user. + $request = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE user_id = {$update['inline_query']['from']['id']} + ORDER BY id DESC LIMIT 3 + " + ); } + + while($answer = $request->fetch_assoc()) { + $rows[] = $answer; + } + + debug_log($rows); + answerInlineQuery($update['inline_query']['id'], $rows); } From a0df7543239e6c4909e3b83d26672c67b54d0faf Mon Sep 17 00:00:00 2001 From: d4NY0H Date: Wed, 16 Aug 2017 12:27:44 +0200 Subject: [PATCH 003/225] removed google api requests to get timezone --- commands/raid.php | 8 +++----- config.php.example | 3 ++- geo_api.php | 31 ++----------------------------- modules/raid_create.php | 8 +++----- 4 files changed, 10 insertions(+), 40 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index 6b180d7..8c5d409 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -14,8 +14,7 @@ $lat = substr($lat,0,strpos('.',$lat)+9); $lon = substr($lon,0,strpos('.',$lon)+9); - - $tz = get_timezone($lat, $lon); + $addr = get_address($lat, $lon); $q = 'INSERT INTO raids SET @@ -29,9 +28,8 @@ gym_name="'.$db->real_escape_string($data[5]).'" '; - if ($tz!==false) { - $q .= ', timezone="'.$tz.'"'; - } + $q .= ', timezone="' . TIMEZONE . '"'; + if ($addr) { $q .= ', address="'.$db->real_escape_string($addr).'"'; } diff --git a/config.php.example b/config.php.example index 01ff278..e08befa 100644 --- a/config.php.example +++ b/config.php.example @@ -1,5 +1,6 @@ '); - $json_response = curl_exec($curl); - debug_log($json_response,'real_escape_string($addr).'"'; } From 59b6c0cd53b329c4050a4861e3774c38105a7753 Mon Sep 17 00:00:00 2001 From: d4NY0H Date: Wed, 16 Aug 2017 12:34:24 +0200 Subject: [PATCH 004/225] debug switch added --- config.php.example | 1 + debug.php | 40 ++++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/config.php.example b/config.php.example index e08befa..cc50896 100644 --- a/config.php.example +++ b/config.php.example @@ -2,6 +2,7 @@ define('GOOGLE_API_KEY', ''); // optional define('TIMEZONE', 'Europe/Berlin'); +define('DEBUG', true); define('CONFIG_LOGFILE', '/var/log/tg-bots/dev-raid-bot.log'); define('CONFIG_HASH', ' = hash(sha_512,tg_bot_key) '); diff --git a/debug.php b/debug.php index 1a320bf..8120782 100644 --- a/debug.php +++ b/debug.php @@ -34,22 +34,26 @@ function my_query($query) { * @param string $type */ function debug_log($val, $type = '*') { - $date = @date('Y-m-d H:i:s'); - $usec = microtime(true); - $date = $date . '.' . str_pad(substr($usec, 11, 4), 4, '0', STR_PAD_RIGHT); - - $bt = debug_backtrace(); - $bl = ''; - - while($btl = array_shift($bt)) { - if ($btl['function'] == __FUNCTION__) continue; - $bl = '[' . basename($btl['file']) . ':' . $btl['line'] . '] '; - break; - } - - if (gettype($val) != 'string') $val = var_export($val, 1); - $rows = explode("\n", $val); - foreach ($rows as $v) { - error_log('[' . $date . '][' . getmypid() . '] ' . $bl . $type . ' ' . $v . "\n", 3, CONFIG_LOGFILE); - } + // Write to log only if debug is enabled. + if (DEBUG === true) { + + $date = @date('Y-m-d H:i:s'); + $usec = microtime(true); + $date = $date . '.' . str_pad(substr($usec, 11, 4), 4, '0', STR_PAD_RIGHT); + + $bt = debug_backtrace(); + $bl = ''; + + while ($btl = array_shift($bt)) { + if ($btl['function'] == __FUNCTION__) continue; + $bl = '[' . basename($btl['file']) . ':' . $btl['line'] . '] '; + break; + } + + if (gettype($val) != 'string') $val = var_export($val, 1); + $rows = explode("\n", $val); + foreach ($rows as $v) { + error_log('[' . $date . '][' . getmypid() . '] ' . $bl . $type . ' ' . $v . "\n", 3, CONFIG_LOGFILE); + } + } } \ No newline at end of file From 3a9f4269698e50bcbed061a0581d42cfe64a626a Mon Sep 17 00:00:00 2001 From: d4NY0H Date: Wed, 16 Aug 2017 12:53:39 +0200 Subject: [PATCH 005/225] reformatting code --- commands/gym.php | 4 +- commands/help.php | 6 +- commands/list.php | 54 ++-- commands/raid.php | 93 +++--- commands/start.php | 2 +- commands/team.php | 44 +-- constants.php | 70 ++--- debug.php | 27 +- functions.php | 323 ++++++++++---------- geo_api.php | 5 +- index.php | 4 +- logic.php | 621 ++++++++++++++++++++------------------- modules/edit.php | 142 ++++----- modules/edit_left.php | 54 ++-- modules/edit_poke.php | 46 +-- modules/raid_create.php | 66 ++--- modules/vote.php | 36 +-- modules/vote_arrived.php | 28 +- modules/vote_cancel.php | 22 +- modules/vote_done.php | 22 +- modules/vote_edit.php | 2 +- modules/vote_refresh.php | 2 +- modules/vote_team.php | 26 +- modules/vote_time.php | 28 +- webhook.html | 44 +-- 25 files changed, 899 insertions(+), 872 deletions(-) diff --git a/commands/gym.php b/commands/gym.php index 10d5fbd..9dac5b8 100644 --- a/commands/gym.php +++ b/commands/gym.php @@ -10,14 +10,14 @@ $query = 'UPDATE raids SET gym_name="' . $db->real_escape_string($gym_name) . '" WHERE user_id=' . $update['message']['from']['id'] . ' ORDER BY id DESC LIMIT 1'; my_query($query); - sendMessage($update['message']['chat']['id'],'Gym name updated'); + sendMessage($update['message']['chat']['id'], 'Gym name updated'); } else { if ($update['message']['reply_to_message']['text']) { $lines = explode(CR, $update['message']['reply_to_message']['text']); $last_line = array_pop($lines); $pos = strpos($last_line, 'ID = '); - $id = intval(trim(substr($last_line, $pos+5))); + $id = intval(trim(substr($last_line, $pos + 5))); debug_log('Gym ID=' . $id . ' name=' . $gym_name); $query = 'SELECT COUNT(*) FROM users WHERE user_id=' . $update['message']['from']['id'] . ' AND moderator=1'; diff --git a/commands/help.php b/commands/help.php index d9867fc..3b31a2f 100644 --- a/commands/help.php +++ b/commands/help.php @@ -1,6 +1,6 @@ EN Guide on how to create a raid poll raid bot 1) make sure the raid hasn\'t been posted yet in the chat 2) check how much time is left for the raid @@ -11,6 +11,6 @@ 7) press share and choose yourRaid channel 8) wait until the option with the boss name appears and select it '; - $msg = 'This is a private bot.'; - sendMessage($update['message']['from']['id'], $msg); +$msg = 'This is a private bot.'; +sendMessage($update['message']['from']['id'], $msg); \ No newline at end of file diff --git a/commands/list.php b/commands/list.php index cecb331..be9fa7e 100644 --- a/commands/list.php +++ b/commands/list.php @@ -1,32 +1,32 @@ fetch_assoc(); - if (!$row) { - sendMessage($update['message']['from']['id'],'Can\'t determine your location, please participate in at least 1 raid'); - exit; - } - $tz = $row['timezone']; +debug_log('LIST'); +$q = 'SELECT timezone FROM raids WHERE id=(SELECT raid_id FROM attendance WHERE user_id=' . $update['message']['from']['id'] . ' ORDER BY id DESC LIMIT 1)'; +debug_log($q); +$rs = my_query($q); +$row = $rs->fetch_assoc(); +if (!$row) { + sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + exit; +} - $request = my_query('SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) as ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE end_time>NOW() AND timezone="'.$tz.'" ORDER BY end_time ASC LIMIT 20'); +$tz = $row['timezone']; - while($raid = $request->fetch_assoc()) { - $keys = [[[ - 'text' => 'Expand', 'callback_data' => $raid['id'].':vote_refresh:0', - ]]]; - $msg = show_raid_poll_small($raid); - send_message($update['message']['from']['id'],$msg, $keys, - ['reply_markup' => ['selective'=>true, 'one_time_keyboard'=>true]] - ); - } +$request = my_query('SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) as ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids WHERE end_time>NOW() AND timezone="' . $tz . '" ORDER BY end_time ASC LIMIT 20'); - - exit; +while ($raid = $request->fetch_assoc()) { + $keys = [[[ + 'text' => 'Expand', 'callback_data' => $raid['id'] . ':vote_refresh:0', + ]]]; + $msg = show_raid_poll_small($raid); + send_message($update['message']['from']['id'], $msg, $keys, + ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]] + ); +} + + +exit; diff --git a/commands/raid.php b/commands/raid.php index 8c5d409..d8abb30 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -1,70 +1,69 @@ real_escape_string($gym_name).'" WHERE user_id='.$update['message']['from']['id'].' ORDER BY id DESC LIMIT 1'; - $lat = floatval($data[1]); - $lon = floatval($data[2]); +if (count($data) < 6) { + send_message($update['message']['chat']['id'], 'Invalid input', []); + exit; +} +$query = 'UPDATE raids SET gym_name="' . $db->real_escape_string($gym_name) . '" WHERE user_id=' . $update['message']['from']['id'] . ' ORDER BY id DESC LIMIT 1'; +$lat = floatval($data[1]); +$lon = floatval($data[2]); - $lat = substr($lat,0,strpos('.',$lat)+9); - $lon = substr($lon,0,strpos('.',$lon)+9); +$lat = substr($lat, 0, strpos('.', $lat) + 9); +$lon = substr($lon, 0, strpos('.', $lon) + 9); - $addr = get_address($lat, $lon); +$addr = get_address($lat, $lon); - $q = 'INSERT INTO raids SET - pokemon="'.$db->real_escape_string($data[0]).'", - user_id='.$update['message']['from']['id'].', - lat="'.$lat.'", - lon="'.$lon.'", +$q = 'INSERT INTO raids SET + pokemon="' . $db->real_escape_string($data[0]) . '", + user_id=' . $update['message']['from']['id'] . ', + lat="' . $lat . '", + lon="' . $lon . '", first_seen=NOW(), - end_time=DATE_ADD(first_seen, INTERVAL '.$data[3].' MINUTE), - gym_team="'.$db->real_escape_string($data[4]).'", - gym_name="'.$db->real_escape_string($data[5]).'" + end_time=DATE_ADD(first_seen, INTERVAL ' . $data[3] . ' MINUTE), + gym_team="' . $db->real_escape_string($data[4]) . '", + gym_name="' . $db->real_escape_string($data[5]) . '" '; - $q .= ', timezone="' . TIMEZONE . '"'; +$q .= ', timezone="' . TIMEZONE . '"'; - if ($addr) { - $q .= ', address="'.$db->real_escape_string($addr).'"'; - } +if ($addr) { + $q .= ', address="' . $db->real_escape_string($addr) . '"'; +} - $rs = my_query($q); - $id = my_insert_id(); - debug_log('ID='.$id); +$rs = my_query($q); +$id = my_insert_id(); +debug_log('ID=' . $id); - $rs = my_query('SELECT *, +$rs = my_query('SELECT *, UNIX_TIMESTAMP(end_time) AS ts_end, UNIX_TIMESTAMP(NOW()) as ts_now, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE id='.$id.''); - $raid = $rs->fetch_assoc(); + FROM raids WHERE id=' . $id . ''); +$raid = $rs->fetch_assoc(); - $text = show_raid_poll($raid); - $keys = keys_vote($raid); +$text = show_raid_poll($raid); +$keys = keys_vote($raid); +if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { - if ($update['message']['chat']['type']=='private' || $update['callback_query']['message']['chat']['type']=='private') { + $keys = [[[ + 'text' => 'Share', 'switch_inline_query' => strval($id), + ]]]; - $keys = [[[ - 'text'=>'Share','switch_inline_query'=>strval($id), - ]]]; - - send_message($update['message']['chat']['id'],$text, $keys); + send_message($update['message']['chat']['id'], $text, $keys); - } else { - $reply_to = $update['message']['chat']['id']; - if ($update['message']['reply_to_message']['message_id']) $reply_to = $update['message']['reply_to_message']['message_id']; +} else { + $reply_to = $update['message']['chat']['id']; + if ($update['message']['reply_to_message']['message_id']) $reply_to = $update['message']['reply_to_message']['message_id']; - send_message($update['message']['chat']['id'],$text, $keys, - ['reply_to_message_id'=>$reply_to, 'reply_markup' => ['selective'=>true, 'one_time_keyboard'=>true]] - ); - } - - exit; + send_message($update['message']['chat']['id'], $text, $keys, + ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]] + ); +} + +exit; diff --git a/commands/start.php b/commands/start.php index db5d1dc..a73f87a 100644 --- a/commands/start.php +++ b/commands/start.php @@ -1,3 +1,3 @@ Please send location to start Raid announce '); +sendMessage($update['message']['chat']['id'], 'Please send location to start Raid announce '); diff --git a/commands/team.php b/commands/team.php index 585a0eb..15faa9c 100644 --- a/commands/team.php +++ b/commands/team.php @@ -1,26 +1,26 @@ 'mystic', - 'instinct' => 'instinct', - 'valor' => 'valor', - 'red' => 'valor', - 'blue' => 'mystic', - 'yellow' => 'instinct', - 'r' => 'valor', - 'b' => 'mystic', - 'y' => 'instinct', - ); - - if ($teams[$gym_team]) { - $query = 'UPDATE raids SET gym_team="'.$teams[$gym_team].'" WHERE user_id='.$update['message']['from']['id'].' ORDER BY id DESC LIMIT 1'; - my_query($query); - - sendMessage($update['message']['chat']['id'],'Gym team set to '.ucfirst($teams[$gym_team])); - } else { - sendMessage($update['message']['chat']['id'],'Invalid team name - type Mystic, Valor, Instinct or Blue, Red, Yellow'); - } +$gym_team = trim(strtolower(substr($update['message']['text'], 5))); + +$teams = array( + 'mystic' => 'mystic', + 'instinct' => 'instinct', + 'valor' => 'valor', + 'red' => 'valor', + 'blue' => 'mystic', + 'yellow' => 'instinct', + 'r' => 'valor', + 'b' => 'mystic', + 'y' => 'instinct', +); + +if ($teams[$gym_team]) { + $query = 'UPDATE raids SET gym_team="' . $teams[$gym_team] . '" WHERE user_id=' . $update['message']['from']['id'] . ' ORDER BY id DESC LIMIT 1'; + my_query($query); + + sendMessage($update['message']['chat']['id'], 'Gym team set to ' . ucfirst($teams[$gym_team])); +} else { + sendMessage($update['message']['chat']['id'], 'Invalid team name - type Mystic, Valor, Instinct or Blue, Red, Yellow'); +} \ No newline at end of file diff --git a/constants.php b/constants.php index 0ffaaa5..f9c669b 100644 --- a/constants.php +++ b/constants.php @@ -3,48 +3,48 @@ define('CR', "\n"); define('CR2', "\n"); -define('TEAM_B', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f499))); -define('TEAM_R', iconv('UCS-4LE', 'UTF-8', pack('V', 0x2764))); -define('TEAM_Y', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f49B))); -define('TEAM_CANCEL', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f494))); -define('TEAM_DONE', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f4aa))); -define('TEAM_UNKNOWN', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f680))); +define('TEAM_B', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f499))); +define('TEAM_R', iconv('UCS-4LE', 'UTF-8', pack('V', 0x2764))); +define('TEAM_Y', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f49B))); +define('TEAM_CANCEL', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f494))); +define('TEAM_DONE', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f4aa))); +define('TEAM_UNKNOWN', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f680))); define('EMOJI_REFRESH', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F504))); $teams = array( - 'mystic' => TEAM_B, - 'valor' => TEAM_R, - 'instinct' => TEAM_Y, - 'unknown' => TEAM_UNKNOWN, - 'cancel' => TEAM_CANCEL + 'mystic' => TEAM_B, + 'valor' => TEAM_R, + 'instinct' => TEAM_Y, + 'unknown' => TEAM_UNKNOWN, + 'cancel' => TEAM_CANCEL ); $pokemon = array( - '5' => array( - 'Arktos', - 'Lugia', - 'Lavados', - 'Zapdos', - ), - '4' => array( - 'Despotar', - 'Relaxo', - 'Lapras', - 'Rizeros', - 'Glurak', - 'Bisasflor', - 'Turtok', - ), - '3' => array( - 'Machamp', - 'Vaporeon', - 'Flareon', - 'Jolteon', - 'Alakazam', - 'Arcanine', - 'Gengar', - ) + '5' => array( + 'Arktos', + 'Lugia', + 'Lavados', + 'Zapdos', + ), + '4' => array( + 'Despotar', + 'Relaxo', + 'Lapras', + 'Rizeros', + 'Glurak', + 'Bisasflor', + 'Turtok', + ), + '3' => array( + 'Machamp', + 'Vaporeon', + 'Flareon', + 'Jolteon', + 'Alakazam', + 'Arcanine', + 'Gengar', + ) ); diff --git a/debug.php b/debug.php index 8120782..a81e32e 100644 --- a/debug.php +++ b/debug.php @@ -3,10 +3,11 @@ * Get last insert id from db. * @return mixed */ -function my_insert_id() { - global $db; +function my_insert_id() +{ + global $db; - return $db->insert_id; + return $db->insert_id; } /** @@ -14,18 +15,19 @@ function my_insert_id() { * @param $query * @return bool|mysqli_result */ -function my_query($query) { - global $db; +function my_query($query) +{ + global $db; - debug_log($query, '?'); + debug_log($query, '?'); - $res = $db->query($query); + $res = $db->query($query); - if ($db->error) { - debug_log($db->error, '!'); - } + if ($db->error) { + debug_log($db->error, '!'); + } - return $res; + return $res; } /** @@ -33,7 +35,8 @@ function my_query($query) { * @param $val * @param string $type */ -function debug_log($val, $type = '*') { +function debug_log($val, $type = '*') +{ // Write to log only if debug is enabled. if (DEBUG === true) { diff --git a/functions.php b/functions.php index 8f7a9ff..a300060 100644 --- a/functions.php +++ b/functions.php @@ -1,33 +1,34 @@ - 'sendMessage', - 'chat_id' => $chat_id, + $reply_content = [ + 'method' => 'sendMessage', + 'chat_id' => $chat_id, 'parse_mode' => 'HTML', - 'text' => $text - ]; - - if (isset($inline_keyboard)) { - $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; - } + 'text' => $text + ]; + + if (isset($inline_keyboard)) { + $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; + } // Encode data to json. - $reply_json = json_encode($reply_content); + $reply_json = json_encode($reply_content); // Set header to json. - header('Content-Type: application/json'); + header('Content-Type: application/json'); // Write to log. - debug_log($reply_json,'>'); + debug_log($reply_json, '>'); // Send request to telegram api. - curl_json_request($reply_json); + curl_json_request($reply_json); } /** @@ -37,38 +38,39 @@ function sendMessage($chat_id, $text = array()) { * @param mixed $inline_keyboard * @param array $merge_args */ -function send_message($chat_id, $text = array(), $inline_keyboard = false, $merge_args = []) { +function send_message($chat_id, $text = array(), $inline_keyboard = false, $merge_args = []) +{ // Create response content array. - $reply_content = [ - 'method' => 'sendMessage', - 'chat_id' => $chat_id, - 'parse_mode' => 'HTML', - 'text' => $text - ]; + $reply_content = [ + 'method' => 'sendMessage', + 'chat_id' => $chat_id, + 'parse_mode' => 'HTML', + 'text' => $text + ]; // Write to log. - debug_log('KEYS'); - debug_log($inline_keyboard); + debug_log('KEYS'); + debug_log($inline_keyboard); - if (isset($inline_keyboard)) { - $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; - } + if (isset($inline_keyboard)) { + $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; + } - if (is_array($merge_args) && count($merge_args)) { - $reply_content = array_merge_recursive($reply_content, $merge_args); - } + if (is_array($merge_args) && count($merge_args)) { + $reply_content = array_merge_recursive($reply_content, $merge_args); + } // Encode data to json. - $reply_json = json_encode($reply_content); + $reply_json = json_encode($reply_content); // Set header to json. - header('Content-Type: application/json'); + header('Content-Type: application/json'); // Write to log. - debug_log($reply_json,'>'); + debug_log($reply_json, '>'); // Send request to telegram api. - curl_json_request($reply_json); + curl_json_request($reply_json); } /** @@ -79,34 +81,35 @@ function send_message($chat_id, $text = array(), $inline_keyboard = false, $merg * @param bool $inline_keyboard * @return mixed */ -function send_location($chat_id, $lat, $lon, $inline_keyboard = false) { +function send_location($chat_id, $lat, $lon, $inline_keyboard = false) +{ // Create reply content array. - $reply_content = [ - 'method' => 'sendLocation', - 'chat_id' => $chat_id, - 'latitude' => $lat, - 'longitude' => $lon - ]; + $reply_content = [ + 'method' => 'sendLocation', + 'chat_id' => $chat_id, + 'latitude' => $lat, + 'longitude' => $lon + ]; // Write to log. - debug_log('KEYS'); - debug_log($inline_keyboard); + debug_log('KEYS'); + debug_log($inline_keyboard); - if (is_array($inline_keyboard)) { - $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; - } + if (is_array($inline_keyboard)) { + $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; + } // Encode data to json. - $reply_json = json_encode($reply_content); + $reply_json = json_encode($reply_content); // Set header to json. - header('Content-Type: application/json'); + header('Content-Type: application/json'); // Write to log. - debug_log($reply_json, '>'); + debug_log($reply_json, '>'); // Send request to telegram api and return response. - return curl_json_request($reply_json); + return curl_json_request($reply_json); } /** @@ -114,26 +117,27 @@ function send_location($chat_id, $lat, $lon, $inline_keyboard = false) { * @param $chat_id * @param $text */ -function sendMessageEcho($chat_id, $text) { - // Create reply content array. - $reply_content = [ +function sendMessageEcho($chat_id, $text) +{ + // Create reply content array. + $reply_content = [ 'method' => 'sendMessage', 'chat_id' => $chat_id, 'parse_mode' => 'HTML', 'text' => $text - ]; + ]; // Encode data to json. - $reply_json = json_encode($reply_content); + $reply_json = json_encode($reply_content); // Set header to json. - header('Content-Type: application/json'); + header('Content-Type: application/json'); // Write to log. - debug_log($reply_json, '>'); + debug_log($reply_json, '>'); // Echo json. - echo($reply_json); + echo($reply_json); } /** @@ -141,13 +145,14 @@ function sendMessageEcho($chat_id, $text) { * @param $query_id * @param $text */ -function answerCallbackQuery($query_id, $text) { +function answerCallbackQuery($query_id, $text) +{ // Create response array. $response = [ - 'method' => 'answerCallbackQuery', - 'callback_query_id' => $query_id, - 'text' => $text - ]; + 'method' => 'answerCallbackQuery', + 'callback_query_id' => $query_id, + 'text' => $text + ]; // Encode response to json format. $json_response = json_encode($response); @@ -167,49 +172,50 @@ function answerCallbackQuery($query_id, $text) { * @param $query_id * @param $contents */ -function answerInlineQuery($query_id, $contents) { +function answerInlineQuery($query_id, $contents) +{ // Init empty result array. $results = array(); // For each content. - foreach ($contents as $key => $row) { + foreach ($contents as $key => $row) { // Get raid poll. - $text = show_raid_poll($row); + $text = show_raid_poll($row); // Get inline keyboard. $inline_keyboard = keys_vote($row); // Create input message content array. $input_message_content = [ - 'parse_mode' => 'HTML', - 'message_text' => $text, - 'disable_web_page_preview' => true - ]; + 'parse_mode' => 'HTML', + 'message_text' => $text, + 'disable_web_page_preview' => true + ]; // Fill results array. - $results[] = [ - 'type' => 'article', - 'id' => $query_id . $key, - 'title' => ucfirst($row['pokemon']) . ' ' . unix2tz($row['ts_end'], $row['timezone']), - 'description' => strval($row['gym_name']), - 'input_message_content' => $input_message_content, - 'reply_markup' => [ + $results[] = [ + 'type' => 'article', + 'id' => $query_id . $key, + 'title' => ucfirst($row['pokemon']) . ' ' . unix2tz($row['ts_end'], $row['timezone']), + 'description' => strval($row['gym_name']), + 'input_message_content' => $input_message_content, + 'reply_markup' => [ 'inline_keyboard' => $inline_keyboard ] - ]; - } + ]; + } // Create reply content array. - $reply_content = [ - 'method' => 'answerInlineQuery', - 'inline_query_id' => $query_id, - 'is_personal' => true, - 'cache_time' => 10, - 'results' => $results - ]; + $reply_content = [ + 'method' => 'answerInlineQuery', + 'inline_query_id' => $query_id, + 'is_personal' => true, + 'cache_time' => 10, + 'results' => $results + ]; // Encode to json and send request to telegram api. - curl_json_request(json_encode($reply_content)); + curl_json_request(json_encode($reply_content)); } /** @@ -220,49 +226,50 @@ function answerInlineQuery($query_id, $contents) { * @param null $chat_id * @param bool $merge_args */ -function editMessageText($id_val, $text_val, $markup_val, $chat_id = NULL, $merge_args = false) { +function editMessageText($id_val, $text_val, $markup_val, $chat_id = NULL, $merge_args = false) +{ // Create response array. $response = [ - 'method' => 'editMessageText', - 'text' => $text_val, - 'parse_mode' => 'HTML', - 'reply_markup' => [ + 'method' => 'editMessageText', + 'text' => $text_val, + 'parse_mode' => 'HTML', + 'reply_markup' => [ 'inline_keyboard' => $markup_val ] - ]; + ]; - if ($markup_val == false) { - unset($response['reply_markup']); - $response['remove_keyboard'] = true; - } + if ($markup_val == false) { + unset($response['reply_markup']); + $response['remove_keyboard'] = true; + } // Valid chat id. - if ($chat_id != null) { - $response['chat_id'] = $chat_id; - $response['message_id'] = $id_val; - } else { - $response['inline_message_id'] = $id_val; - } + if ($chat_id != null) { + $response['chat_id'] = $chat_id; + $response['message_id'] = $id_val; + } else { + $response['inline_message_id'] = $id_val; + } // Write to log. - debug_log($merge_args, 'K'); - debug_log($response, 'K'); + debug_log($merge_args, 'K'); + debug_log($response, 'K'); - if (is_array($merge_args) && count($merge_args)) { - $response = array_merge_recursive($response, $merge_args); - } + if (is_array($merge_args) && count($merge_args)) { + $response = array_merge_recursive($response, $merge_args); + } // Write to log. - debug_log($response,'K'); + debug_log($response, 'K'); // Encode response to json format. - $json_response = json_encode($response); + $json_response = json_encode($response); // Write to log. - debug_log($response,'<-'); + debug_log($response, '<-'); // Send request to telegram api. - curl_json_request($json_response); + curl_json_request($json_response); } /** @@ -271,29 +278,30 @@ function editMessageText($id_val, $text_val, $markup_val, $chat_id = NULL, $merg * @param $markup_val * @param $chat_id */ -function editMessageReplyMarkup($id_val, $markup_val, $chat_id) { +function editMessageReplyMarkup($id_val, $markup_val, $chat_id) +{ // Create response array. $response = [ - 'method' => 'editMessageReplyMarkup', - 'reply_markup' => [ + 'method' => 'editMessageReplyMarkup', + 'reply_markup' => [ 'inline_keyboard' => $markup_val ] - ]; + ]; // Valid chat id. - if ($chat_id != null) { - $response['chat_id'] = $chat_id; - $response['message_id'] = $id_val; + if ($chat_id != null) { + $response['chat_id'] = $chat_id; + $response['message_id'] = $id_val; - } else { - $response['inline_message_id'] = $id_val; - } + } else { + $response['inline_message_id'] = $id_val; + } // Encode response to json format. - $json_response = json_encode($response); + $json_response = json_encode($response); // Write to log. - debug_log($response,'->'); + debug_log($response, '->'); // Send request to telegram api. curl_json_request($json_response); @@ -305,32 +313,33 @@ function editMessageReplyMarkup($id_val, $markup_val, $chat_id) { * @param $markup_val * @param $chat_id */ -function edit_message_keyboard($id_val, $markup_val, $chat_id) { - // Create response array. +function edit_message_keyboard($id_val, $markup_val, $chat_id) +{ + // Create response array. $response = [ - 'method' => 'editMessageReplyMarkup', - 'reply_markup' => [ + 'method' => 'editMessageReplyMarkup', + 'reply_markup' => [ 'inline_keyboard' => $markup_val ] - ]; - - // Valid chat id. + ]; + + // Valid chat id. if ($chat_id != null) { - $response['chat_id'] = $chat_id; - $response['message_id'] = $id_val; + $response['chat_id'] = $chat_id; + $response['message_id'] = $id_val; - } else { - $response['inline_message_id'] = $id_val; - } + } else { + $response['inline_message_id'] = $id_val; + } // Encode response to json format. - $json_response = json_encode($response); + $json_response = json_encode($response); // Write to log. - debug_log($response,'->'); + debug_log($response, '->'); // Send request to telegram api. - curl_json_request($json_response); + curl_json_request($json_response); } /** @@ -340,12 +349,13 @@ function edit_message_keyboard($id_val, $markup_val, $chat_id) { * @param $keys * @param bool $merge_args */ -function edit_message($update, $message, $keys, $merge_args = false) { +function edit_message($update, $message, $keys, $merge_args = false) +{ if (isset($update['callback_query']['inline_message_id'])) { - editMessageText($update['callback_query']['inline_message_id'], $message, $keys, NULL, $merge_args); - } else { - editMessageText($update['callback_query']['message']['message_id'], $message, $keys, $update['callback_query']['message']['chat']['id'], $merge_args); - } + editMessageText($update['callback_query']['inline_message_id'], $message, $keys, NULL, $merge_args); + } else { + editMessageText($update['callback_query']['message']['message_id'], $message, $keys, $update['callback_query']['message']['chat']['id'], $merge_args); + } } /** @@ -353,27 +363,28 @@ function edit_message($update, $message, $keys, $merge_args = false) { * @param $json * @return mixed */ -function curl_json_request($json) { +function curl_json_request($json) +{ - $curl = curl_init('https://api.telegram.org/bot' . API_KEY . '/'); + $curl = curl_init('https://api.telegram.org/bot' . API_KEY . '/'); - curl_setopt($curl, CURLOPT_HEADER, false); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json")); - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $json); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json")); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $json); // Write to log. - debug_log($json, '->'); + debug_log($json, '->'); // Execute curl request. - $json_response = curl_exec($curl); + $json_response = curl_exec($curl); // Write to log. - debug_log($json_response, '<-'); + debug_log($json_response, '<-'); // Decode json response. - $response = json_decode($json_response, true); + $response = json_decode($json_response, true); // Validate response. if ($response['ok'] != true || isset($response['update_id'])) { @@ -382,5 +393,5 @@ function curl_json_request($json) { } // Return response. - return $response; + return $response; } diff --git a/geo_api.php b/geo_api.php index af36b1f..274b320 100644 --- a/geo_api.php +++ b/geo_api.php @@ -5,7 +5,8 @@ * @param $lon * @return bool|string */ -function get_address($lat, $lon) { +function get_address($lat, $lon) +{ // Set maps geocode url. $url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $lat . ',' . $lon; @@ -38,7 +39,7 @@ function get_address($lat, $lon) { $result = $v['formatted_address']; $type = $v['geometry']['location_type']; } - if ($type=='ROOFTOP') return $result; + if ($type == 'ROOFTOP') return $result; } // Return the result. diff --git a/index.php b/index.php index 2ae19fb..0b29759 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,4 @@ -fetch_assoc(); +function raid_access_check($update, $data) +{ + $rs = my_query("SELECT * FROM raids WHERE id = {$data['id']}"); + $raid = $rs->fetch_assoc(); - if ($update['callback_query']['from']['id'] != $raid['user_id']) { - $query = "SELECT COUNT(*) FROM users WHERE user_id={$update['callback_query']['from']['id']} AND moderator=1"; - $rs = my_query($query); - $row = $rs->fetch_row(); + if ($update['callback_query']['from']['id'] != $raid['user_id']) { + $query = "SELECT COUNT(*) FROM users WHERE user_id={$update['callback_query']['from']['id']} AND moderator=1"; + $rs = my_query($query); + $row = $rs->fetch_row(); - if (empty($row['0'])) { + if (empty($row['0'])) { $callback_response = 'You are not allowed to edit this raid'; answerCallbackQuery($update['callback_query']['id'], $callback_response); exit; } - } + } } /** @@ -28,21 +29,22 @@ function raid_access_check($update, $data) { * @param $columns * @return array */ -function inline_key_array($buttons, $columns) { - $result = array(); - $col = 0; - $row = 0; - - foreach ($buttons as $v) { - $result[$row][$col] = $v; - $col++; - - if ($col >= $columns) { - $row++; - $col=0; - } - } - return $result; +function inline_key_array($buttons, $columns) +{ + $result = array(); + $col = 0; + $row = 0; + + foreach ($buttons as $v) { + $result[$row][$col] = $v; + $col++; + + if ($col >= $columns) { + $row++; + $col = 0; + } + } + return $result; } /** @@ -50,37 +52,38 @@ function inline_key_array($buttons, $columns) { * @param $id * @return array */ -function raid_edit_start_keys($id) { - $keys = [ +function raid_edit_start_keys($id) +{ + $keys = [ + [ [ - [ - 'text' => 'Legendary Raid *****', - 'callback_data' => $id . ':edit:type_5' - ] + 'text' => 'Legendary Raid *****', + 'callback_data' => $id . ':edit:type_5' + ] + ], + [ + [ + 'text' => '4 Star Raid ****', + 'callback_data' => $id . ':edit:type_4' ], [ - [ - 'text' => '4 Star Raid ****', - 'callback_data' => $id . ':edit:type_4' - ], - [ - 'text' => '3 Star Raid ***', - 'callback_data' => $id . ':edit:type_3' - ] + 'text' => '3 Star Raid ***', + 'callback_data' => $id . ':edit:type_3' + ] + ], + [ + [ + 'text' => '2 Star Raid **', + 'callback_data' => $id . ':edit:type_2' ], [ - [ - 'text' => '2 Star Raid **', - 'callback_data' => $id . ':edit:type_2' - ], - [ - 'text' => '1 Star Raid *', - 'callback_data' => $id . ':edit:type_1' - ] + 'text' => '1 Star Raid *', + 'callback_data' => $id . ':edit:type_1' ] - ]; + ] + ]; - return $keys; + return $keys; } /** @@ -88,36 +91,37 @@ function raid_edit_start_keys($id) { * @param $data * @return array */ -function keys_raid_people($data) { - - if (!is_array($data)) { - $data = array('id' => $data); - } +function keys_raid_people($data) +{ - $keys = [ - [ - 'text' => '+1', - 'callback_data' => $data['id'] . ':vote:1' - ], - [ - 'text' => '+2', - 'callback_data' => $data['id'] . ':vote:2' - ], - [ - 'text' => '+3', - 'callback_data' => $data['id'] . ':vote:3' - ], - [ - 'text' => '+4', - 'callback_data' => $data['id'] . ':vote:4' - ], - [ - 'text' => '+5', - 'callback_data' => $data['id'] . ':vote:5' - ] - ]; + if (!is_array($data)) { + $data = array('id' => $data); + } - return $keys; + $keys = [ + [ + 'text' => '+1', + 'callback_data' => $data['id'] . ':vote:1' + ], + [ + 'text' => '+2', + 'callback_data' => $data['id'] . ':vote:2' + ], + [ + 'text' => '+3', + 'callback_data' => $data['id'] . ':vote:3' + ], + [ + 'text' => '+4', + 'callback_data' => $data['id'] . ':vote:4' + ], + [ + 'text' => '+5', + 'callback_data' => $data['id'] . ':vote:5' + ] + ]; + + return $keys; } /** @@ -125,110 +129,111 @@ function keys_raid_people($data) { * @param $raid * @return array */ -function keys_vote($raid) { - // Init keys time array. - $keys_time = []; +function keys_vote($raid) +{ + // Init keys time array. + $keys_time = []; - $end_time = $raid['ts_end']; - $now = $raid['ts_now']; + $end_time = $raid['ts_end']; + $now = $raid['ts_now']; - $keys = [ + $keys = [ + [ [ - [ - 'text' => 'alleine', - 'callback_data' => $raid['id'] . ':vote:1' - ], - [ - 'text' => '+1', - 'callback_data' => $raid['id'] . ':vote:2' - ], - [ - 'text' => '+2', - 'callback_data' => $raid['id'] . ':vote:3' - ], - [ - 'text' => '+3', - 'callback_data' => $raid['id'] . ':vote:4' - ], - [ - 'text' => '+4', - 'callback_data' => $raid['id'] . ':vote:5' - ] + 'text' => 'alleine', + 'callback_data' => $raid['id'] . ':vote:1' ], [ - [ - 'text' => TEAM_B . ' Mystic', - 'callback_data' => $raid['id'] . ':vote_team:mystic' - ], - [ - 'text' => TEAM_R . ' Valor', - 'callback_data' => $raid['id'] . ':vote_team:valor' - ], - [ - 'text' => TEAM_Y . ' Instinct', - 'callback_data' => $raid['id'] . ':vote_team:instinct' - ] - ] - ]; - - if ($end_time < $now) { - $keys[] = [ - array( - 'text' =>'Raid beendet.', - 'callback_data' => $raid['id'] . ':vote_time:' . (ceil(time()/900)*900) - ) - ]; - - } else { - $col = 1; - for ($i=ceil($now/900)*900; $i<=($end_time-900); $i=$i+900) { - - if ($col++ >= 4) { - $keys[] = $keys_time; - $keys_time = []; - $col = 1; - } - - $keys_time[] = array( - 'text' => unix2tz($i, $raid['timezone']), - 'callback_data' => $raid['id'] . ':vote_time:' . $i - ); - } - - $keys[] = $keys_time; - } - - - $keys[] = [ - [ - 'text' => EMOJI_REFRESH, - 'callback_data' => $raid['id'] . ':vote_refresh:0' + 'text' => '+1', + 'callback_data' => $raid['id'] . ':vote:2' ], - [ - 'text' => 'Bin da', - 'callback_data' => $raid['id'] . ':vote_arrived:0' + [ + 'text' => '+2', + 'callback_data' => $raid['id'] . ':vote:3' ], - [ - 'text' => 'Fertig', - 'callback_data' => $raid['id'] . ':vote_done:0' + [ + 'text' => '+3', + 'callback_data' => $raid['id'] . ':vote:4' ], - [ - 'text' => 'Absage', - 'callback_data' => $raid['id'] . ':vote_cancel:0' + [ + 'text' => '+4', + 'callback_data' => $raid['id'] . ':vote:5' + ] + ], + [ + [ + 'text' => TEAM_B . ' Mystic', + 'callback_data' => $raid['id'] . ':vote_team:mystic' + ], + [ + 'text' => TEAM_R . ' Valor', + 'callback_data' => $raid['id'] . ':vote_team:valor' ], - ]; + [ + 'text' => TEAM_Y . ' Instinct', + 'callback_data' => $raid['id'] . ':vote_team:instinct' + ] + ] + ]; + + if ($end_time < $now) { + $keys[] = [ + array( + 'text' => 'Raid beendet.', + 'callback_data' => $raid['id'] . ':vote_time:' . (ceil(time() / 900) * 900) + ) + ]; + + } else { + $col = 1; + for ($i = ceil($now / 900) * 900; $i <= ($end_time - 900); $i = $i + 900) { + + if ($col++ >= 4) { + $keys[] = $keys_time; + $keys_time = []; + $col = 1; + } - if ($end_time < $now) { - $keys = [ + $keys_time[] = array( + 'text' => unix2tz($i, $raid['timezone']), + 'callback_data' => $raid['id'] . ':vote_time:' . $i + ); + } + + $keys[] = $keys_time; + } + + + $keys[] = [ + [ + 'text' => EMOJI_REFRESH, + 'callback_data' => $raid['id'] . ':vote_refresh:0' + ], + [ + 'text' => 'Bin da', + 'callback_data' => $raid['id'] . ':vote_arrived:0' + ], + [ + 'text' => 'Fertig', + 'callback_data' => $raid['id'] . ':vote_done:0' + ], + [ + 'text' => 'Absage', + 'callback_data' => $raid['id'] . ':vote_cancel:0' + ], + ]; + + if ($end_time < $now) { + $keys = [ + [ [ - [ - 'text' => 'Raid beendet', - 'callback_data' => $raid['id'] . ':vote_refresh:0' - ] + 'text' => 'Raid beendet', + 'callback_data' => $raid['id'] . ':vote_refresh:0' ] - ]; - } - return $keys; + ] + ]; + } + return $keys; } /** @@ -236,7 +241,8 @@ function keys_vote($raid) { * @param $update * @return bool|mysqli_result */ -function update_user($update) { +function update_user($update) +{ global $db; $name = ''; @@ -293,7 +299,8 @@ function update_user($update) { * @param $data * @param bool $new */ -function send_response_vote($update, $data, $new = false) { +function send_response_vote($update, $data, $new = false) +{ $rs = my_query( " SELECT *, @@ -320,7 +327,7 @@ function send_response_vote($update, $data, $new = false) { debug_log($loc); send_message($update['callback_query']['message']['chat']['id'], $msg . "\n", $keys, ['reply_to_message_id' => $loc['result']['message_id']]); - answerCallbackQuery($update['callback_query']['id'],$msg); + answerCallbackQuery($update['callback_query']['id'], $msg); } else { edit_message($update, $msg, $keys); @@ -337,14 +344,15 @@ function send_response_vote($update, $data, $new = false) { * @param string $format * @return bool|string */ -function unix2tz($unix, $tz, $format = 'H:i') { - if (!$unix) { +function unix2tz($unix, $tz, $format = 'H:i') +{ + if (!$unix) { return false; } - $dt = new DateTime('@' . $unix); - $dt->setTimeZone(new DateTimeZone($tz)); - return $dt->format($format); + $dt = new DateTime('@' . $unix); + $dt->setTimeZone(new DateTimeZone($tz)); + return $dt->format($format); } /** @@ -352,37 +360,38 @@ function unix2tz($unix, $tz, $format = 'H:i') { * @param $raid * @return string */ -function show_raid_poll($raid) { - $time_left = floor($raid['t_left']/60); - $time_left = floor($time_left/60) . ':' . str_pad($time_left%60,2, '0', STR_PAD_LEFT) . 'h übrig '; +function show_raid_poll($raid) +{ + $time_left = floor($raid['t_left'] / 60); + $time_left = floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h übrig '; // Init empty message string. - $msg = ''; + $msg = ''; - if ($raid['gym_name'] || $raid['gym_team']) { - $msg .= 'Arena: ' . $raid['gym_name'] . ''; - if ($raid['gym_team']) { + if ($raid['gym_name'] || $raid['gym_team']) { + $msg .= 'Arena: ' . $raid['gym_name'] . ''; + if ($raid['gym_team']) { $msg .= ' ' . $GLOBALS['teams'][$raid['gym_team']] . ' ' . ucfirst($raid['gym_team']); } - $msg .= CR; - } + $msg .= CR; + } - if ($raid['address']) { - $addr = explode(',', $raid['address'], 4); - array_pop($addr); - $addr = implode(',', $addr); - $msg .= 'Adresse: ' . $addr . '' . CR2; - } - $msg .= 'Raid Boss: ' . ucfirst($raid['pokemon']) . '' . CR2; + if ($raid['address']) { + $addr = explode(',', $raid['address'], 4); + array_pop($addr); + $addr = implode(',', $addr); + $msg .= 'Adresse: ' . $addr . '' . CR2; + } + $msg .= 'Raid Boss: ' . ucfirst($raid['pokemon']) . '' . CR2; - if ($time_left < 0) { - $msg .= 'Raid beendet.' . CR2; + if ($time_left < 0) { + $msg .= 'Raid beendet.' . CR2; - } else { - $msg .= ''.$time_left.' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . CR; - } + } else { + $msg .= '' . $time_left . ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . CR; + } - $rs = my_query( + $rs = my_query( " SELECT *, UNIX_TIMESTAMP(attend_time) AS ts_att @@ -396,35 +405,35 @@ function show_raid_poll($raid) { " ); - $data = array(); - - while ($row = $rs->fetch_assoc()) { - if ($row['cancel']) { + $data = array(); + + while ($row = $rs->fetch_assoc()) { + if ($row['cancel']) { $row['team'] = 'cancel'; } - if ($row['raid_done']) { + if ($row['raid_done']) { $row['team'] = 'done'; } - if (!$row['team']) { + if (!$row['team']) { $row['team'] = 'unknown'; } $data[$row['team']][] = $row; if ($row['extra_people']) { - for ($i = 1; $i <= $row['extra_people']; $i++) { - $data[$row['team']][] = false; - } - } - } - - debug_log($data); - - if (count($data) == 0) { - $msg .= CR . 'Noch keine Teilnehmer.' . CR; - } - - $rs = my_query( + for ($i = 1; $i <= $row['extra_people']; $i++) { + $data[$row['team']][] = false; + } + } + } + + debug_log($data); + + if (count($data) == 0) { + $msg .= CR . 'Noch keine Teilnehmer.' . CR; + } + + $rs = my_query( " SELECT DISTINCT UNIX_TIMESTAMP(attend_time) AS ts_att, count(attend_time) AS count, @@ -440,18 +449,18 @@ function show_raid_poll($raid) { ); // Init empty time slots array. - $timeSlots = array(); + $timeSlots = array(); - while ($row = $rs->fetch_assoc()) { + while ($row = $rs->fetch_assoc()) { $timeSlots[] = $row; - } + } // Write to log. - debug_log($timeSlots); - - foreach ($timeSlots as $ts) { + debug_log($timeSlots); + + foreach ($timeSlots as $ts) { // Add to message. - $msg .= CR . '' . unix2tz($ts['ts_att'], $raid['timezone']) . '' . ' [' . ($ts['count']+$ts['extra']) . ']' . CR; + $msg .= CR . '' . unix2tz($ts['ts_att'], $raid['timezone']) . '' . ' [' . ($ts['count'] + $ts['extra']) . ']' . CR; $user_rs = my_query( " @@ -470,13 +479,13 @@ function show_raid_poll($raid) { while ($rowusers = $user_rs->fetch_assoc()) { - $att_users[] = $rowusers; - } + $att_users[] = $rowusers; + } // Write to log. - debug_log($att_users); - - foreach ($att_users as $vv) { + debug_log($att_users); + + foreach ($att_users as $vv) { // Write to log. debug_log($vv['user_id']); @@ -488,46 +497,46 @@ function show_raid_poll($raid) { " ); - $row = $rs->fetch_assoc(); + $row = $rs->fetch_assoc(); - // Always use name. - $name = htmlspecialchars($row['name']); + // Always use name. + $name = htmlspecialchars($row['name']); // Unknown team. if ($row['team'] === NULL) { - $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' ' . $name . ' '; + $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' ' . $name . ' '; - // Known team. - } else { - $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name . ' '; - } + // Known team. + } else { + $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name . ' '; + } // Arrived. - if ($vv['arrived']) { - $msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + if ($vv['arrived']) { + $msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; - // Cancelled. - } else if ($vv['cancel']) { - $msg .= '[abgesagt] '; - } + // Cancelled. + } else if ($vv['cancel']) { + $msg .= '[abgesagt] '; + } // Add extra people. - if ($vv['extra_people']) { + if ($vv['extra_people']) { $msg .= '+' . $vv['extra_people']; } - - $msg .= CR; - } - } - - // DONE - if (count($data['done'])) { + + $msg .= CR; + } + } + + // DONE + if (count($data['done'])) { // Add to message. - $msg .= CR . TEAM_DONE . ' Fertig: ' . ' [' . count($data['done']) . ']' . CR; + $msg .= CR . TEAM_DONE . ' Fertig: ' . ' [' . count($data['done']) . ']' . CR; foreach ($data['done'] as $vv) { - if (!$vv['raid_done']) continue; + if (!$vv['raid_done']) continue; $rs = my_query( " @@ -542,29 +551,29 @@ function show_raid_poll($raid) { $name = htmlspecialchars($row['name']); // Add to message. - $msg .= ' └ '.$GLOBALS['teams'][$row['team']].' '.$name.' '; + $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name . ' '; // Done. - if ($vv['raid_done']) { - $msg .= '[Fertig '.unix2tz($vv['ts_att'],$raid['timezone']).'] '; - } + if ($vv['raid_done']) { + $msg .= '[Fertig ' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + } // Add extra people. - if ($vv['extra_people']) { + if ($vv['extra_people']) { $msg .= '+' . $vv['extra_people']; } - $msg .= CR; - } - } + $msg .= CR; + } + } // CANCEL - if (count($data['cancel'])) { - // Add to message. + if (count($data['cancel'])) { + // Add to message. $msg .= CR . TEAM_CANCEL . ' Abgesagt: ' . ' [' . count($data['cancel']) . ']' . CR; foreach ($data['cancel'] as $vv) { - if (!$vv['cancel']) continue; + if (!$vv['cancel']) continue; $rs = my_query( " @@ -582,22 +591,22 @@ function show_raid_poll($raid) { // Cancel. if ($vv['cancel']) { - $msg .= '[Abgesagt '.unix2tz($vv['ts_att'],$raid['timezone']).'] '; - } + $msg .= '[Abgesagt ' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + } // Add extra people. - if ($vv['extra_people']) { + if ($vv['extra_people']) { $msg .= '+' . $vv['extra_people']; } - $msg .= CR; - } - } + $msg .= CR; + } + } // Add update time and raid id to message. - $msg .= CR . 'Aktualisiert: ' . unix2tz(time(), $raid['timezone'], 'H:i:s') . ' ID = ' . $raid['id']; + $msg .= CR . 'Aktualisiert: ' . unix2tz(time(), $raid['timezone'], 'H:i:s') . ' ID = ' . $raid['id']; // Return the message. - return $msg; + return $msg; } /** @@ -605,23 +614,24 @@ function show_raid_poll($raid) { * @param $raid * @return string */ -function show_raid_poll_small($raid) { - $time_left = floor($raid['t_left']/60); - $time_left = floor($time_left/60) . ':' . str_pad($time_left%60, 2, '0', STR_PAD_LEFT) . ' left'; +function show_raid_poll_small($raid) +{ + $time_left = floor($raid['t_left'] / 60); + $time_left = floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . ' left'; - $msg = '' . ucfirst($raid['pokemon']) . ' ' . $time_left . ' ' . $raid['gym_name'] . '' . CR; + $msg = '' . ucfirst($raid['pokemon']) . ' ' . $time_left . ' ' . $raid['gym_name'] . '' . CR; // Address found. if ($raid['address']) { - $addr = explode(',', $raid['address'], 4); - array_pop($addr); - $addr = implode(',', $addr); + $addr = explode(',', $raid['address'], 4); + array_pop($addr); + $addr = implode(',', $addr); // Add to message. - $msg .= '' . $addr . '' . CR2; - } + $msg .= '' . $addr . '' . CR2; + } // Build query. - $rs = my_query( + $rs = my_query( " SELECT team, COUNT(*) AS cnt, @@ -633,45 +643,46 @@ function show_raid_poll_small($raid) { GROUP BY team " ); - - $total = 0; - $sep = ''; + + $total = 0; + $sep = ''; while ($row = $rs->fetch_assoc()) { - $sum = $row['cnt']+$row['extra']; + $sum = $row['cnt'] + $row['extra']; - if ($sum==0) continue; + if ($sum == 0) continue; // Add to message. $msg .= $sep . $GLOBALS['teams'][$row['team']] . ' ' . $sum; - $sep = ' | '; - $total += $sum; - } + $sep = ' | '; + $total += $sum; + } - if (!$total) { - $msg .= ' Keine Teilnehmer' . CR; - } else { - $msg .= ' = ' . $total . '' . CR; - } + if (!$total) { + $msg .= ' Keine Teilnehmer' . CR; + } else { + $msg .= ' = ' . $total . '' . CR; + } - return $msg; + return $msg; } /** * Raid list. * @param $update */ -function raid_list($update) { +function raid_list($update) +{ // Init empty rows array. $rows = array(); - // Inline list polls. - if ($update['inline_query']['query']) { + // Inline list polls. + if ($update['inline_query']['query']) { $iqq = intval($update['inline_query']['query']); - // By ID. - $request = my_query( + // By ID. + $request = my_query( " SELECT *, UNIX_TIMESTAMP(end_time) AS ts_end, @@ -683,8 +694,8 @@ function raid_list($update) { ); } else { - // By user. - $request = my_query( + // By user. + $request = my_query( " SELECT *, UNIX_TIMESTAMP(end_time) AS ts_end, @@ -695,9 +706,9 @@ function raid_list($update) { ORDER BY id DESC LIMIT 3 " ); - } + } - while($answer = $request->fetch_assoc()) { + while ($answer = $request->fetch_assoc()) { $rows[] = $answer; } diff --git a/modules/edit.php b/modules/edit.php index 83b7b79..9cfc2e1 100644 --- a/modules/edit.php +++ b/modules/edit.php @@ -1,79 +1,79 @@ 'Articuno', 'callback_data' => $id.':edit_poke:articuno', - ],[ - 'text' => 'Lugia', 'callback_data' => $id.':edit_poke:lugia', - ],[ - 'text' => 'Moltres', 'callback_data' => $id.':edit_poke:moltres', - ],[ - 'text' => 'Zapdos', 'callback_data' => $id.':edit_poke:zapdos', - ]]]; - - } else if ($data['arg']=='type_4') { - $keys = - [[[ - 'text' => 'Tyranitar', 'callback_data' => $id.':edit_poke:tyranitar', - ]],[[ - 'text' => 'Snorlax', 'callback_data' => $id.':edit_poke:snorlax', - ],[ - 'text' => 'Lapras', 'callback_data' => $id.':edit_poke:lapras', - ],[ - 'text' => 'Rhydon', 'callback_data' => $id.':edit_poke:rhydon', - ]],[[ - 'text' => 'Charizard', 'callback_data' => $id.':edit_poke:charizard', - ],[ - 'text' => 'Venusaur', 'callback_data' => $id.':edit_poke:venusaur', - ],[ - 'text' => 'Blastoise', 'callback_data' => $id.':edit_poke:blastoise', - ]]]; - } else if ($data['arg']=='type_3') { - $keys = - [[[ - 'text' => 'Machamp', 'callback_data' => $id.':edit_poke:machamp', - ]],[[ - 'text' => 'Vaporeon', 'callback_data' => $id.':edit_poke:vaporeon', - ],[ - 'text' => 'Flareon', 'callback_data' => $id.':edit_poke:flareon', - ],[ - 'text' => 'Jolteon', 'callback_data' => $id.':edit_poke:jolteon', - ]],[[ - 'text' => 'Alakazam', 'callback_data' => $id.':edit_poke:alakazam', - ],[ - 'text' => 'Arcanine', 'callback_data' => $id.':edit_poke:arcanine', - ],[ - 'text' => 'Gengar', 'callback_data' => $id.':edit_poke:gengar', - ]]]; - } else if ($data['arg']=='type_2') { - $keys = - [[[ - 'text' => 'Muk', 'callback_data' => $id.':edit_poke:muk', - ]]]; - } else if ($data['arg']=='type_1') { - $keys = [[[ 'text' => 'Not supported', 'callback_data' => 'edit:not_supported' ]]]; - } else { - /* Edit pokemon */ - $keys = raid_edit_start_keys(); - } +if ($data['arg'] == 'type_5') { + $keys = + [[[ + 'text' => 'Articuno', 'callback_data' => $id . ':edit_poke:articuno', + ], [ + 'text' => 'Lugia', 'callback_data' => $id . ':edit_poke:lugia', + ], [ + 'text' => 'Moltres', 'callback_data' => $id . ':edit_poke:moltres', + ], [ + 'text' => 'Zapdos', 'callback_data' => $id . ':edit_poke:zapdos', + ]]]; - if (!$keys) $keys = [[[ 'text' => 'Not supported', 'callback_data' => 'edit:not_supported' ]]]; +} else if ($data['arg'] == 'type_4') { + $keys = + [[[ + 'text' => 'Tyranitar', 'callback_data' => $id . ':edit_poke:tyranitar', + ]], [[ + 'text' => 'Snorlax', 'callback_data' => $id . ':edit_poke:snorlax', + ], [ + 'text' => 'Lapras', 'callback_data' => $id . ':edit_poke:lapras', + ], [ + 'text' => 'Rhydon', 'callback_data' => $id . ':edit_poke:rhydon', + ]], [[ + 'text' => 'Charizard', 'callback_data' => $id . ':edit_poke:charizard', + ], [ + 'text' => 'Venusaur', 'callback_data' => $id . ':edit_poke:venusaur', + ], [ + 'text' => 'Blastoise', 'callback_data' => $id . ':edit_poke:blastoise', + ]]]; +} else if ($data['arg'] == 'type_3') { + $keys = + [[[ + 'text' => 'Machamp', 'callback_data' => $id . ':edit_poke:machamp', + ]], [[ + 'text' => 'Vaporeon', 'callback_data' => $id . ':edit_poke:vaporeon', + ], [ + 'text' => 'Flareon', 'callback_data' => $id . ':edit_poke:flareon', + ], [ + 'text' => 'Jolteon', 'callback_data' => $id . ':edit_poke:jolteon', + ]], [[ + 'text' => 'Alakazam', 'callback_data' => $id . ':edit_poke:alakazam', + ], [ + 'text' => 'Arcanine', 'callback_data' => $id . ':edit_poke:arcanine', + ], [ + 'text' => 'Gengar', 'callback_data' => $id . ':edit_poke:gengar', + ]]]; +} else if ($data['arg'] == 'type_2') { + $keys = + [[[ + 'text' => 'Muk', 'callback_data' => $id . ':edit_poke:muk', + ]]]; +} else if ($data['arg'] == 'type_1') { + $keys = [[['text' => 'Not supported', 'callback_data' => 'edit:not_supported']]]; +} else { + /* Edit pokemon */ + $keys = raid_edit_start_keys(); +} - if (isset($update['callback_query']['inline_message_id'])) { - editMessageText($update['callback_query']['inline_message_id'],'Choose Raid Boss:',$keys); - } else { - editMessageText($update['callback_query']['message']['message_id'],'Choose Raid Boss',$keys,$update['callback_query']['message']['chat']['id'],$keys); - } - - //edit_message_keyboard($update['callback_query']['message']['message_id'],$keys,$update['callback_query']['message']['chat']['id']); - $callback_response = 'Ok'; - answerCallbackQuery($update['callback_query']['id'],$callback_response); +if (!$keys) $keys = [[['text' => 'Not supported', 'callback_data' => 'edit:not_supported']]]; + +if (isset($update['callback_query']['inline_message_id'])) { + editMessageText($update['callback_query']['inline_message_id'], 'Choose Raid Boss:', $keys); +} else { + editMessageText($update['callback_query']['message']['message_id'], 'Choose Raid Boss', $keys, $update['callback_query']['message']['chat']['id'], $keys); +} + +//edit_message_keyboard($update['callback_query']['message']['message_id'],$keys,$update['callback_query']['message']['chat']['id']); +$callback_response = 'Ok'; +answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/edit_left.php b/modules/edit_left.php index cc88e7e..a5a08cb 100644 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -1,43 +1,43 @@ 'Share','switch_inline_query'=>strval($id), - ]]]; - - $msg = 'Raid saved.'.CR.'Optional - set gym name and team:'.CR2.'/gym gym name'.CR.'/team Mystic/Valor/Instinct/Blue/Red/Yellow'; - edit_message($update, $msg, $keys, false); +if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { + $keys = [[[ + 'text' => 'Share', 'switch_inline_query' => strval($id), + ]]]; - $callback_response = 'End time set to '.$data['arg'].' minutes'; - answerCallbackQuery($update['callback_query']['id'],$callback_response); + $msg = 'Raid saved.' . CR . 'Optional - set gym name and team:' . CR2 . '/gym gym name' . CR . '/team Mystic/Valor/Instinct/Blue/Red/Yellow'; + edit_message($update, $msg, $keys, false); - } else { + $callback_response = 'End time set to ' . $data['arg'] . ' minutes'; + answerCallbackQuery($update['callback_query']['id'], $callback_response); - $rs = my_query('SELECT *, +} else { + + $rs = my_query('SELECT *, UNIX_TIMESTAMP(end_time) AS ts_end, UNIX_TIMESTAMP(NOW()) as ts_now, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE id='.$data['id'].''); - $raid = $rs->fetch_assoc(); - - $text = show_raid_poll($raid); - $keys = keys_vote($raid); + FROM raids WHERE id=' . $data['id'] . ''); + $raid = $rs->fetch_assoc(); + + $text = show_raid_poll($raid); + $keys = keys_vote($raid); - edit_message($update, $text, $keys, $false); + edit_message($update, $text, $keys, $false); - $callback_response = 'End time set to '.$data['arg'].' minutes'; - answerCallbackQuery($update['callback_query']['id'],$callback_response); - } + $callback_response = 'End time set to ' . $data['arg'] . ' minutes'; + answerCallbackQuery($update['callback_query']['id'], $callback_response); +} diff --git a/modules/edit_poke.php b/modules/edit_poke.php index 38df3b8..790f88c 100644 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -1,33 +1,33 @@ =25; $i=$i-5) { - $keys[] = array('text' => floor($i/60).':'.str_pad($i%60,2,'0',STR_PAD_LEFT).' left', 'callback_data' => $id.':edit_left:'.$i); - } - $keys = inline_key_array($keys,4); - debug_log($keys); + $keys = array(); + for ($i = 120; $i >= 25; $i = $i - 5) { + $keys[] = array('text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT) . ' left', 'callback_data' => $id . ':edit_left:' . $i); + } + $keys = inline_key_array($keys, 4); + debug_log($keys); - } else { - /* Edit pokemon */ - $keys = raid_edit_start_keys(); - } +} else { + /* Edit pokemon */ + $keys = raid_edit_start_keys(); +} - if (!$keys) $keys = [[[ 'text' => 'Not supported', 'callback_data' => 'edit:not_supported' ]]]; - - edit_message($update, 'How much time is left for Raid?', $keys); +if (!$keys) $keys = [[['text' => 'Not supported', 'callback_data' => 'edit:not_supported']]]; - $callback_response = 'Pokemon set to '.$data['arg']; - answerCallbackQuery($update['callback_query']['id'],$callback_response); +edit_message($update, 'How much time is left for Raid?', $keys); + +$callback_response = 'Pokemon set to ' . $data['arg']; +answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/raid_create.php b/modules/raid_create.php index bb58250..905f238 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -1,39 +1,39 @@ real_escape_string($addr).'"'; - } - - $rs = my_query($q); - $id = my_insert_id(); - debug_log('ID='.$id); - - $keys = raid_edit_start_keys($id); - - $msg = 'Create Raid at '.$addr.''; - - if ($update['message']['chat']['type']=='private') { - send_message($update['message']['chat']['id'],$msg.CR.'Choose Raid level:', $keys); - } else { - $reply_to = $update['message']['chat']['id']; - if ($update['message']['reply_to_message']['message_id']) $reply_to = $update['message']['reply_to_message']['message_id']; - - send_message($update['message']['chat']['id'],$msg.CR.'Choose Raid level:', $keys, - ['reply_to_message_id'=>$reply_to, 'reply_markup' => ['selective'=>true, 'one_time_keyboard'=>true]] - ); - } - exit(); +$q .= ', timezone="' . TIMEZONE . '"'; + +if ($addr) { + $q .= ', address="' . $db->real_escape_string($addr) . '"'; +} + +$rs = my_query($q); +$id = my_insert_id(); +debug_log('ID=' . $id); + +$keys = raid_edit_start_keys($id); + +$msg = 'Create Raid at ' . $addr . ''; + +if ($update['message']['chat']['type'] == 'private') { + send_message($update['message']['chat']['id'], $msg . CR . 'Choose Raid level:', $keys); +} else { + $reply_to = $update['message']['chat']['id']; + if ($update['message']['reply_to_message']['message_id']) $reply_to = $update['message']['reply_to_message']['message_id']; + + send_message($update['message']['chat']['id'], $msg . CR . 'Choose Raid level:', $keys, + ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]] + ); +} +exit(); diff --git a/modules/vote.php b/modules/vote.php index 5c29ae7..d3b63fc 100644 --- a/modules/vote.php +++ b/modules/vote.php @@ -1,23 +1,23 @@ fetch_assoc(); - debug_log($answer); +$rs = my_query('SELECT * FROM attendance WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +$answer = $rs->fetch_assoc(); +debug_log($answer); - $rs = my_query('SELECT * FROM users WHERE user_id='.$update['callback_query']['from']['id'].''); - $row=$rs->fetch_assoc(); - - $qq = 'extra_people='.intval($data['arg']-1); - if ($row['team']) $qq .= ', team="'.$row['team'].'"'; - debug_log($row); - debug_log($qq); - - if (!$answer) { - my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', '.$qq); - } else { - my_query('UPDATE attendance SET '.$qq.' WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); - } - - send_response_vote($update, $data); +$rs = my_query('SELECT * FROM users WHERE user_id=' . $update['callback_query']['from']['id'] . ''); +$row = $rs->fetch_assoc(); + +$qq = 'extra_people=' . intval($data['arg'] - 1); +if ($row['team']) $qq .= ', team="' . $row['team'] . '"'; +debug_log($row); +debug_log($qq); + +if (!$answer) { + my_query('INSERT INTO attendance SET raid_id=' . $data['id'] . ', user_id=' . $update['callback_query']['from']['id'] . ', ' . $qq); +} else { + my_query('UPDATE attendance SET ' . $qq . ' WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +} + +send_response_vote($update, $data); diff --git a/modules/vote_arrived.php b/modules/vote_arrived.php index b27fa78..676f0f5 100644 --- a/modules/vote_arrived.php +++ b/modules/vote_arrived.php @@ -1,18 +1,18 @@ fetch_assoc(); - debug_log($answer); - - if (!$answer) { - //$query = 'SELECT * FROM users WHERE user_id='.$update['callback_query']['from']['id']; - //$rs = my_query($query); - //$row = $rs->fetch_assoc(); +$rs = my_query('SELECT * FROM attendance WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +$answer = $rs->fetch_assoc(); +debug_log($answer); - //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', arrived=1, team="'.$row['team'].'", attend_time=NOW()'); - } else { - my_query('UPDATE attendance SET arrived=1,raid_done=0,cancel=0 WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); - } - - send_response_vote($update, $data); +if (!$answer) { + //$query = 'SELECT * FROM users WHERE user_id='.$update['callback_query']['from']['id']; + //$rs = my_query($query); + //$row = $rs->fetch_assoc(); + + //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', arrived=1, team="'.$row['team'].'", attend_time=NOW()'); +} else { + my_query('UPDATE attendance SET arrived=1,raid_done=0,cancel=0 WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +} + +send_response_vote($update, $data); diff --git a/modules/vote_cancel.php b/modules/vote_cancel.php index d0e140c..94c1093 100644 --- a/modules/vote_cancel.php +++ b/modules/vote_cancel.php @@ -1,14 +1,14 @@ fetch_assoc(); - debug_log($answer); - - if (!$answer) { - //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', cancel=1, attend_time=NULL'); - } else { - my_query('UPDATE attendance SET cancel=1, raid_done=0, arrived=0 WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); - } - - send_response_vote($update, $data); +$rs = my_query('SELECT * FROM attendance WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +$answer = $rs->fetch_assoc(); +debug_log($answer); + +if (!$answer) { + //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', cancel=1, attend_time=NULL'); +} else { + my_query('UPDATE attendance SET cancel=1, raid_done=0, arrived=0 WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +} + +send_response_vote($update, $data); diff --git a/modules/vote_done.php b/modules/vote_done.php index e38bc42..8e2a702 100644 --- a/modules/vote_done.php +++ b/modules/vote_done.php @@ -1,14 +1,14 @@ fetch_assoc(); - debug_log($answer); - - if (!$answer) { - //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', raid_done=1'); - } else { - my_query('UPDATE attendance SET raid_done=1 WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); - } - - send_response_vote($update, $data); +$rs = my_query('SELECT * FROM attendance WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +$answer = $rs->fetch_assoc(); +debug_log($answer); + +if (!$answer) { + //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', raid_done=1'); +} else { + my_query('UPDATE attendance SET raid_done=1 WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +} + +send_response_vote($update, $data); diff --git a/modules/vote_edit.php b/modules/vote_edit.php index f122dd5..d2db2e1 100644 --- a/modules/vote_edit.php +++ b/modules/vote_edit.php @@ -1,4 +1,4 @@ fetch_assoc(); - debug_log($answer); - - if (!$answer) { - my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', team="'.$data['arg'].'"'); - } else { - my_query('UPDATE attendance SET team="'.$data['arg'].'" WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); - } - - my_query('UPDATE users SET team="'.$data['arg'].'" WHERE user_id='.$update['callback_query']['from']['id'].''); - - send_response_vote($update, $data); +$rs = my_query('SELECT * FROM attendance WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +$answer = $rs->fetch_assoc(); +debug_log($answer); + +if (!$answer) { + my_query('INSERT INTO attendance SET raid_id=' . $data['id'] . ', user_id=' . $update['callback_query']['from']['id'] . ', team="' . $data['arg'] . '"'); +} else { + my_query('UPDATE attendance SET team="' . $data['arg'] . '" WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +} + +my_query('UPDATE users SET team="' . $data['arg'] . '" WHERE user_id=' . $update['callback_query']['from']['id'] . ''); + +send_response_vote($update, $data); diff --git a/modules/vote_time.php b/modules/vote_time.php index 4393aa2..4f21446 100644 --- a/modules/vote_time.php +++ b/modules/vote_time.php @@ -1,18 +1,18 @@ fetch_assoc(); - debug_log($answer); +$rs = my_query('SELECT * FROM attendance WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +$answer = $rs->fetch_assoc(); +debug_log($answer); - if (!$answer) { - $query = 'SELECT * FROM users WHERE user_id='.$update['callback_query']['from']['id']; - $rs = my_query($query); - $row = $rs->fetch_assoc(); - - my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', attend_time=FROM_UNIXTIME('.$data['arg'].'), team="'.$row['team'].'"'); - } else { - my_query('UPDATE attendance SET attend_time=FROM_UNIXTIME('.$data['arg'].'), cancel=0, arrived=0,raid_done=0 WHERE raid_id='.$data['id'].' AND user_id='.$update['callback_query']['from']['id'].''); - } - - send_response_vote($update, $data); +if (!$answer) { + $query = 'SELECT * FROM users WHERE user_id=' . $update['callback_query']['from']['id']; + $rs = my_query($query); + $row = $rs->fetch_assoc(); + + my_query('INSERT INTO attendance SET raid_id=' . $data['id'] . ', user_id=' . $update['callback_query']['from']['id'] . ', attend_time=FROM_UNIXTIME(' . $data['arg'] . '), team="' . $row['team'] . '"'); +} else { + my_query('UPDATE attendance SET attend_time=FROM_UNIXTIME(' . $data['arg'] . '), cancel=0, arrived=0,raid_done=0 WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); +} + +send_response_vote($update, $data); diff --git a/webhook.html b/webhook.html index a3f3943..ae6d60d 100644 --- a/webhook.html +++ b/webhook.html @@ -1,37 +1,39 @@ -Set Webhooks + Set Webhooks
-
- Enter your Bot Token:
- Enter your Bot Url:
- MAX Connections?:
- Enter your Certificate:
-
- -
+
+ Enter your Bot Token:
+ Enter your Bot Url:
+ MAX Connections?:
+ Enter your Certificate:
+
+ +
From 304e2f6f323d50a069a32ef71ff53b17aec209dc Mon Sep 17 00:00:00 2001 From: d4NY0H Date: Wed, 16 Aug 2017 16:54:38 +0200 Subject: [PATCH 006/225] cleanup done for now --- commands/gym.php | 54 ++++++++--- commands/help.php | 2 +- commands/list.php | 64 +++++++++---- commands/raid.php | 112 ++++++++++++++++------- commands/start.php | 2 +- commands/team.php | 40 +++++--- constants.php | 42 +++++---- functions.php | 2 +- index.php | 6 +- logic.php | 72 +++++++++------ modules/edit.php | 192 ++++++++++++++++++++++++++++----------- modules/edit_left.php | 64 ++++++++++--- modules/edit_poke.php | 2 +- modules/raid_create.php | 57 +++++++++--- modules/vote.php | 36 ++++++-- modules/vote_arrived.php | 63 +++++++++++-- modules/vote_cancel.php | 47 ++++++++-- modules/vote_done.php | 42 ++++++++- modules/vote_edit.php | 2 +- modules/vote_refresh.php | 2 +- modules/vote_team.php | 48 +++++++++- modules/vote_time.php | 62 +++++++++++-- 22 files changed, 760 insertions(+), 253 deletions(-) diff --git a/commands/gym.php b/commands/gym.php index 9dac5b8..7cc86f8 100644 --- a/commands/gym.php +++ b/commands/gym.php @@ -1,36 +1,68 @@ real_escape_string($gym_name) . '" WHERE user_id=' . $update['message']['from']['id'] . ' ORDER BY id DESC LIMIT 1'; - my_query($query); + // Build query. + my_query( + " + UPDATE raids + SET gym_name = '{$db->real_escape_string($gym_name)}' + WHERE user_id = {$update['message']['from']['id']} + ORDER BY id DESC LIMIT 1 + " + ); sendMessage($update['message']['chat']['id'], 'Gym name updated'); } else { if ($update['message']['reply_to_message']['text']) { + $lines = explode(CR, $update['message']['reply_to_message']['text']); $last_line = array_pop($lines); $pos = strpos($last_line, 'ID = '); $id = intval(trim(substr($last_line, $pos + 5))); + + // Write to log. debug_log('Gym ID=' . $id . ' name=' . $gym_name); - $query = 'SELECT COUNT(*) FROM users WHERE user_id=' . $update['message']['from']['id'] . ' AND moderator=1'; - $rs = my_query($query); + // Build query. + $rs = my_query( + " + SELECT COUNT(*) + FROM users + WHERE user_id = {$update['message']['from']['id']} + AND moderator = 1 + " + ); $row = $rs->fetch_row(); - $q = ' AND user_id=' . $update['message']['from']['id']; + + if ($row[0]) { - $q = ''; - } + // Build query. + my_query( + " + UPDATE raids + SET gym_name = '{$db->real_escape_string($gym_name)}' + WHERE id = {$id} + " + ); - $query = 'UPDATE raids SET gym_name="' . $db->real_escape_string($gym_name) . '" WHERE id=' . $id . ' ' . $q; - my_query($query); + } else { + // Build query. + my_query( + " + UPDATE raids + SET gym_name = '{$db->real_escape_string($gym_name)}' + WHERE id = {$id} + AND user_id = {$update['message']['from']['id']} + " + ); + } $rs = my_query( " diff --git a/commands/help.php b/commands/help.php index 3b31a2f..ba1af2c 100644 --- a/commands/help.php +++ b/commands/help.php @@ -11,6 +11,6 @@ 7) press share and choose yourRaid channel 8) wait until the option with the boss name appears and select it '; -$msg = 'This is a private bot.'; +$msg = 'This is a private bot.'; // temp sendMessage($update['message']['from']['id'], $msg); \ No newline at end of file diff --git a/commands/list.php b/commands/list.php index be9fa7e..3132bf1 100644 --- a/commands/list.php +++ b/commands/list.php @@ -1,32 +1,60 @@ fetch_assoc(); + +// No data found. if (!$row) { sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); exit; } -$tz = $row['timezone']; - -$request = my_query('SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) as ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE end_time>NOW() AND timezone="' . $tz . '" ORDER BY end_time ASC LIMIT 20'); +// Build query. +$request = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE end_time>NOW() + AND timezone='{$row['timezone']}' + ORDER BY end_time ASC LIMIT 20 + " +); while ($raid = $request->fetch_assoc()) { - $keys = [[[ - 'text' => 'Expand', 'callback_data' => $raid['id'] . ':vote_refresh:0', - ]]]; + // Create keys array. + $keys = [ + [ + [ + 'text' => 'Expand', + 'callback_data' => $raid['id'] . ':vote_refresh:0', + ] + ] + ]; + + // Get message. $msg = show_raid_poll_small($raid); - send_message($update['message']['from']['id'], $msg, $keys, - ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]] - ); -} + // Send message. + send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); +} exit; diff --git a/commands/raid.php b/commands/raid.php index d8abb30..eef935a 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -1,69 +1,117 @@ real_escape_string($gym_name) . '" WHERE user_id=' . $update['message']['from']['id'] . ' ORDER BY id DESC LIMIT 1'; + +// Get latitude / longitude from data. $lat = floatval($data[1]); $lon = floatval($data[2]); +// Format lat/long values. $lat = substr($lat, 0, strpos('.', $lat) + 9); $lon = substr($lon, 0, strpos('.', $lon) + 9); +// Get the address. $addr = get_address($lat, $lon); -$q = 'INSERT INTO raids SET - pokemon="' . $db->real_escape_string($data[0]) . '", - user_id=' . $update['message']['from']['id'] . ', - lat="' . $lat . '", - lon="' . $lon . '", - first_seen=NOW(), - end_time=DATE_ADD(first_seen, INTERVAL ' . $data[3] . ' MINUTE), - gym_team="' . $db->real_escape_string($data[4]) . '", - gym_name="' . $db->real_escape_string($data[5]) . '" - '; - -$q .= ', timezone="' . TIMEZONE . '"'; - +// Address found. if ($addr) { - $q .= ', address="' . $db->real_escape_string($addr) . '"'; + // Build the query. + $rs = my_query( + " + INSERT INTO raids + SET pokemon = '{$db->real_escape_string($data[0])}', + user_id = {$update['message']['from']['id']}, + lat = '{$lat}', + lon = '{$lon}', + first_seen = NOW(), + end_time = DATE_ADD(first_seen, INTERVAL {$data[3]} MINUTE), + gym_team = '{$db->real_escape_string($data[4])}', + gym_name = '{$db->real_escape_string($data[5])}', + timezone = '{$tz}', + address = '{$db->real_escape_string($addr)}' + " + ); + +// No address found. +} else { + // Build the query. + $rs = my_query( + " + INSERT INTO raids + SET pokemon = '{$db->real_escape_string($data[0])}', + user_id = {$update['message']['from']['id']}, + lat = '{$lat}', + lon = '{$lon}', + first_seen = NOW(), + end_time = DATE_ADD(first_seen, INTERVAL {$data[3]} MINUTE), + gym_team = '{$db->real_escape_string($data[4])}', + gym_name = '{$db->real_escape_string($data[5])}', + timezone = '{$tz}' + " + ); } -$rs = my_query($q); +// Get last insert id from db. $id = my_insert_id(); + +// Write to log. debug_log('ID=' . $id); -$rs = my_query('SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) as ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE id=' . $id . ''); +// Build query. +$rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$id} + " +); + +// Get row. $raid = $rs->fetch_assoc(); +// Set text. $text = show_raid_poll($raid); -$keys = keys_vote($raid); - if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { - - $keys = [[[ - 'text' => 'Share', 'switch_inline_query' => strval($id), - ]]]; - + // Set keys. + $keys = [ + [ + [ + 'text' => 'Share', + 'switch_inline_query' => strval($id), + ] + ] + ]; + + // Send the message. send_message($update['message']['chat']['id'], $text, $keys); } else { + // Set reply to. $reply_to = $update['message']['chat']['id']; - if ($update['message']['reply_to_message']['message_id']) $reply_to = $update['message']['reply_to_message']['message_id']; - send_message($update['message']['chat']['id'], $text, $keys, - ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]] - ); + // Set keys. + $keys = keys_vote($raid); + + if ($update['message']['reply_to_message']['message_id']) { + $reply_to = $update['message']['reply_to_message']['message_id']; + } + + // Send the message. + send_message($update['message']['chat']['id'], $text, $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); } exit; diff --git a/commands/start.php b/commands/start.php index a73f87a..1f8a299 100644 --- a/commands/start.php +++ b/commands/start.php @@ -1,3 +1,3 @@ Please send location to start Raid announce '); diff --git a/commands/team.php b/commands/team.php index 15faa9c..cf11bbf 100644 --- a/commands/team.php +++ b/commands/team.php @@ -1,26 +1,36 @@ 'mystic', - 'instinct' => 'instinct', - 'valor' => 'valor', - 'red' => 'valor', - 'blue' => 'mystic', - 'yellow' => 'instinct', - 'r' => 'valor', - 'b' => 'mystic', - 'y' => 'instinct', + 'mystic' => 'mystic', + 'instinct' => 'instinct', + 'valor' => 'valor', + 'red' => 'valor', + 'blue' => 'mystic', + 'yellow' => 'instinct', + 'r' => 'valor', + 'b' => 'mystic', + 'y' => 'instinct' ); +// Valid team name. if ($teams[$gym_team]) { - $query = 'UPDATE raids SET gym_team="' . $teams[$gym_team] . '" WHERE user_id=' . $update['message']['from']['id'] . ' ORDER BY id DESC LIMIT 1'; - my_query($query); - + // Build Query. + my_query( + " + UPDATE raids + SET gym_team = '{$teams[$gym_team]}' + WHERE user_id = {$update['message']['from']['id']} + ORDER BY id DESC LIMIT 1 + " + ); + // Send the message. sendMessage($update['message']['chat']['id'], 'Gym team set to ' . ucfirst($teams[$gym_team])); + +// Invalid team name. } else { + // Send the message. sendMessage($update['message']['chat']['id'], 'Invalid team name - type Mystic, Valor, Instinct or Blue, Red, Yellow'); } - - \ No newline at end of file diff --git a/constants.php b/constants.php index f9c669b..7bc3032 100644 --- a/constants.php +++ b/constants.php @@ -1,25 +1,27 @@ TEAM_B, - 'valor' => TEAM_R, - 'instinct' => TEAM_Y, - 'unknown' => TEAM_UNKNOWN, - 'cancel' => TEAM_CANCEL + 'mystic' => TEAM_B, + 'valor' => TEAM_R, + 'instinct' => TEAM_Y, + 'unknown' => TEAM_UNKNOWN, + 'cancel' => TEAM_CANCEL ); +// Raid boss pokemon. $pokemon = array( '5' => array( 'Arktos', @@ -37,12 +39,12 @@ 'Turtok', ), '3' => array( - 'Machamp', - 'Vaporeon', - 'Flareon', - 'Jolteon', - 'Alakazam', - 'Arcanine', + 'Machomei', + 'Aquana', + 'Flamara', + 'Blitza', + 'Simsala', + 'Arkani', 'Gengar', ) ); diff --git a/functions.php b/functions.php index a300060..78b0e0f 100644 --- a/functions.php +++ b/functions.php @@ -224,7 +224,7 @@ function answerInlineQuery($query_id, $contents) * @param $text_val * @param $markup_val * @param null $chat_id - * @param bool $merge_args + * @param mixed $merge_args */ function editMessageText($id_val, $text_val, $markup_val, $chat_id = NULL, $merge_args = false) { diff --git a/index.php b/index.php index 0b29759..3e11555 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,8 @@ fetch_assoc(); if ($update['callback_query']['from']['id'] != $raid['user_id']) { - $query = "SELECT COUNT(*) FROM users WHERE user_id={$update['callback_query']['from']['id']} AND moderator=1"; - $rs = my_query($query); + // Build query. + $rs = my_query( + " + SELECT COUNT(*) + FROM users + WHERE user_id = {$update['callback_query']['from']['id']} + AND moderator = 1 + " + ); + $row = $rs->fetch_row(); if (empty($row['0'])) { @@ -57,27 +73,27 @@ function raid_edit_start_keys($id) $keys = [ [ [ - 'text' => 'Legendary Raid *****', + 'text' => 'Legendary Raid *****', 'callback_data' => $id . ':edit:type_5' ] ], [ [ - 'text' => '4 Star Raid ****', + 'text' => '4 Star Raid ****', 'callback_data' => $id . ':edit:type_4' ], [ - 'text' => '3 Star Raid ***', + 'text' => '3 Star Raid ***', 'callback_data' => $id . ':edit:type_3' ] ], [ [ - 'text' => '2 Star Raid **', + 'text' => '2 Star Raid **', 'callback_data' => $id . ':edit:type_2' ], [ - 'text' => '1 Star Raid *', + 'text' => '1 Star Raid *', 'callback_data' => $id . ':edit:type_1' ] ] @@ -100,23 +116,23 @@ function keys_raid_people($data) $keys = [ [ - 'text' => '+1', + 'text' => '+1', 'callback_data' => $data['id'] . ':vote:1' ], [ - 'text' => '+2', + 'text' => '+2', 'callback_data' => $data['id'] . ':vote:2' ], [ - 'text' => '+3', + 'text' => '+3', 'callback_data' => $data['id'] . ':vote:3' ], [ - 'text' => '+4', + 'text' => '+4', 'callback_data' => $data['id'] . ':vote:4' ], [ - 'text' => '+5', + 'text' => '+5', 'callback_data' => $data['id'] . ':vote:5' ] ]; @@ -140,37 +156,37 @@ function keys_vote($raid) $keys = [ [ [ - 'text' => 'alleine', + 'text' => 'alleine', 'callback_data' => $raid['id'] . ':vote:1' ], [ - 'text' => '+1', + 'text' => '+1', 'callback_data' => $raid['id'] . ':vote:2' ], [ - 'text' => '+2', + 'text' => '+2', 'callback_data' => $raid['id'] . ':vote:3' ], [ - 'text' => '+3', + 'text' => '+3', 'callback_data' => $raid['id'] . ':vote:4' ], [ - 'text' => '+4', + 'text' => '+4', 'callback_data' => $raid['id'] . ':vote:5' ] ], [ [ - 'text' => TEAM_B . ' Mystic', + 'text' => TEAM_B . ' Mystic', 'callback_data' => $raid['id'] . ':vote_team:mystic' ], [ - 'text' => TEAM_R . ' Valor', + 'text' => TEAM_R . ' Valor', 'callback_data' => $raid['id'] . ':vote_team:valor' ], [ - 'text' => TEAM_Y . ' Instinct', + 'text' => TEAM_Y . ' Instinct', 'callback_data' => $raid['id'] . ':vote_team:instinct' ] ] @@ -179,7 +195,7 @@ function keys_vote($raid) if ($end_time < $now) { $keys[] = [ array( - 'text' => 'Raid beendet.', + 'text' => 'Raid beendet.', 'callback_data' => $raid['id'] . ':vote_time:' . (ceil(time() / 900) * 900) ) ]; @@ -195,7 +211,7 @@ function keys_vote($raid) } $keys_time[] = array( - 'text' => unix2tz($i, $raid['timezone']), + 'text' => unix2tz($i, $raid['timezone']), 'callback_data' => $raid['id'] . ':vote_time:' . $i ); } @@ -206,19 +222,19 @@ function keys_vote($raid) $keys[] = [ [ - 'text' => EMOJI_REFRESH, + 'text' => EMOJI_REFRESH, 'callback_data' => $raid['id'] . ':vote_refresh:0' ], [ - 'text' => 'Bin da', + 'text' => 'Bin da', 'callback_data' => $raid['id'] . ':vote_arrived:0' ], [ - 'text' => 'Fertig', + 'text' => 'Fertig', 'callback_data' => $raid['id'] . ':vote_done:0' ], [ - 'text' => 'Absage', + 'text' => 'Absage', 'callback_data' => $raid['id'] . ':vote_cancel:0' ], ]; @@ -227,7 +243,7 @@ function keys_vote($raid) $keys = [ [ [ - 'text' => 'Raid beendet', + 'text' => 'Raid beendet', 'callback_data' => $raid['id'] . ':vote_refresh:0' ] ] diff --git a/modules/edit.php b/modules/edit.php index 9cfc2e1..c6159da 100644 --- a/modules/edit.php +++ b/modules/edit.php @@ -1,71 +1,159 @@ 'Articuno', 'callback_data' => $id . ':edit_poke:articuno', - ], [ - 'text' => 'Lugia', 'callback_data' => $id . ':edit_poke:lugia', - ], [ - 'text' => 'Moltres', 'callback_data' => $id . ':edit_poke:moltres', - ], [ - 'text' => 'Zapdos', 'callback_data' => $id . ':edit_poke:zapdos', - ]]]; + // Set keys. + $keys = [ + [ + [ + 'text' => 'Articuno', + 'callback_data' => $id . ':edit_poke:articuno' + ], + [ + 'text' => 'Lugia', + 'callback_data' => $id . ':edit_poke:lugia' + ], + [ + 'text' => 'Moltres', + 'callback_data' => $id . ':edit_poke:moltres' + ], + [ + 'text' => 'Zapdos', + 'callback_data' => $id . ':edit_poke:zapdos' + ] + ] + ]; +// Level 4 boss. } else if ($data['arg'] == 'type_4') { - $keys = - [[[ - 'text' => 'Tyranitar', 'callback_data' => $id . ':edit_poke:tyranitar', - ]], [[ - 'text' => 'Snorlax', 'callback_data' => $id . ':edit_poke:snorlax', - ], [ - 'text' => 'Lapras', 'callback_data' => $id . ':edit_poke:lapras', - ], [ - 'text' => 'Rhydon', 'callback_data' => $id . ':edit_poke:rhydon', - ]], [[ - 'text' => 'Charizard', 'callback_data' => $id . ':edit_poke:charizard', - ], [ - 'text' => 'Venusaur', 'callback_data' => $id . ':edit_poke:venusaur', - ], [ - 'text' => 'Blastoise', 'callback_data' => $id . ':edit_poke:blastoise', - ]]]; + // Set keys. + $keys = [ + [ + [ + 'text' => 'Tyranitar', + 'callback_data' => $id . ':edit_poke:tyranitar' + ] + ], + [ + [ + 'text' => 'Snorlax', + 'callback_data' => $id . ':edit_poke:snorlax' + ], + [ + 'text' => 'Lapras', + 'callback_data' => $id . ':edit_poke:lapras' + ], + [ + 'text' => 'Rhydon', + 'callback_data' => $id . ':edit_poke:rhydon' + ] + ], + [ + [ + 'text' => 'Charizard', + 'callback_data' => $id . ':edit_poke:charizard' + ], + [ + 'text' => 'Venusaur', + 'callback_data' => $id . ':edit_poke:venusaur' + ], + [ + 'text' => 'Blastoise', + 'callback_data' => $id . ':edit_poke:blastoise' + ] + ] + ]; + +// Level 3 boss. } else if ($data['arg'] == 'type_3') { - $keys = - [[[ - 'text' => 'Machamp', 'callback_data' => $id . ':edit_poke:machamp', - ]], [[ - 'text' => 'Vaporeon', 'callback_data' => $id . ':edit_poke:vaporeon', - ], [ - 'text' => 'Flareon', 'callback_data' => $id . ':edit_poke:flareon', - ], [ - 'text' => 'Jolteon', 'callback_data' => $id . ':edit_poke:jolteon', - ]], [[ - 'text' => 'Alakazam', 'callback_data' => $id . ':edit_poke:alakazam', - ], [ - 'text' => 'Arcanine', 'callback_data' => $id . ':edit_poke:arcanine', - ], [ - 'text' => 'Gengar', 'callback_data' => $id . ':edit_poke:gengar', - ]]]; + // Set keys. + $keys = [ + [ + [ + 'text' => 'Machamp', + 'callback_data' => $id . ':edit_poke:machamp' + ] + ], + [ + [ + 'text' => 'Vaporeon', + 'callback_data' => $id . ':edit_poke:vaporeon' + ], + [ + 'text' => 'Flareon', + 'callback_data' => $id . ':edit_poke:flareon' + ], + [ + 'text' => 'Jolteon', + 'callback_data' => $id . ':edit_poke:jolteon' + ] + ], + [ + [ + 'text' => 'Alakazam', + 'callback_data' => $id . ':edit_poke:alakazam' + ], + [ + 'text' => 'Arcanine', + 'callback_data' => $id . ':edit_poke:arcanine' + ], + [ + 'text' => 'Gengar', + 'callback_data' => $id . ':edit_poke:gengar' + ] + ] + ]; + +// Level 2 boss. } else if ($data['arg'] == 'type_2') { - $keys = - [[[ - 'text' => 'Muk', 'callback_data' => $id . ':edit_poke:muk', - ]]]; + // Set keys. + $keys = [ + [ + [ + 'text' => 'Muk', + 'callback_data' => $id . ':edit_poke:muk' + ] + ] + ]; + +// Level 1 boss. } else if ($data['arg'] == 'type_1') { - $keys = [[['text' => 'Not supported', 'callback_data' => 'edit:not_supported']]]; + // Set keys. + $keys = [ + [ + [ + 'text' => 'Not supported', + 'callback_data' => 'edit:not_supported' + ] + ] + ]; + + } else { - /* Edit pokemon */ - $keys = raid_edit_start_keys(); + // Edit pokemon. + $keys = raid_edit_start_keys($id); } -if (!$keys) $keys = [[['text' => 'Not supported', 'callback_data' => 'edit:not_supported']]]; +// No keys found. +if (!$keys) { + $keys = [ + [ + [ + 'text' => 'Not supported', + 'callback_data' => 'edit:not_supported' + ] + ] + ]; +} if (isset($update['callback_query']['inline_message_id'])) { editMessageText($update['callback_query']['inline_message_id'], 'Choose Raid Boss:', $keys); @@ -73,7 +161,5 @@ editMessageText($update['callback_query']['message']['message_id'], 'Choose Raid Boss', $keys, $update['callback_query']['message']['chat']['id'], $keys); } -//edit_message_keyboard($update['callback_query']['message']['message_id'],$keys,$update['callback_query']['message']['chat']['id']); $callback_response = 'Ok'; answerCallbackQuery($update['callback_query']['id'], $callback_response); - diff --git a/modules/edit_left.php b/modules/edit_left.php index a5a08cb..29b8505 100644 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -1,43 +1,77 @@ 'Share', 'switch_inline_query' => strval($id), - ]]]; + // Set the keys. + $keys = [ + [ + [ + 'text' => 'Share', + 'switch_inline_query' => strval($id) + ] + ] + ]; - $msg = 'Raid saved.' . CR . 'Optional - set gym name and team:' . CR2 . '/gym gym name' . CR . '/team Mystic/Valor/Instinct/Blue/Red/Yellow'; + // Build message string. + $msg = 'Raid saved.' . CR; + $msg .= 'Optional - set gym name and team:' . CR2; + $msg .= '/gym gym name' . CR; + $msg .= '/team Mystic/Valor/Instinct/Blue/Red/Yellow'; + + // Edit message. edit_message($update, $msg, $keys, false); + // Build callback message string. $callback_response = 'End time set to ' . $data['arg'] . ' minutes'; + + // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); } else { + // Build query. + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$data['id']} + " + ); - $rs = my_query('SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) as ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids WHERE id=' . $data['id'] . ''); + // Fetch the row. $raid = $rs->fetch_assoc(); + // Get text and keys. $text = show_raid_poll($raid); $keys = keys_vote($raid); - edit_message($update, $text, $keys, $false); + // Edit message. + edit_message($update, $text, $keys, false); + // Build callback message string. $callback_response = 'End time set to ' . $data['arg'] . ' minutes'; + + // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); } diff --git a/modules/edit_poke.php b/modules/edit_poke.php index 790f88c..b7d0e2c 100644 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -22,7 +22,7 @@ } else { /* Edit pokemon */ - $keys = raid_edit_start_keys(); + $keys = raid_edit_start_keys($id); } if (!$keys) $keys = [[['text' => 'Not supported', 'callback_data' => 'edit:not_supported']]]; diff --git a/modules/raid_create.php b/modules/raid_create.php index 905f238..5e03a6d 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -1,39 +1,66 @@ real_escape_string($addr) . '"'; + // Build the query. + $rs = my_query( + " + INSERT INTO raids + SET user_id = {$update['message']['from']['id']}, + lat = '{$lat}', + lon = '{$lon}', + first_seen = NOW(), + timezone = '{$tz}', + address = '{$db->real_escape_string($addr)}' + " + ); + +// No address found. +} else { + // Build the query. + $rs = my_query( + " + INSERT INTO raids + SET user_id = {$update['message']['from']['id']}, + lat = '{$lat}', + lon = '{$lon}', + first_seen = NOW(), + timezone = '{$tz}' + " + ); } -$rs = my_query($q); +// Get last insert id from db. $id = my_insert_id(); + +// Write to log. debug_log('ID=' . $id); +// Get the keys. $keys = raid_edit_start_keys($id); +// Build message. $msg = 'Create Raid at ' . $addr . ''; if ($update['message']['chat']['type'] == 'private') { + // Send the message. send_message($update['message']['chat']['id'], $msg . CR . 'Choose Raid level:', $keys); + } else { $reply_to = $update['message']['chat']['id']; - if ($update['message']['reply_to_message']['message_id']) $reply_to = $update['message']['reply_to_message']['message_id']; + if ($update['message']['reply_to_message']['message_id']) { + $reply_to = $update['message']['reply_to_message']['message_id']; + } - send_message($update['message']['chat']['id'], $msg . CR . 'Choose Raid level:', $keys, - ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]] - ); + // Send the message. + send_message($update['message']['chat']['id'], $msg . CR . 'Choose Raid level:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); } exit(); diff --git a/modules/vote.php b/modules/vote.php index d3b63fc..ebbd903 100644 --- a/modules/vote.php +++ b/modules/vote.php @@ -1,23 +1,47 @@ fetch_assoc(); + +// Write to log. debug_log($answer); -$rs = my_query('SELECT * FROM users WHERE user_id=' . $update['callback_query']['from']['id'] . ''); +// Build the query. +$rs = my_query( + " + SELECT * + FROM users + WHERE user_id = {$update['callback_query']['from']['id']} + " +); + +// Get the row. $row = $rs->fetch_assoc(); $qq = 'extra_people=' . intval($data['arg'] - 1); -if ($row['team']) $qq .= ', team="' . $row['team'] . '"'; + +if ($row['team']) { + $qq .= ', team="' . $row['team'] . '"'; +} + +// Write to log. debug_log($row); debug_log($qq); if (!$answer) { my_query('INSERT INTO attendance SET raid_id=' . $data['id'] . ', user_id=' . $update['callback_query']['from']['id'] . ', ' . $qq); } else { - my_query('UPDATE attendance SET ' . $qq . ' WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); + my_query('UPDATE attendance SET ' . $qq . ' WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id']); } +// Send vote response. send_response_vote($update, $data); - - diff --git a/modules/vote_arrived.php b/modules/vote_arrived.php index 676f0f5..39063b4 100644 --- a/modules/vote_arrived.php +++ b/modules/vote_arrived.php @@ -1,18 +1,65 @@ fetch_assoc(); + +// Write to log. debug_log($answer); -if (!$answer) { - //$query = 'SELECT * FROM users WHERE user_id='.$update['callback_query']['from']['id']; - //$rs = my_query($query); - //$row = $rs->fetch_assoc(); +// User has voted before. +if (!empty($answer)) { + // Update attendance. + my_query( + " + UPDATE attendance + SET arrived = 1, + raid_done = 0, + cancel = 0 + WHERE raid_id = {$data['id']} + AND user_id = {$update['callback_query']['from']['id']} + " + ); - //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', arrived=1, team="'.$row['team'].'", attend_time=NOW()'); +// User has not voted before. } else { - my_query('UPDATE attendance SET arrived=1,raid_done=0,cancel=0 WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); + /* + // Get users data. + $rs = my_query( + " + SELECT * + FROM users + WHERE user_id = {$update['callback_query']['from']['id']} + " + ); + + // Get the row. + $row = $rs->fetch_assoc(); + + // Check if we found the users team. + $team = !empty($row['team']) ? $row['team'] : ''; + + // Create attendance. + my_query( + " + INSERT INTO attendance + SET raid_id = {$data['id']}, + user_id = {$update['callback_query']['from']['id']}, + arrived = 1, + team = '{$team}', + attend_time = NOW() + " + ); +*/ } +// Send vote response. send_response_vote($update, $data); - diff --git a/modules/vote_cancel.php b/modules/vote_cancel.php index 94c1093..f6746d1 100644 --- a/modules/vote_cancel.php +++ b/modules/vote_cancel.php @@ -1,14 +1,49 @@ fetch_assoc(); + +// Write to log. debug_log($answer); -if (!$answer) { - //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', cancel=1, attend_time=NULL'); +// User has voted before. +if (!empty($answer)) { + // Update attendance. + my_query( + " + UPDATE attendance + SET cancel = 1, + raid_done = 0, + arrived = 0 + WHERE raid_id = {$data['id']} + AND user_id = {$update['callback_query']['from']['id']} + " + ); + +// User has not voted before. } else { - my_query('UPDATE attendance SET cancel=1, raid_done=0, arrived=0 WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); + /* + // Create attendance. + my_query( + " + INSERT INTO attendance + SET raid_id = {$data['id']}, + user_id = {$update['callback_query']['from']['id']}, + cancel = 1, + attend_time = NULL + " + ); + */ } +// Send the vote response. send_response_vote($update, $data); - - diff --git a/modules/vote_done.php b/modules/vote_done.php index 8e2a702..88015ac 100644 --- a/modules/vote_done.php +++ b/modules/vote_done.php @@ -1,14 +1,46 @@ fetch_assoc(); + +// Write to log. debug_log($answer); -if (!$answer) { - //my_query('INSERT INTO attendance SET raid_id='.$data['id'].', user_id='.$update['callback_query']['from']['id'].', raid_done=1'); +// User has voted before. +if (!empty($answer)) { + // Update attendance. + my_query( + " + UPDATE attendance + SET raid_done = 1 + WHERE raid_id = {$data['id']} + AND user_id = {$update['callback_query']['from']['id']} + " + ); + +// User has not voted before. } else { - my_query('UPDATE attendance SET raid_done=1 WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); + /* + // Create attendance. + my_query( + " + INSERT INTO attendance + SET raid_id = {$data['id']}, + user_id = {$update['callback_query']['from']['id']}, + raid_done = 1 + " + ); + */ } +// Send vote response. send_response_vote($update, $data); - diff --git a/modules/vote_edit.php b/modules/vote_edit.php index d2db2e1..3a3fbc3 100644 --- a/modules/vote_edit.php +++ b/modules/vote_edit.php @@ -1,4 +1,4 @@ fetch_assoc(); + +// Write to log. debug_log($answer); -if (!$answer) { - my_query('INSERT INTO attendance SET raid_id=' . $data['id'] . ', user_id=' . $update['callback_query']['from']['id'] . ', team="' . $data['arg'] . '"'); +// User has voted before. +if (!empty($answer)) { + // Update attendance. + my_query( + " + UPDATE attendance + SET team = '{$data['arg']}' + WHERE raid_id = {$data['id']} + AND user_id = {$update['callback_query']['from']['id']} + " + ); + +// User has not voted before. } else { - my_query('UPDATE attendance SET team="' . $data['arg'] . '" WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); + // Create attendance. + my_query( + " + INSERT INTO attendance + SET raid_id = {$data['id']}, + user_id = {$update['callback_query']['from']['id']}, + team = '{$data['arg']}' + " + ); } -my_query('UPDATE users SET team="' . $data['arg'] . '" WHERE user_id=' . $update['callback_query']['from']['id'] . ''); +// Update users team. +my_query( + " + UPDATE users + SET team = '{$data['arg']}' + WHERE user_id = {$update['callback_query']['from']['id']} + " +); +// Send vote response. send_response_vote($update, $data); diff --git a/modules/vote_time.php b/modules/vote_time.php index 4f21446..927a996 100644 --- a/modules/vote_time.php +++ b/modules/vote_time.php @@ -1,18 +1,64 @@ fetch_assoc(); + +// Write to log. debug_log($answer); -if (!$answer) { - $query = 'SELECT * FROM users WHERE user_id=' . $update['callback_query']['from']['id']; - $rs = my_query($query); - $row = $rs->fetch_assoc(); +// User has voted before. +if (!empty($answer)) { + // Update attendance. + my_query( + " + UPDATE attendance + SET attend_time = FROM_UNIXTIME({$data['arg']}), + cancel = 0, + arrived = 0, + raid_done = 0 + WHERE raid_id = {$data['id']} + AND user_id = {$update['callback_query']['from']['id']} + " + ); - my_query('INSERT INTO attendance SET raid_id=' . $data['id'] . ', user_id=' . $update['callback_query']['from']['id'] . ', attend_time=FROM_UNIXTIME(' . $data['arg'] . '), team="' . $row['team'] . '"'); +// User has not voted before. } else { - my_query('UPDATE attendance SET attend_time=FROM_UNIXTIME(' . $data['arg'] . '), cancel=0, arrived=0,raid_done=0 WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id'] . ''); + + // Get users data. + $rs = my_query( + " + SELECT * + FROM users + WHERE user_id = {$update['callback_query']['from']['id']} + " + ); + + // Get the row. + $row = $rs->fetch_assoc(); + + // Check if we found the users team. + $team = !empty($row['team']) ? $row['team'] : ''; + + // Create attendance. + my_query( + " + INSERT INTO attendance + SET raid_id = {$data['id']}, + user_id = {$update['callback_query']['from']['id']}, + attend_time = FROM_UNIXTIME({$data['arg']}), + team = '{$team}' + " + ); } +// Send vote response. send_response_vote($update, $data); - From ff2d77cb936fa667dbf0d03fd338677861948fc6 Mon Sep 17 00:00:00 2001 From: d4NY0H Date: Thu, 17 Aug 2017 14:41:15 +0200 Subject: [PATCH 007/225] cleanup --- commands/gym.php | 4 +++- commands/raid.php | 1 + commands/team.php | 5 +++-- modules/edit.php | 3 +++ modules/edit_left.php | 2 +- modules/edit_poke.php | 46 ++++++++++++++++++++++++++++++++++------ modules/raid_create.php | 8 ++++--- modules/vote.php | 38 +++++++++++++++++++++++++-------- modules/vote_arrived.php | 4 ++-- modules/vote_time.php | 4 ++-- 10 files changed, 88 insertions(+), 27 deletions(-) diff --git a/commands/gym.php b/commands/gym.php index 7cc86f8..484abdd 100644 --- a/commands/gym.php +++ b/commands/gym.php @@ -5,8 +5,9 @@ // Write to log. debug_log('SET gym name to ' . $gym_name); +// Private chat type. if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { - // Build query. + // Update gym name in raid table. my_query( " UPDATE raids @@ -16,6 +17,7 @@ " ); + // Send the message. sendMessage($update['message']['chat']['id'], 'Gym name updated'); } else { diff --git a/commands/raid.php b/commands/raid.php index eef935a..b85676c 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -85,6 +85,7 @@ // Set text. $text = show_raid_poll($raid); +// Private chat type. if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { // Set keys. $keys = [ diff --git a/commands/team.php b/commands/team.php index cf11bbf..d20ccd0 100644 --- a/commands/team.php +++ b/commands/team.php @@ -17,15 +17,16 @@ // Valid team name. if ($teams[$gym_team]) { - // Build Query. + // Update team in raids table. my_query( " UPDATE raids SET gym_team = '{$teams[$gym_team]}' WHERE user_id = {$update['message']['from']['id']} - ORDER BY id DESC LIMIT 1 + ORDER BY id DESC LIMIT 1 " ); + // Send the message. sendMessage($update['message']['chat']['id'], 'Gym team set to ' . ucfirst($teams[$gym_team])); diff --git a/modules/edit.php b/modules/edit.php index c6159da..7bd8378 100644 --- a/modules/edit.php +++ b/modules/edit.php @@ -161,5 +161,8 @@ editMessageText($update['callback_query']['message']['message_id'], 'Choose Raid Boss', $keys, $update['callback_query']['message']['chat']['id'], $keys); } +// Build callback message string. $callback_response = 'Ok'; + +// Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/edit_left.php b/modules/edit_left.php index 29b8505..471e4d0 100644 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -46,7 +46,7 @@ answerCallbackQuery($update['callback_query']['id'], $callback_response); } else { - // Build query. + // Get raid times. $rs = my_query( " SELECT *, diff --git a/modules/edit_poke.php b/modules/edit_poke.php index b7d0e2c..7e1e9eb 100644 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -1,33 +1,65 @@ = 25; $i = $i - 5) { - $keys[] = array('text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT) . ' left', 'callback_data' => $id . ':edit_left:' . $i); + // Create the keys. + $keys[] = array( + 'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT) . ' left', + 'callback_data' => $id . ':edit_left:' . $i + ); } + + // Get the inline key array. $keys = inline_key_array($keys, 4); + + // Write to log. debug_log($keys); } else { - /* Edit pokemon */ + // Edit pokemon. $keys = raid_edit_start_keys($id); } -if (!$keys) $keys = [[['text' => 'Not supported', 'callback_data' => 'edit:not_supported']]]; +// No keys found. +if (!$keys) { + // Create the keys. + $keys = [ + [ + [ + 'text' => 'Not supported', + 'callback_data' => 'edit:not_supported' + ] + ] + ]; +} +// Edit the message. edit_message($update, 'How much time is left for Raid?', $keys); +// Build callback message string. $callback_response = 'Pokemon set to ' . $data['arg']; + +// Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/raid_create.php b/modules/raid_create.php index 5e03a6d..f3576a4 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -9,8 +9,8 @@ $addr = get_address($lat, $lon); // Address found. -if ($addr) { - // Build the query. +if (!empty($addr)) { + // Create raid with address. $rs = my_query( " INSERT INTO raids @@ -25,7 +25,7 @@ // No address found. } else { - // Build the query. + // Create raid without address. $rs = my_query( " INSERT INTO raids @@ -50,6 +50,7 @@ // Build message. $msg = 'Create Raid at ' . $addr . ''; +// Private chat type. if ($update['message']['chat']['type'] == 'private') { // Send the message. send_message($update['message']['chat']['id'], $msg . CR . 'Choose Raid level:', $keys); @@ -63,4 +64,5 @@ // Send the message. send_message($update['message']['chat']['id'], $msg . CR . 'Choose Raid level:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); } + exit(); diff --git a/modules/vote.php b/modules/vote.php index ebbd903..0059ae1 100644 --- a/modules/vote.php +++ b/modules/vote.php @@ -1,5 +1,5 @@ fetch_assoc(); -$qq = 'extra_people=' . intval($data['arg'] - 1); +// Get extra people. +$extraPeople = intval($data['arg'] - 1); -if ($row['team']) { - $qq .= ', team="' . $row['team'] . '"'; -} +// Check if we found the users team. +$team = !empty($row['team']) ? "'" . $row['team'] . "'" : NULL; // Write to log. debug_log($row); -debug_log($qq); -if (!$answer) { - my_query('INSERT INTO attendance SET raid_id=' . $data['id'] . ', user_id=' . $update['callback_query']['from']['id'] . ', ' . $qq); +// User has voted before. +if (!empty($answer)) { + // Update attendance. + my_query( + " + UPDATE attendance + SET extra_people = {$extraPeople}, + team = {$team} + WHERE raid_id = {$data['id']} + AND user_id = {$update['callback_query']['from']['id']} + " + ); + +// User has not voted before. } else { - my_query('UPDATE attendance SET ' . $qq . ' WHERE raid_id=' . $data['id'] . ' AND user_id=' . $update['callback_query']['from']['id']); + // Create attendance. + my_query( + " + INSERT INTO attendance + SET raid_id = {$data['id']}, + user_id = {$update['callback_query']['from']['id']}, + extra_people = {$extraPeople}, + team = '{$team}' + " + ); } // Send vote response. diff --git a/modules/vote_arrived.php b/modules/vote_arrived.php index 39063b4..bf26c12 100644 --- a/modules/vote_arrived.php +++ b/modules/vote_arrived.php @@ -45,7 +45,7 @@ $row = $rs->fetch_assoc(); // Check if we found the users team. - $team = !empty($row['team']) ? $row['team'] : ''; + $team = !empty($row['team']) ? "'" . $row['team'] . "'" : NULL; // Create attendance. my_query( @@ -54,7 +54,7 @@ SET raid_id = {$data['id']}, user_id = {$update['callback_query']['from']['id']}, arrived = 1, - team = '{$team}', + team = {$team}, attend_time = NOW() " ); diff --git a/modules/vote_time.php b/modules/vote_time.php index 927a996..b1a35a2 100644 --- a/modules/vote_time.php +++ b/modules/vote_time.php @@ -46,7 +46,7 @@ $row = $rs->fetch_assoc(); // Check if we found the users team. - $team = !empty($row['team']) ? $row['team'] : ''; + $team = !empty($row['team']) ? "'" . $row['team'] . "'" : NULL; // Create attendance. my_query( @@ -55,7 +55,7 @@ SET raid_id = {$data['id']}, user_id = {$update['callback_query']['from']['id']}, attend_time = FROM_UNIXTIME({$data['arg']}), - team = '{$team}' + team = {$team} " ); } From 909d6294062ec7fa4528c144ef3b84bd78e9615b Mon Sep 17 00:00:00 2001 From: d4NY0 Date: Thu, 17 Aug 2017 19:13:54 +0200 Subject: [PATCH 008/225] fix team in query --- modules/vote.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/vote.php b/modules/vote.php index 0059ae1..c2c93e3 100644 --- a/modules/vote.php +++ b/modules/vote.php @@ -58,7 +58,7 @@ SET raid_id = {$data['id']}, user_id = {$update['callback_query']['from']['id']}, extra_people = {$extraPeople}, - team = '{$team}' + team = {$team} " ); } From 66b4c152cc17ef7a8c51e912de593887b9dfe982 Mon Sep 17 00:00:00 2001 From: marrah83 Date: Fri, 18 Aug 2017 10:22:10 +0200 Subject: [PATCH 009/225] added Level Up / Down basic functionality use alter table users add column level int(10) unsigned DEFAULT 0; if db is already present --- logic.php | 18 +++++++++++++----- modules/vote_level.php | 32 ++++++++++++++++++++++++++++++++ raid-pokemon-bot.sql | 9 +++++---- 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 modules/vote_level.php diff --git a/logic.php b/logic.php index 066a9be..ac20839 100644 --- a/logic.php +++ b/logic.php @@ -178,16 +178,24 @@ function keys_vote($raid) ], [ [ - 'text' => TEAM_B . ' Mystic', + 'text' => TEAM_B, 'callback_data' => $raid['id'] . ':vote_team:mystic' ], [ - 'text' => TEAM_R . ' Valor', + 'text' => TEAM_R, 'callback_data' => $raid['id'] . ':vote_team:valor' ], [ - 'text' => TEAM_Y . ' Instinct', + 'text' => TEAM_Y, 'callback_data' => $raid['id'] . ':vote_team:instinct' + ], + [ + 'text' => 'Lvl +', + 'callback_data' => $raid['id'] . ':vote_level:up' + ], + [ + 'text' => 'Lvl -', + 'callback_data' => $raid['id'] . ':vote_level:down' ] ] ]; @@ -520,11 +528,11 @@ function show_raid_poll($raid) // Unknown team. if ($row['team'] === NULL) { - $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' ' . $name . ' '; + $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' ' . $row['level'] . ' ' . $name . ' '; // Known team. } else { - $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name . ' '; + $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $row['level'] . ' ' . $name . ' '; } // Arrived. diff --git a/modules/vote_level.php b/modules/vote_level.php new file mode 100644 index 0000000..44f205e --- /dev/null +++ b/modules/vote_level.php @@ -0,0 +1,32 @@ + Date: Fri, 18 Aug 2017 14:04:51 +0200 Subject: [PATCH 010/225] only some comments and tab2spaces --- logic.php | 37 ++++++++++++++++++++++++++------ modules/vote_level.php | 48 +++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 31 deletions(-) diff --git a/logic.php b/logic.php index ac20839..0e5fbdf 100644 --- a/logic.php +++ b/logic.php @@ -302,6 +302,7 @@ function update_user($update) $name .= $sep . $msg['last_name']; } + // Create or update the user. $request = my_query( " INSERT INTO users @@ -325,6 +326,7 @@ function update_user($update) */ function send_response_vote($update, $data, $new = false) { + // Get the raid data by id. $rs = my_query( " SELECT *, @@ -336,6 +338,7 @@ function send_response_vote($update, $data, $new = false) " ); + // Get the row. $raid = $rs->fetch_assoc(); $msg = show_raid_poll($raid); @@ -347,15 +350,21 @@ function send_response_vote($update, $data, $new = false) if ($new) { $loc = send_location($update['callback_query']['message']['chat']['id'], $raid['lat'], $raid['lon']); + // Write to log. debug_log('location:'); debug_log($loc); + // Send the message. send_message($update['callback_query']['message']['chat']['id'], $msg . "\n", $keys, ['reply_to_message_id' => $loc['result']['message_id']]); + // Answer the callback. answerCallbackQuery($update['callback_query']['id'], $msg); } else { + // Edit the message. edit_message($update, $msg, $keys); + // Change message string. $msg = 'Abstimmung aktualisiert'; + // Answer the callback. answerCallbackQuery($update['callback_query']['id'], $msg); } @@ -363,6 +372,7 @@ function send_response_vote($update, $data, $new = false) } /** + * Convert unix timestamp to time string by timezone settings. * @param $unix * @param $tz * @param string $format @@ -370,13 +380,20 @@ function send_response_vote($update, $data, $new = false) */ function unix2tz($unix, $tz, $format = 'H:i') { - if (!$unix) { + // Unix timestamp is required. + if (!empty($unix)) { + // Create dateTime object. + $dt = new DateTime('@' . $unix); + + // Set the timezone. + $dt->setTimeZone(new DateTimeZone($tz)); + + // Return formatted time. + return $dt->format($format); + + } else { return false; } - - $dt = new DateTime('@' . $unix); - $dt->setTimeZone(new DateTimeZone($tz)); - return $dt->format($format); } /** @@ -394,6 +411,7 @@ function show_raid_poll($raid) if ($raid['gym_name'] || $raid['gym_team']) { $msg .= 'Arena: ' . $raid['gym_name'] . ''; + if ($raid['gym_team']) { $msg .= ' ' . $GLOBALS['teams'][$raid['gym_team']] . ' ' . ucfirst($raid['gym_team']); } @@ -404,8 +422,10 @@ function show_raid_poll($raid) $addr = explode(',', $raid['address'], 4); array_pop($addr); $addr = implode(',', $addr); + $msg .= 'Adresse: ' . $addr . '' . CR2; } + $msg .= 'Raid Boss: ' . ucfirst($raid['pokemon']) . '' . CR2; if ($time_left < 0) { @@ -429,6 +449,7 @@ function show_raid_poll($raid) " ); + // Init empty data array. $data = array(); while ($row = $rs->fetch_assoc()) { @@ -513,6 +534,7 @@ function show_raid_poll($raid) // Write to log. debug_log($vv['user_id']); + // Get user data. $rs = my_query( " SELECT * @@ -521,6 +543,7 @@ function show_raid_poll($raid) " ); + // Get the row. $row = $rs->fetch_assoc(); // Always use name. @@ -530,7 +553,7 @@ function show_raid_poll($raid) if ($row['team'] === NULL) { $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' ' . $row['level'] . ' ' . $name . ' '; - // Known team. + // Known team. } else { $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $row['level'] . ' ' . $name . ' '; } @@ -539,7 +562,7 @@ function show_raid_poll($raid) if ($vv['arrived']) { $msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; - // Cancelled. + // Cancelled. } else if ($vv['cancel']) { $msg .= '[abgesagt] '; } diff --git a/modules/vote_level.php b/modules/vote_level.php index 44f205e..0fa2701 100644 --- a/modules/vote_level.php +++ b/modules/vote_level.php @@ -1,31 +1,31 @@ 0 + " + ); } // Send vote response. From 15f8b5a80ae9324a4fa151340c9ab987dd50a293 Mon Sep 17 00:00:00 2001 From: d4NY0 Date: Sat, 19 Aug 2017 08:49:58 +0200 Subject: [PATCH 011/225] moved db settings to config translations --- config.php.example | 4 ++++ hash.php | 3 +++ index.php | 6 ++--- modules/edit.php | 60 +++++++++++++++++++++++----------------------- webhook.html | 4 ++-- 5 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 hash.php diff --git a/config.php.example b/config.php.example index cc50896..221d7d9 100644 --- a/config.php.example +++ b/config.php.example @@ -6,6 +6,10 @@ define('DEBUG', true); define('CONFIG_LOGFILE', '/var/log/tg-bots/dev-raid-bot.log'); define('CONFIG_HASH', ' = hash(sha_512,tg_bot_key) '); +define('DB_NAME', 'your_database_name'); +define('DB_USER', 'your_database_user'); +define('DB_PASSWORD', 'your_database_password'); + define('MAINTAINER', '@your_tg_username'); define('MAINTAINER_ID', 'your_tg_integer'); define('BOT_NAME', '@RaidPokemonBot'); diff --git a/hash.php b/hash.php new file mode 100644 index 0000000..bae7365 --- /dev/null +++ b/hash.php @@ -0,0 +1,3 @@ +connect_errno) { diff --git a/modules/edit.php b/modules/edit.php index 7bd8378..f881ee2 100644 --- a/modules/edit.php +++ b/modules/edit.php @@ -15,16 +15,16 @@ $keys = [ [ [ - 'text' => 'Articuno', - 'callback_data' => $id . ':edit_poke:articuno' + 'text' => 'Arktos', + 'callback_data' => $id . ':edit_poke:arktos' ], [ 'text' => 'Lugia', 'callback_data' => $id . ':edit_poke:lugia' ], [ - 'text' => 'Moltres', - 'callback_data' => $id . ':edit_poke:moltres' + 'text' => 'Lavados', + 'callback_data' => $id . ':edit_poke:lavados' ], [ 'text' => 'Zapdos', @@ -39,36 +39,36 @@ $keys = [ [ [ - 'text' => 'Tyranitar', - 'callback_data' => $id . ':edit_poke:tyranitar' + 'text' => 'Despotar', + 'callback_data' => $id . ':edit_poke:despotar' ] ], [ [ - 'text' => 'Snorlax', - 'callback_data' => $id . ':edit_poke:snorlax' + 'text' => 'Relaxo', + 'callback_data' => $id . ':edit_poke:relaxo' ], [ 'text' => 'Lapras', 'callback_data' => $id . ':edit_poke:lapras' ], [ - 'text' => 'Rhydon', - 'callback_data' => $id . ':edit_poke:rhydon' + 'text' => 'Rizeros', + 'callback_data' => $id . ':edit_poke:rizeros' ] ], [ [ - 'text' => 'Charizard', - 'callback_data' => $id . ':edit_poke:charizard' + 'text' => 'Glurak', + 'callback_data' => $id . ':edit_poke:glurak' ], [ - 'text' => 'Venusaur', - 'callback_data' => $id . ':edit_poke:venusaur' + 'text' => 'Bisasflor', + 'callback_data' => $id . ':edit_poke:bisasflor' ], [ - 'text' => 'Blastoise', - 'callback_data' => $id . ':edit_poke:blastoise' + 'text' => 'Turtok', + 'callback_data' => $id . ':edit_poke:turtok' ] ] ]; @@ -79,32 +79,32 @@ $keys = [ [ [ - 'text' => 'Machamp', - 'callback_data' => $id . ':edit_poke:machamp' + 'text' => 'Machomei', + 'callback_data' => $id . ':edit_poke:machomei' ] ], [ [ - 'text' => 'Vaporeon', - 'callback_data' => $id . ':edit_poke:vaporeon' + 'text' => 'Aquana', + 'callback_data' => $id . ':edit_poke:aquana' ], [ - 'text' => 'Flareon', - 'callback_data' => $id . ':edit_poke:flareon' + 'text' => 'Flamara', + 'callback_data' => $id . ':edit_poke:flamara' ], [ - 'text' => 'Jolteon', - 'callback_data' => $id . ':edit_poke:jolteon' + 'text' => 'Blitza', + 'callback_data' => $id . ':edit_poke:blitza' ] ], [ [ - 'text' => 'Alakazam', - 'callback_data' => $id . ':edit_poke:alakazam' + 'text' => 'Simsala', + 'callback_data' => $id . ':edit_poke:simsala' ], [ - 'text' => 'Arcanine', - 'callback_data' => $id . ':edit_poke:arcanine' + 'text' => 'Arkani', + 'callback_data' => $id . ':edit_poke:arkani' ], [ 'text' => 'Gengar', @@ -119,8 +119,8 @@ $keys = [ [ [ - 'text' => 'Muk', - 'callback_data' => $id . ':edit_poke:muk' + 'text' => 'Sleimok', + 'callback_data' => $id . ':edit_poke:sleimok' ] ] ]; diff --git a/webhook.html b/webhook.html index ae6d60d..4fd2491 100644 --- a/webhook.html +++ b/webhook.html @@ -14,7 +14,7 @@ Enter your Bot Token:
Enter your Bot Url:
MAX Connections?:
- Enter your Certificate:
+ Enter your Certificate (only if self-signed):

@@ -31,7 +31,7 @@ return 'https://api.telegram.org/bot' + this.token + '/setwebhook' }, bot_url: function () { - return 'https://your-server-address.com:' + this.port + '/' + this.token + return 'https://your-server-address.com:' + this.port + '/' + this.token + '/?apikey=' + this.token } } }) From 4f2d02cdd6d66f286ee2446fb0501de869651285 Mon Sep 17 00:00:00 2001 From: d4NY0 Date: Sat, 19 Aug 2017 09:49:31 +0200 Subject: [PATCH 012/225] translations --- commands/gym.php | 2 +- commands/raid.php | 2 +- commands/start.php | 2 +- commands/team.php | 10 +++++----- index.php | 2 +- logic.php | 12 ++++++------ modules/edit.php | 8 ++++---- modules/edit_left.php | 12 ++++++------ modules/edit_poke.php | 6 +++--- modules/raid_create.php | 6 +++--- 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/commands/gym.php b/commands/gym.php index 484abdd..bcb6a3a 100644 --- a/commands/gym.php +++ b/commands/gym.php @@ -18,7 +18,7 @@ ); // Send the message. - sendMessage($update['message']['chat']['id'], 'Gym name updated'); + sendMessage($update['message']['chat']['id'], 'Der Arena Name wurde aktualisiert.'); } else { if ($update['message']['reply_to_message']['text']) { diff --git a/commands/raid.php b/commands/raid.php index b85676c..52cc61c 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -91,7 +91,7 @@ $keys = [ [ [ - 'text' => 'Share', + 'text' => 'Teilen', 'switch_inline_query' => strval($id), ] ] diff --git a/commands/start.php b/commands/start.php index 1f8a299..5d7521a 100644 --- a/commands/start.php +++ b/commands/start.php @@ -1,3 +1,3 @@ Please send location to start Raid announce '); +sendMessage($update['message']['chat']['id'], 'Bitte sende mir zuerst einen Standort. '); diff --git a/commands/team.php b/commands/team.php index d20ccd0..6a26692 100644 --- a/commands/team.php +++ b/commands/team.php @@ -7,9 +7,9 @@ 'mystic' => 'mystic', 'instinct' => 'instinct', 'valor' => 'valor', - 'red' => 'valor', - 'blue' => 'mystic', - 'yellow' => 'instinct', + 'rot' => 'valor', + 'blau' => 'mystic', + 'gelb' => 'instinct', 'r' => 'valor', 'b' => 'mystic', 'y' => 'instinct' @@ -28,10 +28,10 @@ ); // Send the message. - sendMessage($update['message']['chat']['id'], 'Gym team set to ' . ucfirst($teams[$gym_team])); + sendMessage($update['message']['chat']['id'], 'Arena Team gesetzt auf: ' . ucfirst($teams[$gym_team])); // Invalid team name. } else { // Send the message. - sendMessage($update['message']['chat']['id'], 'Invalid team name - type Mystic, Valor, Instinct or Blue, Red, Yellow'); + sendMessage($update['message']['chat']['id'], 'Ungültiger Team Name - schreibe: Mystic, Valor, Instinct oder Blau, Rot, Gelb'); } diff --git a/index.php b/index.php index ec3f6af..c8be242 100644 --- a/index.php +++ b/index.php @@ -136,7 +136,7 @@ } // Echo bot response. - sendMessage($update['message']['chat']['id'], 'Please send location to start Raid announce'); + sendMessage($update['message']['chat']['id'], 'Bitte sende mir zuerst einen Standort.'); } } diff --git a/logic.php b/logic.php index 0e5fbdf..c40d1c2 100644 --- a/logic.php +++ b/logic.php @@ -73,27 +73,27 @@ function raid_edit_start_keys($id) $keys = [ [ [ - 'text' => 'Legendary Raid *****', + 'text' => '5 Sterne Raid', 'callback_data' => $id . ':edit:type_5' ] ], [ [ - 'text' => '4 Star Raid ****', + 'text' => '4 Sterne Raid', 'callback_data' => $id . ':edit:type_4' ], [ - 'text' => '3 Star Raid ***', + 'text' => '3 Sterne Raid', 'callback_data' => $id . ':edit:type_3' ] ], [ [ - 'text' => '2 Star Raid **', + 'text' => '2 Sterne Raid', 'callback_data' => $id . ':edit:type_2' ], [ - 'text' => '1 Star Raid *', + 'text' => '1 Stern Raid', 'callback_data' => $id . ':edit:type_1' ] ] @@ -664,7 +664,7 @@ function show_raid_poll($raid) function show_raid_poll_small($raid) { $time_left = floor($raid['t_left'] / 60); - $time_left = floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . ' left'; + $time_left = 'noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT); $msg = '' . ucfirst($raid['pokemon']) . ' ' . $time_left . ' ' . $raid['gym_name'] . '' . CR; diff --git a/modules/edit.php b/modules/edit.php index f881ee2..707ba79 100644 --- a/modules/edit.php +++ b/modules/edit.php @@ -131,7 +131,7 @@ $keys = [ [ [ - 'text' => 'Not supported', + 'text' => 'Nicht unterstützt', 'callback_data' => 'edit:not_supported' ] ] @@ -148,7 +148,7 @@ $keys = [ [ [ - 'text' => 'Not supported', + 'text' => 'Nicht unterstützt', 'callback_data' => 'edit:not_supported' ] ] @@ -156,9 +156,9 @@ } if (isset($update['callback_query']['inline_message_id'])) { - editMessageText($update['callback_query']['inline_message_id'], 'Choose Raid Boss:', $keys); + editMessageText($update['callback_query']['inline_message_id'], 'Raid Boss auswählen:', $keys); } else { - editMessageText($update['callback_query']['message']['message_id'], 'Choose Raid Boss', $keys, $update['callback_query']['message']['chat']['id'], $keys); + editMessageText($update['callback_query']['message']['message_id'], 'Raid Boss auswählen', $keys, $update['callback_query']['message']['chat']['id'], $keys); } // Build callback message string. diff --git a/modules/edit_left.php b/modules/edit_left.php index 471e4d0..ee05c44 100644 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -24,23 +24,23 @@ $keys = [ [ [ - 'text' => 'Share', + 'text' => 'Teilen', 'switch_inline_query' => strval($id) ] ] ]; // Build message string. - $msg = 'Raid saved.' . CR; - $msg .= 'Optional - set gym name and team:' . CR2; - $msg .= '/gym gym name' . CR; - $msg .= '/team Mystic/Valor/Instinct/Blue/Red/Yellow'; + $msg = 'Raid gespeichert.' . CR; + $msg .= 'Optional - Arena Name und Arena Team:' . CR2; + $msg .= '/gym Name der Arena' . CR; + $msg .= '/team Mystic/Valor/Instinct/Blau/Rot/Gelb'; // Edit message. edit_message($update, $msg, $keys, false); // Build callback message string. - $callback_response = 'End time set to ' . $data['arg'] . ' minutes'; + $callback_response = 'Ablaufzeit gesetzt auf ' . $data['arg'] . ' Minuten'; // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/edit_poke.php b/modules/edit_poke.php index 7e1e9eb..bce4f19 100644 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -26,7 +26,7 @@ for ($i = 120; $i >= 25; $i = $i - 5) { // Create the keys. $keys[] = array( - 'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT) . ' left', + 'text' => 'noch ' . floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), 'callback_data' => $id . ':edit_left:' . $i ); } @@ -56,10 +56,10 @@ } // Edit the message. -edit_message($update, 'How much time is left for Raid?', $keys); +edit_message($update, 'Wie lange läuft der Raid noch?', $keys); // Build callback message string. -$callback_response = 'Pokemon set to ' . $data['arg']; +$callback_response = 'Pokemon gespeichert: ' . $data['arg']; // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/raid_create.php b/modules/raid_create.php index f3576a4..5b988b5 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -48,12 +48,12 @@ $keys = raid_edit_start_keys($id); // Build message. -$msg = 'Create Raid at ' . $addr . ''; +$msg = 'Erstelle Raid in: ' . $addr . ''; // Private chat type. if ($update['message']['chat']['type'] == 'private') { // Send the message. - send_message($update['message']['chat']['id'], $msg . CR . 'Choose Raid level:', $keys); + send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys); } else { $reply_to = $update['message']['chat']['id']; @@ -62,7 +62,7 @@ } // Send the message. - send_message($update['message']['chat']['id'], $msg . CR . 'Choose Raid level:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); } exit(); From 1d8aeae944aa71070eca7060575c3ef186255f5a Mon Sep 17 00:00:00 2001 From: d4NY0 Date: Sat, 19 Aug 2017 13:42:11 +0200 Subject: [PATCH 013/225] some comments while bugfixing --- index.php | 5 ++++- logic.php | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index c8be242..8e6ab3f 100644 --- a/index.php +++ b/index.php @@ -65,7 +65,10 @@ } // Update the user. -update_user($update); +$userUpdate = update_user($update); + +// Write to log. +debug_log('Update user: ' . $userUpdate); // Callback query received. if (isset($update['callback_query'])) { diff --git a/logic.php b/logic.php index c40d1c2..66e7173 100644 --- a/logic.php +++ b/logic.php @@ -409,15 +409,21 @@ function show_raid_poll($raid) // Init empty message string. $msg = ''; + // Display gym details. if ($raid['gym_name'] || $raid['gym_team']) { - $msg .= 'Arena: ' . $raid['gym_name'] . ''; - + // Add gym name to message. + if ($raid['gym_name']) { + $msg .= 'Arena: ' . $raid['gym_name'] . ' '; + } + // Add team to message. if ($raid['gym_team']) { - $msg .= ' ' . $GLOBALS['teams'][$raid['gym_team']] . ' ' . ucfirst($raid['gym_team']); + $msg .= $GLOBALS['teams'][$raid['gym_team']] . ' ' . ucfirst($raid['gym_team']); } + $msg .= CR; } + // Display address. if ($raid['address']) { $addr = explode(',', $raid['address'], 4); array_pop($addr); @@ -426,15 +432,19 @@ function show_raid_poll($raid) $msg .= 'Adresse: ' . $addr . '' . CR2; } + // Display raid boss. $msg .= 'Raid Boss: ' . ucfirst($raid['pokemon']) . '' . CR2; + // Add raid is done message. if ($time_left < 0) { $msg .= 'Raid beendet.' . CR2; + // Add time left message. } else { $msg .= '' . $time_left . ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . CR; } + // Get attendance for this raid. $rs = my_query( " SELECT *, @@ -452,10 +462,13 @@ function show_raid_poll($raid) // Init empty data array. $data = array(); + // For each attendance. while ($row = $rs->fetch_assoc()) { + // Set cancel text. if ($row['cancel']) { $row['team'] = 'cancel'; } + // Set done text. if ($row['raid_done']) { $row['team'] = 'done'; } @@ -474,6 +487,7 @@ function show_raid_poll($raid) debug_log($data); + // Add no attendance found message. if (count($data) == 0) { $msg .= CR . 'Noch keine Teilnehmer.' . CR; } @@ -503,6 +517,7 @@ function show_raid_poll($raid) // Write to log. debug_log($timeSlots); + // TIMES foreach ($timeSlots as $ts) { // Add to message. $msg .= CR . '' . unix2tz($ts['ts_att'], $raid['timezone']) . '' . ' [' . ($ts['count'] + $ts['extra']) . ']' . CR; @@ -523,8 +538,8 @@ function show_raid_poll($raid) $att_users = array(); - while ($rowusers = $user_rs->fetch_assoc()) { - $att_users[] = $rowusers; + while ($rowUsers = $user_rs->fetch_assoc()) { + $att_users[] = $rowUsers; } // Write to log. From b882eb9f4edc220e6852f9f7a2d6fc2b2dbbc6ab Mon Sep 17 00:00:00 2001 From: d4NY0 Date: Sat, 19 Aug 2017 13:43:53 +0200 Subject: [PATCH 014/225] Bugfix: First vote always failed. Fixed database structure. --- raid-pokemon-bot.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index ad73867..354b233 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -25,9 +25,9 @@ CREATE TABLE `attendance` ( `extra_2_team` enum('mystic','valor','instinct') DEFAULT NULL, `extra_3_team` enum('mystic','valor','instinct') DEFAULT NULL, `extra_4_team` enum('mystic','valor','instinct') DEFAULT NULL, - `arrived` tinyint(1) unsigned DEFAULT NULL, - `raid_done` tinyint(1) unsigned DEFAULT NULL, - `cancel` tinyint(1) unsigned DEFAULT NULL, + `arrived` tinyint(1) unsigned DEFAULT 0, + `raid_done` tinyint(1) unsigned DEFAULT 0, + `cancel` tinyint(1) unsigned DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; From 18cb91136d15ecacb2a9e1f84bfa56c4fa069c1d Mon Sep 17 00:00:00 2001 From: d4NY0 Date: Sat, 19 Aug 2017 14:58:12 +0200 Subject: [PATCH 015/225] message refactoring geocoder edited --- commands/raid.php | 5 ++- geo_api.php | 82 +++++++++++++++++++++++++++++++++-------- logic.php | 62 +++++++++++++++++-------------- modules/raid_create.php | 7 +++- 4 files changed, 111 insertions(+), 45 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index 52cc61c..11e73cb 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -23,6 +23,9 @@ // Get the address. $addr = get_address($lat, $lon); +// Get full address. +$fullAddress = (!empty($addr['district']) ? $addr['district'] : '') . (!empty($addr['street']) ? ", " . $addr['street'] : ""); + // Address found. if ($addr) { // Build the query. @@ -38,7 +41,7 @@ gym_team = '{$db->real_escape_string($data[4])}', gym_name = '{$db->real_escape_string($data[5])}', timezone = '{$tz}', - address = '{$db->real_escape_string($addr)}' + address = '{$db->real_escape_string($fullAddress)}' " ); diff --git a/geo_api.php b/geo_api.php index 274b320..10c83a9 100644 --- a/geo_api.php +++ b/geo_api.php @@ -7,8 +7,13 @@ */ function get_address($lat, $lon) { + // Init defaults. + $location = array(); + $location['street'] = ''; + $location['district'] = ''; + // Set maps geocode url. - $url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $lat . ',' . $lon; + $url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $lat . ',' . $lon . '&language=de'; $googleApiKey = GOOGLE_API_KEY; @@ -28,27 +33,74 @@ function get_address($lat, $lon) debug_log($json_response, 'status) && $data->status == 'OK' && !empty($data->results)) { + + // Init vars. + $locality = ''; + $sublocalityLv2 = ''; + $sublocality = ''; + + // Iterate each result. + foreach ($data->results as $result) { + + // Check for address components. + if (!empty($result->address_components)) { + // Iterate each address component. + foreach ($result->address_components as $address_component) { + + // Street found. + if (in_array('route', $address_component->types) && !empty($address_component->long_name)) { + // Set street by first found. + $location['street'] = empty($location['street']) ? $address_component->long_name : $location['street']; + } + + // Sublocality level2 found. + if (in_array('sublocality_level_2', $address_component->types) && !empty($address_component->long_name)) { + // Set sublocality level 2 by first found. + $sublocalityLv2 = empty($sublocalityLv2) ? $address_component->long_name : $sublocalityLv2; + } - if ($response['status'] == 'OK') { - $result = ''; - $type = ''; + // Sublocality found. + if (in_array('sublocality', $address_component->types) && !empty($address_component->long_name)) { + // Set sublocality by first found. + $sublocality = empty($sublocality) ? $address_component->long_name : $sublocality; + } - foreach ($response['results'] as $v) { - if ($v['formatted_address'] && !$result) { - $result = $v['formatted_address']; - $type = $v['geometry']['location_type']; + // Locality found. + if (in_array('locality', $address_component->types) && !empty($address_component->long_name)) { + // Set sublocality by first found. + $locality = empty($sublocality) ? $address_component->long_name : $sublocality; + } + } } - if ($type == 'ROOFTOP') return $result; } - // Return the result. - return $result; + // Set district by priority. + if (!empty($sublocalityLv2)) { + $location['district'] = $sublocalityLv2; - } else { - // Write to log. - debug_log($json_response, '!'); + } else if ($sublocality) { + $location['district'] = $sublocality; + + } else if ($locality) { + $location['district'] = $locality; + } + // Rename street responses. + switch ($location['street']) { + case 'Unnamed Road': + $location['street'] = 'Irgendwo im Wald'; + break; + } + + // Return the location array. + return $location; + + } else { return false; } } diff --git a/logic.php b/logic.php index 66e7173..b3130ca 100644 --- a/logic.php +++ b/logic.php @@ -404,45 +404,44 @@ function unix2tz($unix, $tz, $format = 'H:i') function show_raid_poll($raid) { $time_left = floor($raid['t_left'] / 60); - $time_left = floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h übrig '; + $time_left = 'noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h'; // Init empty message string. $msg = ''; + // Display raid boss name. + $msg .= '' . ucfirst($raid['pokemon']) . ', '; + + // Display address. + if ($raid['address']) { + $msg .= $raid['address'] . ', '; + } + + // Add raid is done message. + if ($time_left < 0) { + $msg .= 'Raid beendet.' . CR2; + + // Add time left message. + } else { + $msg .= 'bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . ' (' . $time_left . ').' . CR; + } + // Display gym details. if ($raid['gym_name'] || $raid['gym_team']) { // Add gym name to message. if ($raid['gym_name']) { - $msg .= 'Arena: ' . $raid['gym_name'] . ' '; + $msg .= 'Arena: ' . $raid['gym_name'] . ''; } // Add team to message. if ($raid['gym_team']) { - $msg .= $GLOBALS['teams'][$raid['gym_team']] . ' ' . ucfirst($raid['gym_team']); + $msg .= ' (' . ucfirst($raid['gym_team']) . ')'; } $msg .= CR; } - // Display address. - if ($raid['address']) { - $addr = explode(',', $raid['address'], 4); - array_pop($addr); - $addr = implode(',', $addr); - - $msg .= 'Adresse: ' . $addr . '' . CR2; - } - - // Display raid boss. - $msg .= 'Raid Boss: ' . ucfirst($raid['pokemon']) . '' . CR2; - - // Add raid is done message. - if ($time_left < 0) { - $msg .= 'Raid beendet.' . CR2; - - // Add time left message. - } else { - $msg .= '' . $time_left . ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . CR; - } + // Add google maps link to message. + $msg .= 'http://maps.google.com/maps?q=' . $raid['lat'] . ',' . $raid['lon'] . '' . CR; // Get attendance for this raid. $rs = my_query( @@ -566,12 +565,18 @@ function show_raid_poll($raid) // Unknown team. if ($row['team'] === NULL) { - $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' ' . $row['level'] . ' ' . $name . ' '; + $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' ' . $name; // Known team. } else { - $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $row['level'] . ' ' . $name . ' '; + $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name; + } + + // Add level. + if ($row['level'] != 0) { + $msg .= ' (Lv.' . $row['level'] . ')'; } + $msg .= ' '; // Arrived. if ($vv['arrived']) { @@ -665,7 +670,8 @@ function show_raid_poll($raid) } // Add update time and raid id to message. - $msg .= CR . 'Aktualisiert: ' . unix2tz(time(), $raid['timezone'], 'H:i:s') . ' ID = ' . $raid['id']; + $msg .= CR . 'Aktualisiert: ' . unix2tz(time(), $raid['timezone'], 'H:i:s') . ''; + // $msg.= ' ID = ' . $raid['id']; // Debug. // Return the message. return $msg; @@ -685,11 +691,13 @@ function show_raid_poll_small($raid) // Address found. if ($raid['address']) { + /* $addr = explode(',', $raid['address'], 4); array_pop($addr); $addr = implode(',', $addr); // Add to message. - $msg .= '' . $addr . '' . CR2; + */ + $msg .= '' . $raid['address'] . '' . CR2; } // Build query. diff --git a/modules/raid_create.php b/modules/raid_create.php index 5b988b5..6c2e312 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -8,6 +8,9 @@ // Get the address. $addr = get_address($lat, $lon); +// Get full address. +$fullAddress = (!empty($addr['district']) ? $addr['district'] : '') . (!empty($addr['street']) ? ", " . $addr['street'] : ""); + // Address found. if (!empty($addr)) { // Create raid with address. @@ -19,7 +22,7 @@ lon = '{$lon}', first_seen = NOW(), timezone = '{$tz}', - address = '{$db->real_escape_string($addr)}' + address = '{$db->real_escape_string($fullAddress)}' " ); @@ -48,7 +51,7 @@ $keys = raid_edit_start_keys($id); // Build message. -$msg = 'Erstelle Raid in: ' . $addr . ''; +$msg = 'Erstelle Raid in: ' . $fullAddress . ''; // Private chat type. if ($update['message']['chat']['type'] == 'private') { From 66df5809d37f91eb9fa05cbd85319024cf83bf62 Mon Sep 17 00:00:00 2001 From: d4NY0 Date: Sun, 20 Aug 2017 14:54:15 +0200 Subject: [PATCH 016/225] send seperate location with raids --- commands/raid.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/commands/raid.php b/commands/raid.php index 11e73cb..63f0b41 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -85,6 +85,13 @@ // Get row. $raid = $rs->fetch_assoc(); +// Send location. +$loc = send_location($update['message']['chat']['id'], $raid['lat'], $raid['lon']); + +// Write to log. +debug_log('location:'); +debug_log($loc); + // Set text. $text = show_raid_poll($raid); From db8db5b2210c24df9fdc5c7d34486d402d4272c4 Mon Sep 17 00:00:00 2001 From: d4NY0H Date: Wed, 23 Aug 2017 11:01:42 +0200 Subject: [PATCH 017/225] automatism changed --- commands/raid.php | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index 63f0b41..4d2ec2c 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -1,13 +1,30 @@ real_escape_string($data[4])}', gym_name = '{$db->real_escape_string($data[5])}', timezone = '{$tz}', - address = '{$db->real_escape_string($fullAddress)}' + address = '{$db->real_escape_string($address)}' " ); From 37cfe315d1674e5e67e086612b67dfaa653e78ea Mon Sep 17 00:00:00 2001 From: d4NY0H Date: Thu, 31 Aug 2017 15:54:07 +0200 Subject: [PATCH 018/225] Added more legendaries --- modules/edit.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/edit.php b/modules/edit.php index 707ba79..cb4e578 100644 --- a/modules/edit.php +++ b/modules/edit.php @@ -30,6 +30,38 @@ 'text' => 'Zapdos', 'callback_data' => $id . ':edit_poke:zapdos' ] + ], + [ + [ + 'text' => 'Mewtu', + 'callback_data' => $id . ':edit_poke:mewtu' + ], + [ + 'text' => 'Mew', + 'callback_data' => $id . ':edit_poke:mew' + ], + [ + 'text' => 'Ho-Oh', + 'callback_data' => $id . ':edit_poke:hooh' + ], + [ + 'text' => 'Celebi', + 'callback_data' => $id . ':edit_poke:celebi' + ] + ], + [ + [ + 'text' => 'Raikou', + 'callback_data' => $id . ':edit_poke:raikou' + ], + [ + 'text' => 'Entei', + 'callback_data' => $id . ':edit_poke:entei' + ], + [ + 'text' => 'Suicune', + 'callback_data' => $id . ':edit_poke:suicune' + ] ] ]; From dfdb96d4077aa5e2606d8d25992cf8b2faabd28c Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Tue, 12 Sep 2017 18:42:48 +0200 Subject: [PATCH 019/225] Fix /raid Command for data, which contains comma you can now use a pipe --- commands/raid.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commands/raid.php b/commands/raid.php index 4d2ec2c..b963f21 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -37,6 +37,9 @@ $lat = substr($lat, 0, strpos('.', $lat) + 9); $lon = substr($lon, 0, strpos('.', $lon) + 9); +// Escape comma in Raidname +$name = str_replace('|',',',$data[5]); + // Build address string. $address = (!empty($data[6]) ? $data[6] : '') . (!empty($data[7]) ? ", " . $data[7] : ""); @@ -53,7 +56,7 @@ first_seen = NOW(), end_time = DATE_ADD(first_seen, INTERVAL {$data[3]} MINUTE), gym_team = '{$db->real_escape_string($data[4])}', - gym_name = '{$db->real_escape_string($data[5])}', + gym_name = '{$db->real_escape_string($name)}', timezone = '{$tz}', address = '{$db->real_escape_string($address)}' " From 42877d1a434903e10f3cfccc7b75a312863e842b Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Tue, 12 Sep 2017 18:44:26 +0200 Subject: [PATCH 020/225] Change time slots to 10 minute slots, and only use 10 minutes for end of raid Remove negative times on update, just call if finished Fix team color from valor, instinct, mystic to blue, yellow, red --- logic.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/logic.php b/logic.php index b3130ca..eb86e6a 100644 --- a/logic.php +++ b/logic.php @@ -209,8 +209,10 @@ function keys_vote($raid) ]; } else { + $timePerSlot = 600; // 10 minutes + $timeBeforeEnd = 600; // 10 minutes $col = 1; - for ($i = ceil($now / 900) * 900; $i <= ($end_time - 900); $i = $i + 900) { + for ($i = ceil($now / $timePerSlot) * $timePerSlot; $i <= ($end_time - $timeBeforeEnd); $i = $i + $timePerSlot) { if ($col++ >= 4) { $keys[] = $keys_time; @@ -404,6 +406,9 @@ function unix2tz($unix, $tz, $format = 'H:i') function show_raid_poll($raid) { $time_left = floor($raid['t_left'] / 60); + if ( strpos(str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) , '-' ) !== false ) + $time_left = 'beendet'; + else $time_left = 'noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h'; // Init empty message string. @@ -434,7 +439,16 @@ function show_raid_poll($raid) } // Add team to message. if ($raid['gym_team']) { - $msg .= ' (' . ucfirst($raid['gym_team']) . ')'; + + // FB: Korrekt Team Color + $team = ''; + if ($raid['gym_team'] == 'valor') + $team = 'blau'; + else if ($raid['gym_team'] == 'instinct') + $team = 'gelb'; + else if ($raid['gym_team'] == 'mystic') + $team = 'rot'; + $msg .= ' (' . $team . ')'; } $msg .= CR; From 28a4656dc59543a8dd6768a7c43b014b2096851f Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 11:03:10 +0200 Subject: [PATCH 021/225] New README, credits to @atis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi there @florianbecker this is the first of several commits following. I'll start with the README.md here as the first commit. Basically I added some functions to the raid-pokemon-bot to make it even better ;) Just read the messages for the upcoming commit and you'll know what was changed and added by me. I've chosen your version @florianbecker since this one had the latest commits, but instead of continuing the forks, I'll provide the pull request here with all my changes and hope you'll merge this. Btw let me say "Thank you" to everyone who put already time and effort into this - so this goes out to you @atis @d4NY0H @marrah83 and @florianbecker Cheers! --- Freundliche Grüße! @Chefkeks (on Github and also on Telegram :wink: ) PS: Once all files I modified and changed are added to the pull request here, I'll let you know by leaving a message (to avoid a too early merge of the PR) --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0ca0d45..b762549 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,47 @@ -TODO: +# Installation + +## Webserver + +Preferrably apache2 with php7 and https certificate ( https://www.letsencrypt.org ) + +## Config + +Copy config.php.example to config.php and edit (values explained further) + +## Log files + +Create log dir, e.g. /var/log/tg-bots/ and set it writeable by webserver +Edit config.php and set `CONFIG_LOGFILE` + +## Bot token + +Start chat with https://t.me/BotFather and create bot token. +Bot Settings: Enable Inline mode, Allow Groups, Group Privacy off + +Use https://www.miniwebtool.com/sha512-hash-generator/ and set `CONFIG_HASH` to hashed value of your token (make sure it is lowecase) + +## Database + +Create database named for your bot ID (first part of your Telegram bot token) +Set database password to second part of your TG bot token +Only allow localhost access +Import `raid-pokemon-bot.sql` as default DB structure + +## Webhooks + +Set Telegram webhook via https://your-hostname/bot-dir/webhooks.html + +## Google maps API + +Optionally you can you use Google maps API to lookup addresses of gyms based on latitude and longitude + +Therefore get a Google maps API key and set it as `GOOGLE_API_KEY` in your config. +Activate it for both Geocoding and Time Zone API + +https://developers.google.com/maps/documentation/timezone/get-api-key +https://developers.google.com/maps/documentation/geocoding/start#get-a-key + +# TODO: arrived - set and show time @@ -8,4 +51,4 @@ TODO: geofencing - auto publish to chat timezones create api / command - \ No newline at end of file + From 86709a045c97984964e0679c06ac04a5184ce6c5 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:23:15 +0200 Subject: [PATCH 022/225] Add start_time to database, for existing installation do an "alter table" or use a tool like phpmyadmin to add the column --- raid-pokemon-bot.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index 354b233..66a3b4b 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -40,6 +40,7 @@ CREATE TABLE `raids` ( `lat` varchar(11) DEFAULT NULL, `lon` varchar(11) DEFAULT NULL, `first_seen` datetime DEFAULT NULL, + `start_time` datetime DEFAULT NULL, `end_time` datetime DEFAULT NULL, `timezone` char(30) DEFAULT NULL, `address` varchar(255) DEFAULT NULL, From c334cbeaf351cfd858786c2e2ab776653ab9c71e Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:27:51 +0200 Subject: [PATCH 023/225] Add /new command, mostly for testing Does actually the same as /raid, but since the Telegram Desktop Client does not allow to send a location (latitude, longitude), I created the /new command, so one can send coordinates with /new from the desktop Example: /new 52.5162746,13.3777041 --- commands/new.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 commands/new.php diff --git a/commands/new.php b/commands/new.php new file mode 100644 index 0000000..4a690ec --- /dev/null +++ b/commands/new.php @@ -0,0 +1,34 @@ + 'Raid anlegen', + 'callback_data' => $userid . ',' . $chattype . ':raid_create:' . $coords, + ] + ] + ]; + +$msg = "Koordination erfolgreich übermittelt!"; + +// Send message. +send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + +exit; From 1e7feda5a102e29f8b92045b9df99c39b43bf4f6 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:28:59 +0200 Subject: [PATCH 024/225] Part of the fixes to get rid of all the "undefined index", "undefined constants", etc. notices in the log files. --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 8e6ab3f..ab12dd6 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ Date: Fri, 20 Oct 2017 16:30:13 +0200 Subject: [PATCH 025/225] Add possibility to set a proxy server for curl Unfortunately I need this in my environment here :( --- functions.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/functions.php b/functions.php index 78b0e0f..4e71a64 100644 --- a/functions.php +++ b/functions.php @@ -374,6 +374,11 @@ function curl_json_request($json) curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); + // Use Proxyserver for curl if configured + if (CURL_USEPROXY == true) { + curl_setopt($curl, CURLOPT_PROXY, CURL_PROXYSERVER); + } + // Write to log. debug_log($json, '->'); From e37bab16381cf3aa6eae42e8dbd57017078179f5 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:30:44 +0200 Subject: [PATCH 026/225] Add curl and raid time related settings to config.php --- config.php.example | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config.php.example b/config.php.example index 221d7d9..1827836 100644 --- a/config.php.example +++ b/config.php.example @@ -2,6 +2,9 @@ define('GOOGLE_API_KEY', ''); // optional define('TIMEZONE', 'Europe/Berlin'); +define('CURL_USEPROXY', false); +define('CURL_PROXYSERVER', 'http://your.proxyserver.com:8080'); + define('DEBUG', true); define('CONFIG_LOGFILE', '/var/log/tg-bots/dev-raid-bot.log'); define('CONFIG_HASH', ' = hash(sha_512,tg_bot_key) '); @@ -13,3 +16,7 @@ define('DB_PASSWORD', 'your_database_password'); define('MAINTAINER', '@your_tg_username'); define('MAINTAINER_ID', 'your_tg_integer'); define('BOT_NAME', '@RaidPokemonBot'); + +define('RAID_DURATION', '60'); // minutes, optional +define('RAID_SLOTS', '15'); // minutes +define('RAID_LAST_START', '10'); // minutes before RAID ends From dccb092a76dab2e90c3a8aaf2c06b26930bb920e Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:31:36 +0200 Subject: [PATCH 027/225] Add street_number and postal_code as well as curl to geo_api.php --- geo_api.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/geo_api.php b/geo_api.php index 10c83a9..d820288 100644 --- a/geo_api.php +++ b/geo_api.php @@ -10,6 +10,8 @@ function get_address($lat, $lon) // Init defaults. $location = array(); $location['street'] = ''; + $location['street_number']; + $location['postal_code']; $location['district'] = ''; // Set maps geocode url. @@ -27,6 +29,11 @@ function get_address($lat, $lon) curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + // Use Proxyserver for curl if configured + if (CURL_USEPROXY == true) { + curl_setopt($curl, CURLOPT_PROXY, CURL_PROXYSERVER); + } + debug_log($url, 'G>'); $json_response = curl_exec($curl); @@ -58,6 +65,18 @@ function get_address($lat, $lon) $location['street'] = empty($location['street']) ? $address_component->long_name : $location['street']; } + // Street number found. + if (in_array('street_number', $address_component->types) && !empty($address_component->long_name)) { + // Set street by first found. + $location['street_number'] = empty($location['street_number']) ? $address_component->long_name : $location['street_number']; + } + + // Postal code found. + if (in_array('postal_code', $address_component->types) && !empty($address_component->long_name)) { + // Set street by first found. + $location['postal_code'] = empty($location['postal_code']) ? $address_component->long_name : $location['postal_code']; + } + // Sublocality level2 found. if (in_array('sublocality_level_2', $address_component->types) && !empty($address_component->long_name)) { // Set sublocality level 2 by first found. From 2f07863f2bdef0831f02c2cf8d363f626ac66267 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:35:51 +0200 Subject: [PATCH 028/225] Add support for the /new command to the raid_create module Also add start_time to SQL queries, introduce some variables instead of always using e.g. $update['message']['from']['id'] and make fullAddress a bit better readable --- modules/raid_create.php | 81 +++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 11 deletions(-) diff --git a/modules/raid_create.php b/modules/raid_create.php index 6c2e312..5f32175 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -1,15 +1,69 @@ real_escape_string($fullAddress)}' " @@ -32,10 +87,11 @@ $rs = my_query( " INSERT INTO raids - SET user_id = {$update['message']['from']['id']}, + SET user_id = {$userid}, lat = '{$lat}', lon = '{$lon}', first_seen = NOW(), + start_time = NOW(), timezone = '{$tz}' " ); @@ -54,18 +110,21 @@ $msg = 'Erstelle Raid in: ' . $fullAddress . ''; // Private chat type. -if ($update['message']['chat']['type'] == 'private') { +if ($chattype == 'private') { // Send the message. - send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys); + //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys); + send_message($chatid, $msg . CR . 'Bitte Raid level auswählen:', $keys); } else { - $reply_to = $update['message']['chat']['id']; + //$reply_to = $update['message']['chat']['id']; + $reply_to = $chatid; if ($update['message']['reply_to_message']['message_id']) { $reply_to = $update['message']['reply_to_message']['message_id']; } // Send the message. - send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + send_message($chatid, $msg . CR . 'Bitte Raid level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); } exit(); From 384230fbd3302b1238a842d275c792e26c0c0cab Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:36:24 +0200 Subject: [PATCH 029/225] Add start_time to SQL queries --- modules/edit_left.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/edit_left.php b/modules/edit_left.php index ee05c44..f87b169 100644 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -14,7 +14,7 @@ my_query( " UPDATE raids - SET end_time = DATE_ADD(first_seen, INTERVAL {$data['arg']} MINUTE) + SET end_time = DATE_ADD(start_time, INTERVAL {$data['arg']} MINUTE) WHERE id = {$id} " ); @@ -50,6 +50,7 @@ $rs = my_query( " SELECT *, + UNIX_TIMESTAMP(start_time) AS ts_start, UNIX_TIMESTAMP(end_time) AS ts_end, UNIX_TIMESTAMP(NOW()) AS ts_now, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left From 805c1bebd1265b4c6603c0513dc07e221f0baaf8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:38:17 +0200 Subject: [PATCH 030/225] Change min. time left for raid creation to 20 minutes and hide text from time selection since on small phones, e.g. an iPhone SE, all you see is "noch ..." but no time :D --- modules/edit_poke.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/edit_poke.php b/modules/edit_poke.php index bce4f19..93b663a 100644 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -23,10 +23,12 @@ // Init empty keys array. $keys = array(); - for ($i = 120; $i >= 25; $i = $i - 5) { + for ($i = 120; $i >= 20; $i = $i - 5) { // Create the keys. $keys[] = array( - 'text' => 'noch ' . floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), + // Just show the time, no text - not everyone has a phone or tablet with a large screen... + //'text' => 'noch ' . floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), + 'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), 'callback_data' => $id . ':edit_left:' . $i ); } From 0a658d2c1acdc0b9273be4d668052f03f80eba68 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:44:27 +0200 Subject: [PATCH 031/225] Add optional start_time in minutes (like a countdown until the raid egg will open) as 9th parameter, make SQL queries work with and without start_time in addition to first_seen Add a default raid duration which will be used, when time left is 0 or empty (this time can be configured in config.php, default is currently 60 minutes) Introduce variables for $data[x] to make code a bit better readable --- commands/raid.php | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index b963f21..5b8b1f3 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -8,8 +8,8 @@ // Get data from message text. (remove: "/raid ") $gym_data = trim(substr($update['message']['text'], 5)); -// Create data array (max. 8) -$data = explode(',', $gym_data, 8); +// Create data array (max. 9) +$data = explode(',', $gym_data, 9); /** * Info: @@ -19,8 +19,9 @@ * [3] = minutes * [4] = gym team * [5] = gym name - * [6] = district - * [7] = street + * [6] = district (or street) + * [7] = street (or district) + * [8] = optional: raid countdown minutes */ // Invalid data received. @@ -29,6 +30,9 @@ exit; } +// Raid boss name +$boss = $data[0]; + // Get latitude / longitude from data. $lat = floatval($data[1]); $lon = floatval($data[2]); @@ -37,25 +41,43 @@ $lat = substr($lat, 0, strpos('.', $lat) + 9); $lon = substr($lon, 0, strpos('.', $lon) + 9); +// Endtime from input / config +if ((!empty($data[3])) && ($data[3] > 0)) { + $endtime = $data[3]; +} else { + $endtime = RAID_DURATION; +} + +// Team +$team = $data[4]; + // Escape comma in Raidname $name = str_replace('|',',',$data[5]); // Build address string. +// Based on input order of [6] and [7] it'll be either: Street, District or District, Street $address = (!empty($data[6]) ? $data[6] : '') . (!empty($data[7]) ? ", " . $data[7] : ""); +// Get countdown minutes when specified, otherwise 0 minutes until raid starts +$countdown = 0; +if (!empty($data[8])) { + $countdown = $data[8]; +} + // Address found. if (!empty($address)) { // Build the query. $rs = my_query( " INSERT INTO raids - SET pokemon = '{$db->real_escape_string($data[0])}', + SET pokemon = '{$db->real_escape_string($boss)}', user_id = {$update['message']['from']['id']}, lat = '{$lat}', lon = '{$lon}', first_seen = NOW(), - end_time = DATE_ADD(first_seen, INTERVAL {$data[3]} MINUTE), - gym_team = '{$db->real_escape_string($data[4])}', + start_time = DATE_ADD(first_seen, INTERVAL {$countdown} MINUTE), + end_time = DATE_ADD(start_time, INTERVAL {$endtime} MINUTE), + gym_team = '{$db->real_escape_string($team)}', gym_name = '{$db->real_escape_string($name)}', timezone = '{$tz}', address = '{$db->real_escape_string($address)}' @@ -68,14 +90,15 @@ $rs = my_query( " INSERT INTO raids - SET pokemon = '{$db->real_escape_string($data[0])}', + SET pokemon = '{$db->real_escape_string($boss)}', user_id = {$update['message']['from']['id']}, lat = '{$lat}', lon = '{$lon}', first_seen = NOW(), - end_time = DATE_ADD(first_seen, INTERVAL {$data[3]} MINUTE), - gym_team = '{$db->real_escape_string($data[4])}', - gym_name = '{$db->real_escape_string($data[5])}', + start_time = DATE_ADD(first_seen, INTERVAL {$countdown} MINUTE), + end_time = DATE_ADD(start_time, INTERVAL {$endtime} MINUTE), + gym_team = '{$db->real_escape_string($team)}', + gym_name = '{$db->real_escape_string($name)}', timezone = '{$tz}' " ); @@ -92,6 +115,7 @@ " SELECT *, UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, UNIX_TIMESTAMP(NOW()) AS ts_now, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids From 96195148ff782a797026da10c24110e0925222e7 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 20 Oct 2017 16:57:36 +0200 Subject: [PATCH 032/225] Finally logic.php, where all the magic happens! :D Add start_time and moved time slot values to config.php Add 60 extra seconds for the voting button (see comment in the file) Add a "last chance to start a raid" time (can be configured in config.php) to display another time voting button when there is still plenty of time but normal configuration of time slots wouldn't allow another voting button. Example: Timeslot: 15min, Last Start before raid ends: 10min, Raid ends: 18:24, Last shown voting option would be 18:00 without my additional button (still 24min left!) and 18:14 with my additional button (18:24 - 10min). Improved layout of the telegram message (hope you like it - it's almost the same layout that MR uses for our raids here in town) and added a "raids starts at hh:ii" message for raids where the egg is not open yet (but the countdown is running) with the ability to already vote even though the raid has not started yet (one of my favorite improvements) Get rid of several "undefined index", "undefined constants", etc. notices in the log files. Some minor adjustments and fixes --- logic.php | 139 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 49 deletions(-) diff --git a/logic.php b/logic.php index eb86e6a..fd5734d 100644 --- a/logic.php +++ b/logic.php @@ -152,6 +152,7 @@ function keys_vote($raid) $end_time = $raid['ts_end']; $now = $raid['ts_now']; + $start_time = $raid['ts_start']; $keys = [ [ @@ -209,21 +210,38 @@ function keys_vote($raid) ]; } else { - $timePerSlot = 600; // 10 minutes - $timeBeforeEnd = 600; // 10 minutes + $timePerSlot = 60*RAID_SLOTS; + $timeBeforeEnd = 60*RAID_LAST_START; $col = 1; - for ($i = ceil($now / $timePerSlot) * $timePerSlot; $i <= ($end_time - $timeBeforeEnd); $i = $i + $timePerSlot) { + //for ($i = ceil($now / $timePerSlot) * $timePerSlot; $i <= ($end_time - $timeBeforeEnd); $i = $i + $timePerSlot) { + for ($i = ceil($start_time / $timePerSlot) * $timePerSlot; $i <= ($end_time - $timeBeforeEnd); $i = $i + $timePerSlot) { if ($col++ >= 4) { $keys[] = $keys_time; $keys_time = []; $col = 1; } - - $keys_time[] = array( - 'text' => unix2tz($i, $raid['timezone']), - 'callback_data' => $raid['id'] . ':vote_time:' . $i - ); + // Plus 60 seconds, so vote button for e.g. 10:00 will disappear after 10:00:59 / at 10:01:00 and not right after 09:59:59 / at 10:00:00 + if (($i + 60) > $now) { + // Display vote buttons for now + 1 additional minute + $keys_time[] = array( + 'text' => unix2tz($i, $raid['timezone']), + 'callback_data' => $raid['id'] . ':vote_time:' . $i + ); + } + + // This is our last run of the for loop since $i + timePerSlot are ahead of $end_time - $timeBeforeEnd + // Offer a last raid, which is x minutes before the raid ends, x = $timeBeforeEnd + if (($i + $timePerSlot) > ($end_time - $timeBeforeEnd)) { + // Set the time for the last possible raid and add vote key if there is enough time left + $timeLastRaid = $end_time - $timeBeforeEnd; + if($timeLastRaid > $i + $timeBeforeEnd && ($timeLastRaid >= $now)){ + $keys_time[] = array( + 'text' => unix2tz($timeLastRaid, $raid['timezone']), + 'callback_data' => $raid['id'] . ':vote_time:' . $timeLastRaid + ); + } + } } $keys[] = $keys_time; @@ -274,15 +292,15 @@ function update_user($update) $name = ''; $sep = ''; - if ($update['message']) { + if (isset($update['message'])) { $msg = $update['message']['from']; } - if ($update['callback_query']) { + if (isset($update['callback_query'])) { $msg = $update['callback_query']['from']; } - if ($update['inline_query']) { + if (isset($update['inline_query'])) { $msg = $update['inline_query']['from']; } @@ -300,7 +318,7 @@ function update_user($update) $sep = ' '; } - if ($msg['last_name']) { + if (isset($msg['last_name'])) { $name .= $sep . $msg['last_name']; } @@ -333,6 +351,7 @@ function send_response_vote($update, $data, $new = false) " SELECT *, UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, UNIX_TIMESTAMP(NOW()) AS ts_now, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids @@ -405,37 +424,14 @@ function unix2tz($unix, $tz, $format = 'H:i') */ function show_raid_poll($raid) { - $time_left = floor($raid['t_left'] / 60); - if ( strpos(str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) , '-' ) !== false ) - $time_left = 'beendet'; - else - $time_left = 'noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h'; - // Init empty message string. $msg = ''; - // Display raid boss name. - $msg .= '' . ucfirst($raid['pokemon']) . ', '; - - // Display address. - if ($raid['address']) { - $msg .= $raid['address'] . ', '; - } - - // Add raid is done message. - if ($time_left < 0) { - $msg .= 'Raid beendet.' . CR2; - - // Add time left message. - } else { - $msg .= 'bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . ' (' . $time_left . ').' . CR; - } - // Display gym details. if ($raid['gym_name'] || $raid['gym_team']) { // Add gym name to message. if ($raid['gym_name']) { - $msg .= 'Arena: ' . $raid['gym_name'] . ''; + $msg .= 'Arena: ' . $raid['gym_name'] . ''; } // Add team to message. if ($raid['gym_team']) { @@ -443,19 +439,54 @@ function show_raid_poll($raid) // FB: Korrekt Team Color $team = ''; if ($raid['gym_team'] == 'valor') - $team = 'blau'; + $team = TEAM_R; else if ($raid['gym_team'] == 'instinct') - $team = 'gelb'; + $team = TEAM_Y; else if ($raid['gym_team'] == 'mystic') - $team = 'rot'; - $msg .= ' (' . $team . ')'; + $team = TEAM_B; + $msg .= ' ' . $team; } $msg .= CR; } // Add google maps link to message. - $msg .= 'http://maps.google.com/maps?q=' . $raid['lat'] . ',' . $raid['lon'] . '' . CR; + if (!empty($raid['address'])) { + $msg .= 'Adresse: ' . $raid['address'] . '' . CR; + } else { + $msg .= 'Adresse: http://maps.google.com/maps?q=' . $raid['lat'] . ',' . $raid['lon'] . '' . CR; + } + + // Display raid boss name. + $msg .= 'Raid Boss: ' . ucfirst($raid['pokemon']) . '' . CR; + + $time_left = floor($raid['t_left'] / 60); + if ( strpos(str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) , '-' ) !== false ) { + // $time_left = 'beendet'; <-- REPLACED BY $tl_msg, so if clause below is still working ($time_left < 0) + $tl_msg .= 'Raid beendet.'; + } else { + // Replace $time_left with $tl_msg too + $tl_msg = ' — noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h'; + } + + // Raid has not started yet - adjust time left message + if ($raid['ts_now'] < $raid['ts_start']) { + $msg .= 'Raid-Ei öffnet sich um ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; + + // Raid has started and active or already ended + } else { + + // Add raid is done message. + // FIXED - $time_left got changed to text above, so added $tl_msg + if ($time_left < 0) { + $msg .= $tl_msg . CR2; + + // Add time left message. + } else { + $msg .= 'Raid bis ' . unix2tz($raid['ts_end'], $raid['timezone']); + $msg .= $tl_msg . CR; + } + } // Get attendance for this raid. $rs = my_query( @@ -579,22 +610,28 @@ function show_raid_poll($raid) // Unknown team. if ($row['team'] === NULL) { - $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' ' . $name; + $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' '; // Known team. } else { - $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name; + $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' '; } // Add level. if ($row['level'] != 0) { - $msg .= ' (Lv.' . $row['level'] . ')'; + $msg .= ''.$row['level'].''; } + $msg .= ' '; + + // Add name. + $msg .= $name; $msg .= ' '; // Arrived. if ($vv['arrived']) { - $msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + // No time is displayed, but undefined_index error in log, so changed it: + //$msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + $msg .= '[Bin da]'; // Cancelled. } else if ($vv['cancel']) { @@ -603,7 +640,7 @@ function show_raid_poll($raid) // Add extra people. if ($vv['extra_people']) { - $msg .= '+' . $vv['extra_people']; + $msg .= ' +' . $vv['extra_people']; } $msg .= CR; @@ -611,7 +648,8 @@ function show_raid_poll($raid) } // DONE - if (count($data['done'])) { + if (isset($data['done']) ? count($data['done']) : '' ) { + //if (count($data['done'])) { // Add to message. $msg .= CR . TEAM_DONE . ' Fertig: ' . ' [' . count($data['done']) . ']' . CR; @@ -648,7 +686,8 @@ function show_raid_poll($raid) } // CANCEL - if (count($data['cancel'])) { + if (isset($data['cancel']) ? count($data['cancel']) : '' ) { + //if (count($data['cancel'])) { // Add to message. $msg .= CR . TEAM_CANCEL . ' Abgesagt: ' . ' [' . count($data['cancel']) . ']' . CR; @@ -685,7 +724,7 @@ function show_raid_poll($raid) // Add update time and raid id to message. $msg .= CR . 'Aktualisiert: ' . unix2tz(time(), $raid['timezone'], 'H:i:s') . ''; - // $msg.= ' ID = ' . $raid['id']; // Debug. + $msg .= ' ID = ' . $raid['id']; // Debug. // Return the message. return $msg; @@ -770,6 +809,7 @@ function raid_list($update) " SELECT *, UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, UNIX_TIMESTAMP(NOW()) AS ts_now, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids @@ -783,6 +823,7 @@ function raid_list($update) " SELECT *, UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, UNIX_TIMESTAMP(NOW()) AS ts_now, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids From caf0d98a66583bd1bf44cfdb4de5378f3d17dbf2 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 30 Oct 2017 11:28:37 +0100 Subject: [PATCH 033/225] Update existing raid after duplication check. Send message back when raid got updated. --- commands/raid.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/commands/raid.php b/commands/raid.php index 5b8b1f3..ddd5669 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -64,6 +64,50 @@ $countdown = $data[8]; } +// Insert new raid or update existing raid? +$raid_id = raid_duplication_check($name,($endtime + $countdown)); + +if ($raid_id != 0){ + // Update pokemon and team in raids table. + my_query( + " + UPDATE raids + SET pokemon = '{$db->real_escape_string($boss)}', + gym_team = '{$db->real_escape_string($team)}' + WHERE id = {$raid_id} + " + ); + + // Debug log + debug_log('Updated raid ID: ' . $raid_id); + + // Build query. + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$raid_id} + " + ); + + // Get row. + $raid = $rs->fetch_assoc(); + + // Set text. + $text = 'Raid aktualisiert! ID = ' . $raid_id . "" . CR; + $text .= CR . show_raid_poll($raid); + + // Send the message + sendMessage($update['message']['chat']['id'], $text); + + // Exit now after update of raid and message. + exit; +} + // Address found. if (!empty($address)) { // Build the query. From 87db231fc037f70863cffa5a5980575cef874ac6 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 30 Oct 2017 11:42:42 +0100 Subject: [PATCH 034/225] Added raid duplication check - searches for last raid details at submitted gym_name and if a database entry was found it checks If the end_time of the new raid is between minus/plus 5 minutes of raid we got from the database. Based on result it creates a new raid or updates an existing raid (currently updates raid boss and gym team). New gyms which are not in the database yet will be handled for sure and don't lead to errors. Additionally added a rounding option to the nearest 5 minutes for the last start / voting option of the raid, so e.g. 11:14 is now rounded to 11:15. Unfortunately this will sometimes decrease the amount of time left, e.g. from 10 minutes (11:14 - 11:24) to 9 minutes (11:15 - 11:24), but makes voting times "beautiful" again :D Last but not least a little undefined $tl_msg issue I missed last time was fixed :) --- logic.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/logic.php b/logic.php index fd5734d..2f5bf6e 100644 --- a/logic.php +++ b/logic.php @@ -39,6 +39,79 @@ function raid_access_check($update, $data) } } +/** + * Raid duplication check. + * @param $gym + * @param $end + * @return $raid['id'] or 0 + */ +function raid_duplication_check($gym,$end) +{ + // Build query. + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE gym_name = '{$gym}' + ORDER BY id DESC + LIMIT 1 + " + ); + + // Get row. + $raid = $rs->fetch_assoc(); + + // Set duplicate ID to 0 + $duplicate_id = 0; + + // If gym is in database and new end_time matches existing end_time the updated duplicate ID to raid ID from database + if ($raid) { + // Timezone - maybe there's a more elegant solution as date_default_timezone_set?! + $tz = TIMEZONE; + date_default_timezone_set($tz); + + // Now + $end = endtime of new raid + $end = time() + $end*60; + + // Compare end time - check 5 minutes before and after database value + $ts_end_before = $raid['ts_end'] - (5*60); + $ts_end_after = $raid['ts_end'] + (5*60); + + // Debug log unix times + debug_log("Unix timestamp of endtime new raid: " . $end); + debug_log("Unix timestamp of endtime-5 existing raid: " . $ts_end_before); + debug_log("Unix timestamp of endtime+5 existing raid: " . $ts_end_after); + + // Debug log + debug_log("Searched database for raids at " . $raid['gym_name']); + debug_log("Database raid ID of last raid at ". $raid['gym_name'] . ": " . $raid['id']); + debug_log("New raid at " . $raid['gym_name'] . " will end: " . unix2tz($end,$tz)); + debug_log("Existing raid at " . $raid['gym_name'] . " will end between " . unix2tz($ts_end_before,$tz) . " and " . unix2tz($ts_end_after,$tz)); + + // Check if end_time of new raid is between plus minus 5 minutes of existing raid + if($end >= $ts_end_before && $end <= $ts_end_after){ + // Update existing raid. + $duplicate_id = $raid['id']; + debug_log("New raid matches end_time of existing raid!"); + debug_log("Updating raid ID: " . $duplicate_id); + } else { + // Create new raid. + debug_log("New raid end_time does not match the end_time of existing raid."); + debug_log("Creating new raid at gym: " . $raid['gym_name']); + } + } else { + debug_log("Gym '" . $gym . "' not found in database!"); + debug_log("Creating new raid at gym: " . $gym); + } + + // Return ID or 0 + return $duplicate_id; +} + /** * Inline key array. * @param $buttons @@ -236,6 +309,9 @@ function keys_vote($raid) // Set the time for the last possible raid and add vote key if there is enough time left $timeLastRaid = $end_time - $timeBeforeEnd; if($timeLastRaid > $i + $timeBeforeEnd && ($timeLastRaid >= $now)){ + // Round last raid time to 5 minutes to avoid crooked voting times + $near5 = 5*60; + $timeLastRaid = round($timeLastRaid / $near5) * $near5; $keys_time[] = array( 'text' => unix2tz($timeLastRaid, $raid['timezone']), 'callback_data' => $raid['id'] . ':vote_time:' . $timeLastRaid @@ -463,7 +539,7 @@ function show_raid_poll($raid) $time_left = floor($raid['t_left'] / 60); if ( strpos(str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) , '-' ) !== false ) { // $time_left = 'beendet'; <-- REPLACED BY $tl_msg, so if clause below is still working ($time_left < 0) - $tl_msg .= 'Raid beendet.'; + $tl_msg = 'Raid beendet.'; } else { // Replace $time_left with $tl_msg too $tl_msg = ' — noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h'; From ec46852599e25b4f53321aea02a7c71a5747912f Mon Sep 17 00:00:00 2001 From: marrah83 Date: Wed, 1 Nov 2017 23:07:02 +0100 Subject: [PATCH 035/225] Fixes wrong DB parameter order --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index ab12dd6..29a21e5 100644 --- a/index.php +++ b/index.php @@ -54,7 +54,7 @@ $command = NULL; // Establish mysql connection. -$db = new mysqli('localhost', DB_NAME, DB_PASSWORD, DB_USER); +$db = new mysqli('localhost', DB_USER, DB_PASSWORD, DB_NAME); // Error connecting to db. if ($db->connect_errno) { From 982f340bf32a85192152e5464ab207dda40a0af8 Mon Sep 17 00:00:00 2001 From: marrah83 Date: Wed, 1 Nov 2017 23:07:28 +0100 Subject: [PATCH 036/225] Calculate address based on lat/lon with GEO API, not based on notifier parameters Add offset parsing for not yet hatched eggs based on fixed duration removed update message for "egg hatched" raid boss update. Unnecessary, unless the real message gets updates without a user side refresh --- commands/raid.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index ddd5669..d406fa7 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -42,7 +42,7 @@ $lon = substr($lon, 0, strpos('.', $lon) + 9); // Endtime from input / config -if ((!empty($data[3])) && ($data[3] > 0)) { +if ((!empty($data[3])) && ($data[3] > 0) && ($data[3] < 60)) { $endtime = $data[3]; } else { $endtime = RAID_DURATION; @@ -55,8 +55,17 @@ $name = str_replace('|',',',$data[5]); // Build address string. -// Based on input order of [6] and [7] it'll be either: Street, District or District, Street -$address = (!empty($data[6]) ? $data[6] : '') . (!empty($data[7]) ? ", " . $data[7] : ""); +$addr = get_address($lat, $lon); + +// Get full address - Street #, ZIP District +$address = ""; +$address .= (!empty($addr['street']) ? $addr['street'] : ""); +$address .= (!empty($addr['street_number']) ? " " . $addr['street_number'] : ""); +$address .= ", "; +$address .= (!empty($addr['postal_code']) ? $addr['postal_code'] . " " : ""); +$address .= (!empty($addr['district']) ? $addr['district'] : ""); + + // Get countdown minutes when specified, otherwise 0 minutes until raid starts $countdown = 0; @@ -102,7 +111,7 @@ $text .= CR . show_raid_poll($raid); // Send the message - sendMessage($update['message']['chat']['id'], $text); + //sendMessage($update['message']['chat']['id'], $text); // Exit now after update of raid and message. exit; From 460274b5a8ee298a1bd92146c10bb32204f05314 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Thu, 2 Nov 2017 10:24:41 +0100 Subject: [PATCH 037/225] Update raid.php --- commands/raid.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/raid.php b/commands/raid.php index d406fa7..e879dbe 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -42,7 +42,7 @@ $lon = substr($lon, 0, strpos('.', $lon) + 9); // Endtime from input / config -if ((!empty($data[3])) && ($data[3] > 0) && ($data[3] < 60)) { +if ((!empty($data[3])) && ($data[3] > 0) && ($data[3] < RAID_DURATION)) { $endtime = $data[3]; } else { $endtime = RAID_DURATION; From 9da99922bec901dcc938eeebc4c36a03416460db Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Thu, 2 Nov 2017 23:23:52 +0100 Subject: [PATCH 038/225] Mark all user to contact them Fix some spacings --- logic.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/logic.php b/logic.php index 2f5bf6e..3df7bfb 100644 --- a/logic.php +++ b/logic.php @@ -528,9 +528,9 @@ function show_raid_poll($raid) // Add google maps link to message. if (!empty($raid['address'])) { - $msg .= 'Adresse: ' . $raid['address'] . '' . CR; + $msg .= '' . $raid['address'] . '' . CR; } else { - $msg .= 'Adresse: http://maps.google.com/maps?q=' . $raid['lat'] . ',' . $raid['lon'] . '' . CR; + $msg .= 'http://maps.google.com/maps?q=' . $raid['lat'] . ',' . $raid['lon'] . '' . CR; } // Display raid boss name. @@ -682,7 +682,7 @@ function show_raid_poll($raid) $row = $rs->fetch_assoc(); // Always use name. - $name = htmlspecialchars($row['name']); + $name = '' . htmlspecialchars($row['name']) . ''; // Unknown team. if ($row['team'] === NULL) { @@ -696,18 +696,18 @@ function show_raid_poll($raid) // Add level. if ($row['level'] != 0) { $msg .= ''.$row['level'].''; + $msg .= ' '; } - $msg .= ' '; - // Add name. - $msg .= $name; + // Add name. + $msg .= $name; $msg .= ' '; // Arrived. if ($vv['arrived']) { // No time is displayed, but undefined_index error in log, so changed it: //$msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; - $msg .= '[Bin da]'; + $msg .= '[Bin da] '; // Cancelled. } else if ($vv['cancel']) { @@ -716,7 +716,7 @@ function show_raid_poll($raid) // Add extra people. if ($vv['extra_people']) { - $msg .= ' +' . $vv['extra_people']; + $msg .= '+' . $vv['extra_people']; } $msg .= CR; @@ -743,7 +743,7 @@ function show_raid_poll($raid) $row = $rs->fetch_assoc(); - $name = htmlspecialchars($row['name']); + $name = '' . htmlspecialchars($row['name']) . ''; // Add to message. $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name . ' '; @@ -781,7 +781,7 @@ function show_raid_poll($raid) $row = $rs->fetch_assoc(); - $name = htmlspecialchars($row['name']); + $name = '' . htmlspecialchars($row['name']) . ''; $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' ' . $name . ' '; From 6489461698f196200ff852a54e728d837d6b9358 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Sun, 5 Nov 2017 07:23:19 +0100 Subject: [PATCH 039/225] Fix default configuration to really work optional --- config.php.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.php.example b/config.php.example index 1827836..5880ae9 100644 --- a/config.php.example +++ b/config.php.example @@ -17,6 +17,6 @@ define('MAINTAINER', '@your_tg_username'); define('MAINTAINER_ID', 'your_tg_integer'); define('BOT_NAME', '@RaidPokemonBot'); -define('RAID_DURATION', '60'); // minutes, optional +define('RAID_DURATION', '0'); // minutes, optional define('RAID_SLOTS', '15'); // minutes define('RAID_LAST_START', '10'); // minutes before RAID ends From 83a9e3bfb338588b59f145eb8bd4c56b113fa970 Mon Sep 17 00:00:00 2001 From: marrah83 Date: Sun, 5 Nov 2017 14:24:37 +0100 Subject: [PATCH 040/225] remove unnecessary RAID_DURATION --- commands/raid.php | 8 +++----- config.php.example | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index e879dbe..8406f57 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -42,11 +42,9 @@ $lon = substr($lon, 0, strpos('.', $lon) + 9); // Endtime from input / config -if ((!empty($data[3])) && ($data[3] > 0) && ($data[3] < RAID_DURATION)) { - $endtime = $data[3]; -} else { - $endtime = RAID_DURATION; -} +// timeleft till raid ends or raid duration if egg hasn't hatched yet +$endtime = $data[3]; + // Team $team = $data[4]; diff --git a/config.php.example b/config.php.example index 1827836..63a4acf 100644 --- a/config.php.example +++ b/config.php.example @@ -17,6 +17,5 @@ define('MAINTAINER', '@your_tg_username'); define('MAINTAINER_ID', 'your_tg_integer'); define('BOT_NAME', '@RaidPokemonBot'); -define('RAID_DURATION', '60'); // minutes, optional define('RAID_SLOTS', '15'); // minutes define('RAID_LAST_START', '10'); // minutes before RAID ends From cffc47a0256ae31ad94e6aa179f0cabaf43ffb2c Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Sun, 5 Nov 2017 23:19:39 +0100 Subject: [PATCH 041/225] Added logic to make address lookup via Google API optional again, changed a little description to make input parameters a bit clearer --- commands/raid.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index e879dbe..dbdf959 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -16,7 +16,7 @@ * [0] = Boss name * [1] = latitude * [2] = longitude - * [3] = minutes + * [3] = raid duration in minutes * [4] = gym team * [5] = gym name * [6] = district (or street) @@ -55,17 +55,20 @@ $name = str_replace('|',',',$data[5]); // Build address string. -$addr = get_address($lat, $lon); - -// Get full address - Street #, ZIP District -$address = ""; -$address .= (!empty($addr['street']) ? $addr['street'] : ""); -$address .= (!empty($addr['street_number']) ? " " . $addr['street_number'] : ""); -$address .= ", "; -$address .= (!empty($addr['postal_code']) ? $addr['postal_code'] . " " : ""); -$address .= (!empty($addr['district']) ? $addr['district'] : ""); - - +if(!empty(GOOGLE_API_KEY)){ + $addr = get_address($lat, $lon); + + // Get full address - Street #, ZIP District + $address = ""; + $address .= (!empty($addr['street']) ? $addr['street'] : ""); + $address .= (!empty($addr['street_number']) ? " " . $addr['street_number'] : ""); + $address .= ", "; + $address .= (!empty($addr['postal_code']) ? $addr['postal_code'] . " " : ""); + $address .= (!empty($addr['district']) ? $addr['district'] : ""); +} else { + //Based on input order of [6] and [7] it'll be either: Street, District or District, Street + $address = (!empty($data[6]) ? $data[6] : '') . (!empty($data[7]) ? ", " . $data[7] : ""); +} // Get countdown minutes when specified, otherwise 0 minutes until raid starts $countdown = 0; @@ -106,9 +109,10 @@ // Get row. $raid = $rs->fetch_assoc(); + //Debug // Set text. - $text = 'Raid aktualisiert! ID = ' . $raid_id . "" . CR; - $text .= CR . show_raid_poll($raid); + //$text = 'Raid aktualisiert! ID = ' . $raid_id . "" . CR; + //$text .= CR . show_raid_poll($raid); // Send the message //sendMessage($update['message']['chat']['id'], $text); From ae8e5f9e5e862ce8c4dd1439ca7563b4043c2c21 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Sun, 5 Nov 2017 23:21:07 +0100 Subject: [PATCH 042/225] Added description of the commands to the README, maybe formatting is not good but should be fixable ;) --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/README.md b/README.md index b762549..1b0e0bc 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,18 @@ Bot Settings: Enable Inline mode, Allow Groups, Group Privacy off Use https://www.miniwebtool.com/sha512-hash-generator/ and set `CONFIG_HASH` to hashed value of your token (make sure it is lowecase) +## Raid times + +There are several options to configure the times related to the raid polls: +Set `RAID_SLOTS` to the amount of minutes which shall be between the voting slots. +Set `RAID_LAST_START` to the minutes for the last start option before the a raid ends. + +## Proxy + +In case you are running the bot behind a proxy server, set `CURL_USEPROXY` to `true`. +Add the proxy server address and port at `CURL_PROXYSERVER`. +Authentication against the proxy server by username and password is currently not supported. + ## Database Create database named for your bot ID (first part of your Telegram bot token) @@ -41,8 +53,44 @@ Activate it for both Geocoding and Time Zone API https://developers.google.com/maps/documentation/timezone/get-api-key https://developers.google.com/maps/documentation/geocoding/start#get-a-key +# Usage + +## Bot commands +Command: No command - just send your location to the bot +The bot will guide you through the creation of the raid poll by asking you for the raid level, the pokemon raid boss and the time left for the raid. Afterwards you can set the gym name and gym team by using the /gym and /team commands. + +Command: /help +The bot will answer you "This is a private bot" so you can verify the bot is working and accepting input. + +Command: /raid +Create a new raid by gomap-notifier or other input. The raid command expects 8 parameters and an optional 9th parameter as input seperated by comma. +Additionally the raid command checks for existing raids, so sending the same command multiple times to the bot will result in an update of the pokemon raid boss and gym team and won't create duplicate raids. +Parameters: Pokemon raid boss, latitude, longitude, raid duration in minutes, gym team, gym name, district or street, district or street, raid pre-hatch egg countdown in minutes (optional) +Example input: `/raid Entei,52.514545,13.350095,60,Mystic,Siegessäule,Großer Stern,10557 Berlin,30` + +Command: /new +The bot expects latitude and longitude seperated by comma and will then guide you through the creation of the raid poll. +This command was implemented since the Telegram Desktop Client does not allow to share a location currently. +Example input: `/new 52.514545,13.350095` + +Command: /list +The bot will send you a list of the last 20 active raids. + +Command: /team +The bot will set the team to Mystic/Valor/Instinct for the last created raid based on your input. +Example input: `/team Mystic` + +Command: /gym +The bot will set the name of gym to your input. +Example input: `/gym Siegessäule` + +# Debugging +Check your bot logfile and other related log files, e.g. apache/httpd log, php log, and so on. + # TODO: +Cleanup logic to delete raid polls once a raid ended. + arrived - set and show time create raid - check permissions (in group) From 8bb7a70a4226c2b57a3c1156a3254ffb5269492b Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Nov 2017 00:40:20 +0100 Subject: [PATCH 043/225] Better formatting of README.md Done via github (prior edit was on console/command line) --- README.md | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1b0e0bc..a3dcc43 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,13 @@ Copy config.php.example to config.php and edit (values explained further) ## Log files Create log dir, e.g. /var/log/tg-bots/ and set it writeable by webserver + Edit config.php and set `CONFIG_LOGFILE` ## Bot token Start chat with https://t.me/BotFather and create bot token. + Bot Settings: Enable Inline mode, Allow Groups, Group Privacy off Use https://www.miniwebtool.com/sha512-hash-generator/ and set `CONFIG_HASH` to hashed value of your token (make sure it is lowecase) @@ -23,20 +25,27 @@ Use https://www.miniwebtool.com/sha512-hash-generator/ and set `CONFIG_HASH` to ## Raid times There are several options to configure the times related to the raid polls: + Set `RAID_SLOTS` to the amount of minutes which shall be between the voting slots. + Set `RAID_LAST_START` to the minutes for the last start option before the a raid ends. ## Proxy In case you are running the bot behind a proxy server, set `CURL_USEPROXY` to `true`. + Add the proxy server address and port at `CURL_PROXYSERVER`. + Authentication against the proxy server by username and password is currently not supported. ## Database Create database named for your bot ID (first part of your Telegram bot token) + Set database password to second part of your TG bot token + Only allow localhost access + Import `raid-pokemon-bot.sql` as default DB structure ## Webhooks @@ -48,40 +57,62 @@ Set Telegram webhook via https://your-hostname/bot-dir/webhooks.html Optionally you can you use Google maps API to lookup addresses of gyms based on latitude and longitude Therefore get a Google maps API key and set it as `GOOGLE_API_KEY` in your config. + Activate it for both Geocoding and Time Zone API https://developers.google.com/maps/documentation/timezone/get-api-key + https://developers.google.com/maps/documentation/geocoding/start#get-a-key # Usage ## Bot commands -Command: No command - just send your location to the bot +#### Command: No command - just send your location to the bot + The bot will guide you through the creation of the raid poll by asking you for the raid level, the pokemon raid boss and the time left for the raid. Afterwards you can set the gym name and gym team by using the /gym and /team commands. -Command: /help + +#### Command: /help + The bot will answer you "This is a private bot" so you can verify the bot is working and accepting input. -Command: /raid + +#### Command: /raid + Create a new raid by gomap-notifier or other input. The raid command expects 8 parameters and an optional 9th parameter as input seperated by comma. + Additionally the raid command checks for existing raids, so sending the same command multiple times to the bot will result in an update of the pokemon raid boss and gym team and won't create duplicate raids. + Parameters: Pokemon raid boss, latitude, longitude, raid duration in minutes, gym team, gym name, district or street, district or street, raid pre-hatch egg countdown in minutes (optional) + Example input: `/raid Entei,52.514545,13.350095,60,Mystic,Siegessäule,Großer Stern,10557 Berlin,30` -Command: /new + +#### Command: /new + The bot expects latitude and longitude seperated by comma and will then guide you through the creation of the raid poll. + This command was implemented since the Telegram Desktop Client does not allow to share a location currently. + Example input: `/new 52.514545,13.350095` -Command: /list + +#### Command: /list + The bot will send you a list of the last 20 active raids. -Command: /team + +#### Command: /team + The bot will set the team to Mystic/Valor/Instinct for the last created raid based on your input. + Example input: `/team Mystic` -Command: /gym + +#### Command: /gym + The bot will set the name of gym to your input. + Example input: `/gym Siegessäule` # Debugging @@ -89,7 +120,7 @@ Check your bot logfile and other related log files, e.g. apache/httpd log, php l # TODO: -Cleanup logic to delete raid polls once a raid ended. +* Cleanup logic to delete raid polls once a raid ended. arrived - set and show time @@ -99,4 +130,3 @@ Cleanup logic to delete raid polls once a raid ended. geofencing - auto publish to chat timezones create api / command - From e285cf3bf6ea1cdfd2812e9ec5b830b1917724a5 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 8 Nov 2017 12:15:46 +0100 Subject: [PATCH 044/225] Fixed undefined index issue in geo_api --- geo_api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geo_api.php b/geo_api.php index d820288..b8e7493 100644 --- a/geo_api.php +++ b/geo_api.php @@ -10,8 +10,8 @@ function get_address($lat, $lon) // Init defaults. $location = array(); $location['street'] = ''; - $location['street_number']; - $location['postal_code']; + $location['street_number'] = ''; + $location['postal_code'] = ''; $location['district'] = ''; // Set maps geocode url. From c37e3ddbcc22f0017dd56f1a9e5eeb7a815fb0aa Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 17 Nov 2017 14:11:17 +0100 Subject: [PATCH 045/225] Added ability to write gyms with address to new gyms table. Added config variable to send location message or just the raid poll message. Fixed undefined index by adding $nick in logic.php --- commands/raid.php | 16 +++++++++------ config.php.example | 1 + logic.php | 49 ++++++++++++++++++++++++++++++++++++++++++-- raid-pokemon-bot.sql | 11 ++++++++++ 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index e36b19f..a33e30a 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -121,6 +121,9 @@ // Address found. if (!empty($address)) { + // Insert gym with address, lat and lon to database if not already in database + $gym2db = insert_gym($name, $lat, $lon, $address); + // Build the query. $rs = my_query( " @@ -138,7 +141,6 @@ address = '{$db->real_escape_string($address)}' " ); - // No address found. } else { // Build the query. @@ -181,12 +183,14 @@ // Get row. $raid = $rs->fetch_assoc(); -// Send location. -$loc = send_location($update['message']['chat']['id'], $raid['lat'], $raid['lon']); +if (RAID_LOCATION == true) { + // Send location. + $loc = send_location($update['message']['chat']['id'], $raid['lat'], $raid['lon']); -// Write to log. -debug_log('location:'); -debug_log($loc); + // Write to log. + debug_log('location:'); + debug_log($loc); +} // Set text. $text = show_raid_poll($raid); diff --git a/config.php.example b/config.php.example index 63a4acf..d0d17a0 100644 --- a/config.php.example +++ b/config.php.example @@ -17,5 +17,6 @@ define('MAINTAINER', '@your_tg_username'); define('MAINTAINER_ID', 'your_tg_integer'); define('BOT_NAME', '@RaidPokemonBot'); +define('RAID_LOCATION', false); // send location as message in addition to raid poll message define('RAID_SLOTS', '15'); // minutes define('RAID_LAST_START', '10'); // minutes before RAID ends diff --git a/logic.php b/logic.php index 3df7bfb..9dc750b 100644 --- a/logic.php +++ b/logic.php @@ -112,6 +112,45 @@ function raid_duplication_check($gym,$end) return $duplicate_id; } +/** + * Insert gym. + * @param $gym_name + * @param $latitude + * @param $longitude + * @param $address + * @return array + */ +function insert_gym($name, $lat, $lon, $address) +{ + global $db; + + // Build query to check if gym is already in database or not + $rs = my_query( + " + SELECT COUNT(*) + FROM gyms + WHERE gym_name = '{$name}' + " + ); + + $row = $rs->fetch_row(); + + // Gym already in database or new + if (empty($row['0'])) { + // Build query for gyms table to add gym to database + debug_log('Gym not found in database gym list! Adding gym "' . $name . '" to the database gym list.'); + $rs = my_query( + " + INSERT INTO gyms + SET lat = '{$lat}', + lon = '{$lon}', + gym_name = '{$db->real_escape_string($name)}', + address = '{$db->real_escape_string($address)}' + " + ); + } +} + /** * Inline key array. * @param $buttons @@ -366,6 +405,7 @@ function update_user($update) global $db; $name = ''; + $nick = ''; $sep = ''; if (isset($update['message'])) { @@ -398,15 +438,19 @@ function update_user($update) $name .= $sep . $msg['last_name']; } + if (isset($msg['username'])) { + $nick = $msg['username']; + } + // Create or update the user. $request = my_query( " INSERT INTO users SET user_id = {$id}, - nick = '{$db->real_escape_string($msg['username'])}', + nick = '{$db->real_escape_string($nick)}', name = '{$db->real_escape_string($name)}' ON DUPLICATE KEY - UPDATE nick = '{$db->real_escape_string($msg['username'])}', + UPDATE nick = '{$db->real_escape_string($nick)}', name = '{$db->real_escape_string($name)}' " ); @@ -916,3 +960,4 @@ function raid_list($update) debug_log($rows); answerInlineQuery($update['inline_query']['id'], $rows); } + diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index 66a3b4b..957b443 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -31,6 +31,17 @@ CREATE TABLE `attendance` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; +/*Table structure for table `gyms` */ + +CREATE TABLE `gyms` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `lat` varchar(11) DEFAULT NULL, + `lon` varchar(11) DEFAULT NULL, + `address` varchar(255) DEFAULT NULL, + `gym_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; + /*Table structure for table `raids` */ CREATE TABLE `raids` ( From 6d3decac222893c723877e2fba128169bf0a1c56 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 27 Nov 2017 23:12:57 +0100 Subject: [PATCH 046/225] Added new functions to readme :D --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3dcc43..128ef89 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,18 @@ Bot Settings: Enable Inline mode, Allow Groups, Group Privacy off Use https://www.miniwebtool.com/sha512-hash-generator/ and set `CONFIG_HASH` to hashed value of your token (make sure it is lowecase) +## Bot access + +Set `BOT_ACCESS` to the name (@Bot_Access_Groupname) or id (-100123456789) of group, supergroup or channel. All administrators (not members!) will gain access to the bot. + +When no group, supergroup or channel is specified, the bot will allow everyone to use it (public access). + ## Raid times There are several options to configure the times related to the raid polls: +Set `RAID_LOCATION` to true to send back the location as message in addition to the raid poll. + Set `RAID_SLOTS` to the amount of minutes which shall be between the voting slots. Set `RAID_LAST_START` to the minutes for the last start option before the a raid ends. @@ -69,7 +77,12 @@ https://developers.google.com/maps/documentation/geocoding/start#get-a-key ## Bot commands #### Command: No command - just send your location to the bot -The bot will guide you through the creation of the raid poll by asking you for the raid level, the pokemon raid boss and the time left for the raid. Afterwards you can set the gym name and gym team by using the /gym and /team commands. +The bot will guide you through the creation of the raid poll by asking you for the raid level, the pokemon raid boss, the time until the raids starts and the time left for the raid. Afterwards you can set the gym name and gym team by using the /gym and /team commands. + + +#### Command: /start + +The bot will guide you through the creation of the raid poll by asking you for the gym, raid level, the pokemon raid boss, the time until the raid starts and the time left for the raid. Afterwards you can set the gym team by using the /team command. #### Command: /help From 99b19fa37dd8ef85c66f489f9ac8edaf0d8e7375 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 27 Nov 2017 23:13:42 +0100 Subject: [PATCH 047/225] A fresh start ;) --- commands/start.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/commands/start.php b/commands/start.php index 5d7521a..4cc0434 100644 --- a/commands/start.php +++ b/commands/start.php @@ -1,3 +1,25 @@ Bitte sende mir zuerst einen Standort. '); +// Write to log. +debug_log('START'); + +// Get the userid and chattype +$userid = $update['message']['from']['id']; +$chattype = $update['message']['chat']['type']; + +// Create keys array. +$keys = [ + [ + [ + 'text' => 'Raid anlegen', + 'callback_data' => $userid . ',' . $chattype . ':raid_by_gym:0', + ] + ] + ]; + +// Set message. +$msg = 'Bitte sende mir zuerst einen Standort.' . CR2 . CR . 'Oder lege ein Raid per Arena-Auswahl an:'; + +// Send message. +send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + +exit; From 7f71ddf1df56af88bb7c1ea0ffadb0fb6ed1b370 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 27 Nov 2017 23:15:40 +0100 Subject: [PATCH 048/225] Added function to get administrators from a specific chat_id --- functions.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/functions.php b/functions.php index 4e71a64..17c2b32 100644 --- a/functions.php +++ b/functions.php @@ -358,6 +358,32 @@ function edit_message($update, $message, $keys, $merge_args = false) } } +/** + * GetChatAdministrators + * @param $chatid + */ +function get_admins($chat_id) +{ + // Create response content array. + $reply_content = [ + 'method' => 'getChatAdministrators', + 'chat_id' => $chat_id, + 'parse_mode' => 'HTML', + ]; + + // Encode data to json. + $reply_json = json_encode($reply_content); + + // Set header to json. + header('Content-Type: application/json'); + + // Write to log. + debug_log($reply_json, '>'); + + // Send request to telegram api. + return curl_json_request($reply_json); +} + /** * Send request to telegram api. * @param $json From de816bddd05fc3ba40a27a28dda79e2bc9127488 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 27 Nov 2017 23:21:43 +0100 Subject: [PATCH 049/225] Added bot access check, gym list keys and gym id functions, weekday function for Ex-Raid raid polls which are usually created a few days before the Ex-Raid --- logic.php | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/logic.php b/logic.php index 9dc750b..11b3499 100644 --- a/logic.php +++ b/logic.php @@ -1,4 +1,44 @@ You are not allowed to use this bot!'; + sendMessage($update['message']['chat']['id'], $response_msg); + exit; + } + } else { + debug_log("Bot access is not restricted! Allowing access for user: " . $update['message']['from']['username'] . " (Id: " . $update['message']['from']['id'] . ")"); + } +} + /** * Raid access check. * @param $update @@ -151,6 +191,26 @@ function insert_gym($name, $lat, $lon, $address) } } +/** + * Get gym. + * @param $id + */ +function get_gym($id) +{ + // Get gyms from database + $rs = my_query( + " + SELECT * + FROM gyms + WHERE id = {$id} + " + ); + + $gym = $rs->fetch_assoc(); + + return $gym; +} + /** * Inline key array. * @param $buttons @@ -214,6 +274,41 @@ function raid_edit_start_keys($id) return $keys; } +/** + * Raid edit start keys. + * @param $id + * @return array + */ +function raid_edit_gym_keys($chatid, $chattype) +{ + // Get gyms from database + $rs = my_query( + " + SELECT * + FROM gyms + ORDER BY gym_name + " + ); + + // Init empty keys array. + $keys = array(); + + while ($gym = $rs->fetch_assoc()) { + $keys[] = array( + 'text' => $gym['gym_name'], + 'callback_data' => $chatid . ',' . $chattype . ':raid_create:' . $gym['lat'] . ',' . $gym['lon'] . ',' . $gym['id'] + ); + } + + // Get the inline key array. + $keys = inline_key_array($keys, 1); + + // Write to log. + debug_log($keys); + + return $keys; +} + /** * Keys raid people. * @param $data @@ -537,6 +632,42 @@ function unix2tz($unix, $tz, $format = 'H:i') } } +/** + * Weekday number to weekday name + * @param weekdaynumber + */ +function weekday_number2name ($weekdaynumber) +{ + // Numeric value below 7 is required + if(is_numeric($weekdaynumber) && $weekdaynumber <= 7) { + switch($weekdaynumber) { + case 1: + $weekday = "Montag"; + break; + case 2: + $weekday = "Dienstag"; + break; + case 3: + $weekday = "Mittwoch"; + break; + case 4: + $weekday = "Donnerstag"; + break; + case 5: + $weekday = "Freitag"; + break; + case 6: + $weekday = "Samstag"; + break; + case 7: + $weekday = "Sonntag"; + break; + } + } + // Return the weekday + return $weekday; +} + /** * Show raid poll. * @param $raid @@ -591,7 +722,14 @@ function show_raid_poll($raid) // Raid has not started yet - adjust time left message if ($raid['ts_now'] < $raid['ts_start']) { - $msg .= 'Raid-Ei öffnet sich um ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; + $weekday_now = date('N', $raid['ts_now']); + $weekday_start = date('N', $raid['ts_start']); + $raid_day = weekday_number2name ($weekday_start); + if ($weekday_now == $weekday_start) { + $msg .= 'Raid-Ei öffnet sich um ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; + } else { + $msg .= 'Raid-Ei öffnet sich am ' . $raid_day .' um ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; + } // Raid has started and active or already ended } else { From ad0517c31a2e212c4a0fe34be23271ffd9dfe771 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 27 Nov 2017 23:23:21 +0100 Subject: [PATCH 050/225] Added bot_access to restrict access to the bot - further adjustments maybe needed to work with gomap-notifier --- config.php.example | 1 + index.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/config.php.example b/config.php.example index d0d17a0..7b19dd8 100644 --- a/config.php.example +++ b/config.php.example @@ -16,6 +16,7 @@ define('DB_PASSWORD', 'your_database_password'); define('MAINTAINER', '@your_tg_username'); define('MAINTAINER_ID', 'your_tg_integer'); define('BOT_NAME', '@RaidPokemonBot'); +define('BOT_ACCESS', ''); define('RAID_LOCATION', false); // send location as message in addition to raid poll message define('RAID_SLOTS', '15'); // minutes diff --git a/index.php b/index.php index 29a21e5..c4f8f4c 100644 --- a/index.php +++ b/index.php @@ -108,18 +108,24 @@ // Inline query received. } else if (isset($update['inline_query'])) { + // Check access to the bot + bot_access_check($update); // List polls and exit. raid_list($update); exit(); // Location received. } else if (isset($update['message']['location'])) { + // Check access to the bot + bot_access_check($update); // Create raid and exit. include_once('modules/raid_create.php'); exit(); // Message is required to check for commands. } else if (isset($update['message'])) { + // Check access to the bot + bot_access_check($update); // Check message text for a leading slash. if (substr($update['message']['text'], 0, 1) == '/') { // Get command name. From a3e49c051d66637e285c29d52253ba98a91d2e2b Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 27 Nov 2017 23:27:06 +0100 Subject: [PATCH 051/225] Added a way to create raids by selecting the gyms from the database - maybe limited to 100 gyms[C due to amount of inline keys by telegram --- modules/raid_by_gym.php | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 modules/raid_by_gym.php diff --git a/modules/raid_by_gym.php b/modules/raid_by_gym.php new file mode 100644 index 0000000..a446b92 --- /dev/null +++ b/modules/raid_by_gym.php @@ -0,0 +1,57 @@ + 'Not supported', + 'callback_data' => 'edit:not_supported' + ] + ] + ]; +} + +// Edit the message. +edit_message($update, 'Bitte Arena auswählen:', $keys); + +// Build callback message string. +$callback_response = 'Los gehts!'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); + +exit(); From 278e38be693b4acba3d9fbed257c66495135e4a3 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 27 Nov 2017 23:28:07 +0100 Subject: [PATCH 052/225] Added a way to define pre-hatch egg time via inline keys --- modules/edit_start.php | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 modules/edit_start.php diff --git a/modules/edit_start.php b/modules/edit_start.php new file mode 100644 index 0000000..afb22d7 --- /dev/null +++ b/modules/edit_start.php @@ -0,0 +1,55 @@ += 15; $i = $i - 5) { + // Create the keys. + $keys[] = array( + // Just show the time, no text - not everyone has a phone or tablet with a large screen... + //'text' => 'noch ' . floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), + 'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), + 'callback_data' => $id . ':edit_left:' . $i + ); + } + + // Get the inline key array. + $keys = inline_key_array($keys, 4); + + // Write to log. + debug_log($keys); + +} else { + // Edit pokemon. + $keys = raid_edit_start_keys($id); +} + +// Edit the message. +edit_message($update, 'Wie lange läuft der Raid?', $keys); + +// Build callback message string. +$callback_response = 'Vorlaufzeit gesetzt auf ' . $data['arg'] . ' Minuten'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); From 45b9f6165a494781ecd5645e0eb22210d3582057 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 27 Nov 2017 23:29:04 +0100 Subject: [PATCH 053/225] Adjustments due to the new option to create a raid by selecting a gym via inline keys --- modules/edit_left.php | 37 ++++++++++++-- modules/edit_poke.php | 6 +-- modules/raid_create.php | 105 ++++++++++++++++++++++++++++++---------- 3 files changed, 117 insertions(+), 31 deletions(-) diff --git a/modules/edit_left.php b/modules/edit_left.php index f87b169..29bf082 100644 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -30,10 +30,41 @@ ] ]; + // Get raid times. + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$data['id']} + " + ); + + // Fetch the row. + $raid = $rs->fetch_assoc(); + // Build message string. - $msg = 'Raid gespeichert.' . CR; - $msg .= 'Optional - Arena Name und Arena Team:' . CR2; - $msg .= '/gym Name der Arena' . CR; + $msg = ''; + $msg .= 'Raid gespeichert:' . CR; + // Pokemon + if(!empty($raid['pokemon'])) { + $msg .= '' . ucfirst($raid['pokemon']) . ''; + } + // End time + if(!empty($raid['ts_end'])) { + $msg .= ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . '' . CR; + } + // Gym Name + if(!empty($raid['gym_name'])) { + $msg .= $raid['gym_name'] . CR2 . CR; + $msg .= 'Optional - Arena Team setzen:' . CR2; + } else { + $msg .= 'Optional - Arena Name und Arena Team:' . CR2; + $msg .= '/gym Name der Arena' . CR; + } $msg .= '/team Mystic/Valor/Instinct/Blau/Rot/Gelb'; // Edit message. diff --git a/modules/edit_poke.php b/modules/edit_poke.php index 93b663a..3af05e4 100644 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -23,13 +23,13 @@ // Init empty keys array. $keys = array(); - for ($i = 120; $i >= 20; $i = $i - 5) { + for ($i = 60; $i >= 0; $i = $i - 5) { // Create the keys. $keys[] = array( // Just show the time, no text - not everyone has a phone or tablet with a large screen... //'text' => 'noch ' . floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), 'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), - 'callback_data' => $id . ':edit_left:' . $i + 'callback_data' => $id . ':edit_start:' . $i ); } @@ -58,7 +58,7 @@ } // Edit the message. -edit_message($update, 'Wie lange läuft der Raid noch?', $keys); +edit_message($update, 'Wann beginnt der Raid?' . CR . 'Raid läuft schon? --- Einfach 0:00 auswählen!', $keys); // Build callback message string. $callback_response = 'Pokemon gespeichert: ' . $data['arg']; diff --git a/modules/raid_create.php b/modules/raid_create.php index 5f32175..bb44fbf 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -20,6 +20,11 @@ $chattype = $update['message']['chat']['type']; } +// Init count_data, gym and gym_id +$count_data = 0; +$gym = 0; +$gym_id = 0; + // Get latitude / longitude from message text if empty // Necessary for Telegram Desktop Client as you cannot send a location :( if (empty($lat) && empty($lon)) { @@ -42,31 +47,53 @@ // Get lat and lon from message text $coords = $data['arg']; - // Create data array (max. 2) - $data = explode(',', $coords, 2); + // Create data array (max. 3) + $count_data = substr_count($coords, ","); + $data = explode(',', $coords, 3); // Set latitude / longitude $lat = $data[0]; $lon = $data[1]; + $gym_id = $data[2]; // Debug debug_log('Lat=' . $lat); debug_log('Lon=' . $lon); -} -// Get the address. -$addr = get_address($lat, $lon); + // Get gym data from database + if($count_data == 2) { + $gym_id = $data[2]; + $gym = get_gym($gym_id); + } +} -// Get full address - Street #, ZIP District +// Init address and gym name $fullAddress = ""; -$fullAddress .= (!empty($addr['street']) ? $addr['street'] : ""); -$fullAddress .= (!empty($addr['street_number']) ? " " . $addr['street_number'] : ""); -$fullAddress .= ", "; -$fullAddress .= (!empty($addr['postal_code']) ? $addr['postal_code'] . " " : ""); -$fullAddress .= (!empty($addr['district']) ? $addr['district'] : ""); +$gym_name = ""; + +// Address and gym name based on input +if($gym_id > 0) { + // Get address from database + $fullAddress = $gym['address']; + $gym_name = $gym['gym_name']; + debug_log('Gym ID: ' . $gym_id); + debug_log('Gym Name: ' . $gym_name); + debug_log('Gym Address: ' . $fullAddress); +} else { + // Get the address. + $addr = get_address($lat, $lon); + + // Get full address - Street #, ZIP District + $fullAddress = ""; + $fullAddress .= (!empty($addr['street']) ? $addr['street'] : ""); + $fullAddress .= (!empty($addr['street_number']) ? " " . $addr['street_number'] : ""); + $fullAddress .= (!empty($fullAddress) ? ", " : ""); + $fullAddress .= (!empty($addr['postal_code']) ? $addr['postal_code'] . " " : ""); + $fullAddress .= (!empty($addr['district']) ? $addr['district'] : ""); +} // Address found. -if (!empty($addr)) { +if (!empty($fullAddress)) { // Create raid with address. $rs = my_query( " @@ -76,6 +103,7 @@ lon = '{$lon}', first_seen = NOW(), start_time = NOW(), + gym_name = '{$db->real_escape_string($gym_name)}', timezone = '{$tz}', address = '{$db->real_escape_string($fullAddress)}' " @@ -92,6 +120,7 @@ lon = '{$lon}', first_seen = NOW(), start_time = NOW(), + gym_name = '{$db->real_escape_string($gym_name)}', timezone = '{$tz}' " ); @@ -106,25 +135,51 @@ // Get the keys. $keys = raid_edit_start_keys($id); +// No keys found. +if (!$keys) { + // Create the keys. + $keys = [ + [ + [ + 'text' => 'Not supported', + 'callback_data' => 'edit:not_supported' + ] + ] + ]; +} + // Build message. $msg = 'Erstelle Raid in: ' . $fullAddress . ''; -// Private chat type. -if ($chattype == 'private') { - // Send the message. - //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys); - send_message($chatid, $msg . CR . 'Bitte Raid level auswählen:', $keys); +// Answer callback or send message based on input prior raid creation +if($gym_id != 0) { + // Edit the message. + edit_message($update, $msg . CR . 'Bitte Raid Level auswählen:', $keys); + + // Build callback message string. + $callback_response = 'Arena gespeichert.'; + // Answer callback. + answerCallbackQuery($update['callback_query']['id'], $callback_response); } else { - //$reply_to = $update['message']['chat']['id']; - $reply_to = $chatid; - if ($update['message']['reply_to_message']['message_id']) { - $reply_to = $update['message']['reply_to_message']['message_id']; + // Private chat type. + if ($chattype == 'private') { + // Send the message. + //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys); + send_message($chatid, $msg . CR . 'Bitte Raid Level auswählen:', $keys); + + } else { + //$reply_to = $update['message']['chat']['id']; + $reply_to = $chatid; + if ($update['message']['reply_to_message']['message_id']) { + $reply_to = $update['message']['reply_to_message']['message_id']; + } + + // Send the message. + //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + send_message($chatid, $msg . CR . 'Bitte Raid Level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); } - // Send the message. - //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); - send_message($chatid, $msg . CR . 'Bitte Raid level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + exit(); } -exit(); From a244560e8bc520b216c6ee9deb0fcbd97e001b67 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 29 Nov 2017 13:58:10 +0100 Subject: [PATCH 054/225] Added egg as emoji --- constants.php | 1 + 1 file changed, 1 insertion(+) diff --git a/constants.php b/constants.php index 7bc3032..2aa9481 100644 --- a/constants.php +++ b/constants.php @@ -10,6 +10,7 @@ define('TEAM_CANCEL', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f494))); define('TEAM_DONE', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f4aa))); define('TEAM_UNKNOWN', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f680))); +define('EMOJI_EGG', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f95a))); define('EMOJI_REFRESH', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F504))); // Teams. From 35ee84f6791151c126d216653e05f8a1e0905d48 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 29 Nov 2017 13:58:38 +0100 Subject: [PATCH 055/225] Added Raid-Egg as inline key option --- modules/edit.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/edit.php b/modules/edit.php index cb4e578..40098f8 100644 --- a/modules/edit.php +++ b/modules/edit.php @@ -185,6 +185,14 @@ ] ] ]; +} else { + $level = substr($data['arg'], -1); + $keys[] = [ + array( + 'text' => EMOJI_EGG . ' Raid-Ei', + 'callback_data' => $id . ':edit_poke:Level ' . $level . ' Ei' + ) + ]; } if (isset($update['callback_query']['inline_message_id'])) { From 196d9bf825ab1233093d435303d33ab4d9b39825 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 29 Nov 2017 14:01:42 +0100 Subject: [PATCH 056/225] Show counters for each team as well as extra people and trainers without team, Added arrived ASC in SQL query so all people who arrived are grouped and people who are not here yet are grouped --- logic.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/logic.php b/logic.php index 11b3499..5cd9062 100644 --- a/logic.php +++ b/logic.php @@ -798,6 +798,10 @@ function show_raid_poll($raid) " SELECT DISTINCT UNIX_TIMESTAMP(attend_time) AS ts_att, count(attend_time) AS count, + sum(team = 'mystic') AS count_mystic, + sum(team = 'valor') AS count_valor, + sum(team = 'instinct') AS count_instinct, + sum(team = 'NULL') AS count_no_team, sum(extra_people) AS extra FROM attendance WHERE raid_id = {$raid['id']} @@ -822,7 +826,15 @@ function show_raid_poll($raid) // TIMES foreach ($timeSlots as $ts) { // Add to message. - $msg .= CR . '' . unix2tz($ts['ts_att'], $raid['timezone']) . '' . ' [' . ($ts['count'] + $ts['extra']) . ']' . CR; + $msg .= CR . '' . unix2tz($ts['ts_att'], $raid['timezone']) . '' . ' [' . ($ts['count'] + $ts['extra']) . ']'; + if ($ts['count'] > 0) { + $msg .= ' — '; + $msg .= (($ts['count_mystic'] > 0) ? TEAM_B . $ts['count_mystic'] . ' ' : ''); + $msg .= (($ts['count_valor'] > 0) ? TEAM_R . $ts['count_valor'] . ' ' : ''); + $msg .= (($ts['count_instinct'] > 0) ? TEAM_Y . $ts['count_instinct'] . ' ' : ''); + $msg .= ((($ts['count_no_team'] + $ts['extra']) > 0) ? TEAM_UNKNOWN . ($ts['count_no_team'] + $ts['extra']) : ''); + $msg .= CR; + } $user_rs = my_query( " @@ -832,7 +844,7 @@ function show_raid_poll($raid) AND raid_done != 1 AND cancel != 1 AND raid_id = {$raid['id']} - ORDER BY team ASC + ORDER BY team ASC, arrived ASC " ); From 466e007f972f4266ecdbadd5c3d611fb208cb3f2 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 29 Nov 2017 14:03:35 +0100 Subject: [PATCH 057/225] Fix error in SQL query - when fix is working, needs to be fixed in other files too where NULL is used --- modules/vote_time.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/vote_time.php b/modules/vote_time.php index b1a35a2..1478264 100644 --- a/modules/vote_time.php +++ b/modules/vote_time.php @@ -46,7 +46,7 @@ $row = $rs->fetch_assoc(); // Check if we found the users team. - $team = !empty($row['team']) ? "'" . $row['team'] . "'" : NULL; + $team = !empty($row['team']) ? "'" . $row['team'] . "'" : "NULL"; // Create attendance. my_query( From 41e1db1080a281f15eeeb5d0d5d1c9239acacb8d Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 29 Nov 2017 14:59:31 +0100 Subject: [PATCH 058/225] Cleanup table --- raid-pokemon-bot.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index 957b443..8a90e1d 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -31,6 +31,16 @@ CREATE TABLE `attendance` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; +/*Table structure for table `cleanup` */ + +CREATE TABLE `cleanup` ( + `raid_id` int(10) unsigned NOT NULL, + `end_time` datetime DEFAULT NULL, + `chat_id` int(10) unsigned NOT NULL, + `message_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`raid_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + /*Table structure for table `gyms` */ CREATE TABLE `gyms` ( From a0be532680853ca5dbd1f032b6082ba0a1206745 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 29 Nov 2017 16:36:58 +0100 Subject: [PATCH 059/225] Add command to change raid boss when poll was created during pre-hatch phase and gomap is not working, so you can updated itself --- commands/pokemon.php | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 commands/pokemon.php diff --git a/commands/pokemon.php b/commands/pokemon.php new file mode 100644 index 0000000..e099e33 --- /dev/null +++ b/commands/pokemon.php @@ -0,0 +1,60 @@ +fetch_assoc(); + +// No data found. +if (!$row) { + sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + exit; +} + +// Build query. +$request = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE end_time>NOW() + AND timezone='{$row['timezone']}' + ORDER BY end_time ASC LIMIT 20 + " +); + +while ($raid = $request->fetch_assoc()) { + // Create keys array. + $keys = [ + [ + [ + 'text' => 'Pokemon aktualisieren', + 'callback_data' => $raid['id'] . ':raid_edit_poke:0', + ] + ] + ]; + + // Get message. + $msg = show_raid_poll_small($raid); + + // Send message. + send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); +} + +exit; From 5025a50a5142ef43bd02d14ad3062c1000637e9a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 29 Nov 2017 16:39:14 +0100 Subject: [PATCH 060/225] Update raid boss, currently level 5 only --- modules/raid_edit_poke.php | 77 ++++++++++++++++++++++++++++++++++++++ modules/raid_set_poke.php | 74 ++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 modules/raid_edit_poke.php create mode 100644 modules/raid_set_poke.php diff --git a/modules/raid_edit_poke.php b/modules/raid_edit_poke.php new file mode 100644 index 0000000..bb0ce9c --- /dev/null +++ b/modules/raid_edit_poke.php @@ -0,0 +1,77 @@ + 'Arktos', + 'callback_data' => $id . ':raid_set_poke:arktos' + ], + [ + 'text' => 'Lugia', + 'callback_data' => $id . ':raid_set_poke:lugia' + ], + [ + 'text' => 'Lavados', + 'callback_data' => $id . ':raid_set_poke:lavados' + ], + [ + 'text' => 'Zapdos', + 'callback_data' => $id . ':raid_set_poke:zapdos' + ] + ], + [ + [ + 'text' => 'Mewtu', + 'callback_data' => $id . ':raid_set_poke:mewtu' + ], + [ + 'text' => 'Mew', + 'callback_data' => $id . ':raid_set_poke:mew' + ], + [ + 'text' => 'Ho-Oh', + 'callback_data' => $id . ':raid_set_poke:hooh' + ], + [ + 'text' => 'Celebi', + 'callback_data' => $id . ':raid_set_poke:celebi' + ] + ], + [ + [ + 'text' => 'Raikou', + 'callback_data' => $id . ':raid_set_poke:raikou' + ], + [ + 'text' => 'Entei', + 'callback_data' => $id . ':raid_set_poke:entei' + ], + [ + 'text' => 'Suicune', + 'callback_data' => $id . ':raid_set_poke:suicune' + ] + ] + ]; + +if (isset($update['callback_query']['inline_message_id'])) { + editMessageText($update['callback_query']['inline_message_id'], 'Raid Boss auswählen:', $keys); +} else { + editMessageText($update['callback_query']['message']['message_id'], 'Raid Boss auswählen:', $keys, $update['callback_query']['message']['chat']['id'], $keys); +} + +// Build callback message string. +$callback_response = 'Ok'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/raid_set_poke.php b/modules/raid_set_poke.php new file mode 100644 index 0000000..2ab9716 --- /dev/null +++ b/modules/raid_set_poke.php @@ -0,0 +1,74 @@ +fetch_assoc(); + + // Create the keys. + $keys = [ + [ + [ + 'text' => 'Fertig!', + 'callback_data' => $raid['id'] . ':vote_refresh:0' + ] + ] + ]; + + // Build message string. + $msg = ''; + $msg .= 'Raid Boss gespeichert:' . CR; + // Pokemon + if(!empty($raid['pokemon'])) { + $msg .= '' . ucfirst($raid['pokemon']) . ''; + } + // End time + if(!empty($raid['ts_end'])) { + $msg .= ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . '' . CR; + } + // Gym Name + if(!empty($raid['gym_name'])) { + $msg .= $raid['gym_name'] . CR; + } + + // Edit message. + edit_message($update, $msg, $keys, false); + + // Build callback message string. + $callback_response = 'OK'; + + // Answer callback. + answerCallbackQuery($update['callback_query']['id'], $callback_response); + +} From 707f8520a817259c69a507606e2f98b2980d11a8 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 30 Nov 2017 11:14:19 +0100 Subject: [PATCH 061/225] Optimization to BOT_ACCESS which now allows comma separated input of groups and a little redesign of the small raid poll --- config.php.example | 2 +- constants.php | 3 +- logic.php | 77 ++++++++++++++++++++++++++++++---------------- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/config.php.example b/config.php.example index 7b19dd8..7392658 100644 --- a/config.php.example +++ b/config.php.example @@ -16,7 +16,7 @@ define('DB_PASSWORD', 'your_database_password'); define('MAINTAINER', '@your_tg_username'); define('MAINTAINER_ID', 'your_tg_integer'); define('BOT_NAME', '@RaidPokemonBot'); -define('BOT_ACCESS', ''); +define('BOT_ACCESS', ''); // optional define('RAID_LOCATION', false); // send location as message in addition to raid poll message define('RAID_SLOTS', '15'); // minutes diff --git a/constants.php b/constants.php index 2aa9481..5745782 100644 --- a/constants.php +++ b/constants.php @@ -11,7 +11,8 @@ define('TEAM_DONE', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f4aa))); define('TEAM_UNKNOWN', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f680))); define('EMOJI_EGG', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f95a))); -define('EMOJI_REFRESH', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F504))); +define('EMOJI_REFRESH', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f504))); +define('EMOJI_GROUP', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f465))); // Teams. $teams = array( diff --git a/logic.php b/logic.php index 5cd9062..21df6e8 100644 --- a/logic.php +++ b/logic.php @@ -9,21 +9,27 @@ function bot_access_check($update) // Restricted or public access if(!empty(BOT_ACCESS)) { $chat_id = BOT_ACCESS; + + // Check each admin chat defined in BOT_ACCESS + $chats = explode(',', $chat_id); + foreach($chats as $chat) { - // Get administrators from chat - $response = get_admins($chat_id); - - // Make sure we get a proper response - if ($response['ok'] == true) { - $allow_access = false; - foreach($response['result'] as $admin) { - // If user is found as administrator allow access to the bot - if ($admin['user']['id'] == $update['message']['from']['id'] || $admin['user']['id'] == $update['inline_query']['from']['id']) { - $allow_access = true; - break; - } - } - } + // Get administrators from chat + $response = get_admins($chat); + debug_log("Getting administrators from chat '" . $chat . "'"); + + // Make sure we get a proper response + if ($response['ok'] == true) { + $allow_access = false; + foreach($response['result'] as $admin) { + // If user is found as administrator allow access to the bot + if ($admin['user']['id'] == $update['message']['from']['id'] || $admin['user']['id'] == $update['inline_query']['from']['id']) { + $allow_access = true; + break; + } + } + } + } // Allow or deny access to the bot and log result if ($allow_access) { @@ -1010,16 +1016,23 @@ function show_raid_poll_small($raid) $time_left = floor($raid['t_left'] / 60); $time_left = 'noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT); - $msg = '' . ucfirst($raid['pokemon']) . ' ' . $time_left . ' ' . $raid['gym_name'] . '' . CR; + // Build message string. + $msg = ''; + // Pokemon + if(!empty($raid['pokemon'])) { + $msg .= '' . ucfirst($raid['pokemon']) . ''; + } + // End time + if(!empty($raid['ts_end'])) { + $msg .= ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . ' — ' . $time_left . CR; + } + // Gym Name + if(!empty($raid['gym_name'])) { + $msg .= $raid['gym_name'] . CR; + } // Address found. - if ($raid['address']) { - /* - $addr = explode(',', $raid['address'], 4); - array_pop($addr); - $addr = implode(',', $addr); - // Add to message. - */ + if (!empty($raid['address'])) { $msg .= '' . $raid['address'] . '' . CR2; } @@ -1038,23 +1051,33 @@ function show_raid_poll_small($raid) ); $total = 0; + $total_extra = 0; $sep = ''; + $msg_teams = ''; while ($row = $rs->fetch_assoc()) { - $sum = $row['cnt'] + $row['extra']; + $sum = $row['cnt']; if ($sum == 0) continue; // Add to message. - $msg .= $sep . $GLOBALS['teams'][$row['team']] . ' ' . $sum; - $sep = ' | '; + $msg_teams .= $sep . $GLOBALS['teams'][$row['team']] . ' ' . $sum; + $sep = ' '; $total += $sum; + + if ($row['extra'] > 0) { + $total_extra += $row['extra']; + $total += $row['extra']; + } + } + if ($total_extra > 0) { + $msg_teams .= $sep . TEAM_UNKNOWN . ' ' . $total_extra; } if (!$total) { - $msg .= ' Keine Teilnehmer' . CR; + $msg .= 'Keine Teilnehmer' . CR; } else { - $msg .= ' = ' . $total . '' . CR; + $msg .= EMOJI_GROUP . ' ' . $total . ' — ' . $msg_teams; } return $msg; From afd7e0f2bb6e527578dd4f1eb946fe73b959bc13 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 30 Nov 2017 11:14:19 +0100 Subject: [PATCH 062/225] Optimization to BOT_ACCESS which now allows comma separated input of groups and a little redesign of the small raid poll --- README.md | 4 ++- config.php.example | 2 +- constants.php | 3 +- logic.php | 77 ++++++++++++++++++++++++++++++---------------- 4 files changed, 56 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 128ef89..3f2b9c4 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,12 @@ Use https://www.miniwebtool.com/sha512-hash-generator/ and set `CONFIG_HASH` to ## Bot access -Set `BOT_ACCESS` to the name (@Bot_Access_Groupname) or id (-100123456789) of group, supergroup or channel. All administrators (not members!) will gain access to the bot. +Set `BOT_ACCESS` to the name (@Bot_Access_Groupname) or id (-100123456789) of one or multiple by comma separated groups, supergroups or channels. All administrators (not members!) will gain access to the bot. When no group, supergroup or channel is specified, the bot will allow everyone to use it (public access). +Example for multiple access groups: `define('BOT_ACCESS', '@Bot_Access_Groupname,@Another_Bot_Access_Group,@Superadmins_Bot_Groups');` + ## Raid times There are several options to configure the times related to the raid polls: diff --git a/config.php.example b/config.php.example index 7b19dd8..7392658 100644 --- a/config.php.example +++ b/config.php.example @@ -16,7 +16,7 @@ define('DB_PASSWORD', 'your_database_password'); define('MAINTAINER', '@your_tg_username'); define('MAINTAINER_ID', 'your_tg_integer'); define('BOT_NAME', '@RaidPokemonBot'); -define('BOT_ACCESS', ''); +define('BOT_ACCESS', ''); // optional define('RAID_LOCATION', false); // send location as message in addition to raid poll message define('RAID_SLOTS', '15'); // minutes diff --git a/constants.php b/constants.php index 2aa9481..5745782 100644 --- a/constants.php +++ b/constants.php @@ -11,7 +11,8 @@ define('TEAM_DONE', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f4aa))); define('TEAM_UNKNOWN', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f680))); define('EMOJI_EGG', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f95a))); -define('EMOJI_REFRESH', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1F504))); +define('EMOJI_REFRESH', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f504))); +define('EMOJI_GROUP', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f465))); // Teams. $teams = array( diff --git a/logic.php b/logic.php index 5cd9062..21df6e8 100644 --- a/logic.php +++ b/logic.php @@ -9,21 +9,27 @@ function bot_access_check($update) // Restricted or public access if(!empty(BOT_ACCESS)) { $chat_id = BOT_ACCESS; + + // Check each admin chat defined in BOT_ACCESS + $chats = explode(',', $chat_id); + foreach($chats as $chat) { - // Get administrators from chat - $response = get_admins($chat_id); - - // Make sure we get a proper response - if ($response['ok'] == true) { - $allow_access = false; - foreach($response['result'] as $admin) { - // If user is found as administrator allow access to the bot - if ($admin['user']['id'] == $update['message']['from']['id'] || $admin['user']['id'] == $update['inline_query']['from']['id']) { - $allow_access = true; - break; - } - } - } + // Get administrators from chat + $response = get_admins($chat); + debug_log("Getting administrators from chat '" . $chat . "'"); + + // Make sure we get a proper response + if ($response['ok'] == true) { + $allow_access = false; + foreach($response['result'] as $admin) { + // If user is found as administrator allow access to the bot + if ($admin['user']['id'] == $update['message']['from']['id'] || $admin['user']['id'] == $update['inline_query']['from']['id']) { + $allow_access = true; + break; + } + } + } + } // Allow or deny access to the bot and log result if ($allow_access) { @@ -1010,16 +1016,23 @@ function show_raid_poll_small($raid) $time_left = floor($raid['t_left'] / 60); $time_left = 'noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT); - $msg = '' . ucfirst($raid['pokemon']) . ' ' . $time_left . ' ' . $raid['gym_name'] . '' . CR; + // Build message string. + $msg = ''; + // Pokemon + if(!empty($raid['pokemon'])) { + $msg .= '' . ucfirst($raid['pokemon']) . ''; + } + // End time + if(!empty($raid['ts_end'])) { + $msg .= ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . ' — ' . $time_left . CR; + } + // Gym Name + if(!empty($raid['gym_name'])) { + $msg .= $raid['gym_name'] . CR; + } // Address found. - if ($raid['address']) { - /* - $addr = explode(',', $raid['address'], 4); - array_pop($addr); - $addr = implode(',', $addr); - // Add to message. - */ + if (!empty($raid['address'])) { $msg .= '' . $raid['address'] . '' . CR2; } @@ -1038,23 +1051,33 @@ function show_raid_poll_small($raid) ); $total = 0; + $total_extra = 0; $sep = ''; + $msg_teams = ''; while ($row = $rs->fetch_assoc()) { - $sum = $row['cnt'] + $row['extra']; + $sum = $row['cnt']; if ($sum == 0) continue; // Add to message. - $msg .= $sep . $GLOBALS['teams'][$row['team']] . ' ' . $sum; - $sep = ' | '; + $msg_teams .= $sep . $GLOBALS['teams'][$row['team']] . ' ' . $sum; + $sep = ' '; $total += $sum; + + if ($row['extra'] > 0) { + $total_extra += $row['extra']; + $total += $row['extra']; + } + } + if ($total_extra > 0) { + $msg_teams .= $sep . TEAM_UNKNOWN . ' ' . $total_extra; } if (!$total) { - $msg .= ' Keine Teilnehmer' . CR; + $msg .= 'Keine Teilnehmer' . CR; } else { - $msg .= ' = ' . $total . '' . CR; + $msg .= EMOJI_GROUP . ' ' . $total . ' — ' . $msg_teams; } return $msg; From 1621f09fe2d28771fb0944375c0cb3151f8a1b24 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 1 Dec 2017 10:58:48 +0100 Subject: [PATCH 063/225] Add another step to select first letter of gym name to make gym selection list shorter :) --- modules/raid_by_gym_letter.php | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 modules/raid_by_gym_letter.php diff --git a/modules/raid_by_gym_letter.php b/modules/raid_by_gym_letter.php new file mode 100644 index 0000000..2e92179 --- /dev/null +++ b/modules/raid_by_gym_letter.php @@ -0,0 +1,57 @@ + 'Not supported', + 'callback_data' => 'edit:not_supported' + ] + ] + ]; +} + +// Edit the message. +edit_message($update, 'Bitte Anfangsbuchstabe der Arena auswählen:', $keys); + +// Build callback message string. +$callback_response = 'Anfangsbuchstabe "' . $data['arg'] . '" ausgewählt.'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); + +exit(); From af9650f5d9d71e95a478c38f35d1efa23577e7fc Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 1 Dec 2017 11:03:01 +0100 Subject: [PATCH 064/225] Update several files to work with the new first letter gym selection --- commands/start.php | 2 +- modules/raid_by_gym.php | 4 +++- modules/raid_create.php | 27 +++++++++++++-------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/commands/start.php b/commands/start.php index 4cc0434..7223c0f 100644 --- a/commands/start.php +++ b/commands/start.php @@ -11,7 +11,7 @@ [ [ 'text' => 'Raid anlegen', - 'callback_data' => $userid . ',' . $chattype . ':raid_by_gym:0', + 'callback_data' => $userid . ',' . $chattype . ':raid_by_gym_letter:0', ] ] ]; diff --git a/modules/raid_by_gym.php b/modules/raid_by_gym.php index a446b92..0c15d8c 100644 --- a/modules/raid_by_gym.php +++ b/modules/raid_by_gym.php @@ -12,6 +12,7 @@ // Get the userid, chat id and type $id_type = $data['id']; +$first = $data['arg']; // Create data array (max. 2) $userdata = explode(',', $id_type, 2); @@ -25,12 +26,13 @@ debug_log('User ID=' . $userid); debug_log('Chat type=' . $chatid); debug_log('Chat type=' . $chattype); +debug_log('First letter=' . $first); // Init id to 0 $id = 0; // Get the keys. -$keys = raid_edit_gym_keys($chatid, $chattype); +$keys = raid_edit_gym_keys($chatid, $chattype, $first); // No keys found. if (!$keys) { diff --git a/modules/raid_create.php b/modules/raid_create.php index bb44fbf..0bccb7c 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -47,23 +47,22 @@ // Get lat and lon from message text $coords = $data['arg']; - // Create data array (max. 3) + // Create data array (max. 2) $count_data = substr_count($coords, ","); - $data = explode(',', $coords, 3); - - // Set latitude / longitude - $lat = $data[0]; - $lon = $data[1]; - $gym_id = $data[2]; - - // Debug - debug_log('Lat=' . $lat); - debug_log('Lon=' . $lon); + $data = explode(',', $coords, 2); - // Get gym data from database - if($count_data == 2) { - $gym_id = $data[2]; + // Latitude and longitude or Gym ID? + if($data[0] == "ID") { + $gym_id = $data[1]; $gym = get_gym($gym_id); + } else { + // Set latitude / longitude + $lat = $data[0]; + $lon = $data[1]; + + // Debug + debug_log('Lat=' . $lat); + debug_log('Lon=' . $lon); } } From e09b7596ac2cf1911cfa9d05ea41d7e979a67b61 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 1 Dec 2017 11:06:59 +0100 Subject: [PATCH 065/225] Remove keys after pokemon got updated --- modules/raid_set_poke.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/modules/raid_set_poke.php b/modules/raid_set_poke.php index 2ab9716..10178d1 100644 --- a/modules/raid_set_poke.php +++ b/modules/raid_set_poke.php @@ -37,14 +37,7 @@ $raid = $rs->fetch_assoc(); // Create the keys. - $keys = [ - [ - [ - 'text' => 'Fertig!', - 'callback_data' => $raid['id'] . ':vote_refresh:0' - ] - ] - ]; + $keys = []; // Build message string. $msg = ''; From 851fecee10b2a5ae2a16a71c23d094a7e4aed230 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 1 Dec 2017 11:06:59 +0100 Subject: [PATCH 066/225] Add new logic for first letter selection and remove keys after pokemon got updated --- logic.php | 56 +++++++++++++++++++++++++++++++++++---- modules/raid_set_poke.php | 9 +------ 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/logic.php b/logic.php index 21df6e8..0ec4160 100644 --- a/logic.php +++ b/logic.php @@ -281,17 +281,63 @@ function raid_edit_start_keys($id) } /** - * Raid edit start keys. - * @param $id - * @return array + * Raid gym first letter selection + * @param $chat_id + * @param $chattype + * @return $keys array + */ +function raid_edit_gyms_first_letter_keys($chatid, $chattype) { + // Get gyms from database + $rs = my_query( + " + SELECT * + FROM gyms + ORDER BY gym_name + " + ); + + // Init empty keys array. + $keys = array(); + + // Init previous first letter + $previous = null; + + while ($gym = $rs->fetch_assoc()) { + $first = strtoupper(substr($gym['gym_name'], 0, 1)); + // Add first letter to keys array + if($previous !== $first) { + $keys[] = array( + 'text' => $first, + 'callback_data' => $chatid . ',' . $chattype . ':raid_by_gym:' . $first + ); + } + $previous = $first; + } + + // Get the inline key array. + $keys = inline_key_array($keys, 4); + + // Write to log. + debug_log($keys); + + return $keys; +} + +/** + * Raid edit gym keys. + * @param $chat_id + * @param $chattype + * @param $first + * @return $keys array */ -function raid_edit_gym_keys($chatid, $chattype) +function raid_edit_gym_keys($chatid, $chattype, $first) { // Get gyms from database $rs = my_query( " SELECT * FROM gyms + WHERE UPPER(LEFT(gym_name, 1)) = UPPER('{$first}') ORDER BY gym_name " ); @@ -302,7 +348,7 @@ function raid_edit_gym_keys($chatid, $chattype) while ($gym = $rs->fetch_assoc()) { $keys[] = array( 'text' => $gym['gym_name'], - 'callback_data' => $chatid . ',' . $chattype . ':raid_create:' . $gym['lat'] . ',' . $gym['lon'] . ',' . $gym['id'] + 'callback_data' => $chatid . ',' . $chattype . ':raid_create:ID,' . $gym['id'] ); } diff --git a/modules/raid_set_poke.php b/modules/raid_set_poke.php index 2ab9716..10178d1 100644 --- a/modules/raid_set_poke.php +++ b/modules/raid_set_poke.php @@ -37,14 +37,7 @@ $raid = $rs->fetch_assoc(); // Create the keys. - $keys = [ - [ - [ - 'text' => 'Fertig!', - 'callback_data' => $raid['id'] . ':vote_refresh:0' - ] - ] - ]; + $keys = []; // Build message string. $msg = ''; From 9cb61982f7940f65fe9e9b2af6b22b31e65d4a87 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 1 Dec 2017 11:44:56 +0100 Subject: [PATCH 067/225] Small change to message displayed --- modules/raid_by_gym_letter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/raid_by_gym_letter.php b/modules/raid_by_gym_letter.php index 2e92179..6b7eb07 100644 --- a/modules/raid_by_gym_letter.php +++ b/modules/raid_by_gym_letter.php @@ -49,7 +49,7 @@ edit_message($update, 'Bitte Anfangsbuchstabe der Arena auswählen:', $keys); // Build callback message string. -$callback_response = 'Anfangsbuchstabe "' . $data['arg'] . '" ausgewählt.'; +$callback_response = 'Anfangsbuchstabe ausgewählt.'; // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); From f27624511863d5063f6707d7f12a7f19d9a973e1 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 1 Dec 2017 12:30:02 +0100 Subject: [PATCH 068/225] Remove /pokemon for the moment --- commands/pokemon.php | 60 -------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 commands/pokemon.php diff --git a/commands/pokemon.php b/commands/pokemon.php deleted file mode 100644 index e099e33..0000000 --- a/commands/pokemon.php +++ /dev/null @@ -1,60 +0,0 @@ -fetch_assoc(); - -// No data found. -if (!$row) { - sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); - exit; -} - -// Build query. -$request = my_query( - " - SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) AS ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids - WHERE end_time>NOW() - AND timezone='{$row['timezone']}' - ORDER BY end_time ASC LIMIT 20 - " -); - -while ($raid = $request->fetch_assoc()) { - // Create keys array. - $keys = [ - [ - [ - 'text' => 'Pokemon aktualisieren', - 'callback_data' => $raid['id'] . ':raid_edit_poke:0', - ] - ] - ]; - - // Get message. - $msg = show_raid_poll_small($raid); - - // Send message. - send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); -} - -exit; From 3ba6d8eadb41f1555f408eeed8325d9c4cc9f870 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 1 Dec 2017 12:30:27 +0100 Subject: [PATCH 069/225] Remove /pokemon for the moment #2 --- modules/raid_edit_poke.php | 77 -------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 modules/raid_edit_poke.php diff --git a/modules/raid_edit_poke.php b/modules/raid_edit_poke.php deleted file mode 100644 index bb0ce9c..0000000 --- a/modules/raid_edit_poke.php +++ /dev/null @@ -1,77 +0,0 @@ - 'Arktos', - 'callback_data' => $id . ':raid_set_poke:arktos' - ], - [ - 'text' => 'Lugia', - 'callback_data' => $id . ':raid_set_poke:lugia' - ], - [ - 'text' => 'Lavados', - 'callback_data' => $id . ':raid_set_poke:lavados' - ], - [ - 'text' => 'Zapdos', - 'callback_data' => $id . ':raid_set_poke:zapdos' - ] - ], - [ - [ - 'text' => 'Mewtu', - 'callback_data' => $id . ':raid_set_poke:mewtu' - ], - [ - 'text' => 'Mew', - 'callback_data' => $id . ':raid_set_poke:mew' - ], - [ - 'text' => 'Ho-Oh', - 'callback_data' => $id . ':raid_set_poke:hooh' - ], - [ - 'text' => 'Celebi', - 'callback_data' => $id . ':raid_set_poke:celebi' - ] - ], - [ - [ - 'text' => 'Raikou', - 'callback_data' => $id . ':raid_set_poke:raikou' - ], - [ - 'text' => 'Entei', - 'callback_data' => $id . ':raid_set_poke:entei' - ], - [ - 'text' => 'Suicune', - 'callback_data' => $id . ':raid_set_poke:suicune' - ] - ] - ]; - -if (isset($update['callback_query']['inline_message_id'])) { - editMessageText($update['callback_query']['inline_message_id'], 'Raid Boss auswählen:', $keys); -} else { - editMessageText($update['callback_query']['message']['message_id'], 'Raid Boss auswählen:', $keys, $update['callback_query']['message']['chat']['id'], $keys); -} - -// Build callback message string. -$callback_response = 'Ok'; - -// Answer callback. -answerCallbackQuery($update['callback_query']['id'], $callback_response); From b416444a47c59542fbdbd0e395e69f2102b3076d Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 1 Dec 2017 12:30:44 +0100 Subject: [PATCH 070/225] Remove /pokemon for the moment #3 --- modules/raid_set_poke.php | 67 --------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 modules/raid_set_poke.php diff --git a/modules/raid_set_poke.php b/modules/raid_set_poke.php deleted file mode 100644 index 10178d1..0000000 --- a/modules/raid_set_poke.php +++ /dev/null @@ -1,67 +0,0 @@ -fetch_assoc(); - - // Create the keys. - $keys = []; - - // Build message string. - $msg = ''; - $msg .= 'Raid Boss gespeichert:' . CR; - // Pokemon - if(!empty($raid['pokemon'])) { - $msg .= '' . ucfirst($raid['pokemon']) . ''; - } - // End time - if(!empty($raid['ts_end'])) { - $msg .= ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . '' . CR; - } - // Gym Name - if(!empty($raid['gym_name'])) { - $msg .= $raid['gym_name'] . CR; - } - - // Edit message. - edit_message($update, $msg, $keys, false); - - // Build callback message string. - $callback_response = 'OK'; - - // Answer callback. - answerCallbackQuery($update['callback_query']['id'], $callback_response); - -} From c583e301ce0ebdb9d74576f3a77e436ac4960dc8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 1 Dec 2017 12:43:09 +0100 Subject: [PATCH 071/225] Remove now unneeded count_data :) --- modules/raid_create.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/raid_create.php b/modules/raid_create.php index 0bccb7c..199b5d1 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -20,8 +20,7 @@ $chattype = $update['message']['chat']['type']; } -// Init count_data, gym and gym_id -$count_data = 0; +// Init gym and gym_id $gym = 0; $gym_id = 0; @@ -48,7 +47,6 @@ $coords = $data['arg']; // Create data array (max. 2) - $count_data = substr_count($coords, ","); $data = explode(',', $coords, 2); // Latitude and longitude or Gym ID? From 1b36ce17bef9dd7fe027947fb1f9f06e0e1a7b7c Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 1 Dec 2017 13:34:40 +0100 Subject: [PATCH 072/225] Oops ... Fixes lat lon in address link :) --- modules/raid_create.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/raid_create.php b/modules/raid_create.php index 199b5d1..467e931 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -73,9 +73,13 @@ // Get address from database $fullAddress = $gym['address']; $gym_name = $gym['gym_name']; + $lat = $gym['lat']; + $lon = $gym['lon']; debug_log('Gym ID: ' . $gym_id); debug_log('Gym Name: ' . $gym_name); debug_log('Gym Address: ' . $fullAddress); + debug_log('Lat=' . $lat); + debug_log('Lon=' . $lon); } else { // Get the address. $addr = get_address($lat, $lon); From ee8265564027abf58ff33f1c9469689bb8507d63 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 00:07:06 +0100 Subject: [PATCH 073/225] Added /pokemon to update the raid boss --- commands/pokemon.php | 61 ++++++++++++++++++++++++++++++++++++++ modules/raid_edit_poke.php | 60 +++++++++++++++++++++++++++++++++++++ modules/raid_set_poke.php | 56 ++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 commands/pokemon.php create mode 100644 modules/raid_edit_poke.php create mode 100644 modules/raid_set_poke.php diff --git a/commands/pokemon.php b/commands/pokemon.php new file mode 100644 index 0000000..b2b28f0 --- /dev/null +++ b/commands/pokemon.php @@ -0,0 +1,61 @@ +fetch_assoc(); + +// No data found. +if (!$row) { + sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + exit; +} + +// Build query. +$request = my_query( + " + SELECT *, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE end_time>NOW() + AND timezone='{$row['timezone']}' + ORDER BY end_time ASC LIMIT 20 + " +); + +while ($raid = $request->fetch_assoc()) { + // Create keys array. + $keys = [ + [ + [ + 'text' => 'Pokemon aktualisieren', + 'callback_data' => $raid['id'] . ':raid_edit_poke:' . $raid['pokemon'], + ] + ] + ]; + + // Get message. + $msg = show_raid_poll_small($raid); + + // Send message. + send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); +} + +exit; diff --git a/modules/raid_edit_poke.php b/modules/raid_edit_poke.php new file mode 100644 index 0000000..273bcf0 --- /dev/null +++ b/modules/raid_edit_poke.php @@ -0,0 +1,60 @@ + $levelmons) { + debug_log("Searching raid boss '" . $old_pokemon . "' in level " . $level . " raids"); + // Compare pokemon by pokemon to get raid level + foreach($levelmons as $key => $pokemon) { + if(strtolower($old_pokemon) == strtolower($pokemon)) { + $level_found = true; + $raid_level = $level; + debug_log("Found raid boss '" . $pokemon . "' in level " . $level . " raids"); + break 2; + } + } +} + +if ($level_found) { + // Get the keys. + $keys = pokemon_keys($raid_id, $raid_level, $pokemonlist, "raid_set_poke"); +} else { + // Create the keys. + $keys = [ + [ + [ + 'text' => 'Not supported', + 'callback_data' => 'edit:not_supported' + ] + ] + ]; +} + +if (isset($update['callback_query']['inline_message_id'])) { + editMessageText($update['callback_query']['inline_message_id'], 'Raid Boss auswählen:', $keys); +} else { + editMessageText($update['callback_query']['message']['message_id'], 'Raid Boss auswählen:', $keys, $update['callback_query']['message']['chat']['id'], $keys); +} + +// Build callback message string. +$callback_response = 'Pokemon auswählen'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/raid_set_poke.php b/modules/raid_set_poke.php new file mode 100644 index 0000000..b1e0a1f --- /dev/null +++ b/modules/raid_set_poke.php @@ -0,0 +1,56 @@ +fetch_assoc(); + + // Create the keys. + $keys = []; + + // Build message string. + $msg = ''; + $msg .= 'Raid gespeichert:' . CR; + $msg .= show_raid_poll_small($raid); + + // Edit message. + edit_message($update, $msg, $keys, false); + + // Build callback message string. + $callback_response = 'Raid-Boss gespeichert!'; + + // Answer callback. + answerCallbackQuery($update['callback_query']['id'], $callback_response); + +} From dcef12f86221bba7cfa859e6252caa6e95953a29 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 00:08:29 +0100 Subject: [PATCH 074/225] Added the new raid bosses, removed the egg emoji --- constants.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/constants.php b/constants.php index 5745782..9dbc04a 100644 --- a/constants.php +++ b/constants.php @@ -10,7 +10,6 @@ define('TEAM_CANCEL', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f494))); define('TEAM_DONE', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f4aa))); define('TEAM_UNKNOWN', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f680))); -define('EMOJI_EGG', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f95a))); define('EMOJI_REFRESH', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f504))); define('EMOJI_GROUP', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f465))); @@ -30,24 +29,43 @@ 'Lugia', 'Lavados', 'Zapdos', + 'Mewtu', + 'Mew', + 'Ho-Oh', + 'Celebi', + 'Raikou', + 'Entei', + 'Suicune', + 'Level 5 Ei', ), '4' => array( 'Despotar', 'Relaxo', 'Lapras', - 'Rizeros', - 'Glurak', + 'Quappo', 'Bisasflor', + 'Glurak', 'Turtok', + 'Sarzenia', + 'Nidoqueen', + 'Nidoking', + 'Rizeros', + 'Geowaz', + 'Level 4 Ei', ), '3' => array( - 'Machomei', 'Aquana', 'Flamara', 'Blitza', - 'Simsala', 'Arkani', + 'Machomei', + 'Simsala', 'Gengar', + 'Sichlor', + 'Porygon', + 'Amoroso', + 'Vulnona', + 'Level 3 Ei', ) ); From 2cd5108192012107f23b7050d79d71f7921f647a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 00:12:28 +0100 Subject: [PATCH 075/225] Added pokemon_keys used by raid_edit_poke.php and edit.php, Added back key function, Removed unused keys_raid_people function, Excluded raid level 1 and 2 from selection for the moment --- logic.php | 100 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 40 deletions(-) diff --git a/logic.php b/logic.php index 0ec4160..bc88ae0 100644 --- a/logic.php +++ b/logic.php @@ -252,29 +252,30 @@ function raid_edit_start_keys($id) [ [ 'text' => '5 Sterne Raid', - 'callback_data' => $id . ':edit:type_5' + 'callback_data' => $id . ':edit:5' ] ], [ [ 'text' => '4 Sterne Raid', - 'callback_data' => $id . ':edit:type_4' + 'callback_data' => $id . ':edit:4' ], [ 'text' => '3 Sterne Raid', - 'callback_data' => $id . ':edit:type_3' + 'callback_data' => $id . ':edit:3' ] - ], +// No raids for level 2 or 1 +/* ], [ [ 'text' => '2 Sterne Raid', - 'callback_data' => $id . ':edit:type_2' + 'callback_data' => $id . ':edit:2' ], [ 'text' => '1 Stern Raid', - 'callback_data' => $id . ':edit:type_1' + 'callback_data' => $id . ':edit:1' ] - ] +*/ ] ]; return $keys; @@ -362,39 +363,57 @@ function raid_edit_gym_keys($chatid, $chattype, $first) } /** - * Keys raid people. - * @param $data + * Pokemon keys. + * @param $raid_id + * @param $raid_level * @return array */ -function keys_raid_people($data) +function pokemon_keys($raid_id, $raid_level, $pokemonlist, $action) { + // Init empty keys array. + $keys = array(); - if (!is_array($data)) { - $data = array('id' => $data); + // Iterate thru the pokemon list to create the keys + foreach($pokemonlist as $level => $levelmons) { + if($level == $raid_level) { + // Create the keys. + foreach($levelmons as $key => $pokemon) { + $keys[] = array( + 'text' => $pokemon, + 'callback_data' => $raid_id . ':' . $action . ':' . $pokemon + ); + } + } } - $keys = [ - [ - 'text' => '+1', - 'callback_data' => $data['id'] . ':vote:1' - ], - [ - 'text' => '+2', - 'callback_data' => $data['id'] . ':vote:2' - ], - [ - 'text' => '+3', - 'callback_data' => $data['id'] . ':vote:3' - ], - [ - 'text' => '+4', - 'callback_data' => $data['id'] . ':vote:4' - ], - [ - 'text' => '+5', - 'callback_data' => $data['id'] . ':vote:5' - ] - ]; + // Get the inline key array. + $keys = inline_key_array($keys, 4); + + // Write to log. + debug_log($keys); + + return $keys; +} + +/** + * Back key. + * @param $keys + * @param $id + * @param $action + * @param $arg + * @return array + */ +function back_key($keys, $id, $action, $arg) +{ + $keys[] = [ + array( + 'text' => 'Zurück', + 'callback_data' => $id . ':' . $action . ':' . $arg + ) + ]; + + // Write to log. + debug_log($keys); return $keys; } @@ -1059,18 +1078,19 @@ function show_raid_poll($raid) */ function show_raid_poll_small($raid) { - $time_left = floor($raid['t_left'] / 60); - $time_left = 'noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT); + // Left for possible future redesign of small raid poll + //$time_left = floor($raid['t_left'] / 60); + //$time_left = 'noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT); // Build message string. $msg = ''; // Pokemon if(!empty($raid['pokemon'])) { - $msg .= '' . ucfirst($raid['pokemon']) . ''; + $msg .= '' . ucfirst($raid['pokemon']) . ' '; } - // End time - if(!empty($raid['ts_end'])) { - $msg .= ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . ' — ' . $time_left . CR; + // Start time and end time + if(!empty($raid['ts_start']) && !empty($raid['ts_end'])) { + $msg .= 'von ' . unix2tz($raid['ts_start'], $raid['timezone']) . ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . '' . CR; } // Gym Name if(!empty($raid['gym_name'])) { From 90aceb41b7914ba4e946d81dea7abaa58ed8e74c Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 00:13:25 +0100 Subject: [PATCH 076/225] Added back key to go back to the gym letter selection --- modules/raid_by_gym.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/raid_by_gym.php b/modules/raid_by_gym.php index 0c15d8c..52be127 100644 --- a/modules/raid_by_gym.php +++ b/modules/raid_by_gym.php @@ -14,6 +14,11 @@ $id_type = $data['id']; $first = $data['arg']; +// Back key id, action and arg +$back_id = $data['id']; +$back_action = "raid_by_gym_letter"; +$back_arg = 0; + // Create data array (max. 2) $userdata = explode(',', $id_type, 2); @@ -45,6 +50,8 @@ ] ] ]; +} else { + $keys = back_key($keys, $back_id, $back_action, $back_arg); } // Edit the message. From 92c8051da1518c41f1efc36b0c228a9225396e36 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 00:16:58 +0100 Subject: [PATCH 077/225] Pokemon selection keys are now generated by new pokemon_keys function and pokemonlist in constants.php --- modules/edit.php | 183 +++-------------------------------------------- 1 file changed, 9 insertions(+), 174 deletions(-) diff --git a/modules/edit.php b/modules/edit.php index 40098f8..b855105 100644 --- a/modules/edit.php +++ b/modules/edit.php @@ -3,177 +3,20 @@ raid_access_check($update, $data); // Write to log. -debug_log('raid_edit()'); +debug_log('edit()'); debug_log($update); // Set the id. -$id = $data['id']; +$raid_id = $data['id']; -// Level 5 boss. -if ($data['arg'] == 'type_5') { - // Set keys. - $keys = [ - [ - [ - 'text' => 'Arktos', - 'callback_data' => $id . ':edit_poke:arktos' - ], - [ - 'text' => 'Lugia', - 'callback_data' => $id . ':edit_poke:lugia' - ], - [ - 'text' => 'Lavados', - 'callback_data' => $id . ':edit_poke:lavados' - ], - [ - 'text' => 'Zapdos', - 'callback_data' => $id . ':edit_poke:zapdos' - ] - ], - [ - [ - 'text' => 'Mewtu', - 'callback_data' => $id . ':edit_poke:mewtu' - ], - [ - 'text' => 'Mew', - 'callback_data' => $id . ':edit_poke:mew' - ], - [ - 'text' => 'Ho-Oh', - 'callback_data' => $id . ':edit_poke:hooh' - ], - [ - 'text' => 'Celebi', - 'callback_data' => $id . ':edit_poke:celebi' - ] - ], - [ - [ - 'text' => 'Raikou', - 'callback_data' => $id . ':edit_poke:raikou' - ], - [ - 'text' => 'Entei', - 'callback_data' => $id . ':edit_poke:entei' - ], - [ - 'text' => 'Suicune', - 'callback_data' => $id . ':edit_poke:suicune' - ] - ] - ]; +// Set the raid level. +$raid_level = $data['arg']; -// Level 4 boss. -} else if ($data['arg'] == 'type_4') { - // Set keys. - $keys = [ - [ - [ - 'text' => 'Despotar', - 'callback_data' => $id . ':edit_poke:despotar' - ] - ], - [ - [ - 'text' => 'Relaxo', - 'callback_data' => $id . ':edit_poke:relaxo' - ], - [ - 'text' => 'Lapras', - 'callback_data' => $id . ':edit_poke:lapras' - ], - [ - 'text' => 'Rizeros', - 'callback_data' => $id . ':edit_poke:rizeros' - ] - ], - [ - [ - 'text' => 'Glurak', - 'callback_data' => $id . ':edit_poke:glurak' - ], - [ - 'text' => 'Bisasflor', - 'callback_data' => $id . ':edit_poke:bisasflor' - ], - [ - 'text' => 'Turtok', - 'callback_data' => $id . ':edit_poke:turtok' - ] - ] - ]; +// Set the pokkemon list +$pokemonlist = $GLOBALS['pokemon']; -// Level 3 boss. -} else if ($data['arg'] == 'type_3') { - // Set keys. - $keys = [ - [ - [ - 'text' => 'Machomei', - 'callback_data' => $id . ':edit_poke:machomei' - ] - ], - [ - [ - 'text' => 'Aquana', - 'callback_data' => $id . ':edit_poke:aquana' - ], - [ - 'text' => 'Flamara', - 'callback_data' => $id . ':edit_poke:flamara' - ], - [ - 'text' => 'Blitza', - 'callback_data' => $id . ':edit_poke:blitza' - ] - ], - [ - [ - 'text' => 'Simsala', - 'callback_data' => $id . ':edit_poke:simsala' - ], - [ - 'text' => 'Arkani', - 'callback_data' => $id . ':edit_poke:arkani' - ], - [ - 'text' => 'Gengar', - 'callback_data' => $id . ':edit_poke:gengar' - ] - ] - ]; - -// Level 2 boss. -} else if ($data['arg'] == 'type_2') { - // Set keys. - $keys = [ - [ - [ - 'text' => 'Sleimok', - 'callback_data' => $id . ':edit_poke:sleimok' - ] - ] - ]; - -// Level 1 boss. -} else if ($data['arg'] == 'type_1') { - // Set keys. - $keys = [ - [ - [ - 'text' => 'Nicht unterstützt', - 'callback_data' => 'edit:not_supported' - ] - ] - ]; - - -} else { - // Edit pokemon. - $keys = raid_edit_start_keys($id); -} +// Get the keys. +$keys = pokemon_keys($raid_id, $raid_level, $pokemonlist, "edit_poke"); // No keys found. if (!$keys) { @@ -185,20 +28,12 @@ ] ] ]; -} else { - $level = substr($data['arg'], -1); - $keys[] = [ - array( - 'text' => EMOJI_EGG . ' Raid-Ei', - 'callback_data' => $id . ':edit_poke:Level ' . $level . ' Ei' - ) - ]; } if (isset($update['callback_query']['inline_message_id'])) { editMessageText($update['callback_query']['inline_message_id'], 'Raid Boss auswählen:', $keys); } else { - editMessageText($update['callback_query']['message']['message_id'], 'Raid Boss auswählen', $keys, $update['callback_query']['message']['chat']['id'], $keys); + editMessageText($update['callback_query']['message']['message_id'], 'Raid Boss auswählen:', $keys, $update['callback_query']['message']['chat']['id'], $keys); } // Build callback message string. From 66b53f99f66db0e47d9023d5a2a2ee574940ddaa Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 00:17:59 +0100 Subject: [PATCH 078/225] Use show_raid_poll_small to unify design --- modules/edit_left.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/edit_left.php b/modules/edit_left.php index 29bf082..e06f028 100644 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -49,17 +49,10 @@ // Build message string. $msg = ''; $msg .= 'Raid gespeichert:' . CR; - // Pokemon - if(!empty($raid['pokemon'])) { - $msg .= '' . ucfirst($raid['pokemon']) . ''; - } - // End time - if(!empty($raid['ts_end'])) { - $msg .= ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . '' . CR; - } + $msg .= show_raid_poll_small($raid) . CR; + // Gym Name if(!empty($raid['gym_name'])) { - $msg .= $raid['gym_name'] . CR2 . CR; $msg .= 'Optional - Arena Team setzen:' . CR2; } else { $msg .= 'Optional - Arena Name und Arena Team:' . CR2; From 8c20fd320b512d1ffc007f9bcdc05da504c576ac Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 00:19:29 +0100 Subject: [PATCH 079/225] Use 5 keys per row and every minute in the selection to allow exact times when creating raid polls --- modules/edit_poke.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/edit_poke.php b/modules/edit_poke.php index 3af05e4..7f49abb 100644 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -23,7 +23,7 @@ // Init empty keys array. $keys = array(); - for ($i = 60; $i >= 0; $i = $i - 5) { + for ($i = 60; $i >= 0; $i = $i - 1) { // Create the keys. $keys[] = array( // Just show the time, no text - not everyone has a phone or tablet with a large screen... @@ -34,7 +34,7 @@ } // Get the inline key array. - $keys = inline_key_array($keys, 4); + $keys = inline_key_array($keys, 5); // Write to log. debug_log($keys); From 5c62e9665c5cfcceaf3746229456d4fac424ce20 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 11:26:38 +0100 Subject: [PATCH 080/225] Only show own raids since raid_access_check does not allow currently to edit raids from others and function to set moderator is missing yet --- commands/pokemon.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/pokemon.php b/commands/pokemon.php index b2b28f0..7aafb7f 100644 --- a/commands/pokemon.php +++ b/commands/pokemon.php @@ -25,6 +25,7 @@ exit; } + // Build query. $request = my_query( " @@ -35,6 +36,7 @@ UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids WHERE end_time>NOW() + AND user_id = {$update['message']['from']['id']} AND timezone='{$row['timezone']}' ORDER BY end_time ASC LIMIT 20 " From b0ceeb0fd959391269babfaae59b76f4c1f55134 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 11:26:38 +0100 Subject: [PATCH 081/225] Only show own raids since raid_access_check does not allow currently to edit raids from others and function to set moderator is missing yet --- commands/pokemon.php | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/pokemon.php b/commands/pokemon.php index b2b28f0..bd6eeb9 100644 --- a/commands/pokemon.php +++ b/commands/pokemon.php @@ -35,6 +35,7 @@ UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids WHERE end_time>NOW() + AND user_id = {$update['message']['from']['id']} AND timezone='{$row['timezone']}' ORDER BY end_time ASC LIMIT 20 " From 7d0aba58ca896bd968dd6921fac47460e19ecab5 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 4 Dec 2017 11:30:20 +0100 Subject: [PATCH 082/225] Update pokemon.php --- commands/pokemon.php | 1 - 1 file changed, 1 deletion(-) diff --git a/commands/pokemon.php b/commands/pokemon.php index 7aafb7f..bd6eeb9 100644 --- a/commands/pokemon.php +++ b/commands/pokemon.php @@ -25,7 +25,6 @@ exit; } - // Build query. $request = my_query( " From d577ed414dd87a07cec7de8f370ded148179289a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 4 Dec 2017 11:44:52 +0100 Subject: [PATCH 083/225] Added /pokemon to the readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 3f2b9c4..107b445 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,13 @@ Parameters: Pokemon raid boss, latitude, longitude, raid duration in minutes, gy Example input: `/raid Entei,52.514545,13.350095,60,Mystic,Siegessäule,Großer Stern,10557 Berlin,30` +#### Command: /pokemon + +Update pokemon of an existing raid poll. With this command you can change the pokemon raid boss from e.g. "Level 5 Egg" to "Lugia" once the egg has hatched. + +You can only change the pokemon raid boss of raid polls you created yourself. You cannot modify the pokemon of raid polls from other bot users. + + #### Command: /new The bot expects latitude and longitude seperated by comma and will then guide you through the creation of the raid poll. From 7eaaef82ad636406dcc0a6ed36bac3de8988ed8e Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 5 Dec 2017 15:53:22 +0100 Subject: [PATCH 084/225] New cleanup database table --- raid-pokemon-bot.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index 8a90e1d..91b8d2d 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -35,9 +35,9 @@ CREATE TABLE `attendance` ( CREATE TABLE `cleanup` ( `raid_id` int(10) unsigned NOT NULL, - `end_time` datetime DEFAULT NULL, - `chat_id` int(10) unsigned NOT NULL, - `message_id` int(10) unsigned NOT NULL, + `end_time` datetime NOT NULL, + `chat_id` bigint(20) unsigned NOT NULL, + `message_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`raid_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 6a3fb3d8c690a9324d501cbc43af627c1d5c257a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 5 Dec 2017 16:03:35 +0100 Subject: [PATCH 085/225] Several small improvements and fixes to e.g. avoid duplicate logging, allow easier raid duration time selection --- commands/raid.php | 4 +--- commands/start.php | 2 +- modules/edit_poke.php | 2 +- modules/edit_start.php | 15 ++++++++++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index a33e30a..194d7e1 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -41,11 +41,9 @@ $lat = substr($lat, 0, strpos('.', $lat) + 9); $lon = substr($lon, 0, strpos('.', $lon) + 9); -// Endtime from input / config -// timeleft till raid ends or raid duration if egg hasn't hatched yet +// Endtime from input $endtime = $data[3]; - // Team $team = $data[4]; diff --git a/commands/start.php b/commands/start.php index 7223c0f..c42d43f 100644 --- a/commands/start.php +++ b/commands/start.php @@ -20,6 +20,6 @@ $msg = 'Bitte sende mir zuerst einen Standort.' . CR2 . CR . 'Oder lege ein Raid per Arena-Auswahl an:'; // Send message. -send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); +send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); exit; diff --git a/modules/edit_poke.php b/modules/edit_poke.php index 7f49abb..26c5aea 100644 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -58,7 +58,7 @@ } // Edit the message. -edit_message($update, 'Wann beginnt der Raid?' . CR . 'Raid läuft schon? --- Einfach 0:00 auswählen!', $keys); +edit_message($update, 'Wann beginnt der Raid?' . CR . CR . 'Raid läuft schon?' . CR .'Einfach 0:00 auswählen!', $keys); // Build callback message string. $callback_response = 'Pokemon gespeichert: ' . $data['arg']; diff --git a/modules/edit_start.php b/modules/edit_start.php index afb22d7..5c513c4 100644 --- a/modules/edit_start.php +++ b/modules/edit_start.php @@ -24,7 +24,16 @@ // Init empty keys array. $keys = array(); - for ($i = 120; $i >= 15; $i = $i - 5) { + // 1 Minute or 5 minute time slots + if ($data['arg'] == 0) { + $slotmax = 60; + $slotsize = 1; + } else { + $slotmax = 120; + $slotsize = 5; + } + + for ($i = $slotmax; $i >= 15; $i = $i - $slotsize) { // Create the keys. $keys[] = array( // Just show the time, no text - not everyone has a phone or tablet with a large screen... @@ -35,7 +44,7 @@ } // Get the inline key array. - $keys = inline_key_array($keys, 4); + $keys = inline_key_array($keys, 5); // Write to log. debug_log($keys); @@ -46,7 +55,7 @@ } // Edit the message. -edit_message($update, 'Wie lange läuft der Raid?', $keys); +edit_message($update, 'Wie lange dauert der Raid?', $keys); // Build callback message string. $callback_response = 'Vorlaufzeit gesetzt auf ' . $data['arg'] . ' Minuten'; From 0be654407b4383f862b82ac6d96b2db857bd2675 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 5 Dec 2017 16:07:09 +0100 Subject: [PATCH 086/225] Added function to insert cleanup info to database, Small improvements to bot access check and duplication check (large amount of time being checked), Removed several debug_log's to keep log shorter - stuff is still logged by other files --- logic.php | 79 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/logic.php b/logic.php index bc88ae0..504c726 100644 --- a/logic.php +++ b/logic.php @@ -31,17 +31,26 @@ function bot_access_check($update) } } + // Prepare logging of username, first_name and/or id + $msg = ''; + $msg .= !empty($update['message']['from']['id']) ? "Id: " . $update['message']['from']['id'] . CR : ''; + $msg .= !empty($update['message']['from']['username']) ? "Username: " . $update['message']['from']['username'] . CR : ''; + $msg .= !empty($update['message']['from']['first_name']) ? "First Name: " . $update['message']['from']['first_name'] . CR : ''; + $msg .= !empty($update['inline_query']['from']['id']) ? "Id: " . $update['inline_query']['from']['id'] . CR : ''; + $msg .= !empty($update['inline_query']['from']['username']) ? "Username: " . $update['inline_query']['from']['username'] . CR : ''; + $msg .= !empty($update['inline_query']['from']['first_name']) ? "First Name: " . $update['inline_query']['from']['first_name'] . CR : ''; + // Allow or deny access to the bot and log result if ($allow_access) { - debug_log("Allowing access to the bot for user: " . $update['message']['from']['username'] . " (Id: " . $update['message']['from']['id'] . ")"); + debug_log("Allowing access to the bot for user:" . CR . $msg); } else { - debug_log("Denying access to the bot for user: " . $update['message']['from']['username'] . " (Id: " . $update['message']['from']['id'] . ")"); + debug_log("Denying access to the bot for user:" . CR . $msg); $response_msg = 'You are not allowed to use this bot!'; sendMessage($update['message']['chat']['id'], $response_msg); exit; } } else { - debug_log("Bot access is not restricted! Allowing access for user: " . $update['message']['from']['username'] . " (Id: " . $update['message']['from']['id'] . ")"); + debug_log("Bot access is not restricted! Allowing access for user: " . CR . $msg); } } @@ -123,9 +132,9 @@ function raid_duplication_check($gym,$end) // Now + $end = endtime of new raid $end = time() + $end*60; - // Compare end time - check 5 minutes before and after database value - $ts_end_before = $raid['ts_end'] - (5*60); - $ts_end_after = $raid['ts_end'] + (5*60); + // Compare end time - check 15 minutes before and after database value + $ts_end_before = $raid['ts_end'] - (15*60); + $ts_end_after = $raid['ts_end'] + (15*60); // Debug log unix times debug_log("Unix timestamp of endtime new raid: " . $end); @@ -164,7 +173,6 @@ function raid_duplication_check($gym,$end) * @param $latitude * @param $longitude * @param $address - * @return array */ function insert_gym($name, $lat, $lon, $address) { @@ -200,6 +208,7 @@ function insert_gym($name, $lat, $lon, $address) /** * Get gym. * @param $id + * @return array */ function get_gym($id) { @@ -318,9 +327,6 @@ function raid_edit_gyms_first_letter_keys($chatid, $chattype) { // Get the inline key array. $keys = inline_key_array($keys, 4); - // Write to log. - debug_log($keys); - return $keys; } @@ -356,9 +362,6 @@ function raid_edit_gym_keys($chatid, $chattype, $first) // Get the inline key array. $keys = inline_key_array($keys, 1); - // Write to log. - debug_log($keys); - return $keys; } @@ -389,9 +392,6 @@ function pokemon_keys($raid_id, $raid_level, $pokemonlist, $action) // Get the inline key array. $keys = inline_key_array($keys, 4); - // Write to log. - debug_log($keys); - return $keys; } @@ -412,12 +412,53 @@ function back_key($keys, $id, $action, $arg) ) ]; - // Write to log. - debug_log($keys); - return $keys; } +/** + * Insert cleanup. + * @param $chat_id + * @param $message_id + * @param $raid_id + */ +function insert_cleanup($chat_id, $message_id, $raid_id) +{ + global $db; + + // Get raid times. + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$raid_id} + " + ); + + // Fetch raid data. + $raid = $rs->fetch_assoc(); + + // Insert cleanup info to database + if (!empty($raid)) { + // Build query for cleanup table to add cleanup info to database + debug_log('Adding cleanup info to database:'); + $rs = my_query( + " + INSERT INTO cleanup + SET raid_id = '{$raid_id}', + end_time = '{$raid['ts_end']}', + chat_id = '{$chat_id}', + message_id = '{$message_id}' + ON DUPLICATE KEY + UPDATE raid_id = '{$raid_id}' + " + ); + } +} + /** * Keys vote. * @param $raid From 4745a5e2f6326d471a1dcd03a3fceb931f872ba7 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 5 Dec 2017 16:09:38 +0100 Subject: [PATCH 087/225] Added delete_message function, Added cleanup preparation stuff in curl_json_request function --- functions.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 17c2b32..4e514f3 100644 --- a/functions.php +++ b/functions.php @@ -358,6 +358,34 @@ function edit_message($update, $message, $keys, $merge_args = false) } } +/** + * Delete message + * @param $chat_id + * @param $message_id + */ +function delete_message($chat_id, $message_id) +{ + // Create response content array. + $reply_content = [ + 'method' => 'deleteMessage', + 'chat_id' => $chat_id, + 'message_id' => $message_id, + 'parse_mode' => 'HTML', + ]; + + // Encode data to json. + $reply_json = json_encode($reply_content); + + // Set header to json. + header('Content-Type: application/json'); + + // Write to log. + debug_log($reply_json, '>'); + + // Send request to telegram api. + return curl_json_request($reply_json); +} + /** * GetChatAdministrators * @param $chatid @@ -391,7 +419,6 @@ function get_admins($chat_id) */ function curl_json_request($json) { - $curl = curl_init('https://api.telegram.org/bot' . API_KEY . '/'); curl_setopt($curl, CURLOPT_HEADER, false); @@ -421,6 +448,43 @@ function curl_json_request($json) if ($response['ok'] != true || isset($response['update_id'])) { // Write error to log. debug_log('ERROR: ' . $json . "\n\n" . $json_response . "\n\n"); + } else { + // Result seems ok, get message_id and chat_id if supergroup or channel message + if ($response['result']['chat']['type'] == ("channel" || "supergroup")) { + // Init raid_id + $raid_id = 0; + + // Set chat and message_id + $chat_id = $response['result']['chat']['id']; + $message_id = $response['result']['message_id']; + + // Get raid id from $json + $json_message = json_decode($json, true); + + // Check if callback_data is present to get the raid_id and reply_to_message_id is set to filter only raid messages + if (!empty($json_message['reply_markup']['inline_keyboard']['0']['0']['callback_data']) && !empty($json_message['reply_to_message_id'])) { + $split_callback_data = explode(':', $json_message['reply_markup']['inline_keyboard']['0']['0']['callback_data']); + $raid_id = $split_callback_data[0]; + debug_log('Found Raid_ID for cleanup preparation from callback_data!'); + debug_log('Raid_ID: ' . $raid_id); + debug_log('Chat_ID: ' . $chat_id); + debug_log('Message_ID: ' . $message_id); + + // Trigger cleanup preparation process when necessary id's are not empty and numeric + //if (is_numeric(!empty($chat_id)) && is_numeric(!empty($message_id)) && is_numeric(($raid_id > 0))) { + if ((is_numeric($chat_id)) && (is_numeric($message_id)) && (is_numeric($raid_id)) && ($raid_id > 0)) { + debug_log('Calling cleanup preparation now!'); + insert_cleanup($chat_id, $message_id, $raid_id); + } else { + debug_log('Invalid input! Cannot call cleanup preparation!'); + $log_msg = ''; + $log_msg .= is_numeric($raid_id) ? 'RAID_ID = numeric' : 'Raid_ID is empty or not numeric!' . CR; + $log_msg .= is_numeric($chat_id) ? 'CHAT_ID = numeric' : 'Chat_ID is empty or not numeric!' . CR; + $log_msg .= is_numeric($message_id) ? 'NUMERIC--'. $message_id . '--NUMERIC' : 'Message_ID is not numeric!' . CR; + debug_log($log_msg); + } + } + } } // Return response. From 33b2317915bd9ad6b29405e80e311355754b4782 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 5 Dec 2017 23:17:58 +0100 Subject: [PATCH 088/225] Deleted some unneeded debug_log's and moved is_numeric check to logic.php --- functions.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/functions.php b/functions.php index 4e514f3..56ff029 100644 --- a/functions.php +++ b/functions.php @@ -471,17 +471,11 @@ function curl_json_request($json) debug_log('Message_ID: ' . $message_id); // Trigger cleanup preparation process when necessary id's are not empty and numeric - //if (is_numeric(!empty($chat_id)) && is_numeric(!empty($message_id)) && is_numeric(($raid_id > 0))) { - if ((is_numeric($chat_id)) && (is_numeric($message_id)) && (is_numeric($raid_id)) && ($raid_id > 0)) { + if (!empty($chat_id) && !empty($message_id) && !empty($raid_id)) { debug_log('Calling cleanup preparation now!'); insert_cleanup($chat_id, $message_id, $raid_id); } else { - debug_log('Invalid input! Cannot call cleanup preparation!'); - $log_msg = ''; - $log_msg .= is_numeric($raid_id) ? 'RAID_ID = numeric' : 'Raid_ID is empty or not numeric!' . CR; - $log_msg .= is_numeric($chat_id) ? 'CHAT_ID = numeric' : 'Chat_ID is empty or not numeric!' . CR; - $log_msg .= is_numeric($message_id) ? 'NUMERIC--'. $message_id . '--NUMERIC' : 'Message_ID is not numeric!' . CR; - debug_log($log_msg); + debug_log('Missing input! Cannot call cleanup preparation!'); } } } From 525b511954a236aaa6221a9b8916d29f261a202f Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 5 Dec 2017 23:18:34 +0100 Subject: [PATCH 089/225] Improved insert_cleanup function --- logic.php | 63 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/logic.php b/logic.php index 504c726..e120c48 100644 --- a/logic.php +++ b/logic.php @@ -423,39 +423,48 @@ function back_key($keys, $id, $action, $arg) */ function insert_cleanup($chat_id, $message_id, $raid_id) { - global $db; - - // Get raid times. - $rs = my_query( - " - SELECT *, - UNIX_TIMESTAMP(start_time) AS ts_start, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) AS ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids - WHERE id = {$raid_id} - " - ); + // Log ID's of raid, chat and message + debug_log('Raid_ID: ' . $raid_id); + debug_log('Chat_ID: ' . $chat_id); + debug_log('Message_ID: ' . $message_id); - // Fetch raid data. - $raid = $rs->fetch_assoc(); + if ((is_numeric($chat_id)) && (is_numeric($message_id)) && (is_numeric($raid_id)) && ($raid_id > 0)) { + global $db; - // Insert cleanup info to database - if (!empty($raid)) { - // Build query for cleanup table to add cleanup info to database - debug_log('Adding cleanup info to database:'); + // Get raid times. $rs = my_query( " - INSERT INTO cleanup - SET raid_id = '{$raid_id}', - end_time = '{$raid['ts_end']}', - chat_id = '{$chat_id}', - message_id = '{$message_id}' - ON DUPLICATE KEY - UPDATE raid_id = '{$raid_id}' + SELECT *, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$raid_id} " ); + + // Fetch raid data. + $raid = $rs->fetch_assoc(); + + // Insert cleanup info to database + if (!empty($raid)) { + // Build query for cleanup table to add cleanup info to database + debug_log('Adding cleanup info to database:'); + $rs = my_query( + " + INSERT INTO cleanup + SET raid_id = '{$raid_id}', + end_time = '{$raid['ts_end']}', + chat_id = '{$chat_id}', + message_id = '{$message_id}' + ON DUPLICATE KEY + UPDATE raid_id = '{$raid_id}' + " + ); + } + } else { + debug_log('Invalid input for cleanup preparation!'); } } From 25697e6751bdc8a2bc6a34838d558ee0c26e31da Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 5 Dec 2017 23:21:57 +0100 Subject: [PATCH 090/225] Added cleanup stuff to index.php --- index.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/index.php b/index.php index c4f8f4c..391721f 100644 --- a/index.php +++ b/index.php @@ -146,6 +146,28 @@ // Echo bot response. sendMessage($update['message']['chat']['id'], 'Bitte sende mir zuerst einen Standort.'); + + // Cleanup channel / supergroup + } else if ($update['channel_post']['chat']['type'] == "channel" || $update['message']['chat']['type'] == "supergroup") { + debug_log('Calling cleanup preparation now!'); + // Channel + if(isset($update['channel_post'])) { + // Get chat_id and message_id + $chat_id = $update['channel_post']['chat']['id']; + $message_id = $update['channel_post']['message_id']; + // Supergroup + } else if ($update['message']['chat']['type'] == "supergroup") { + // Get chat_id and message_id + $chat_id = $update['message']['chat']['id']; + $message_id = $update['message']['message_id']; + } + + // Get raid_id from text. + $raid_id = substr(strrchr($update['message']['text'], "ID = "), 5); + + // Write cleanup info to database. + insert_cleanup($chat_id, $message_id, $raid_id); + exit(); } } From cbd6b1d44ffd640c1c38658c92930f83dc174bb4 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 6 Dec 2017 11:46:28 +0100 Subject: [PATCH 091/225] Oops, fixed count for trainers without team --- logic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.php b/logic.php index e120c48..04d00ca 100644 --- a/logic.php +++ b/logic.php @@ -922,7 +922,7 @@ function show_raid_poll($raid) sum(team = 'mystic') AS count_mystic, sum(team = 'valor') AS count_valor, sum(team = 'instinct') AS count_instinct, - sum(team = 'NULL') AS count_no_team, + sum(team IS NULL) AS count_no_team, sum(extra_people) AS extra FROM attendance WHERE raid_id = {$raid['id']} From 59333ee75ec6e2011a9110bc07e2f4af7ae4d8b3 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 7 Dec 2017 10:04:53 +0100 Subject: [PATCH 092/225] Fixed API Key uppercase/lowercase issues (Finally :D) and improved raid cleanup preparation a bit --- index.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 391721f..9ca2ab7 100644 --- a/index.php +++ b/index.php @@ -19,7 +19,7 @@ $apiKey = $_GET['apikey']; // Check if hashed api key is matching config. -if (hash('sha512', $apiKey) == CONFIG_HASH) { +if (hash('sha512', $apiKey) == strtolower(CONFIG_HASH)) { // Split the api key. $splitKey = explode(':', $apiKey); @@ -149,7 +149,7 @@ // Cleanup channel / supergroup } else if ($update['channel_post']['chat']['type'] == "channel" || $update['message']['chat']['type'] == "supergroup") { - debug_log('Calling cleanup preparation now!'); + debug_log('Collecting cleanup preparation information now!'); // Channel if(isset($update['channel_post'])) { // Get chat_id and message_id @@ -163,10 +163,15 @@ } // Get raid_id from text. - $raid_id = substr(strrchr($update['message']['text'], "ID = "), 5); + $raid_id = 0; + if (isset($update['message']['text'])) { + $raid_id = substr(strrchr($update['message']['text'], "ID = "), 5); + } // Write cleanup info to database. - insert_cleanup($chat_id, $message_id, $raid_id); + if ($raid_id > 0) { + insert_cleanup($chat_id, $message_id, $raid_id); + } exit(); } } From e50ec221187cc6b25962186b14c505802a6137cf Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 7 Dec 2017 16:09:30 +0100 Subject: [PATCH 093/225] Fixed cleanup preparation call for channel_post and added call to cleanup function which is under development --- index.php | 66 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/index.php b/index.php index 9ca2ab7..0d4fe5a 100644 --- a/index.php +++ b/index.php @@ -70,6 +70,19 @@ // Write to log. debug_log('Update user: ' . $userUpdate); +// Cleanup request received. +if (isset($update['cleanup'])) { + debug_log('Cleanup process request received...'); + // Check access to cleanup of bot + if ($update['cleanup'] == CLEANUP_SECRET) { + // Run cleanup + debug_log('Calling cleanup process now!'); + run_cleanup(); + } + // Exit after cleanup + exit(); +} + // Callback query received. if (isset($update['callback_query'])) { // Init empty data array. @@ -146,33 +159,36 @@ // Echo bot response. sendMessage($update['message']['chat']['id'], 'Bitte sende mir zuerst einen Standort.'); + } + +// Cleanup channel / supergroup +} else if ($update['channel_post']['chat']['type'] == "channel" || $update['message']['chat']['type'] == "supergroup") { + // Write to log. + debug_log('Collecting cleanup preparation information...'); + // Init raid_id. + $raid_id = 0; - // Cleanup channel / supergroup - } else if ($update['channel_post']['chat']['type'] == "channel" || $update['message']['chat']['type'] == "supergroup") { - debug_log('Collecting cleanup preparation information now!'); - // Channel - if(isset($update['channel_post'])) { - // Get chat_id and message_id - $chat_id = $update['channel_post']['chat']['id']; - $message_id = $update['channel_post']['message_id']; - // Supergroup - } else if ($update['message']['chat']['type'] == "supergroup") { - // Get chat_id and message_id - $chat_id = $update['message']['chat']['id']; - $message_id = $update['message']['message_id']; - } + // Channel + if(isset($update['channel_post'])) { + // Get chat_id and message_id + $chat_id = $update['channel_post']['chat']['id']; + $message_id = $update['channel_post']['message_id']; // Get raid_id from text. - $raid_id = 0; - if (isset($update['message']['text'])) { - $raid_id = substr(strrchr($update['message']['text'], "ID = "), 5); - } - - // Write cleanup info to database. - if ($raid_id > 0) { - insert_cleanup($chat_id, $message_id, $raid_id); - } - exit(); + $raid_id = substr(strrchr($update['channel_post']['text'], "ID = "), 5); + + // Supergroup + } else if ($update['message']['chat']['type'] == "supergroup") { + // Get chat_id and message_id + $chat_id = $update['message']['chat']['id']; + $message_id = $update['message']['message_id']; + + // Get raid_id from text. + $raid_id = substr(strrchr($update['message']['text'], "ID = "), 5); } -} + // Write cleanup info to database. + debug_log('Calling cleanup preparation now!'); + insert_cleanup($chat_id, $message_id, $raid_id); + exit(); +} From 32f0693f7fe25c76aeec4fedd6ec89f5f5e4053a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 7 Dec 2017 16:11:22 +0100 Subject: [PATCH 094/225] Changed cleanup table to work with negative numbers used by Telegram for supergroups and channels, removed end_time as it'll be realized by querying the raids table --- raid-pokemon-bot.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index 91b8d2d..2c55939 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -35,8 +35,7 @@ CREATE TABLE `attendance` ( CREATE TABLE `cleanup` ( `raid_id` int(10) unsigned NOT NULL, - `end_time` datetime NOT NULL, - `chat_id` bigint(20) unsigned NOT NULL, + `chat_id` bigint(20) signed NOT NULL, `message_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`raid_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 5e786f4ffbaaa2415c021ac1fe0677647a971278 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 7 Dec 2017 16:15:31 +0100 Subject: [PATCH 095/225] Removed end time from function to collect cleanup data, added run_cleanup function (work in progress) and added displaying of the username who created the raid poll --- logic.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/logic.php b/logic.php index 04d00ca..f3c80bf 100644 --- a/logic.php +++ b/logic.php @@ -416,7 +416,7 @@ function back_key($keys, $id, $action, $arg) } /** - * Insert cleanup. + * Insert cleanup info to database. * @param $chat_id * @param $message_id * @param $raid_id @@ -455,7 +455,6 @@ function insert_cleanup($chat_id, $message_id, $raid_id) " INSERT INTO cleanup SET raid_id = '{$raid_id}', - end_time = '{$raid['ts_end']}', chat_id = '{$chat_id}', message_id = '{$message_id}' ON DUPLICATE KEY @@ -468,6 +467,35 @@ function insert_cleanup($chat_id, $message_id, $raid_id) } } +/** + * Run cleanup. + */ +function run_cleanup () { + // Get cleanup info. + $rs = my_query( + " + SELECT * + FROM cleanup + " + ); + + // Fetch cleanup data. + $cleanup = $rs->fetch_assoc(); + + // Write to log. + debug_log("Chat_id:" . $cleanup['chat_id']); + debug_log("Message_id:" . $cleanup['message_id']); + debug_log("Raid_id:" . $cleanup['raid_id']); + + // Delete raid poll telegram message + + // Delete raid from raids table + + // Delete raid from attendance table + + // Delete info from cleanup table +} + /** * Keys vote. * @param $raid @@ -1113,9 +1141,27 @@ function show_raid_poll($raid) } } + // Display user which created the raid. + // Get user data. + $rs = my_query( + " + SELECT * + FROM users + WHERE user_id = {$raid['user_id']} + " + ); + + // Get the row. + $row = $rs->fetch_assoc(); + + // Display creator. + if ($row['user_id'] && $row['name']) { + $msg .= CR . 'Erstellt von: ' . htmlspecialchars($row['name']) . ''; + } + // Add update time and raid id to message. $msg .= CR . 'Aktualisiert: ' . unix2tz(time(), $raid['timezone'], 'H:i:s') . ''; - $msg .= ' ID = ' . $raid['id']; // Debug. + $msg .= ' ID = ' . $raid['id']; // DO NOT REMOVE! --> NEEDED FOR CLEANUP PREPARATION! // Return the message. return $msg; From 96265255532d796d3e03ba0aa219aeaca6f4601a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Sun, 10 Dec 2017 20:58:52 +0100 Subject: [PATCH 096/225] Added id column since raid_id may not be unique when shared to multiple chats --- raid-pokemon-bot.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index 2c55939..61abeed 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -34,11 +34,12 @@ CREATE TABLE `attendance` ( /*Table structure for table `cleanup` */ CREATE TABLE `cleanup` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `raid_id` int(10) unsigned NOT NULL, `chat_id` bigint(20) signed NOT NULL, `message_id` bigint(20) unsigned NOT NULL, - PRIMARY KEY (`raid_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; /*Table structure for table `gyms` */ From 7a16e2c3ab3e070b7cbafdf91952a7321c3a1b7c Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Sun, 10 Dec 2017 21:20:16 +0100 Subject: [PATCH 097/225] Added column to cleanup info from database once everything else is cleaned up --- raid-pokemon-bot.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index 61abeed..e21415d 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -38,6 +38,7 @@ CREATE TABLE `cleanup` ( `raid_id` int(10) unsigned NOT NULL, `chat_id` bigint(20) signed NOT NULL, `message_id` bigint(20) unsigned NOT NULL, + `cleaned` int(10) unsigned DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; From 28011168dc915a38efac8a42a876f82d797d8ab2 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 11 Dec 2017 00:34:15 +0100 Subject: [PATCH 098/225] Moved cleanup process up due to supergroup cleanup info collection issues and improved call for the cleanup logic --- index.php | 74 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/index.php b/index.php index 0d4fe5a..d8b3b37 100644 --- a/index.php +++ b/index.php @@ -71,17 +71,29 @@ debug_log('Update user: ' . $userUpdate); // Cleanup request received. -if (isset($update['cleanup'])) { +if (isset($update['cleanup']) && CLEANUP == true) { debug_log('Cleanup process request received...'); // Check access to cleanup of bot - if ($update['cleanup'] == CLEANUP_SECRET) { + if ($update['cleanup']['secret'] == CLEANUP_SECRET) { + // Get telegram cleanup value if specified. + if (isset($update['cleanup']['telegram'])) { + $telegram = $update['cleanup']['telegram']; + } else { + $telegram = 2; + } + // Get database cleanup value if specified. + if (isset($update['cleanup']['database'])) { + $database = $update['cleanup']['database']; + } else { + $database = 2; + } // Run cleanup debug_log('Calling cleanup process now!'); - run_cleanup(); + run_cleanup($telegram, $database); } // Exit after cleanup exit(); -} +} // Callback query received. if (isset($update['callback_query'])) { @@ -135,33 +147,7 @@ include_once('modules/raid_create.php'); exit(); -// Message is required to check for commands. -} else if (isset($update['message'])) { - // Check access to the bot - bot_access_check($update); - // Check message text for a leading slash. - if (substr($update['message']['text'], 0, 1) == '/') { - // Get command name. - $com = strtolower(str_replace('/', '', str_replace(BOT_NAME, '', explode(' ', $update['message']['text'])[0]))); - - // Set command path. - $command = 'commands/' . basename($com) . '.php'; - - // Write to log. - debug_log($command); - - // Check if command file exits. - if (file_exists($command)) { - // Dynamically include command file and exit. - include_once($command); - exit(); - } - - // Echo bot response. - sendMessage($update['message']['chat']['id'], 'Bitte sende mir zuerst einen Standort.'); - } - -// Cleanup channel / supergroup +// Cleanup collection from channel/supergroup messages. } else if ($update['channel_post']['chat']['type'] == "channel" || $update['message']['chat']['type'] == "supergroup") { // Write to log. debug_log('Collecting cleanup preparation information...'); @@ -191,4 +177,30 @@ debug_log('Calling cleanup preparation now!'); insert_cleanup($chat_id, $message_id, $raid_id); exit(); + +// Message is required to check for commands. +} else if (isset($update['message'])) { + // Check access to the bot + bot_access_check($update); + // Check message text for a leading slash. + if (substr($update['message']['text'], 0, 1) == '/') { + // Get command name. + $com = strtolower(str_replace('/', '', str_replace(BOT_NAME, '', explode(' ', $update['message']['text'])[0]))); + + // Set command path. + $command = 'commands/' . basename($com) . '.php'; + + // Write to log. + debug_log($command); + + // Check if command file exits. + if (file_exists($command)) { + // Dynamically include command file and exit. + include_once($command); + exit(); + } + + // Echo bot response. + sendMessage($update['message']['chat']['id'], 'Bitte sende mir zuerst einen Standort.'); + } } From d98878042693ad2e7a41e7961c0f62dc6ee64f88 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 11 Dec 2017 01:00:29 +0100 Subject: [PATCH 099/225] Added cleanup logic - feature is now complete and working without bugs! (as far as I know :D) TODO: Update readme and example config --- logic.php | 258 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 234 insertions(+), 24 deletions(-) diff --git a/logic.php b/logic.php index f3c80bf..9e53b66 100644 --- a/logic.php +++ b/logic.php @@ -321,7 +321,7 @@ function raid_edit_gyms_first_letter_keys($chatid, $chattype) { 'callback_data' => $chatid . ',' . $chattype . ':raid_by_gym:' . $first ); } - $previous = $first; + $previous = $first; } // Get the inline key array. @@ -446,9 +446,35 @@ function insert_cleanup($chat_id, $message_id, $raid_id) // Fetch raid data. $raid = $rs->fetch_assoc(); + + // Init found. + $found = false; // Insert cleanup info to database - if (!empty($raid)) { + if ($raid) { + // Check if cleanup info is already in database or not + // Needed since raids can be shared to multiple channels / supergroups! + $rs = my_query( + " + SELECT * + FROM cleanup + WHERE raid_id = '{$raid_id}' + " + ); + + // Chat_id and message_id equal to info from database + while ($cleanup = $rs->fetch_assoc()) { + // Leave while loop if cleanup info is already in database + if(($cleanup['chat_id'] == $chat_id) && ($cleanup['message_id'] == $message_id)) { + debug_log('Cleanup preparation info is already in database!'); + $found = true; + break; + } + } + } + + // Insert into database when raid found but no cleanup info found + if ($raid && !$found) { // Build query for cleanup table to add cleanup info to database debug_log('Adding cleanup info to database:'); $rs = my_query( @@ -457,11 +483,9 @@ function insert_cleanup($chat_id, $message_id, $raid_id) SET raid_id = '{$raid_id}', chat_id = '{$chat_id}', message_id = '{$message_id}' - ON DUPLICATE KEY - UPDATE raid_id = '{$raid_id}' " ); - } + } } else { debug_log('Invalid input for cleanup preparation!'); } @@ -469,31 +493,217 @@ function insert_cleanup($chat_id, $message_id, $raid_id) /** * Run cleanup. + * @param $telegram + * @param $database */ -function run_cleanup () { - // Get cleanup info. - $rs = my_query( - " - SELECT * - FROM cleanup - " - ); +function run_cleanup ($telegram = 2, $database = 2) { + // Check configuration, cleanup of telegram needs to happen before database cleanup! + if (CLEANUP_TIME_TG > CLEANUP_TIME_DB) { + debug_log('Configuration issue! Cleanup time for telegram messages needs to be lower or equal to database cleanup time!'); + debug_log('Stopping cleanup process now!'); + exit; + } - // Fetch cleanup data. - $cleanup = $rs->fetch_assoc(); + /* Check input + * 0 = Do nothing + * 1 = Cleanup + * 2 = Read from config + */ - // Write to log. - debug_log("Chat_id:" . $cleanup['chat_id']); - debug_log("Message_id:" . $cleanup['message_id']); - debug_log("Raid_id:" . $cleanup['raid_id']); + // Get cleanup values from config per default. + if ($telegram == 2) { + $telegram = (CLEANUP_TELEGRAM == true) ? 1 : 0; + } - // Delete raid poll telegram message + if ($database == 2) { + $database = (CLEANUP_DATABASE == true) ? 1 : 0; + } - // Delete raid from raids table - - // Delete raid from attendance table + // Start cleanup when at least one parameter is set to trigger cleanup + if ($telegram == 1 || $database == 1) { + // Get cleanup info. + $rs = my_query( + " + SELECT * + FROM cleanup + " + ); + + // Init empty cleanup jobs array. + $cleanup_jobs = array(); - // Delete info from cleanup table + // Fill array with cleanup jobs. + while ($rowJob = $rs->fetch_assoc()) { + $cleanup_jobs[] = $rowJob; + } + + // Write to log. + debug_log($cleanup_jobs); + + // Init previous raid id. + $prev_raid_id = "FIRST_RUN"; + + foreach ($cleanup_jobs as $row) { + // Set current raid id. + $current_raid_id = ($row['raid_id'] == 0) ? $row['cleaned'] : $row['raid_id']; + + // Write to log. + debug_log("Cleanup ID: " . $row['id']); + debug_log("Chat ID: " . $row['chat_id']); + debug_log("Message ID: " . $row['message_id']); + debug_log("Raid ID: " . $row['raid_id']); + + // Get raid data only when raid_id changed compared to previous run + if ($prev_raid_id != $current_raid_id) { + // Get the raid data by id. + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$current_raid_id} + " + ); + + // Fetch raid data. + $raid = $rs->fetch_assoc(); + + // Set times. + $end = $raid['ts_end']; + $tz = $raid['timezone']; + $now = $raid['ts_now']; + $cleanup_time_tg = 60*CLEANUP_TIME_TG; + $cleanup_time_db = 60*CLEANUP_TIME_DB; + + // Write times to log. + debug_log("Raid end time: " . unix2tz($end,$tz,"Y-m-d H:i:s")); + debug_log("Raid cleanup time: " . unix2tz(($end + $cleanup_time),$tz,"Y-m-d H:i:s")); + debug_log("Current time: " . unix2tz($now,$tz,"Y-m-d H:i:s")); + + // Write unix timestamps to log. + debug_log("Unix timestamps:"); + debug_log("Raid end time: " . $end); + debug_log("Telegram cleanup time: " . ($end + $cleanup_time_tg)); + debug_log("Database cleanup time: " . ($end + $cleanup_time_db)); + debug_log("Current time: " . $now); + } + + // Time for telegram cleanup? + if (($end + $cleanup_time_tg) < $now) { + // Delete raid poll telegram message if not already deleted + if ($telegram == 1 && $row['chat_id'] != 0 && $row['message_id'] != 0) { + // Delete telegram message. + debug_log('Deleting telegram message ' . $row['message_id'] . ' from chat ' . $row['chat_id'] . ' for raid ' . $row['raid_id']); + delete_message($row['chat_id'], $row['message_id']); + // Set database values of chat_id and message_id to 0 so we know telegram message was deleted already. + debug_log('Updating telegram cleanup inforamtion.'); + my_query( + " + UPDATE cleanup + SET chat_id = 0, + message_id = 0 + WHERE id = {$row['id']} + " + ); + } else { + if ($telegram == 1) { + debug_log('Telegram message is already deleted!'); + } else { + debug_log('Telegram cleanup was not triggered! Skipping...'); + } + } + } else { + debug_log('Skipping cleanup of telegram for this raid! Cleanup time has not yet come...'); + } + + // Time for database cleanup? + if (($end + $cleanup_time_db) < $now) { + // Delete raid from attendance table. + // Make sure to delete only once - raid may be in multiple channels/supergroups, but only 1 time in database + if (($database == 1) && $row['raid_id'] != 0 && ($prev_raid_id != $current_raid_id)) { + // Delete raid from attendance table. + debug_log('Deleting attendances for raid ' . $current_raid_id); + my_query( + " + DELETE FROM attendance + WHERE id = {$row['raid_id']} + " + ); + + // Set database value of raid_id to 0 so we know attendance info was deleted already + // Use raid_id in where clause since the same raid_id can in cleanup more than once + debug_log('Updating database cleanup inforamtion.'); + my_query( + " + UPDATE cleanup + SET raid_id = 0, + cleaned = {$row['raid_id']} + WHERE raid_id = {$row['raid_id']} + " + ); + } else { + if ($database == 1) { + debug_log('Attendances are already deleted!'); + } else { + debug_log('Attendance cleanup was not triggered! Skipping...'); + } + } + + // Delete raid from cleanup table and raid table once every value is set to 0 and cleaned got updated from 0 to the raid_id + // In addition trigger deletion only when previous and current raid_id are different to avoid unnecessary sql queries + if ($row['raid_id'] == 0 && $row['chat_id'] == 0 && $row['message_id'] == 0 && $row['cleaned'] != 0 && ($prev_raid_id != $current_raid_id)) { + // Delete raid from raids table. + debug_log('Deleting raid ' . $row['cleaned'] . ' from database.'); + my_query( + " + DELETE FROM raids + WHERE id = {$row['cleaned']} + " + ); + + // Get all cleanup jobs which will be deleted now. + debug_log('Removing cleanup info from database:'); + $rs_cl = my_query( + " + SELECT * + FROM cleanup + WHERE cleaned = {$row['cleaned']} + " + ); + + // Log each cleanup ID which will be deleted. + while($rs_cleanups = $rs_cl->fetch_assoc()) { + debug_log('Cleanup ID: ' . $rs_cleanups['id'] . ', Former Raid ID: ' . $rs_cleanups['cleaned']); + } + + // Finally delete from cleanup table. + my_query( + " + DELETE FROM cleanup + WHERE cleaned = {$row['cleaned']} + " + ); + } else { + if ($prev_raid_id != $current_raid_id) { + debug_log('Time for complete removal of raid from database has not yet come.'); + } else { + debug_log('Complete removal of raid from database was already done!'); + } + } + } else { + debug_log('Skipping cleanup of database for this raid! Cleanup time has not yet come...'); + } + + // Store current raid id as previous id for next loop + $prev_raid_id = $current_raid_id; + } + + // Write to log. + debug_log('Finished with cleanup process!'); + } } /** From f8e735b41b7512b98034d02f2aa8ce09dd3e0a56 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 11 Dec 2017 08:56:39 +0100 Subject: [PATCH 100/225] Updated example config for cleanup --- config.php.example | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config.php.example b/config.php.example index 7392658..a11027e 100644 --- a/config.php.example +++ b/config.php.example @@ -21,3 +21,10 @@ define('BOT_ACCESS', ''); // optional define('RAID_LOCATION', false); // send location as message in addition to raid poll message define('RAID_SLOTS', '15'); // minutes define('RAID_LAST_START', '10'); // minutes before RAID ends + +define('CLEANUP', false); // must be true for cleanup +define('CLEANUP_SECRET', 'your-cleanup-secret/passphrase'); +define('CLEANUP_TELEGRAM', true); +define('CLEANUP_TIME_TG', '10'); // minutes after RAID ended +define('CLEANUP_DATABASE', true); +define('CLEANUP_TIME_DB', '10080'); // minutes after RAID ended From 02c6820c131fc379f1dce3d5ab14f991c8e070b1 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 11 Dec 2017 12:14:06 +0100 Subject: [PATCH 101/225] Added cleanup features to readme --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 107b445..41a1fe2 100644 --- a/README.md +++ b/README.md @@ -68,11 +68,59 @@ Optionally you can you use Google maps API to lookup addresses of gyms based on Therefore get a Google maps API key and set it as `GOOGLE_API_KEY` in your config. -Activate it for both Geocoding and Time Zone API +To get a new API key, navigate to https://console.developers.google.com/apis/credentials and create a new API project, e.g. raid-telegram-bot -https://developers.google.com/maps/documentation/timezone/get-api-key +Once the project is created select "API key" from the "Create credentials" dropdown menu - a new API key is created. -https://developers.google.com/maps/documentation/geocoding/start#get-a-key +After the key is created, you need to activate it for both: Geocoding and Timezone API + +Therefore go to "Dashboard" on the left navigation pane and afterwards hit "Enable APIs and services" on top of the page. + +Search for Geocoding and Timezone API and enable them. Alternatively use these links to get to Geocoding and Timezone API services: + +https://console.developers.google.com/apis/library/timezone-backend.googleapis.com + +https://console.developers.google.com/apis/library/geocoding-backend.googleapis.com + +Finally check the dashboard again and make sure Google Maps Geocoding API and Google Maps Time Zone API are listed as enabled services. + +## Cleanup + +The bot features an automatic cleanup of telegram raid poll messages as well as cleanup of the database (attendance and raids tables). + +To activate cleanup you need to change the config and create a cronjob to trigger the cleanup process as follows: + +Set the `CLEANUP` in the config to `true` and define a cleanup secret/passphrase under `CLEANUP_SECRET`. + +Activate the cleanup of telegram messages and/or the database by setting `CLEANUP_TELEGRAM` / `CLEANUP_DATABASE` to true. + +Specify the amount of minutes which need to pass by after raid has ended before the bot executes the cleanup. Times are in minutes in `CLEANUP_TIME_TG` for telegram cleanup and `CLEANUP_TIME_DB` for database cleanup. + +The value for the minutes of the database cleanup `CLEANUP_TIME_DB` must be greater than then one for telegram cleanup `CLEANUP_TIME_TG`. Otherwise cleanup will do nothing and exit due to misconfiguration! + +Finally set up a cronjob to trigger the cleanup. You can also trigger telegram / database cleanup per cronjob: For no cleanup use 0, for cleanup use 1 and to use your config file use 2 or leave "telegram" and "database" out of the request data array. + +A few examples - make sure to replace the URL with yours: + +#### Cronjob using cleanup values from config.php: Just the secret without telegram/database OR telegram = 2 and database = 2 + +`curl -k -d '{"cleanup":{"secret":"your-cleanup-secret/passphrase"}}' https://localhost/index.php?apikey=111111111:AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP123` + +OR + +`curl -k -d '{"cleanup":{"secret":"your-cleanup-secret/passphrase","telegram":"2","database":"2"}}' https://localhost/index.php?apikey=111111111:AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP123` + +#### Cronjob to clean up telegram messages only: telegram = 1 and database = 0 + +`curl -k -d '{"cleanup":{"secret":"your-cleanup-secret/passphrase","telegram":"1","database":"0"}}' https://localhost/index.php?apikey=111111111:AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP123` + +#### Cronjob to clean up telegram messages and database: telegram = 1 and database = 1 + +`curl -k -d '{"cleanup":{"secret":"your-cleanup-secret/passphrase","telegram":"1","database":"1"}}' https://localhost/index.php?apikey=111111111:AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP123` + +#### Cronjob to clean up database and maybe telegram messages (when specified in config): telegram = 2 and database = 1 + +`curl -k -d '{"cleanup":{"secret":"your-cleanup-secret/passphrase","telegram":"2","database":"1"}}' https://localhost/index.php?apikey=111111111:AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP123` # Usage From 172621fa0c88e91bcefd75c64faa8f43d077624f Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 11 Dec 2017 13:36:39 +0100 Subject: [PATCH 102/225] Changed logging stuff to reflect recent changes to 15 minutes duplication check --- logic.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logic.php b/logic.php index 9e53b66..0e7feed 100644 --- a/logic.php +++ b/logic.php @@ -138,8 +138,8 @@ function raid_duplication_check($gym,$end) // Debug log unix times debug_log("Unix timestamp of endtime new raid: " . $end); - debug_log("Unix timestamp of endtime-5 existing raid: " . $ts_end_before); - debug_log("Unix timestamp of endtime+5 existing raid: " . $ts_end_after); + debug_log("Unix timestamp of endtime-15 existing raid: " . $ts_end_before); + debug_log("Unix timestamp of endtime+15 existing raid: " . $ts_end_after); // Debug log debug_log("Searched database for raids at " . $raid['gym_name']); From b7821c362eea3995722e93bbdc094abafde281b1 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 11 Dec 2017 14:27:59 +0100 Subject: [PATCH 103/225] Add message to raid poll if raid boss is in list for exclusive raids pokemon that ex-raid-pass is required to participate in raid Updated Pokemon Raid list with Absol --- constants.php | 5 +++++ logic.php | 15 ++++++++++++++- modules/raid_edit_poke.php | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/constants.php b/constants.php index 9dbc04a..a56b9e2 100644 --- a/constants.php +++ b/constants.php @@ -12,6 +12,7 @@ define('TEAM_UNKNOWN', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f680))); define('EMOJI_REFRESH', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f504))); define('EMOJI_GROUP', iconv('UCS-4LE', 'UTF-8', pack('V', 0x1f465))); +define('EMOJI_WARN', iconv('UCS-4LE', 'UTF-8', pack('V', 0x26A0))); // Teams. $teams = array( @@ -24,6 +25,9 @@ // Raid boss pokemon. $pokemon = array( + 'X' => array( + 'Mewtu', + ), '5' => array( 'Arktos', 'Lugia', @@ -51,6 +55,7 @@ 'Nidoking', 'Rizeros', 'Geowaz', + 'Absol', 'Level 4 Ei', ), '3' => array( diff --git a/logic.php b/logic.php index 0e7feed..2328f69 100644 --- a/logic.php +++ b/logic.php @@ -390,7 +390,7 @@ function pokemon_keys($raid_id, $raid_level, $pokemonlist, $action) } // Get the inline key array. - $keys = inline_key_array($keys, 4); + $keys = inline_key_array($keys, 3); return $keys; } @@ -1148,6 +1148,19 @@ function show_raid_poll($raid) debug_log($data); + // Add Ex-Raid Message if Pokemon is in Ex-Raid-List. + $pokemonlist = $GLOBALS['pokemon']; + foreach($pokemonlist as $level => $levelmons) { + if($level == "X") { + foreach($levelmons as $key => $pokemon) { + if(strtolower($pokemon) == strtolower($raid['pokemon'])) { + $msg.= CR . EMOJI_WARN . ' TEILNAHME IST NUR MIT EX-RAID-PASS MÖGLICH ' . EMOJI_WARN; + break 2; + } + } + } + } + // Add no attendance found message. if (count($data) == 0) { $msg .= CR . 'Noch keine Teilnehmer.' . CR; diff --git a/modules/raid_edit_poke.php b/modules/raid_edit_poke.php index 273bcf0..e71b032 100644 --- a/modules/raid_edit_poke.php +++ b/modules/raid_edit_poke.php @@ -20,6 +20,7 @@ // Iterate thru the pokemon list to get raid level $pokemonlist = $GLOBALS['pokemon']; foreach($pokemonlist as $level => $levelmons) { + if($level == "X") continue; debug_log("Searching raid boss '" . $old_pokemon . "' in level " . $level . " raids"); // Compare pokemon by pokemon to get raid level foreach($levelmons as $key => $pokemon) { From 1afeafb372181adcddb4e1da3ae077d2441ae9f5 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 12 Dec 2017 12:22:27 +0100 Subject: [PATCH 104/225] Added message if no active raids are found --- commands/list.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/commands/list.php b/commands/list.php index 3132bf1..14bbce2 100644 --- a/commands/list.php +++ b/commands/list.php @@ -40,6 +40,11 @@ ); while ($raid = $request->fetch_assoc()) { + if(!$raid) { + sendMessage($update['message']['from']['id'], 'Aktuell sind keine laufenden Raids im System!'); + exit; + } + // Create keys array. $keys = [ [ From 25a14bb1b6d2c18689957985e4fa9c2a6fb3e2c7 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 12 Dec 2017 12:22:44 +0100 Subject: [PATCH 105/225] Added get_chat function --- functions.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/functions.php b/functions.php index 56ff029..0df21a9 100644 --- a/functions.php +++ b/functions.php @@ -386,6 +386,32 @@ function delete_message($chat_id, $message_id) return curl_json_request($reply_json); } +/** + * GetChat + * @param $chatid + */ +function get_chat($chat_id) +{ + // Create response content array. + $reply_content = [ + 'method' => 'getChat', + 'chat_id' => $chat_id, + 'parse_mode' => 'HTML', + ]; + + // Encode data to json. + $reply_json = json_encode($reply_content); + + // Set header to json. + header('Content-Type: application/json'); + + // Write to log. + debug_log($reply_json, '>'); + + // Send request to telegram api. + return curl_json_request($reply_json); +} + /** * GetChatAdministrators * @param $chatid From ee443a86f836e46c844d74a2d8e86aa9c4290f02 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 12 Dec 2017 12:23:58 +0100 Subject: [PATCH 106/225] Improved bot_access_check and fixed SQL issue discovered by @Olimpius1985 --- logic.php | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/logic.php b/logic.php index 2328f69..121e999 100644 --- a/logic.php +++ b/logic.php @@ -4,31 +4,48 @@ * @param $update * @param $chat_id */ -function bot_access_check($update) +function bot_access_check($update, $access_type = BOT_ACCESS) { // Restricted or public access - if(!empty(BOT_ACCESS)) { - $chat_id = BOT_ACCESS; + if(!empty($access_type)) { + $all_chats = ''; + $all_chats .= !empty(MAINTAINER_ID) ? MAINTAINER_ID . ',' : ''; + $all_chats .= $access_type; - // Check each admin chat defined in BOT_ACCESS - $chats = explode(',', $chat_id); + // Check each admin chat defined in $access_type + $chats = explode(',', $all_chats); foreach($chats as $chat) { - + // Get chat object + $chat_obj = get_chat($chat); + debug_log("Getting chat object for '" . $chat . "'"); + + // Check chat object for proper response. + if ($chat_obj['ok'] == true) { + $allow_access = false; + // ID matching $chat and private chat type? + if ($chat_obj['result']['id'] == $chat && $chat_obj['result']['type'] == "private") { + $allow_access = true; + break; + } + } else { + debug_log('Chat ' . $chat . ' does not exist! Continuing with next chat...'); + continue; + } + // Get administrators from chat $response = get_admins($chat); debug_log("Getting administrators from chat '" . $chat . "'"); // Make sure we get a proper response if ($response['ok'] == true) { - $allow_access = false; foreach($response['result'] as $admin) { // If user is found as administrator allow access to the bot if ($admin['user']['id'] == $update['message']['from']['id'] || $admin['user']['id'] == $update['inline_query']['from']['id']) { $allow_access = true; - break; + break 2; } - } - } + } + } } // Prepare logging of username, first_name and/or id @@ -45,7 +62,7 @@ function bot_access_check($update) debug_log("Allowing access to the bot for user:" . CR . $msg); } else { debug_log("Denying access to the bot for user:" . CR . $msg); - $response_msg = 'You are not allowed to use this bot!'; + $response_msg = 'You are not allowed to use this command or bot!'; sendMessage($update['message']['chat']['id'], $response_msg); exit; } @@ -1174,7 +1191,8 @@ function show_raid_poll($raid) sum(team = 'valor') AS count_valor, sum(team = 'instinct') AS count_instinct, sum(team IS NULL) AS count_no_team, - sum(extra_people) AS extra + sum(extra_people) AS extra, + attend_time FROM attendance WHERE raid_id = {$raid['id']} AND attend_time IS NOT NULL From 0efa3b030060869418fda79b5adcc4690b55a9a6 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 12 Dec 2017 12:25:05 +0100 Subject: [PATCH 107/225] Added BOT_ADMINS in preparation of adding commands to add and remove moderator capabilities for bot users --- config.php.example | 1 + 1 file changed, 1 insertion(+) diff --git a/config.php.example b/config.php.example index a11027e..24c057f 100644 --- a/config.php.example +++ b/config.php.example @@ -16,6 +16,7 @@ define('DB_PASSWORD', 'your_database_password'); define('MAINTAINER', '@your_tg_username'); define('MAINTAINER_ID', 'your_tg_integer'); define('BOT_NAME', '@RaidPokemonBot'); +define('BOT_ADMINS', ''); // optional define('BOT_ACCESS', ''); // optional define('RAID_LOCATION', false); // send location as message in addition to raid poll message From 4de1366316afd1f78e3b31fa91d3113e9bd6f49a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 13 Dec 2017 16:10:07 +0100 Subject: [PATCH 108/225] Added some TODO / IDEA stuff so I don't forget --- README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 41a1fe2..427f837 100644 --- a/README.md +++ b/README.md @@ -190,13 +190,10 @@ Check your bot logfile and other related log files, e.g. apache/httpd log, php l # TODO: -* Cleanup logic to delete raid polls once a raid ended. - - arrived - set and show time - - create raid - check permissions (in group) - create raid moderators - allow create any raid - - geofencing - auto publish to chat - timezones - create api / command +* Moderators support: Add, remove and list moderators - only specified BOT_ADMINS are allowed to add, remove and list moderators +* Multilanguage support: Supporting multiple languages +* New gyms: Adding gyms to database without creating a raid via /raid +* Duplication check 2.0: Add support to notify user that a raid is already in the database when creating one via /start +* Preferred pokemon raid boss: When multiple level 5 raids are available, e.g. Lugia and Zapdos, add buttons to tell that you're coming a) only if Lugia, b) only if Zapdos, c) independently of the pokemon +* Delete raids: Allow BOT_ADMINS to delete raids +* Delete incomplete raids automatically: When a bot user starts to create a raid via /start, but does not finish the raid creation, incomplete raid data is stored in the raids table. A method to automatically delete them without interfering with raids just being created would be nice. From 821a6438129a274628c5619e8c3138e0c613b092 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 13 Dec 2017 16:12:19 +0100 Subject: [PATCH 109/225] Added moderator keys function, a NEXT key function and a get_user function to display info about a user/moderator --- logic.php | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 1 deletion(-) diff --git a/logic.php b/logic.php index 121e999..c1db844 100644 --- a/logic.php +++ b/logic.php @@ -2,7 +2,7 @@ /** * Bot access check. * @param $update - * @param $chat_id + * @param $access_type */ function bot_access_check($update, $access_type = BOT_ACCESS) { @@ -243,6 +243,139 @@ function get_gym($id) return $gym; } +/** + * Get user. + * @param $id + * @return message + */ +function get_user($id) +{ + // Get user details. + $rs = my_query( + " + SELECT * + FROM users + WHERE id = {$id} + " + ); + + // Fetch the row. + $row = $rs->fetch_assoc(); + + // Build message string. + $msg = ''; + + // Add name. + $msg .= 'Name: ' . htmlspecialchars($row['name']) . '' . CR; + + // Unknown team. + if ($row['team'] === NULL) { + $msg .= 'Team: ' . $GLOBALS['teams']['unknown'] . CR; + + // Known team. + } else { + $msg .= 'Team: ' . $GLOBALS['teams'][$row['team']] . CR; + } + + // Add level. + if ($row['level'] != 0) { + $msg .= 'Level: ' . $row['level'] . CR; + } + + return $msg; +} + +/** + * Moderator keys. + * @param $limit + * @param $action + * @return array + */ +function edit_moderator_keys($limit, $action) +{ + // Number of entries to display at once. + $entries = 10; + + // Init empty keys array. + $keys = array(); + + // Get moderators from database + if ($action == "list" || $action == "delete") { + $rs = my_query( + " + SELECT * + FROM users + WHERE moderator = 1 + ORDER BY name + LIMIT $limit, $entries + " + ); + + // Number of entries + $cnt = my_query( + " + SELECT COUNT(*) + FROM users + WHERE moderator = 1 + " + ); + } else if ($action == "add") { + $rs = my_query( + " + SELECT * + FROM users + WHERE (moderator = 0 OR moderator IS NULL) + ORDER BY name + LIMIT $limit, $entries + " + ); + + // Number of entries + $cnt = my_query( + " + SELECT COUNT(*) + FROM users + WHERE (moderator = 0 OR moderator IS NULL) + " + ); + } + + // Number of database entries found. + $sum = $cnt->fetch_row(); + $count = $sum['0']; + + // List users / moderators + while ($mod = $rs->fetch_assoc()) { + $keys[] = array( + 'text' => $mod['name'], + 'callback_data' => '0:mods_' . $action . ':' . $mod['id'] + ); + } + + // Add back key. + if ($limit > 0) { + $new_limit = $limit - $entries; + $empty_back_key = array(); + $key_back = back_key($empty_back_key, $new_limit, "mods", $action); + $key_back = $key_back[0]; + $keys = array_merge($key_back, $keys); + } + + // Add next key. + if (($limit + $entries) < $count) { + $new_limit = $limit + $entries; + $empty_next_key = array(); + $key_next = next_key($empty_next_key, $new_limit, "mods", $action); + $key_next = $key_next[0]; + $keys = array_merge($keys, $key_next); + } + + // Get the inline key array. + $keys = inline_key_array($keys, 1); + + return $keys; +} + /** * Inline key array. * @param $buttons @@ -432,6 +565,26 @@ function back_key($keys, $id, $action, $arg) return $keys; } +/** + * Next key. + * @param $keys + * @param $id + * @param $action + * @param $arg + * @return array + */ +function next_key($keys, $id, $action, $arg) +{ + $keys[] = [ + array( + 'text' => 'Weiter', + 'callback_data' => $id . ':' . $action . ':' . $arg + ) + ]; + + return $keys; +} + /** * Insert cleanup info to database. * @param $chat_id From abe0a7f1a1639a67d06e868aedfa81866afc3ef3 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 13 Dec 2017 16:13:36 +0100 Subject: [PATCH 110/225] Added moderator command /mods to list/add/delete moderators --- commands/mods.php | 35 +++++++++++++++++++++++++++++ modules/mods.php | 49 +++++++++++++++++++++++++++++++++++++++++ modules/mods_add.php | 38 ++++++++++++++++++++++++++++++++ modules/mods_delete.php | 38 ++++++++++++++++++++++++++++++++ modules/mods_list.php | 30 +++++++++++++++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 commands/mods.php create mode 100644 modules/mods.php create mode 100644 modules/mods_add.php create mode 100644 modules/mods_delete.php create mode 100644 modules/mods_list.php diff --git a/commands/mods.php b/commands/mods.php new file mode 100644 index 0000000..651fd03 --- /dev/null +++ b/commands/mods.php @@ -0,0 +1,35 @@ + 'Anzeigen', + 'callback_data' => '0:mods:list' + ], + [ + 'text' => 'Hinzufügen', + 'callback_data' => '0:mods:add' + ], + [ + 'text' => 'Löschen', + 'callback_data' => '0:mods:delete' + ] + ] +]; + +// Set message. +$msg = 'Moderatoren anzeigen, hinzufügen oder löschen:'; + +// Send message. +send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + +exit; diff --git a/modules/mods.php b/modules/mods.php new file mode 100644 index 0000000..c0672b9 --- /dev/null +++ b/modules/mods.php @@ -0,0 +1,49 @@ +Moderator gespeichert!' . CR . CR; + $msg .= 'Infos zum neuen Moderator:' . CR; + $msg .= get_user($id); + + // Create the keys. + $keys = []; + + // Edit message. + edit_message($update, $msg, $keys, false); + + // Build callback message string. + $callback_response = 'Moderator gespeichert!'; + + // Answer callback. + answerCallbackQuery($update['callback_query']['id'], $callback_response); + +} diff --git a/modules/mods_delete.php b/modules/mods_delete.php new file mode 100644 index 0000000..cd46b77 --- /dev/null +++ b/modules/mods_delete.php @@ -0,0 +1,38 @@ +Moderator entfernt!' . CR . CR; + $msg .= 'Infos zum ehemaligen Moderator:' . CR; + $msg .= get_user($id); + + // Create the keys. + $keys = []; + + // Edit message. + edit_message($update, $msg, $keys, false); + + // Build callback message string. + $callback_response = 'Moderator entfernt!'; + + // Answer callback. + answerCallbackQuery($update['callback_query']['id'], $callback_response); + +} diff --git a/modules/mods_list.php b/modules/mods_list.php new file mode 100644 index 0000000..b0b7f7b --- /dev/null +++ b/modules/mods_list.php @@ -0,0 +1,30 @@ + Date: Wed, 13 Dec 2017 23:22:18 +0100 Subject: [PATCH 111/225] Added button to switch view from minutes until raid start to clock time selection for raid start. Added an own 'Raid already running' button too --- modules/edit_poke.php | 93 +++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 20 deletions(-) diff --git a/modules/edit_poke.php b/modules/edit_poke.php index 26c5aea..f81bafb 100644 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -1,6 +1,6 @@ = 0; $i = $i - 1) { - // Create the keys. - $keys[] = array( - // Just show the time, no text - not everyone has a phone or tablet with a large screen... - //'text' => 'noch ' . floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), - 'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), - 'callback_data' => $id . ':edit_start:' . $i - ); + if ($arg == "minutes") { + // Set switch view. + $switch_text = "Uhrzeit-Ansicht"; + $switch_view = "clocktime"; + + for ($i = 1; $i <= 60; $i = $i + 1) { + // Create the keys. + $keys[] = array( + // Just show the time, no text - not everyone has a phone or tablet with a large screen... + 'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), + //'text' => unix2tz($now_plus_i,$tz,"H:i"), + 'callback_data' => $id . ':edit_start:' . $i + ); + } + } else { + // Set switch view. + $switch_text = "Minuten-Ansicht"; + $switch_view = "minutes"; + + // Timezone - maybe there's a more elegant solution as date_default_timezone_set?! + $tz = TIMEZONE; + date_default_timezone_set($tz); + + // Now + $now = time(); + + for ($i = 1; $i <= 60; $i = $i + 1) { + $now_plus_i = $now + $i*60; + // Create the keys. + $keys[] = array( + // Just show the time, no text - not everyone has a phone or tablet with a large screen... + //'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), + 'text' => unix2tz($now_plus_i,$tz,"H:i"), + 'callback_data' => $id . ':edit_start:' . $i + ); + } } + // Raid already running + $keys[] = array( + 'text' => "Raid läuft schon!", + 'callback_data' => $id . ':edit_start:0' + ); + + // Switch view: clocktime / minutes until start + $keys[] = array( + 'text' => $switch_text, + 'callback_data' => $id . ':edit_poke:' . $switch_view + ); + // Get the inline key array. $keys = inline_key_array($keys, 5); @@ -58,10 +103,18 @@ } // Edit the message. -edit_message($update, 'Wann beginnt der Raid?' . CR . CR . 'Raid läuft schon?' . CR .'Einfach 0:00 auswählen!', $keys); +if ($arg == "minutes") { + edit_message($update, 'In wie viel Minuten beginnt der Raid?', $keys); +} else { + edit_message($update, 'Wann beginnt der Raid?', $keys); +} // Build callback message string. -$callback_response = 'Pokemon gespeichert: ' . $data['arg']; +if ($arg == "minutes" || $arg == "clocktime") { + $callback_response = 'Ansicht geändert!'; +} else { + $callback_response = 'Pokemon gespeichert: ' . $data['arg']; +} // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); From 3ce6a27c14f98001088818ee0ce99fd83f15bc96 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 14 Dec 2017 17:01:01 +0100 Subject: [PATCH 112/225] Duplication check 2.0: Works now with /start command :D, Small adjustments to get_user and edit_mods_keys --- logic.php | 75 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/logic.php b/logic.php index c1db844..e84d4cb 100644 --- a/logic.php +++ b/logic.php @@ -145,42 +145,63 @@ function raid_duplication_check($gym,$end) // Timezone - maybe there's a more elegant solution as date_default_timezone_set?! $tz = TIMEZONE; date_default_timezone_set($tz); + + // Now + $now = time(); + + // Compare time - check minutes before and after database value + $beforeAfter = 15; + $extendBefore = 180; + + // Seems raid is being created at the moment + if ($raid['ts_end'] === NULL) { + // Compare via start_time. + $compare = "start"; + $time4compare = $now; + + // Set compare values. + $ts_compare_before = $raid['ts_start'] - ($beforeAfter*60); + $ts_compare_after = $raid['ts_start'] + ($beforeAfter*60); + } else { + // Compare via end_time. + $compare = "end"; + $time4compare = $now + $end*60; + + // Set compare values. + // Extend compare time for raid times if $time4compare is equal to $now which means $end must be 0 + $ts_compare_before = ($time4compare == $now) ? ($raid['ts_end'] - ($extendBefore*60)) : ($raid['ts_end'] - ($beforeiAfter*60)); + $ts_compare_after = $raid['ts_end'] + ($beforeAfter*60); + } - // Now + $end = endtime of new raid - $end = time() + $end*60; - - // Compare end time - check 15 minutes before and after database value - $ts_end_before = $raid['ts_end'] - (15*60); - $ts_end_after = $raid['ts_end'] + (15*60); - - // Debug log unix times - debug_log("Unix timestamp of endtime new raid: " . $end); - debug_log("Unix timestamp of endtime-15 existing raid: " . $ts_end_before); - debug_log("Unix timestamp of endtime+15 existing raid: " . $ts_end_after); + // Debug log unix times + debug_log('Unix timestamp of ' . $compare . 'time new raid: ' . $time4compare); + debug_log('Unix timestamp of ' . $compare . 'time -' . (($time4compare == $now) ? $extendBefore : $beforeAfter) . ' minutes of existing raid: ' . $ts_compare_before); + debug_log('Unix timestamp of ' . $compare . 'time +' . $beforeAfter . ' minutes of existing raid: ' . $ts_compare_after); // Debug log - debug_log("Searched database for raids at " . $raid['gym_name']); - debug_log("Database raid ID of last raid at ". $raid['gym_name'] . ": " . $raid['id']); - debug_log("New raid at " . $raid['gym_name'] . " will end: " . unix2tz($end,$tz)); - debug_log("Existing raid at " . $raid['gym_name'] . " will end between " . unix2tz($ts_end_before,$tz) . " and " . unix2tz($ts_end_after,$tz)); + debug_log('Searched database for raids at ' . $raid['gym_name']); + debug_log('Database raid ID of last raid at '. $raid['gym_name'] . ': ' . $raid['id']); + debug_log('New raid at ' . $raid['gym_name'] . ' will ' . $compare . ': ' . unix2tz($time4compare,$tz)); + debug_log('Existing raid at ' . $raid['gym_name'] . ' will ' . $compare . ' between ' . unix2tz($ts_compare_before,$tz) . ' and ' . unix2tz($ts_compare_after,$tz)); - // Check if end_time of new raid is between plus minus 5 minutes of existing raid - if($end >= $ts_end_before && $end <= $ts_end_after){ + // Check if end_time of new raid is between plus minus the specified minutes of existing raid + if($time4compare >= $ts_compare_before && $time4compare <= $ts_compare_after){ // Update existing raid. - $duplicate_id = $raid['id']; - debug_log("New raid matches end_time of existing raid!"); - debug_log("Updating raid ID: " . $duplicate_id); + // Negative raid ID if compare method is start and not end time + $duplicate_id = ($compare == "start") ? (0-$raid['id']) : $raid['id']; + debug_log('New raid matches ' . $compare . 'time of existing raid!'); + debug_log('Updating raid ID: ' . $duplicate_id); } else { // Create new raid. - debug_log("New raid end_time does not match the end_time of existing raid."); - debug_log("Creating new raid at gym: " . $raid['gym_name']); + debug_log('New raid ' . $compare . 'time does not match the ' . $compare . 'time of existing raid.'); + debug_log('Creating new raid at gym: ' . $raid['gym_name']); } } else { debug_log("Gym '" . $gym . "' not found in database!"); debug_log("Creating new raid at gym: " . $gym); } - // Return ID or 0 + // Return ID, -ID or 0 return $duplicate_id; } @@ -245,17 +266,17 @@ function get_gym($id) /** * Get user. - * @param $id + * @param $user_id * @return message */ -function get_user($id) +function get_user($user_id) { // Get user details. $rs = my_query( " SELECT * FROM users - WHERE id = {$id} + WHERE user_id = {$user_id} " ); @@ -348,7 +369,7 @@ function edit_moderator_keys($limit, $action) while ($mod = $rs->fetch_assoc()) { $keys[] = array( 'text' => $mod['name'], - 'callback_data' => '0:mods_' . $action . ':' . $mod['id'] + 'callback_data' => '0:mods_' . $action . ':' . $mod['user_id'] ); } From b5492cd4974bb48f936505d55dfee0acb71927c5 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 14 Dec 2017 17:02:25 +0100 Subject: [PATCH 113/225] Duplication check 2.0 adjustment since raid_id can now be negative, so make sure it is greater 0 --- commands/raid.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/raid.php b/commands/raid.php index 194d7e1..47c7d32 100644 --- a/commands/raid.php +++ b/commands/raid.php @@ -75,7 +75,7 @@ // Insert new raid or update existing raid? $raid_id = raid_duplication_check($name,($endtime + $countdown)); -if ($raid_id != 0){ +if ($raid_id > 0){ // Update pokemon and team in raids table. my_query( " From b9a8a80ee11f48bda74333e2fc259d70a36089c0 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 14 Dec 2017 17:03:42 +0100 Subject: [PATCH 114/225] Adjustments due to changed get_user function --- modules/mods_add.php | 7 +++---- modules/mods_delete.php | 9 ++++----- modules/mods_list.php | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/modules/mods_add.php b/modules/mods_add.php index de92118..3ae1066 100644 --- a/modules/mods_add.php +++ b/modules/mods_add.php @@ -5,7 +5,7 @@ debug_log($data); // Set the id. -$id = $data['arg']; +$user_id = $data['arg']; if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { // Update the user. @@ -13,15 +13,14 @@ " UPDATE users SET moderator = 1 - WHERE id = {$id} + WHERE user_id = {$user_id} " ); // Build message string. $msg = ''; $msg .= 'Moderator gespeichert!' . CR . CR; - $msg .= 'Infos zum neuen Moderator:' . CR; - $msg .= get_user($id); + $msg .= get_user($user_id); // Create the keys. $keys = []; diff --git a/modules/mods_delete.php b/modules/mods_delete.php index cd46b77..bf1d1af 100644 --- a/modules/mods_delete.php +++ b/modules/mods_delete.php @@ -5,7 +5,7 @@ debug_log($data); // Set the id. -$id = $data['arg']; +$user_id = $data['arg']; if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { // Update the user. @@ -13,15 +13,14 @@ " UPDATE users SET moderator = 0 - WHERE id = {$id} + WHERE user_id = {$user_id} " ); // Build message string. $msg = ''; - $msg .= 'Moderator entfernt!' . CR . CR; - $msg .= 'Infos zum ehemaligen Moderator:' . CR; - $msg .= get_user($id); + $msg .= 'Moderator entfernt!' . CR; + $msg .= get_user($user_id); // Create the keys. $keys = []; diff --git a/modules/mods_list.php b/modules/mods_list.php index b0b7f7b..765faca 100644 --- a/modules/mods_list.php +++ b/modules/mods_list.php @@ -5,7 +5,7 @@ debug_log($data); // Set the id. -$id = $data['arg']; +$user_id = $data['arg']; if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { // Build message string. @@ -13,7 +13,7 @@ $msg .= 'Infos zum Moderator:' . CR; // Add name. - $msg .= get_user($id); + $msg .= get_user($user_id); // Create the keys. $keys = []; From 64f30647075425c54b10879a14e5dae39cd37b31 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 14 Dec 2017 17:08:09 +0100 Subject: [PATCH 115/225] Added duplication check to raid creation via /start to warn user when raid is already created or someone else is creating the raid currently --- modules/raid_create.php | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/modules/raid_create.php b/modules/raid_create.php index 467e931..4973694 100644 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -93,6 +93,71 @@ $fullAddress .= (!empty($addr['district']) ? $addr['district'] : ""); } +// Insert new raid or warn about existing raid? +$raid_id = raid_duplication_check($gym_name,0); + +// Insert new raid +if ($raid_id != 0) { + // Check raid ID + // Positive ID: Raid is completely created + // Negative ID: Raid is being created at the moment + $raid_status = (substr($raid_id, 0, 1) == '-') ? 'start' : 'end'; + + // Change negative raid ID to positive ID + $raid_id = ($raid_status == "start") ? (ltrim($raid_id, '-')) : $raid_id; + + // Get the raid data by id. + $rs = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = {$raid_id} + " + ); + + // Fetch raid data. + $raid = $rs->fetch_assoc(); + + // Create the keys. + if ($raid_status == "end") { + // Update pokemon? + $keys = [ + [ + [ + 'text' => 'Pokemon aktualisieren', + 'callback_data' => $raid['id'] . ':raid_edit_poke:' . $raid['pokemon'], + ] + ], + [ + [ + 'text' => 'Teilen', + 'switch_inline_query' => strval($raid['id']) + ] + ] + ]; + } else { + $keys = []; + } + + // Build message string. + $msg = ($raid_status == "start") ? ('Raid wird gerade angelegt von:' . CR . get_user($raid['user_id'])) : ('Raid existiert bereits!' . CR . show_raid_poll_small($raid)); + + // Edit the message. + edit_message($update, $msg, $keys); + + // Build callback message string. + $callback_response = 'OK'; + + // Answer callback. + answerCallbackQuery($update['callback_query']['id'], $callback_response); + + exit(); +} + // Address found. if (!empty($fullAddress)) { // Create raid with address. From 9d6d2f76c39f852b9daa114a428b7ab93bebf0a1 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Dec 2017 23:40:43 +0100 Subject: [PATCH 116/225] Update README Add some overview of access permissions. Access permissions, e.g. raid_access_check will need to be re-worked, so BOT_ADMINS and MAINTAINER_ID don't need to be moderators to do anything. Currently you'll need to add them as moderator that they are possible to do anything and pass raid_access_check. --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 427f837..9ea912b 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,27 @@ OR `curl -k -d '{"cleanup":{"secret":"your-cleanup-secret/passphrase","telegram":"2","database":"1"}}' https://localhost/index.php?apikey=111111111:AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP123` +# Access permissions + +With BOT_ADMINS and BOT_ACCESS being used to restrict access, there are several access roles / types. When you do not configure BOT_ACCESS, everyone will have access to your bot (public access). + +As MAINTAINER_ID and as a member of BOT_ADMINS you have the permissions to do anything. But for some actions you'll need to make yourself a moderator. +(#TODO: MAINTAINER_ID and BOT_ADMINS should be able to do anything even when they're not moderator) + +As a member of BOT_ACCESS you can create raid polls, update your own raid polls' pokemon and change the gym team of your last raid poll. BOT_ACCESS members who are moderators can change the gym name and update raid polls' pokemon of others. + +Telegram Users can only vote on raid polls, but have no access to other bot functions. + + +| Access | Database | Raid poll | | | Pokemon | | Gym | | Moderators | | | Help | +|---------------|-----------|-----------|--------------------------------------|------------------|-------------------------------|-------------------------------|-----------------|------------------|------------------|-----------------|--------------------|------------------| +| | | **Vote** | **Create** `/start`, `/raid`, `/new` | **List** `/list` | **All raid polls** `/pokemon` | **Own raid polls** `/pokemon` | **Name** `/gym` | **Team** `/team` | **List** `/mods` | **Add** `/mods` | **Delete** `/mods` | **Show** `/help` | +| MAINTAINER_ID | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | +| BOT_ADMINS | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | +| BOT_ACCESS | Moderator | Yes | Yes | Yes | Yes | Yes | Yes | Yes | | | | Yes | +| BOT_ACCESS | User | Yes | Yes | Yes | | Yes | | Yes | | | | Yes | +| Telegram | User | Yes | | | | | | | | | | | + # Usage ## Bot commands From 247492bf3f51e2d2814c41a7b6f003faf4f986a5 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 14 Dec 2017 23:44:11 +0100 Subject: [PATCH 117/225] Always add maintainer_id and bot_admins even when checking for access_type = bot_access --- logic.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/logic.php b/logic.php index e84d4cb..62d2a83 100644 --- a/logic.php +++ b/logic.php @@ -9,8 +9,10 @@ function bot_access_check($update, $access_type = BOT_ACCESS) // Restricted or public access if(!empty($access_type)) { $all_chats = ''; + // Always add maintainer and admins. $all_chats .= !empty(MAINTAINER_ID) ? MAINTAINER_ID . ',' : ''; - $all_chats .= $access_type; + $all_chats .= !empty(BOT_ADMINS) ? BOT_ADMINS . ',' : ''; + $all_chats .= ($access_type == BOT_ADMINS) ? '' : $access_type; // Check each admin chat defined in $access_type $chats = explode(',', $all_chats); From 0bd0abc985704d2d009eff786b22f86a2046ca55 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Fri, 15 Dec 2017 21:54:20 +0100 Subject: [PATCH 118/225] Language Support for EN, DE and NL --- commands/gym.php | 2 +- commands/new.php | 4 +- commands/pokemon.php | 2 +- commands/raid.php | 2 +- commands/start.php | 4 +- commands/team.php | 13 +- config.php.example | 2 + constants.php | 71 ++--- functions.php | 17 ++ geo_api.php | 4 +- index.php | 4 +- language.json | 517 +++++++++++++++++++++++++++++++++ logic.php | 68 ++--- modules/edit.php | 6 +- modules/edit_left.php | 14 +- modules/edit_poke.php | 6 +- modules/edit_start.php | 4 +- modules/raid_by_gym.php | 6 +- modules/raid_by_gym_letter.php | 4 +- modules/raid_create.php | 10 +- modules/raid_edit_poke.php | 6 +- modules/raid_set_poke.php | 4 +- 22 files changed, 650 insertions(+), 120 deletions(-) mode change 100644 => 100755 commands/gym.php mode change 100644 => 100755 commands/new.php mode change 100644 => 100755 commands/pokemon.php mode change 100644 => 100755 commands/raid.php mode change 100644 => 100755 commands/start.php mode change 100644 => 100755 commands/team.php mode change 100644 => 100755 config.php.example mode change 100644 => 100755 constants.php mode change 100644 => 100755 functions.php mode change 100644 => 100755 geo_api.php mode change 100644 => 100755 index.php create mode 100755 language.json mode change 100644 => 100755 logic.php mode change 100644 => 100755 modules/edit.php mode change 100644 => 100755 modules/edit_left.php mode change 100644 => 100755 modules/edit_poke.php mode change 100644 => 100755 modules/edit_start.php mode change 100644 => 100755 modules/raid_by_gym.php mode change 100644 => 100755 modules/raid_by_gym_letter.php mode change 100644 => 100755 modules/raid_create.php mode change 100644 => 100755 modules/raid_edit_poke.php mode change 100644 => 100755 modules/raid_set_poke.php diff --git a/commands/gym.php b/commands/gym.php old mode 100644 new mode 100755 index bcb6a3a..c2055d3 --- a/commands/gym.php +++ b/commands/gym.php @@ -18,7 +18,7 @@ ); // Send the message. - sendMessage($update['message']['chat']['id'], 'Der Arena Name wurde aktualisiert.'); + sendMessage($update['message']['chat']['id'], getTranslation('gym_name_updated')); } else { if ($update['message']['reply_to_message']['text']) { diff --git a/commands/new.php b/commands/new.php old mode 100644 new mode 100755 index 4a690ec..42e906e --- a/commands/new.php +++ b/commands/new.php @@ -20,13 +20,13 @@ $keys = [ [ [ - 'text' => 'Raid anlegen', + 'text' => getTranslation('create_a_raid'), 'callback_data' => $userid . ',' . $chattype . ':raid_create:' . $coords, ] ] ]; -$msg = "Koordination erfolgreich übermittelt!"; +$msg = getTranslation('coordination_succes'); // Send message. send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); diff --git a/commands/pokemon.php b/commands/pokemon.php old mode 100644 new mode 100755 index bd6eeb9..e30365b --- a/commands/pokemon.php +++ b/commands/pokemon.php @@ -46,7 +46,7 @@ $keys = [ [ [ - 'text' => 'Pokemon aktualisieren', + 'text' => getTranslation('refresh_pokemon'), 'callback_data' => $raid['id'] . ':raid_edit_poke:' . $raid['pokemon'], ] ] diff --git a/commands/raid.php b/commands/raid.php old mode 100644 new mode 100755 index 194d7e1..3209d6b --- a/commands/raid.php +++ b/commands/raid.php @@ -199,7 +199,7 @@ $keys = [ [ [ - 'text' => 'Teilen', + 'text' => getTranslation('share'), 'switch_inline_query' => strval($id), ] ] diff --git a/commands/start.php b/commands/start.php old mode 100644 new mode 100755 index c42d43f..4bc69e6 --- a/commands/start.php +++ b/commands/start.php @@ -10,14 +10,14 @@ $keys = [ [ [ - 'text' => 'Raid anlegen', + 'text' => getTranslation('create_a_raid'), 'callback_data' => $userid . ',' . $chattype . ':raid_by_gym_letter:0', ] ] ]; // Set message. -$msg = 'Bitte sende mir zuerst einen Standort.' . CR2 . CR . 'Oder lege ein Raid per Arena-Auswahl an:'; +$msg = '' . getTranslation('send_location') . '' . CR2 . CR . '' . getTranslation('raid_by_gym') . ''; // Send message. send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); diff --git a/commands/team.php b/commands/team.php old mode 100644 new mode 100755 index 6a26692..5f42085 --- a/commands/team.php +++ b/commands/team.php @@ -7,12 +7,13 @@ 'mystic' => 'mystic', 'instinct' => 'instinct', 'valor' => 'valor', - 'rot' => 'valor', - 'blau' => 'mystic', - 'gelb' => 'instinct', + getTranslation('red') => 'valor', + getTranslation('blue') => 'mystic', + getTranslation('yellow') => 'instinct', 'r' => 'valor', 'b' => 'mystic', - 'y' => 'instinct' + 'y' => 'instinct', + 'g' => 'instinct' ); // Valid team name. @@ -28,10 +29,10 @@ ); // Send the message. - sendMessage($update['message']['chat']['id'], 'Arena Team gesetzt auf: ' . ucfirst($teams[$gym_team])); + sendMessage($update['message']['chat']['id'], getTranslation('gym_team_set_to') . ucfirst($teams[$gym_team])); // Invalid team name. } else { // Send the message. - sendMessage($update['message']['chat']['id'], 'Ungültiger Team Name - schreibe: Mystic, Valor, Instinct oder Blau, Rot, Gelb'); + sendMessage($update['message']['chat']['id'], getTranslation('invalid_team')); } diff --git a/config.php.example b/config.php.example old mode 100644 new mode 100755 index a11027e..5861d87 --- a/config.php.example +++ b/config.php.example @@ -28,3 +28,5 @@ define('CLEANUP_TELEGRAM', true); define('CLEANUP_TIME_TG', '10'); // minutes after RAID ended define('CLEANUP_DATABASE', true); define('CLEANUP_TIME_DB', '10080'); // minutes after RAID ended + +define('LANGUAGE', 'EN'); // language for the text EN, DE or NL diff --git a/constants.php b/constants.php old mode 100644 new mode 100755 index a56b9e2..42021bc --- a/constants.php +++ b/constants.php @@ -26,51 +26,44 @@ // Raid boss pokemon. $pokemon = array( 'X' => array( - 'Mewtu', + getTranslation('mewtwo') ), '5' => array( - 'Arktos', - 'Lugia', - 'Lavados', - 'Zapdos', - 'Mewtu', - 'Mew', - 'Ho-Oh', - 'Celebi', - 'Raikou', - 'Entei', - 'Suicune', - 'Level 5 Ei', + getTranslation('articuno'), + getTranslation('lugia'), + getTranslation('moltres'), + getTranslation('zapdos'), + getTranslation('mew'), + getTranslation('hooh'), + getTranslation('celebi'), + getTranslation('raikou'), + getTranslation('entei'), + getTranslation('suicune'), + getTranslation('egg_5') ), '4' => array( - 'Despotar', - 'Relaxo', - 'Lapras', - 'Quappo', - 'Bisasflor', - 'Glurak', - 'Turtok', - 'Sarzenia', - 'Nidoqueen', - 'Nidoking', - 'Rizeros', - 'Geowaz', - 'Absol', - 'Level 4 Ei', + getTranslation('tyranitar'), + getTranslation('snorlax'), + getTranslation('lapras'), + getTranslation('poliwrath'), + getTranslation('victreebel'), + getTranslation('nidoqueen'), + getTranslation('nidoking'), + getTranslation('rhydon'), + getTranslation('golem'), + getTranslation('absol'), + getTranslation('egg_4') ), '3' => array( - 'Aquana', - 'Flamara', - 'Blitza', - 'Arkani', - 'Machomei', - 'Simsala', - 'Gengar', - 'Sichlor', - 'Porygon', - 'Amoroso', - 'Vulnona', - 'Level 3 Ei', + getTranslation('arcanine'), + getTranslation('machamp'), + getTranslation('alakazam'), + getTranslation('gengar'), + getTranslation('scyther'), + getTranslation('porygon'), + getTranslation('omastar'), + getTranslation('ninetails'), + getTranslation('egg_3') ) ); diff --git a/functions.php b/functions.php old mode 100644 new mode 100755 index 56ff029..aa370ee --- a/functions.php +++ b/functions.php @@ -484,3 +484,20 @@ function curl_json_request($json) // Return response. return $response; } + +/** + * Gets a table translation out of the json file. + * @param $text + * @return translation + */ +function getTranslation($text) +{ + debug_log($text); + + $str = file_get_contents('./language.json'); + + $json = json_decode($str, true); + $translation = $json[$text][LANGUAGE]; + + return $translation; +} diff --git a/geo_api.php b/geo_api.php old mode 100644 new mode 100755 index b8e7493..4cabe07 --- a/geo_api.php +++ b/geo_api.php @@ -15,7 +15,7 @@ function get_address($lat, $lon) $location['district'] = ''; // Set maps geocode url. - $url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $lat . ',' . $lon . '&language=de'; + $url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $lat . ',' . $lon . '&language=' . strtolower( LANGUAGE ); $googleApiKey = GOOGLE_API_KEY; @@ -112,7 +112,7 @@ function get_address($lat, $lon) // Rename street responses. switch ($location['street']) { case 'Unnamed Road': - $location['street'] = 'Irgendwo im Wald'; + $location['street'] = getTranslation('forrest'); break; } diff --git a/index.php b/index.php old mode 100644 new mode 100755 index d8b3b37..0f17a6d --- a/index.php +++ b/index.php @@ -10,8 +10,8 @@ // Include files. require_once('config.php'); require_once('debug.php'); -require_once('constants.php'); require_once('functions.php'); +require_once('constants.php'); require_once('logic.php'); require_once('geo_api.php'); @@ -201,6 +201,6 @@ } // Echo bot response. - sendMessage($update['message']['chat']['id'], 'Bitte sende mir zuerst einen Standort.'); + sendMessage($update['message']['chat']['id'], '' . getTranslation('send_location') . ''); } } diff --git a/language.json b/language.json new file mode 100755 index 0000000..d8c7e58 --- /dev/null +++ b/language.json @@ -0,0 +1,517 @@ +{ + "5stars" : { + "NL": "5 Sterren Raid", + "DE": "5 Stern Raid", + "EN": "5 Stars Raid" + }, + "4stars" : { + "NL": "4 Sterren Raid", + "DE": "4 Stern Raid", + "EN": "4 Stars Raid" + }, + "3stars" : { + "NL": "3 Sterren Raid", + "DE": "3 Stern Raid", + "EN": "3 Stars Raid" + }, + "2stars" : { + "NL": "2 Sterren Raid", + "DE": "2 Stern Raid", + "EN": "2 Stars Raid" + }, + "1stars" : { + "NL": "1 Sterren Raid", + "DE": "1 Stern Raid", + "EN": "1 Stars Raid" + }, + "back" : { + "NL": "Terug", + "DE": "Zurück", + "EN": "Back" + }, + "alone" : { + "NL": "Alleen", + "DE": "Alleine", + "EN": "Alone" + }, + "raid_done" : { + "NL": "Raid beëindigd", + "DE": "Raid beendet.", + "EN": "Raid done" + }, + "here" : { + "NL": "Ik ben er", + "DE": "Bin da", + "EN": "Here" + }, + "done" : { + "NL": "Klaar", + "DE": "Fertig", + "EN": "Done" + }, + "absent" : { + "NL": "Afwezig", + "DE": "Absage", + "EN": "Absent" + }, + "vote_updated" : { + "NL": "Stem geüpdatet", + "DE": "Montag", + "EN": "vote updated" + }, + "monday" : { + "NL": "Maandag", + "DE": "Abstimmung aktualisiert", + "EN": "Monday" + }, + "tuesday" : { + "NL": "Dinsdag", + "DE": "Dienstag", + "EN": "Tuesday" + }, + "wensday" : { + "NL": "Woensdag", + "DE": "Mittwoch", + "EN": "Wensday" + }, + "thursday" : { + "NL": "Donderdag", + "DE": "Donnerstag", + "EN": "Thursday" + }, + "friday" : { + "NL": "Vrijdag", + "DE": "Freitag", + "EN": "Friday" + }, + "saterday" : { + "NL": "Zaterdag", + "DE": "Samstag", + "EN": "Saterday" + }, + "sunday" : { + "NL": "Zondag", + "DE": "Sonntag", + "EN": "Sunday" + }, + "still" : { + "NL": "nog", + "DE": "noch", + "EN": "still" + }, + "raid_egg_opens" : { + "NL": "Raid ei gaat open", + "DE": "Raid-Ei öffnet sich um", + "EN": "Raid egg opens up" + }, + "exraid_pass" : { + "NL": "DEELNAME IS ALLEEN MOGELIJK MET EX-RAID PASS", + "DE": "TEILNAHME IST NUR MIT EX-RAID-PASS MÖGLICH", + "EN": "PARTICIPATION IS POSSIBLE ONLY WITH EX-RAID PASS" + }, + "no_participants_yet" : { + "NL": "Nog geen deelnemers", + "DE": "Noch keine Teilnehmer.", + "EN": "No participants yet" + }, + "finished" : { + "NL": "Klaar", + "DE": "Fertig", + "EN": "Finished" + }, + "cancel" : { + "NL": "Annuleren", + "DE": "Abgesagt", + "EN": "Cancel" + }, + "created_by" : { + "NL": "Aangemaakt door", + "DE": "Erstellt von", + "EN": "Created by" + }, + "updated" : { + "NL": "Bijgewerkt", + "DE": "Aktualisiert", + "EN": "Updated" + }, + "from" : { + "NL": "van", + "DE": "von", + "EN": "from" + }, + "to" : { + "NL": "tot", + "DE": "bis", + "EN": "to" + }, + "no_participants" : { + "NL": "Geen deelnemers", + "DE": "Keine Teilnehmer", + "EN": "No participants" + }, + "send_location" : { + "NL": "Stuur me alsjeblieft eerst een locatie.", + "DE": "Bitte sende mir zuerst einen Standort.", + "EN": "Please send me a location first" + }, + "mew" : { + "NL": "Mew", + "DE": "Mew", + "EN": "Mew" + }, + "mewtwo" : { + "NL": "Mewtwo", + "DE": "Mewtu", + "EN": "Mewtwo" + }, + "lugia" : { + "NL": "Lugia", + "DE": "Lugia", + "EN": "Lugia" + }, + "zapdos" : { + "NL": "Zapdos", + "DE": "Zapdos", + "EN": "Zapdos" + }, + "hooh" : { + "NL": "Ho-oh", + "DE": "Ho-oh", + "EN": "Ho-oh" + }, + "zapdos" : { + "NL": "Zapdos", + "DE": "Zapdos", + "EN": "Zapdos" + }, + "celebi" : { + "NL": "Celebi", + "DE": "Celebi", + "EN": "Celebi" + }, + "raikou" : { + "NL": "Raikou", + "DE": "Raikou", + "EN": "Raikou" + }, + "entei" : { + "NL": "Entei", + "DE": "Entei", + "EN": "Entei" + }, + "suicune" : { + "NL": "Suicune", + "DE": "Suicune", + "EN": "Suicune" + }, + "moltres" : { + "NL": "Moltres", + "DE": "Lavados", + "EN": "Moltres" + }, + "articuno" : { + "NL": "Articuno", + "DE": "Arktos", + "EN": "Articuno" + }, + "egg_5" : { + "NL": "Level 5 Ei", + "DE": "Level 5 Ei", + "EN": "Level 5 Egg" + }, + "egg_4" : { + "NL": "Level 4 Ei", + "DE": "Level 4 Ei", + "EN": "Level 4 Egg" + }, + "egg_3" : { + "NL": "Level 3 Ei", + "DE": "Level 3 Ei", + "EN": "Level 3 Egg" + }, + "lapras" : { + "NL": "Lapras", + "DE": "Lapras", + "EN": "Lapras" + }, + "nidoqueen" : { + "NL": "Nidoqueen", + "DE": "Nidoqueen", + "EN": "Nidoqueen" + }, + "nidoking" : { + "NL": "Nidoking", + "DE": "Nidoking", + "EN": "Nidoking" + }, + "absol" : { + "NL": "Absol", + "DE": "Absol", + "EN": "Absol" + }, + "tyranitar" : { + "NL": "Tyranitar", + "DE": "Despotar", + "EN": "Tyranitar" + }, + "snorlax" : { + "NL": "Snorlax", + "DE": "Relaxo", + "EN": "Snorlax" + }, + "golem" : { + "NL": "Golem", + "DE": "Geowaz", + "EN": "Golem" + }, + "rhydon" : { + "NL": "Rhydon", + "DE": "Rizeros", + "EN": "Rhydon" + }, + "porygon" : { + "NL": "Porygon", + "DE": "Porygon", + "EN": "Porygon" + }, + "gengar" : { + "NL": "Gengar", + "DE": "Gengar", + "EN": "Gengar" + }, + "poliwrath" : { + "NL": "Poliwrath", + "DE": "Quappo", + "EN": "Poliwrath" + }, + "victreebel" : { + "NL": "Victreebel", + "DE": "Sarzenia", + "EN": "Victreebel" + }, + "arcanine" : { + "NL": "Arcanine", + "DE": "Arkani", + "EN": "Arcanine" + }, + "machamp" : { + "NL": "Machamp", + "DE": "Machomei", + "EN": "Machamp" + }, + "alakazam" : { + "NL": "Alakazam", + "DE": "Simsala", + "EN": "Alakazam" + }, + "scyther" : { + "NL": "Scyther", + "DE": "Sichlor", + "EN": "Scyther" + }, + "omastar" : { + "NL": "Omastar", + "DE": "Amoroso", + "EN": "Omastar" + }, + "ninetails" : { + "NL": "Ninetails", + "DE": "Vulnona", + "EN": "Ninetails" + }, + "forrest" : { + "NL": "Ergens in het bos", + "DE": "Irgendwo im Wald", + "EN": "Somewhere in the forrest" + }, + "select_gym_first_letter" : { + "NL": "Selecteer alstublieft de eerste letter van de gym:", + "DE": "Bitte Anfangsbuchstabe der Arena auswählen:", + "EN": "Please select the first letter of the gym:" + }, + "select_gym" : { + "NL": "Beginletter geselecteerd.", + "DE": "Anfangsbuchstabe ausgewählt.", + "EN": "First letter selected." + }, + "create_raid" : { + "NL": "Begin Raid in", + "DE": "Erstelle Raid in", + "EN": "Create Raid in" + }, + "select_raid_level" : { + "NL": "Selecteer Raid level", + "DE": "Bitte Raid Level auswählen", + "EN": "Select Raid level" + }, + "gym_saved" : { + "NL": "Gym opgeslagen.", + "DE": "Arena gespeichert.", + "EN": "Gym saved." + }, + "select_raid_boss" : { + "NL": "Selecteer Raid baas", + "DE": "Raid Boss auswählen", + "EN": "Select Raid boss" + }, + "select_pokemon" : { + "NL": "Selecteer Pokemon", + "DE": "Pokemon auswählen", + "EN": "Select Pokemon" + }, + "raid_saved" : { + "NL": "Raid opgeslagen:", + "DE": "Raid gespeichert:", + "EN": "Raid saved:" + }, + "raid_boss_saved" : { + "NL": "Raid baas opgeslagen!", + "DE": "Raid-Boss gespeichert!", + "EN": "Raid boss saved!" + }, + "not_supported" : { + "NL": "Niet ondersteund", + "DE": "Nicht unterstützt", + "EN": "Not supported" + }, + "share" : { + "NL": "Delen", + "DE": "Teilen", + "EN": "Share" + }, + "set_gym_name_and_team" : { + "NL": "Optioneel - Gym naam and Gym Team:", + "DE": "Optional - Arena Name und Arena Team:", + "EN": "Optional - Gym name and Gym Team:" + }, + "set_gym_team" : { + "NL": "/gym Naam van de Gym", + "DE": "/gym Name der Arena", + "EN": "/gym Name of the Gym" + }, + "set_gym_team" : { + "NL": "/gym Naam van de Gym", + "DE": "/gym Name der Arena", + "EN": "/gym Name of the Gym" + }, + "set_gym_and_team" : { + "NL": "Optioneel - zet Gym en Team", + "DE": "Optional - Arena Team setzen", + "EN": "Optional - set Gym and Team" + }, + "end_time" : { + "NL": "Eindtijd gezet op ", + "DE": "Ablaufzeit gesetzt auf ", + "EN": "Endtime set to " + }, + "minutes" : { + "NL": " minuten", + "DE": " Minuten", + "EN": " minutes" + }, + "set_team" : { + "NL": " /team Mystic/Valor/Instinct/Blauw/Rood/Geel", + "DE": " /team Mystic/Valor/Instinct/Blau/Rot/Gelb", + "EN": " /team Mystic/Valor/Instinct/Blue/Red/Yellow" + }, + "raid_starts_when" : { + "NL": "Wanneer begint de Raid?", + "DE": "Wann beginnt der Raid?", + "EN": "When will the Raid begin?" + }, + "is_raid_active" : { + "NL": "Is de Raid al actief?", + "DE": "Raid läuft schon?", + "EN": "Is the Raid already active?" + }, + "select_0" : { + "NL": "Selecteer dan gewoon 0:00!", + "DE": "Einfach 0:00 auswählen!", + "EN": "Select then 0:00!" + }, + "pokemon_saved" : { + "NL": "Pokemon opgeslagen: ", + "DE": "Pokemon gespeichert: ", + "EN": "Pokemon saved: " + }, + "how_long_raid" : { + "NL": "Hoe lang duurt de Raid?", + "DE": "Wie lange dauert der Raid?", + "EN": "How long will the raid last?" + }, + "lead_time_set_to" : { + "NL": "Doorlooptijd ingesteld op ", + "DE": "Vorlaufzeit gesetzt auf ", + "EN": "Lead time set to " + }, + "select_gym_name" : { + "NL": "Selecteer Gym:", + "DE": "Bitte Arena auswählen:", + "EN": "Select Gym:" + }, + "here_we_go" : { + "NL": "Hier gaan we!", + "DE": "Los gehts!", + "EN": "Here we go!" + }, + "create_a_raid" : { + "NL": "Maak een Raid", + "DE": "Raid anlegen", + "EN": "Create a Raid" + }, + "coordination_succes" : { + "NL": "Coördinatie geslaagd!", + "DE": "Koordination erfolgreich übermittelt!", + "EN": "Coordination successfully transmitted!" + }, + "refresh_pokemon" : { + "NL": "Pokemon vernieuwen", + "DE": "Pokemon aktualisieren", + "EN": "Refresh Pokemon" + }, + "send_location" : { + "NL": "Stuur me alsjeblieft eerst een locatie.", + "DE": "Bitte sende mir zuerst einen Standort.", + "EN": "Please send me a location first." + }, + "raid_by_gym" : { + "NL": "Of maak een raid door een Gym te selecteren:", + "DE": "Oder lege ein Raid per Arena-Auswahl an:", + "EN": "Or make a raid per arena selection:" + }, + "red" : { + "NL": "rood", + "DE": "rot", + "EN": "red" + }, + "yellow" : { + "NL": "geel", + "DE": "gelb", + "EN": "yellow" + }, + "blue" : { + "NL": "blauw", + "DE": "blau", + "EN": "blue" + }, + "gym_team_set_to" : { + "NL": "Gym Team gezet op: ", + "DE": "Arena Team gesetzt auf: ", + "EN": "Gym Team set to: " + }, + "invalid_team" : { + "NL": "Ongeldige team naam: schrijf: Mystic, Valor, Instinct or Blauw, Rood, Geel ", + "DE": "Ungültiger Team Name - schreibe: Mystic, Valor, Instinct oder Blau, Rot, Gelb", + "EN": "Invalid team name - write: Mystic, Valor, Instinct or Blue, Red, Yellow " + }, + "gym_name_updated" : { + "NL": "Gym naam aangepast.", + "DE": "Der Arena Name wurde aktualisiert.", + "EN": "Gym name updated." + } + + + + + +} \ No newline at end of file diff --git a/logic.php b/logic.php old mode 100644 new mode 100755 index 2328f69..8ab77fb --- a/logic.php +++ b/logic.php @@ -260,28 +260,28 @@ function raid_edit_start_keys($id) $keys = [ [ [ - 'text' => '5 Sterne Raid', + 'text' => getTranslation('5stars'), 'callback_data' => $id . ':edit:5' ] ], [ [ - 'text' => '4 Sterne Raid', + 'text' => getTranslation('4stars'), 'callback_data' => $id . ':edit:4' ], [ - 'text' => '3 Sterne Raid', + 'text' => getTranslation('3stars'), 'callback_data' => $id . ':edit:3' ] // No raids for level 2 or 1 /* ], [ [ - 'text' => '2 Sterne Raid', + 'text' => getTranslation('2stars'), 'callback_data' => $id . ':edit:2' ], [ - 'text' => '1 Stern Raid', + 'text' => getTranslation('5stars'), 'callback_data' => $id . ':edit:1' ] */ ] @@ -407,7 +407,7 @@ function back_key($keys, $id, $action, $arg) { $keys[] = [ array( - 'text' => 'Zurück', + 'text' => getTranslation('back'), 'callback_data' => $id . ':' . $action . ':' . $arg ) ]; @@ -723,7 +723,7 @@ function keys_vote($raid) $keys = [ [ [ - 'text' => 'alleine', + 'text' => getTranslation('alleen'), 'callback_data' => $raid['id'] . ':vote:1' ], [ @@ -770,7 +770,7 @@ function keys_vote($raid) if ($end_time < $now) { $keys[] = [ array( - 'text' => 'Raid beendet.', + 'text' => getTranslation('raid_done'), 'callback_data' => $raid['id'] . ':vote_time:' . (ceil(time() / 900) * 900) ) ]; @@ -823,15 +823,15 @@ function keys_vote($raid) 'callback_data' => $raid['id'] . ':vote_refresh:0' ], [ - 'text' => 'Bin da', + 'text' => getTranslation('here'), 'callback_data' => $raid['id'] . ':vote_arrived:0' ], [ - 'text' => 'Fertig', + 'text' => getTranslation('done'), 'callback_data' => $raid['id'] . ':vote_done:0' ], [ - 'text' => 'Absage', + 'text' => getTranslation('absent'), 'callback_data' => $raid['id'] . ':vote_cancel:0' ], ]; @@ -840,7 +840,7 @@ function keys_vote($raid) $keys = [ [ [ - 'text' => 'Raid beendet', + 'text' => getTranslation('raid_done'), 'callback_data' => $raid['id'] . ':vote_refresh:0' ] ] @@ -958,7 +958,7 @@ function send_response_vote($update, $data, $new = false) // Edit the message. edit_message($update, $msg, $keys); // Change message string. - $msg = 'Abstimmung aktualisiert'; + $msg = getTranslation('vote_updated'); // Answer the callback. answerCallbackQuery($update['callback_query']['id'], $msg); } @@ -1001,25 +1001,25 @@ function weekday_number2name ($weekdaynumber) if(is_numeric($weekdaynumber) && $weekdaynumber <= 7) { switch($weekdaynumber) { case 1: - $weekday = "Montag"; + $weekday = getTranslation('monday'); break; case 2: - $weekday = "Dienstag"; + $weekday = getTranslation('tuesday'); break; case 3: - $weekday = "Mittwoch"; + $weekday = getTranslation('wensday'); break; case 4: - $weekday = "Donnerstag"; + $weekday = getTranslation('thursday'); break; case 5: - $weekday = "Freitag"; + $weekday = getTranslation('friday'); break; case 6: - $weekday = "Samstag"; + $weekday = getTranslation('saterday'); break; case 7: - $weekday = "Sonntag"; + $weekday = getTranslation('sunday'); break; } } @@ -1073,10 +1073,10 @@ function show_raid_poll($raid) $time_left = floor($raid['t_left'] / 60); if ( strpos(str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) , '-' ) !== false ) { // $time_left = 'beendet'; <-- REPLACED BY $tl_msg, so if clause below is still working ($time_left < 0) - $tl_msg = 'Raid beendet.'; + $tl_msg = ' ' . getTranslation('raid_done') . ''; } else { // Replace $time_left with $tl_msg too - $tl_msg = ' — noch ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h'; + $tl_msg = ' — ' . getTranslation('still') . ' ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h'; } // Raid has not started yet - adjust time left message @@ -1085,9 +1085,9 @@ function show_raid_poll($raid) $weekday_start = date('N', $raid['ts_start']); $raid_day = weekday_number2name ($weekday_start); if ($weekday_now == $weekday_start) { - $msg .= 'Raid-Ei öffnet sich um ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; + $msg .= '' . getTranslation('raid_egg_opens') . ' ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; } else { - $msg .= 'Raid-Ei öffnet sich am ' . $raid_day .' um ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; + $msg .= '' . getTranslation('raid_egg_opens') . ' ' . $raid_day .' um ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; } // Raid has started and active or already ended @@ -1154,7 +1154,7 @@ function show_raid_poll($raid) if($level == "X") { foreach($levelmons as $key => $pokemon) { if(strtolower($pokemon) == strtolower($raid['pokemon'])) { - $msg.= CR . EMOJI_WARN . ' TEILNAHME IST NUR MIT EX-RAID-PASS MÖGLICH ' . EMOJI_WARN; + $msg.= CR . EMOJI_WARN . ' ' . getTranslation('exraid_pass') . ' ' . EMOJI_WARN; break 2; } } @@ -1163,7 +1163,7 @@ function show_raid_poll($raid) // Add no attendance found message. if (count($data) == 0) { - $msg .= CR . 'Noch keine Teilnehmer.' . CR; + $msg .= CR . getTranslation('no_participants_yet') . CR; } $rs = my_query( @@ -1293,7 +1293,7 @@ function show_raid_poll($raid) if (isset($data['done']) ? count($data['done']) : '' ) { //if (count($data['done'])) { // Add to message. - $msg .= CR . TEAM_DONE . ' Fertig: ' . ' [' . count($data['done']) . ']' . CR; + $msg .= CR . TEAM_DONE . ' ' . getTranslation('finished') . ': ' . ' [' . count($data['done']) . ']' . CR; foreach ($data['done'] as $vv) { @@ -1316,7 +1316,7 @@ function show_raid_poll($raid) // Done. if ($vv['raid_done']) { - $msg .= '[Fertig ' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + $msg .= '[' . getTranslation('finished') . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; } // Add extra people. if ($vv['extra_people']) { @@ -1331,7 +1331,7 @@ function show_raid_poll($raid) if (isset($data['cancel']) ? count($data['cancel']) : '' ) { //if (count($data['cancel'])) { // Add to message. - $msg .= CR . TEAM_CANCEL . ' Abgesagt: ' . ' [' . count($data['cancel']) . ']' . CR; + $msg .= CR . TEAM_CANCEL . ' ' . getTranslation('cancel') . ': ' . ' [' . count($data['cancel']) . ']' . CR; foreach ($data['cancel'] as $vv) { @@ -1353,7 +1353,7 @@ function show_raid_poll($raid) // Cancel. if ($vv['cancel']) { - $msg .= '[Abgesagt ' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + $msg .= '[' . getTranslation('cancel') . ' ' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; } // Add extra people. if ($vv['extra_people']) { @@ -1379,11 +1379,11 @@ function show_raid_poll($raid) // Display creator. if ($row['user_id'] && $row['name']) { - $msg .= CR . 'Erstellt von: ' . htmlspecialchars($row['name']) . ''; + $msg .= CR . getTranslation('created_by') . ': ' . htmlspecialchars($row['name']) . ''; } // Add update time and raid id to message. - $msg .= CR . 'Aktualisiert: ' . unix2tz(time(), $raid['timezone'], 'H:i:s') . ''; + $msg .= CR . '' . getTranslation('updated') . ': ' . unix2tz(time(), $raid['timezone'], 'H:i:s') . ''; $msg .= ' ID = ' . $raid['id']; // DO NOT REMOVE! --> NEEDED FOR CLEANUP PREPARATION! // Return the message. @@ -1409,7 +1409,7 @@ function show_raid_poll_small($raid) } // Start time and end time if(!empty($raid['ts_start']) && !empty($raid['ts_end'])) { - $msg .= 'von ' . unix2tz($raid['ts_start'], $raid['timezone']) . ' bis ' . unix2tz($raid['ts_end'], $raid['timezone']) . '' . CR; + $msg .= '' . getTranslation('from') . ' ' . unix2tz($raid['ts_start'], $raid['timezone']) . ' ' . getTranslation('to') . ' ' . unix2tz($raid['ts_end'], $raid['timezone']) . '' . CR; } // Gym Name if(!empty($raid['gym_name'])) { @@ -1460,7 +1460,7 @@ function show_raid_poll_small($raid) } if (!$total) { - $msg .= 'Keine Teilnehmer' . CR; + $msg .= getTranslation('no_participants') . CR; } else { $msg .= EMOJI_GROUP . ' ' . $total . ' — ' . $msg_teams; } diff --git a/modules/edit.php b/modules/edit.php old mode 100644 new mode 100755 index b855105..8ff3094 --- a/modules/edit.php +++ b/modules/edit.php @@ -23,7 +23,7 @@ $keys = [ [ [ - 'text' => 'Nicht unterstützt', + 'text' => getTranslation('not_supported'), 'callback_data' => 'edit:not_supported' ] ] @@ -31,9 +31,9 @@ } if (isset($update['callback_query']['inline_message_id'])) { - editMessageText($update['callback_query']['inline_message_id'], 'Raid Boss auswählen:', $keys); + editMessageText($update['callback_query']['inline_message_id'], getTranslation('select_raid_boss') . ':', $keys); } else { - editMessageText($update['callback_query']['message']['message_id'], 'Raid Boss auswählen:', $keys, $update['callback_query']['message']['chat']['id'], $keys); + editMessageText($update['callback_query']['message']['message_id'], getTranslation('select_raid_boss') . ':', $keys, $update['callback_query']['message']['chat']['id'], $keys); } // Build callback message string. diff --git a/modules/edit_left.php b/modules/edit_left.php old mode 100644 new mode 100755 index e06f028..929dc98 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -24,7 +24,7 @@ $keys = [ [ [ - 'text' => 'Teilen', + 'text' => getTranslation('share'), 'switch_inline_query' => strval($id) ] ] @@ -48,23 +48,23 @@ // Build message string. $msg = ''; - $msg .= 'Raid gespeichert:' . CR; + $msg .= getTranslation('raid_saved') . CR; $msg .= show_raid_poll_small($raid) . CR; // Gym Name if(!empty($raid['gym_name'])) { - $msg .= 'Optional - Arena Team setzen:' . CR2; + $msg .= getTranslation('set_gym_and_team') . CR2; } else { - $msg .= 'Optional - Arena Name und Arena Team:' . CR2; - $msg .= '/gym Name der Arena' . CR; + $msg .= getTranslation('set_gym_name_and_team') . CR2; + $msg .= getTranslation('set_gym_team') . CR; } - $msg .= '/team Mystic/Valor/Instinct/Blau/Rot/Gelb'; + $msg .= getTranslation('set_team'); // Edit message. edit_message($update, $msg, $keys, false); // Build callback message string. - $callback_response = 'Ablaufzeit gesetzt auf ' . $data['arg'] . ' Minuten'; + $callback_response = getTranslation('end_time') . $data['arg'] . getTranslation('minutes'); // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/edit_poke.php b/modules/edit_poke.php old mode 100644 new mode 100755 index 26c5aea..804f05d --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -50,7 +50,7 @@ $keys = [ [ [ - 'text' => 'Not supported', + 'text' => getTranslation('not_supported'), 'callback_data' => 'edit:not_supported' ] ] @@ -58,10 +58,10 @@ } // Edit the message. -edit_message($update, 'Wann beginnt der Raid?' . CR . CR . 'Raid läuft schon?' . CR .'Einfach 0:00 auswählen!', $keys); +edit_message($update, getTranslation('raid_starts_when') . CR . CR . getTranslation('is_raid_active') . CR . getTranslation('select_0'), $keys); // Build callback message string. -$callback_response = 'Pokemon gespeichert: ' . $data['arg']; +$callback_response = getTranslation('pokemon_saved') . $data['arg']; // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/edit_start.php b/modules/edit_start.php old mode 100644 new mode 100755 index 5c513c4..fdc5674 --- a/modules/edit_start.php +++ b/modules/edit_start.php @@ -55,10 +55,10 @@ } // Edit the message. -edit_message($update, 'Wie lange dauert der Raid?', $keys); +edit_message($update, getTranslation('how_long_raid'), $keys); // Build callback message string. -$callback_response = 'Vorlaufzeit gesetzt auf ' . $data['arg'] . ' Minuten'; +$callback_response = getTranslation('lead_time_set_to') . $data['arg'] . getTranslation('minutes'); // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/raid_by_gym.php b/modules/raid_by_gym.php old mode 100644 new mode 100755 index 52be127..fb7e7bd --- a/modules/raid_by_gym.php +++ b/modules/raid_by_gym.php @@ -45,7 +45,7 @@ $keys = [ [ [ - 'text' => 'Not supported', + 'text' => getTranslation('not_supported'), 'callback_data' => 'edit:not_supported' ] ] @@ -55,10 +55,10 @@ } // Edit the message. -edit_message($update, 'Bitte Arena auswählen:', $keys); +edit_message($update, getTranslation('select_gym_name'), $keys); // Build callback message string. -$callback_response = 'Los gehts!'; +$callback_response = getTranslation('here_we_go'); // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/raid_by_gym_letter.php b/modules/raid_by_gym_letter.php old mode 100644 new mode 100755 index 6b7eb07..0836f2a --- a/modules/raid_by_gym_letter.php +++ b/modules/raid_by_gym_letter.php @@ -46,10 +46,10 @@ } // Edit the message. -edit_message($update, 'Bitte Anfangsbuchstabe der Arena auswählen:', $keys); +edit_message($update, getTranslation('select_gym_first_letter'), $keys); // Build callback message string. -$callback_response = 'Anfangsbuchstabe ausgewählt.'; +$callback_response = getTranslation('select_gym'); // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/raid_create.php b/modules/raid_create.php old mode 100644 new mode 100755 index 467e931..e5f5d09 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -150,15 +150,15 @@ } // Build message. -$msg = 'Erstelle Raid in: ' . $fullAddress . ''; +$msg = getTranslation('create_raid') . ': ' . $fullAddress . ''; // Answer callback or send message based on input prior raid creation if($gym_id != 0) { // Edit the message. - edit_message($update, $msg . CR . 'Bitte Raid Level auswählen:', $keys); + edit_message($update, $msg . CR . getTranslation('select_raid_level') . ':', $keys); // Build callback message string. - $callback_response = 'Arena gespeichert.'; + $callback_response = getTranslation('gym_saved'); // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); @@ -167,7 +167,7 @@ if ($chattype == 'private') { // Send the message. //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys); - send_message($chatid, $msg . CR . 'Bitte Raid Level auswählen:', $keys); + send_message($chatid, $msg . CR . getTranslation('select_raid_level') . ':', $keys); } else { //$reply_to = $update['message']['chat']['id']; @@ -178,7 +178,7 @@ // Send the message. //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); - send_message($chatid, $msg . CR . 'Bitte Raid Level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + send_message($chatid, $msg . CR . getTranslation('select_raid_level') . ':', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); } exit(); diff --git a/modules/raid_edit_poke.php b/modules/raid_edit_poke.php old mode 100644 new mode 100755 index e71b032..ac553fb --- a/modules/raid_edit_poke.php +++ b/modules/raid_edit_poke.php @@ -49,13 +49,13 @@ } if (isset($update['callback_query']['inline_message_id'])) { - editMessageText($update['callback_query']['inline_message_id'], 'Raid Boss auswählen:', $keys); + editMessageText($update['callback_query']['inline_message_id'], getTranslation('select_raid_boss') . ':', $keys); } else { - editMessageText($update['callback_query']['message']['message_id'], 'Raid Boss auswählen:', $keys, $update['callback_query']['message']['chat']['id'], $keys); + editMessageText($update['callback_query']['message']['message_id'], getTranslation('select_raid_boss') . ':', $keys, $update['callback_query']['message']['chat']['id'], $keys); } // Build callback message string. -$callback_response = 'Pokemon auswählen'; +$callback_response = getTranslation('select_pokemon'); // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/raid_set_poke.php b/modules/raid_set_poke.php old mode 100644 new mode 100755 index b1e0a1f..184243f --- a/modules/raid_set_poke.php +++ b/modules/raid_set_poke.php @@ -41,14 +41,14 @@ // Build message string. $msg = ''; - $msg .= 'Raid gespeichert:' . CR; + $msg .= getTranslation('raid_saved') . CR; $msg .= show_raid_poll_small($raid); // Edit message. edit_message($update, $msg, $keys, false); // Build callback message string. - $callback_response = 'Raid-Boss gespeichert!'; + $callback_response = getTranslation('raid_boss_saved'); // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); From 8ae01ad3cbdf913d4d35681b82b6a5e07c79a48b Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Fri, 15 Dec 2017 22:06:19 +0100 Subject: [PATCH 119/225] Translation fix --- language.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/language.json b/language.json index d8c7e58..ed8483d 100755 --- a/language.json +++ b/language.json @@ -2,27 +2,27 @@ "5stars" : { "NL": "5 Sterren Raid", "DE": "5 Stern Raid", - "EN": "5 Stars Raid" + "EN": "5 Star Raid" }, "4stars" : { "NL": "4 Sterren Raid", "DE": "4 Stern Raid", - "EN": "4 Stars Raid" + "EN": "4 Star Raid" }, "3stars" : { "NL": "3 Sterren Raid", "DE": "3 Stern Raid", - "EN": "3 Stars Raid" + "EN": "3 Star Raid" }, "2stars" : { "NL": "2 Sterren Raid", "DE": "2 Stern Raid", - "EN": "2 Stars Raid" + "EN": "2 Star Raid" }, "1stars" : { "NL": "1 Sterren Raid", "DE": "1 Stern Raid", - "EN": "1 Stars Raid" + "EN": "1 Star Raid" }, "back" : { "NL": "Terug", From d6826ad2723aa61c537c8707ccb22821df835c5a Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Fri, 15 Dec 2017 22:13:54 +0100 Subject: [PATCH 120/225] Insert Groudon Raid Boss --- constants.php | 1 + language.json | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/constants.php b/constants.php index 42021bc..5549324 100755 --- a/constants.php +++ b/constants.php @@ -39,6 +39,7 @@ getTranslation('raikou'), getTranslation('entei'), getTranslation('suicune'), + getTranslation('groudon'), getTranslation('egg_5') ), '4' => array( diff --git a/language.json b/language.json index ed8483d..7293869 100755 --- a/language.json +++ b/language.json @@ -214,6 +214,11 @@ "DE": "Arktos", "EN": "Articuno" }, + "groudon" : { + "NL": "Groudon", + "DE": "Groudon", + "EN": "Groudon" + }, "egg_5" : { "NL": "Level 5 Ei", "DE": "Level 5 Ei", From 2fe832896f4e4149881c3793331f819850d79646 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Fri, 15 Dec 2017 22:46:35 +0100 Subject: [PATCH 121/225] Fix spelling key --- logic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.php b/logic.php index 8ab77fb..1a86f1f 100755 --- a/logic.php +++ b/logic.php @@ -723,7 +723,7 @@ function keys_vote($raid) $keys = [ [ [ - 'text' => getTranslation('alleen'), + 'text' => getTranslation('alone'), 'callback_data' => $raid['id'] . ':vote:1' ], [ From 0a5f0e1fc81f1262d4315328e5f3d4c3d6ef4857 Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sun, 17 Dec 2017 12:52:54 +0100 Subject: [PATCH 122/225] Update edit_poke.php --- modules/edit_poke.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/edit_poke.php b/modules/edit_poke.php index 804f05d..1125c7f 100755 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -23,7 +23,7 @@ // Init empty keys array. $keys = array(); - for ($i = 60; $i >= 0; $i = $i - 1) { + for ($i = RAID_EGG_DURATION; $i >= 0; $i = $i - 1) { // Create the keys. $keys[] = array( // Just show the time, no text - not everyone has a phone or tablet with a large screen... From 9685407be33bc07226892b315845e28c297b4351 Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sun, 17 Dec 2017 12:54:29 +0100 Subject: [PATCH 123/225] Update config.php.example I added 'RAID_EGG_DURATION' 'RAID_POKEMON_DURATION' --- config.php.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config.php.example b/config.php.example index 5861d87..7249f77 100755 --- a/config.php.example +++ b/config.php.example @@ -22,6 +22,9 @@ define('RAID_LOCATION', false); // send location as message in addition to r define('RAID_SLOTS', '15'); // minutes define('RAID_LAST_START', '10'); // minutes before RAID ends +define ('RAID_EGG_DURATION', '60'); //minutes till egg comes out +define ('RAID_POKEMON_DURATION', '45'); //minutes till pokemon leave + define('CLEANUP', false); // must be true for cleanup define('CLEANUP_SECRET', 'your-cleanup-secret/passphrase'); define('CLEANUP_TELEGRAM', true); From 5c174368bd51f6a5966163189f3350d03247b80b Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sun, 17 Dec 2017 12:56:11 +0100 Subject: [PATCH 124/225] Update edit_start.php I added 'RAID_EGG_DURATION' 'RAID_POKEMON_DURATION' --- modules/edit_start.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/edit_start.php b/modules/edit_start.php index fdc5674..45be61d 100755 --- a/modules/edit_start.php +++ b/modules/edit_start.php @@ -26,10 +26,10 @@ // 1 Minute or 5 minute time slots if ($data['arg'] == 0) { - $slotmax = 60; + $slotmax = RAID_POKEMON_DURATION; $slotsize = 1; } else { - $slotmax = 120; + $slotmax = RAID_POKEMON_DURATION; $slotsize = 5; } From cc3328a42de401f838aaf323da6e4e2691c6c7cf Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Dec 2017 13:50:10 +0100 Subject: [PATCH 125/225] Language fixes --- language.json | 29 ++++++++++++----------------- logic.php | 11 ++++++----- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/language.json b/language.json index 7293869..7f217bc 100755 --- a/language.json +++ b/language.json @@ -40,7 +40,7 @@ "EN": "Raid done" }, "here" : { - "NL": "Ik ben er", + "NL": "Ben er", "DE": "Bin da", "EN": "Here" }, @@ -149,11 +149,6 @@ "DE": "Keine Teilnehmer", "EN": "No participants" }, - "send_location" : { - "NL": "Stuur me alsjeblieft eerst een locatie.", - "DE": "Bitte sende mir zuerst einen Standort.", - "EN": "Please send me a location first" - }, "mew" : { "NL": "Mew", "DE": "Mew", @@ -179,11 +174,6 @@ "DE": "Ho-oh", "EN": "Ho-oh" }, - "zapdos" : { - "NL": "Zapdos", - "DE": "Zapdos", - "EN": "Zapdos" - }, "celebi" : { "NL": "Celebi", "DE": "Celebi", @@ -394,11 +384,6 @@ "DE": "/gym Name der Arena", "EN": "/gym Name of the Gym" }, - "set_gym_team" : { - "NL": "/gym Naam van de Gym", - "DE": "/gym Name der Arena", - "EN": "/gym Name of the Gym" - }, "set_gym_and_team" : { "NL": "Optioneel - zet Gym en Team", "DE": "Optional - Arena Team setzen", @@ -420,7 +405,7 @@ "EN": " /team Mystic/Valor/Instinct/Blue/Red/Yellow" }, "raid_starts_when" : { - "NL": "Wanneer begint de Raid?", + "NL": "Wanneer gaat het Raid ei open?", "DE": "Wann beginnt der Raid?", "EN": "When will the Raid begin?" }, @@ -513,6 +498,16 @@ "NL": "Gym naam aangepast.", "DE": "Der Arena Name wurde aktualisiert.", "EN": "Gym name updated." + }, + "gym" : { + "NL": "Gym", + "DE": "Arena", + "EN": "Gym" + }, + "raid_to" : { + "NL": "Raid tot ", + "DE": "Raid bis ", + "EN": "Raid to " } diff --git a/logic.php b/logic.php index 1a86f1f..45981dd 100755 --- a/logic.php +++ b/logic.php @@ -1041,7 +1041,7 @@ function show_raid_poll($raid) if ($raid['gym_name'] || $raid['gym_team']) { // Add gym name to message. if ($raid['gym_name']) { - $msg .= 'Arena: ' . $raid['gym_name'] . ''; + $msg .= getTranslation('gym') . ': ' . $raid['gym_name'] . ''; } // Add team to message. if ($raid['gym_team']) { @@ -1100,7 +1100,7 @@ function show_raid_poll($raid) // Add time left message. } else { - $msg .= 'Raid bis ' . unix2tz($raid['ts_end'], $raid['timezone']); + $msg .= getTranslation('raid_to') . unix2tz($raid['ts_end'], $raid['timezone']); $msg .= $tl_msg . CR; } } @@ -1174,7 +1174,8 @@ function show_raid_poll($raid) sum(team = 'valor') AS count_valor, sum(team = 'instinct') AS count_instinct, sum(team IS NULL) AS count_no_team, - sum(extra_people) AS extra + sum(extra_people) AS extra, + attend_time FROM attendance WHERE raid_id = {$raid['id']} AND attend_time IS NOT NULL @@ -1273,11 +1274,11 @@ function show_raid_poll($raid) if ($vv['arrived']) { // No time is displayed, but undefined_index error in log, so changed it: //$msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; - $msg .= '[Bin da] '; + $msg .= getTranslation('here') . ' '; // Cancelled. } else if ($vv['cancel']) { - $msg .= '[abgesagt] '; + $msg .= getTranslation('cancel') . ' '; } // Add extra people. From 6209e62bdeb978bcc55e21c11ded8dca5f6ed5f7 Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sun, 17 Dec 2017 13:58:31 +0100 Subject: [PATCH 126/225] Update config.php.example --- config.php.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.php.example b/config.php.example index 7249f77..5b15730 100755 --- a/config.php.example +++ b/config.php.example @@ -23,7 +23,8 @@ define('RAID_SLOTS', '15'); // minutes define('RAID_LAST_START', '10'); // minutes before RAID ends define ('RAID_EGG_DURATION', '60'); //minutes till egg comes out -define ('RAID_POKEMON_DURATION', '45'); //minutes till pokemon leave +define ('RAID_POKEMON_DURATION_LONG', '45'); //minutes till pokemon leave +define ('RAID_POKEMON_DURATION_SHORT', '45'); //minutes till pokemon leave define('CLEANUP', false); // must be true for cleanup define('CLEANUP_SECRET', 'your-cleanup-secret/passphrase'); From 61f5c6d344a3cc9dda6d141ab0972d08a471dd7a Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sun, 17 Dec 2017 13:59:22 +0100 Subject: [PATCH 127/225] Update edit_start.php --- modules/edit_start.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/edit_start.php b/modules/edit_start.php index 45be61d..93e1740 100755 --- a/modules/edit_start.php +++ b/modules/edit_start.php @@ -26,10 +26,10 @@ // 1 Minute or 5 minute time slots if ($data['arg'] == 0) { - $slotmax = RAID_POKEMON_DURATION; + $slotmax = RAID_POKEMON_DURATION_SHORT; $slotsize = 1; } else { - $slotmax = RAID_POKEMON_DURATION; + $slotmax = RAID_POKEMON_DURATION_LONG; $slotsize = 5; } From f5aed45ef408bac3fd4defb064b3c638e8dc8bae Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Sun, 17 Dec 2017 19:59:46 +0100 Subject: [PATCH 128/225] Allow moderators to edit any raid --- commands/pokemon.php | 8 +++++++- logic.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/commands/pokemon.php b/commands/pokemon.php index bd6eeb9..fa51d56 100644 --- a/commands/pokemon.php +++ b/commands/pokemon.php @@ -35,7 +35,13 @@ UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids WHERE end_time>NOW() - AND user_id = {$update['message']['from']['id']} + AND (user_id = {$update['message']['from']['id']} + OR user_id IN ( + SELECT user_id + FROM users + WHERE moderator = 1 + ) + ) AND timezone='{$row['timezone']}' ORDER BY end_time ASC LIMIT 20 " diff --git a/logic.php b/logic.php index 62d2a83..c0f7304 100644 --- a/logic.php +++ b/logic.php @@ -99,7 +99,7 @@ function raid_access_check($update, $data) SELECT COUNT(*) FROM users WHERE user_id = {$update['callback_query']['from']['id']} - AND moderator = 1 + OR moderator = 1 " ); From 915fdb496ac97316c67b431c9085390c6708f43b Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 18 Dec 2017 13:47:14 +0100 Subject: [PATCH 129/225] Added handling for moderators who have not votet on a raid before by using the default timezone from config --- commands/pokemon.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/commands/pokemon.php b/commands/pokemon.php index 111cdc7..8bdbf85 100755 --- a/commands/pokemon.php +++ b/commands/pokemon.php @@ -21,8 +21,11 @@ // No data found. if (!$row) { - sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); - exit; + //sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + //exit; + $tz = TIMEZONE; +} else { + $tz = $row['timezone']; } // Build query. @@ -35,14 +38,7 @@ UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids WHERE end_time>NOW() - AND (user_id = {$update['message']['from']['id']} - OR user_id IN ( - SELECT user_id - FROM users - WHERE moderator = 1 - ) - ) - AND timezone='{$row['timezone']}' + AND timezone='{$tz}' ORDER BY end_time ASC LIMIT 20 " ); From 80130fb02ee4c5758a5d6b64b2661f8ddaeaabfa Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 18 Dec 2017 15:56:33 +0100 Subject: [PATCH 130/225] Language optimizations --- commands/pokemon.php | 2 +- commands/team.php | 2 +- language.json | 49 +++++++++++++++++++++++++++--------------- modules/edit_left.php | 2 +- modules/edit_start.php | 2 +- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/commands/pokemon.php b/commands/pokemon.php index 8bdbf85..6a0bbe4 100755 --- a/commands/pokemon.php +++ b/commands/pokemon.php @@ -48,7 +48,7 @@ $keys = [ [ [ - 'text' => getTranslation('refresh_pokemon'), + 'text' => getTranslation('update_pokemon'), 'callback_data' => $raid['id'] . ':raid_edit_poke:' . $raid['pokemon'], ] ] diff --git a/commands/team.php b/commands/team.php index 5f42085..cbfe2f1 100755 --- a/commands/team.php +++ b/commands/team.php @@ -29,7 +29,7 @@ ); // Send the message. - sendMessage($update['message']['chat']['id'], getTranslation('gym_team_set_to') . ucfirst($teams[$gym_team])); + sendMessage($update['message']['chat']['id'], getTranslation('gym_team_set_to') . ' ' . ucfirst($teams[$gym_team])); // Invalid team name. } else { diff --git a/language.json b/language.json index 579e63a..5112632 100755 --- a/language.json +++ b/language.json @@ -62,7 +62,7 @@ "vote_updated" : { "NL": "Stem geüpdatet", "DE": "Abstimmung aktualisiert", - "EN": "vote updated" + "EN": "Vote updated" }, "monday" : { "NL": "Maandag", @@ -349,6 +349,16 @@ "DE": "Anfangsbuchstabe ausgewählt.", "EN": "First letter selected." }, + "raid_being_created_by_other_user" : { + "NL": "Another user is currently creating a raid for this gym:", + "DE": "Ein Raid für diese Arena wird gerade angelegt von:", + "EN": "Another user is currently creating a raid for this gym:" + }, + "raid_already_exists" : { + "NL": "Raid already exists!", + "DE": "Raid existiert bereits!", + "EN": "Raid already exists!" + }, "create_raid" : { "NL": "Begin Raid in", "DE": "Erstelle Raid in", @@ -420,9 +430,9 @@ "EN": "Optional - set Gym and Team" }, "set_gym_team_command" : { - "NL": " /team Mystic/Valor/Instinct/Blauw/Rood/Geel", - "DE": " /team Mystic/Valor/Instinct/Blau/Rot/Gelb", - "EN": " /team Mystic/Valor/Instinct/Blue/Red/Yellow" + "NL": "/team Mystic/Valor/Instinct/Blauw/Rood/Geel", + "DE": "/team Mystic/Valor/Instinct/Blau/Rot/Gelb", + "EN": "/team Mystic/Valor/Instinct/Blue/Red/Yellow" }, "end_time" : { "NL": "Eindtijd gezet op ", @@ -430,9 +440,9 @@ "EN": "Endtime set to " }, "minutes" : { - "NL": " minuten", - "DE": " Minuten", - "EN": " minutes" + "NL": "minuten", + "DE": "Minuten", + "EN": "minutes" }, "raid_starts_when" : { "NL": "Wanneer begint de Raid?", @@ -464,6 +474,11 @@ "DE": "Raid läuft schon!", "EN": "Raid is already active!" }, + "raid_access_denied" : { + "NL": "You are not allowed to edit this raid!", + "DE": "Sie haben keine Berechtigung dieses Raid zu bearbeiten!", + "EN": "You are not allowed to edit this raid!" + }, "pokemon_saved" : { "NL": "Pokemon opgeslagen: ", "DE": "Pokemon gespeichert: ", @@ -475,9 +490,9 @@ "EN": "How long will the raid last?" }, "lead_time_set_to" : { - "NL": "Doorlooptijd ingesteld op ", - "DE": "Vorlaufzeit gesetzt auf ", - "EN": "Lead time set to " + "NL": "Doorlooptijd ingesteld op", + "DE": "Vorlaufzeit gesetzt auf", + "EN": "Lead time set to" }, "select_gym_name" : { "NL": "Selecteer Gym:", @@ -496,13 +511,13 @@ }, "coordination_succes" : { "NL": "Coördinatie geslaagd!", - "DE": "Koordination erfolgreich übermittelt!", - "EN": "Coordination successfully transmitted!" + "DE": "Koordinaten erfolgreich übermittelt!", + "EN": "Coordinates successfully submitted!" }, - "refresh_pokemon" : { + "update_pokemon" : { "NL": "Pokemon vernieuwen", "DE": "Pokemon aktualisieren", - "EN": "Refresh Pokemon" + "EN": "Update Pokemon" }, "send_location" : { "NL": "Stuur me alsjeblieft eerst een locatie.", @@ -530,9 +545,9 @@ "EN": "blue" }, "gym_team_set_to" : { - "NL": "Gym Team gezet op: ", - "DE": "Arena Team gesetzt auf: ", - "EN": "Gym Team set to: " + "NL": "Gym Team gezet op:", + "DE": "Arena Team gesetzt auf:", + "EN": "Gym Team set to:" }, "invalid_team" : { "NL": "Ongeldige team naam: schrijf: Mystic, Valor, Instinct or Blauw, Rood, Geel ", diff --git a/modules/edit_left.php b/modules/edit_left.php index ae98a51..f0cebe0 100755 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -64,7 +64,7 @@ edit_message($update, $msg, $keys, false); // Build callback message string. - $callback_response = getTranslation('end_time') . $data['arg'] . getTranslation('minutes'); + $callback_response = getTranslation('end_time') . $data['arg'] . ' ' . getTranslation('minutes'); // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/edit_start.php b/modules/edit_start.php index fdc5674..edeef23 100755 --- a/modules/edit_start.php +++ b/modules/edit_start.php @@ -58,7 +58,7 @@ edit_message($update, getTranslation('how_long_raid'), $keys); // Build callback message string. -$callback_response = getTranslation('lead_time_set_to') . $data['arg'] . getTranslation('minutes'); +$callback_response = getTranslation('lead_time_set_to') . ' ' . $data['arg'] . ' ' . getTranslation('minutes'); // Answer callback. answerCallbackQuery($update['callback_query']['id'], $callback_response); From 0b028baf767244bf428da4650369c26cb1c4bfc4 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 18 Dec 2017 15:57:53 +0100 Subject: [PATCH 131/225] Improvements to bot_access_check and raid_access_check --- logic.php | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/logic.php b/logic.php index 11f5f7b..16b93fd 100755 --- a/logic.php +++ b/logic.php @@ -4,7 +4,7 @@ * @param $update * @param $access_type */ -function bot_access_check($update, $access_type = BOT_ACCESS) +function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = false) { // Restricted or public access if(!empty($access_type)) { @@ -34,6 +34,9 @@ function bot_access_check($update, $access_type = BOT_ACCESS) continue; } + // Clear chat_obj since it did not match + $chat_obj = ''; + // Get administrators from chat $response = get_admins($chat); debug_log("Getting administrators from chat '" . $chat . "'"); @@ -52,16 +55,29 @@ function bot_access_check($update, $access_type = BOT_ACCESS) // Prepare logging of username, first_name and/or id $msg = ''; - $msg .= !empty($update['message']['from']['id']) ? "Id: " . $update['message']['from']['id'] . CR : ''; - $msg .= !empty($update['message']['from']['username']) ? "Username: " . $update['message']['from']['username'] . CR : ''; - $msg .= !empty($update['message']['from']['first_name']) ? "First Name: " . $update['message']['from']['first_name'] . CR : ''; - $msg .= !empty($update['inline_query']['from']['id']) ? "Id: " . $update['inline_query']['from']['id'] . CR : ''; - $msg .= !empty($update['inline_query']['from']['username']) ? "Username: " . $update['inline_query']['from']['username'] . CR : ''; - $msg .= !empty($update['inline_query']['from']['first_name']) ? "First Name: " . $update['inline_query']['from']['first_name'] . CR : ''; + if(!empty($chat_obj['result']['id'])) { + $msg .= !empty($chat_obj['result']['id']) ? "Id: " . $chat_obj['result']['id'] . CR : ''; + $msg .= !empty($chat_obj['result']['username']) ? "Username: " . $chat_obj['result']['username'] . CR : ''; + $msg .= !empty($chat_obj['result']['first_name']) ? "First Name: " . $chat_obj['result']['first_name'] . CR : ''; + } else if (!empty($update['message']['from']['id'])) { + $msg .= !empty($update['message']['from']['id']) ? "Id: " . $update['message']['from']['id'] . CR : ''; + $msg .= !empty($update['message']['from']['username']) ? "Username: " . $update['message']['from']['username'] . CR : ''; + $msg .= !empty($update['message']['from']['first_name']) ? "First Name: " . $update['message']['from']['first_name'] . CR : ''; + } else if (!empty($update['inline_query']['from']['id'])) { + $msg .= !empty($update['inline_query']['from']['id']) ? "Id: " . $update['inline_query']['from']['id'] . CR : ''; + $msg .= !empty($update['inline_query']['from']['username']) ? "Username: " . $update['inline_query']['from']['username'] . CR : ''; + $msg .= !empty($update['inline_query']['from']['first_name']) ? "First Name: " . $update['inline_query']['from']['first_name'] . CR : ''; + } // Allow or deny access to the bot and log result - if ($allow_access) { + if ($allow_access && !$return_result) { debug_log("Allowing access to the bot for user:" . CR . $msg); + } else if ($allow_access && $return_result) { + debug_log("Allowing access to the bot for user:" . CR . $msg); + return $allow_access; + } else if (!$allow_access && $return_result) { + debug_log("Denying access to the bot for user:" . CR . $msg); + return $allow_access; } else { debug_log("Denying access to the bot for user:" . CR . $msg); $response_msg = 'You are not allowed to use this command or bot!'; @@ -99,16 +115,24 @@ function raid_access_check($update, $data) SELECT COUNT(*) FROM users WHERE user_id = {$update['callback_query']['from']['id']} - OR moderator = 1 + AND moderator = 1 " ); $row = $rs->fetch_row(); if (empty($row['0'])) { - $callback_response = 'You are not allowed to edit this raid'; - answerCallbackQuery($update['callback_query']['id'], $callback_response); - exit; + $admin_access = bot_access_check($update, BOT_ADMINS, true); + if (!$admin_access) { + $keys = []; + if (isset($update['callback_query']['inline_message_id'])) { + editMessageText($update['callback_query']['inline_message_id'], '' . getTranslation('raid_access_denied') . '', $keys); + } else { + editMessageText($update['callback_query']['message']['message_id'], '' . getTranslation('raid_access_denied') . '', $keys, $update['callback_query']['message']['chat']['id'], $keys); + } + answerCallbackQuery($update['callback_query']['id'], getTranslation('raid_access_denied')); + exit; + } } } } From 46d755acfbcb4a27e09473e0da2a82af858c835e Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 18 Dec 2017 16:00:15 +0100 Subject: [PATCH 132/225] Fixed raid duplication check for empty gym name, Fixed send message being used instead of editMessage for /new and added translation stuff for a positive raid duplication check result --- modules/raid_create.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/raid_create.php b/modules/raid_create.php index 3153746..df3e8be 100755 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -94,7 +94,9 @@ } // Insert new raid or warn about existing raid? -$raid_id = raid_duplication_check($gym_name,0); +if (!empty($gym_name)) { + $raid_id = raid_duplication_check($gym_name,0); +} // Insert new raid if ($raid_id != 0) { @@ -128,13 +130,13 @@ $keys = [ [ [ - 'text' => 'Pokemon aktualisieren', + 'text' => getTranslation('update_pokemon'), 'callback_data' => $raid['id'] . ':raid_edit_poke:' . $raid['pokemon'], ] ], [ [ - 'text' => 'Teilen', + 'text' => getTranslation('share'), 'switch_inline_query' => strval($raid['id']) ] ] @@ -144,7 +146,7 @@ } // Build message string. - $msg = ($raid_status == "start") ? ('Raid wird gerade angelegt von:' . CR . get_user($raid['user_id'])) : ('Raid existiert bereits!' . CR . show_raid_poll_small($raid)); + $msg = ($raid_status == "start") ? (getTranslation('raid_being_created_by_other_user') . CR . get_user($raid['user_id'])) : (getTranslation('raid_already_exists') . CR . show_raid_poll_small($raid)); // Edit the message. edit_message($update, $msg, $keys); @@ -207,7 +209,7 @@ $keys = [ [ [ - 'text' => 'Not supported', + 'text' => getTranslation('not_supported'), 'callback_data' => 'edit:not_supported' ] ] @@ -218,7 +220,7 @@ $msg = getTranslation('create_raid') . ': ' . $fullAddress . ''; // Answer callback or send message based on input prior raid creation -if($gym_id != 0) { +if($gym_id != 0 || (empty($update['message']['location']['latitude']) && empty($update['message']['location']['longitude']))) { // Edit the message. edit_message($update, $msg . CR . getTranslation('select_raid_level') . ':', $keys); @@ -231,7 +233,6 @@ // Private chat type. if ($chattype == 'private') { // Send the message. - //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys); send_message($chatid, $msg . CR . getTranslation('select_raid_level') . ':', $keys); } else { @@ -242,7 +243,6 @@ } // Send the message. - //send_message($update['message']['chat']['id'], $msg . CR . 'Bitte Raid level auswählen:', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); send_message($chatid, $msg . CR . getTranslation('select_raid_level') . ':', $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); } From dfa9d40b917532d78367423ee63a5287e3825a0e Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 18 Dec 2017 16:06:34 +0100 Subject: [PATCH 133/225] Fixed spelling and spaces --- constants.php | 8 ++++---- language.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/constants.php b/constants.php index 5549324..029f1f3 100755 --- a/constants.php +++ b/constants.php @@ -26,7 +26,7 @@ // Raid boss pokemon. $pokemon = array( 'X' => array( - getTranslation('mewtwo') + getTranslation('mewtwo') ), '5' => array( getTranslation('articuno'), @@ -40,7 +40,7 @@ getTranslation('entei'), getTranslation('suicune'), getTranslation('groudon'), - getTranslation('egg_5') + getTranslation('egg_5') ), '4' => array( getTranslation('tyranitar'), @@ -53,7 +53,7 @@ getTranslation('rhydon'), getTranslation('golem'), getTranslation('absol'), - getTranslation('egg_4') + getTranslation('egg_4') ), '3' => array( getTranslation('arcanine'), @@ -64,7 +64,7 @@ getTranslation('porygon'), getTranslation('omastar'), getTranslation('ninetails'), - getTranslation('egg_3') + getTranslation('egg_3') ) ); diff --git a/language.json b/language.json index 5112632..8963e23 100755 --- a/language.json +++ b/language.json @@ -527,7 +527,7 @@ "raid_by_gym" : { "NL": "Of maak een raid door een Gym te selecteren:", "DE": "Oder lege ein Raid per Arena-Auswahl an:", - "EN": "Or make a raid per arena selection:" + "EN": "Or make a raid per gym selection:" }, "red" : { "NL": "rood", From 53d95a3921d127d88e2dfc9eb368f65c711e5eb0 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 18 Dec 2017 16:16:52 +0100 Subject: [PATCH 134/225] Added /mods to the readme --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9ea912b..b6148c8 100644 --- a/README.md +++ b/README.md @@ -126,8 +126,7 @@ OR With BOT_ADMINS and BOT_ACCESS being used to restrict access, there are several access roles / types. When you do not configure BOT_ACCESS, everyone will have access to your bot (public access). -As MAINTAINER_ID and as a member of BOT_ADMINS you have the permissions to do anything. But for some actions you'll need to make yourself a moderator. -(#TODO: MAINTAINER_ID and BOT_ADMINS should be able to do anything even when they're not moderator) +With your MAINTAINER_ID and as a member of BOT_ADMINS you have the permissions to do anything. **For performance improvements, it's recommended to add the MAINTAINER and all members of BOT_ADMINS as moderator via /mods command!** As a member of BOT_ACCESS you can create raid polls, update your own raid polls' pokemon and change the gym team of your last raid poll. BOT_ACCESS members who are moderators can change the gym name and update raid polls' pokemon of others. @@ -161,6 +160,11 @@ The bot will guide you through the creation of the raid poll by asking you for t The bot will answer you "This is a private bot" so you can verify the bot is working and accepting input. +#### Command: /mods + +The bot allows you to set some users as moderators. You can list, add and delete moderators from the bot. Note that when you have restricted the access to your bot via BOT_ADMINS and BOT_ACCESS, you need to add the users as administrators of a chat or their Telegram IDs to either BOT_ADMINS or BOT_ACCESS. Otherwise they won't have access to the bot, even though you have added them as moderators! + + #### Command: /raid Create a new raid by gomap-notifier or other input. The raid command expects 8 parameters and an optional 9th parameter as input seperated by comma. @@ -211,10 +215,7 @@ Check your bot logfile and other related log files, e.g. apache/httpd log, php l # TODO: -* Moderators support: Add, remove and list moderators - only specified BOT_ADMINS are allowed to add, remove and list moderators -* Multilanguage support: Supporting multiple languages * New gyms: Adding gyms to database without creating a raid via /raid -* Duplication check 2.0: Add support to notify user that a raid is already in the database when creating one via /start * Preferred pokemon raid boss: When multiple level 5 raids are available, e.g. Lugia and Zapdos, add buttons to tell that you're coming a) only if Lugia, b) only if Zapdos, c) independently of the pokemon * Delete raids: Allow BOT_ADMINS to delete raids * Delete incomplete raids automatically: When a bot user starts to create a raid via /start, but does not finish the raid creation, incomplete raid data is stored in the raids table. A method to automatically delete them without interfering with raids just being created would be nice. From b77a9cbdb22ec54d2a5db0248b7610351628659a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 18 Dec 2017 16:33:11 +0100 Subject: [PATCH 135/225] Add /list to new multilanguage support, fixed no timezone found issue by using default timezone --- commands/list.php | 13 ++++++++----- language.json | 10 ++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/commands/list.php b/commands/list.php index 14bbce2..5878166 100644 --- a/commands/list.php +++ b/commands/list.php @@ -21,8 +21,11 @@ // No data found. if (!$row) { - sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); - exit; + //sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + //exit; + $tz = TIMEZONE; +} else { + $tz = $row['timezone']; } // Build query. @@ -34,14 +37,14 @@ UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids WHERE end_time>NOW() - AND timezone='{$row['timezone']}' + AND timezone='{$tz}' ORDER BY end_time ASC LIMIT 20 " ); while ($raid = $request->fetch_assoc()) { if(!$raid) { - sendMessage($update['message']['from']['id'], 'Aktuell sind keine laufenden Raids im System!'); + sendMessage($update['message']['from']['id'], '' . getTranslation('no_active_raids_found') . ''); exit; } @@ -49,7 +52,7 @@ $keys = [ [ [ - 'text' => 'Expand', + 'text' => getTranslation('expand'), 'callback_data' => $raid['id'] . ':vote_refresh:0', ] ] diff --git a/language.json b/language.json index 8963e23..73db809 100755 --- a/language.json +++ b/language.json @@ -479,6 +479,16 @@ "DE": "Sie haben keine Berechtigung dieses Raid zu bearbeiten!", "EN": "You are not allowed to edit this raid!" }, + "no_active_raids_found" : { + "NL": "No active raids found in the system!", + "DE": "Aktuell sind keine laufenden Raids im System!", + "EN": "No active raids found in the system!" + }, + "expand" : { + "NL": "Expand", + "DE": "Ausklappen", + "EN": "Expand" + }, "pokemon_saved" : { "NL": "Pokemon opgeslagen: ", "DE": "Pokemon gespeichert: ", From 97e06c4911d90071464793580e78c08e1558ac1c Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 18 Dec 2017 16:59:06 +0100 Subject: [PATCH 136/225] Fixed untranslated 'Bin da', shortend cancellation and done to just show the time as they are grouped by cancellation/done already --- logic.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/logic.php b/logic.php index 16b93fd..995e681 100755 --- a/logic.php +++ b/logic.php @@ -1491,11 +1491,11 @@ function show_raid_poll($raid) if ($vv['arrived']) { // No time is displayed, but undefined_index error in log, so changed it: //$msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; - $msg .= '[Bin da] '; + $msg .= '[' . getTranslation('here') . '] '; // Cancelled. } else if ($vv['cancel']) { - $msg .= '[abgesagt] '; + $msg .= '[' . getTranslation('cancel') . '] '; } // Add extra people. @@ -1534,7 +1534,7 @@ function show_raid_poll($raid) // Done. if ($vv['raid_done']) { - $msg .= '[' . getTranslation('finished') . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + $msg .= '[' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; } // Add extra people. if ($vv['extra_people']) { @@ -1571,7 +1571,7 @@ function show_raid_poll($raid) // Cancel. if ($vv['cancel']) { - $msg .= '[' . getTranslation('cancel') . ' ' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + $msg .= '[' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; } // Add extra people. if ($vv['extra_people']) { From fedda79dd4211b9863a9013f649f49a1887e15e2 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 19 Dec 2017 12:14:24 +0100 Subject: [PATCH 137/225] Added option for admins to continue with warning message, non-administrators get a just the message that some else is already creating the raid without the possibility to continue --- language.json | 22 +++++++++++++++++++++- modules/raid_create.php | 25 +++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/language.json b/language.json index 73db809..d01adb3 100755 --- a/language.json +++ b/language.json @@ -349,6 +349,11 @@ "DE": "Anfangsbuchstabe ausgewählt.", "EN": "First letter selected." }, + "raid_creation_started_at" : { + "NL": "Raid creation was started at", + "DE": "Das Raid wird angelegt seit", + "EN": "Raid creation was started at" + }, "raid_being_created_by_other_user" : { "NL": "Another user is currently creating a raid for this gym:", "DE": "Ein Raid für diese Arena wird gerade angelegt von:", @@ -364,10 +369,25 @@ "DE": "Erstelle Raid in", "EN": "Create Raid in" }, + "raid_creation_in_progress_warning" : { + "NL": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!", + "DE": "Das Raid kann weiter angelegt werden, aber dies wird das Raid welches gerade zeitgleich erstellt wird überschreiben und ist daher definitiv NICHT EMPFOHLEN!", + "EN": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!" + }, + "raid_creation_in_progress" : { + "NL": "Raid creation in progress", + "DE": "Raid wird gerade erstellt", + "EN": "Raid creation in progress" + }, + "select_raid_level_to_continue" : { + "NL": "To really continue, please select raid level", + "DE": "Um wirklich fortzufahren, bitte Raid Level auswählen", + "EN": "To really continue, please select raid level" + }, "select_raid_level" : { "NL": "Selecteer Raid level", "DE": "Bitte Raid Level auswählen", - "EN": "Select Raid level" + "EN": "Select raid level" }, "gym" : { "NL": "Gym", diff --git a/modules/raid_create.php b/modules/raid_create.php index df3e8be..250deda 100755 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -126,7 +126,8 @@ // Create the keys. if ($raid_status == "end") { - // Update pokemon? + $msg = getTranslation('raid_already_exists') . CR . show_raid_poll_small($raid); + // Update pokemon or share raid? $keys = [ [ [ @@ -142,11 +143,31 @@ ] ]; } else { - $keys = []; + // Set message string + $msg_main = getTranslation('raid_being_created_by_other_user') . CR . get_user($raid['user_id']); + $msg_main .= getTranslation('raid_creation_started_at') . " " . unix2tz($raid['ts_start'], $raid['timezone']) . '.'; + $access_msg_header = ''; + $access_msg_footer = ''; + + // Check access to overwrite raid. + $admin_access = bot_access_check($update, BOT_ADMINS, true); + if ($admin_access) { + $access_msg_header .= CR . EMOJI_WARN . "" . getTranslation('raid_creation_in_progress') . "" . EMOJI_WARN . CR; + $access_msg_header .= CR . "" . getTranslation('raid_creation_in_progress_warning') . "" . CR . CR; + $access_msg_footer .= CR . CR . getTranslation('select_raid_level_to_continue') . ':'; + $keys = raid_edit_start_keys($raid['id']); + } else { + $keys = []; + } + + // Build message string. + $msg = $access_msg_header . $msg_main . $access_msg_footer; } // Build message string. + /* $msg = ($raid_status == "start") ? (getTranslation('raid_being_created_by_other_user') . CR . get_user($raid['user_id'])) : (getTranslation('raid_already_exists') . CR . show_raid_poll_small($raid)); + */ // Edit the message. edit_message($update, $msg, $keys); From 2fb0e81e134e52e09b563460351ac7c3b123bdc8 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 19 Dec 2017 22:56:27 +0100 Subject: [PATCH 138/225] Oops! Fixed security issue in BOT_ACCESS_CHECK! --- logic.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/logic.php b/logic.php index 995e681..e05ed6a 100755 --- a/logic.php +++ b/logic.php @@ -25,9 +25,12 @@ function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = f if ($chat_obj['ok'] == true) { $allow_access = false; // ID matching $chat and private chat type? - if ($chat_obj['result']['id'] == $chat && $chat_obj['result']['type'] == "private") { + if ($chat_obj['result']['id'] == $update['message']['from']['id'] && $chat_obj['result']['type'] == "private") { $allow_access = true; break; + } else { + // Result was ok, but access not granted. Continue then. + continue; } } else { debug_log('Chat ' . $chat . ' does not exist! Continuing with next chat...'); @@ -85,6 +88,10 @@ function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = f exit; } } else { + $msg = ''; + $msg .= !empty($update['message']['from']['id']) ? "Id: " . $update['message']['from']['id'] . CR : ''; + $msg .= !empty($update['message']['from']['username']) ? "Username: " . $update['message']['from']['username'] . CR : ''; + $msg .= !empty($update['message']['from']['first_name']) ? "First Name: " . $update['message']['from']['first_name'] . CR : ''; debug_log("Bot access is not restricted! Allowing access for user: " . CR . $msg); } } From ade1ee41f0a7c19b42f4141390534f07a2ef373a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 20 Dec 2017 14:01:17 +0100 Subject: [PATCH 139/225] Oops! Used wrong translation string for raid message. Discovered by @klablabla :) --- logic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.php b/logic.php index e05ed6a..2216d29 100755 --- a/logic.php +++ b/logic.php @@ -1324,7 +1324,7 @@ function show_raid_poll($raid) // Add time left message. } else { - $msg .= getTranslation('raid_egg_opens') . ' ' . unix2tz($raid['ts_end'], $raid['timezone']); + $msg .= getTranslation('raid_until') . ' ' . unix2tz($raid['ts_end'], $raid['timezone']); $msg .= $tl_msg . CR; } } From 6cd9bbc004d12aa243a7f741b47948600d9ffdf5 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Wed, 20 Dec 2017 21:32:59 +0100 Subject: [PATCH 140/225] Fix missing x raid boss mewtu --- constants.php | 1 + 1 file changed, 1 insertion(+) diff --git a/constants.php b/constants.php index 029f1f3..4b97d8e 100755 --- a/constants.php +++ b/constants.php @@ -34,6 +34,7 @@ getTranslation('moltres'), getTranslation('zapdos'), getTranslation('mew'), + getTranslation('mewtwo'), getTranslation('hooh'), getTranslation('celebi'), getTranslation('raikou'), From 15e75fc2e83d11da438d910e87d2b4052c8fdc8f Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Wed, 20 Dec 2017 21:36:23 +0100 Subject: [PATCH 141/225] Use most relevant geo api entry --- geo_api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/geo_api.php b/geo_api.php index 3f1228a..ac39e4d 100755 --- a/geo_api.php +++ b/geo_api.php @@ -96,6 +96,7 @@ function get_address($lat, $lon) } } } + break; } // Set district by priority. From c95f6f4d27cdf6e7b3d07f78379cb37d6bfbb0ba Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 21 Dec 2017 09:55:59 +0100 Subject: [PATCH 142/225] Added update sql statement to insert_gym function, lookup address always via geo_api when using /start --- commands/raid.php | 2 +- logic.php | 12 ++++++++++++ modules/raid_create.php | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index 2f813e0..35309c9 100755 --- a/commands/raid.php +++ b/commands/raid.php @@ -58,7 +58,7 @@ $address = ""; $address .= (!empty($addr['street']) ? $addr['street'] : ""); $address .= (!empty($addr['street_number']) ? " " . $addr['street_number'] : ""); - $address .= ", "; + $address .= (!empty($fullAddress) ? ", " : ""); $address .= (!empty($addr['postal_code']) ? $addr['postal_code'] . " " : ""); $address .= (!empty($addr['district']) ? $addr['district'] : ""); } else { diff --git a/logic.php b/logic.php index 2216d29..18e7e6f 100755 --- a/logic.php +++ b/logic.php @@ -273,6 +273,18 @@ function insert_gym($name, $lat, $lon, $address) address = '{$db->real_escape_string($address)}' " ); + } else { + // Update gyms table to reflect gym changes. + debug_log('Gym found in database gym list! Updating gym "' . $name . '" now.'); + $rs = my_query( + " + UPDATE gyms + SET lat = '{$lat}', + lon = '{$lon}', + address = '{$db->real_escape_string($address)}' + WHERE gym_name = '{$name}' + " + ); } } diff --git a/modules/raid_create.php b/modules/raid_create.php index 250deda..6651aa5 100755 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -70,11 +70,26 @@ // Address and gym name based on input if($gym_id > 0) { - // Get address from database - $fullAddress = $gym['address']; + // Set name and coordinates. $gym_name = $gym['gym_name']; $lat = $gym['lat']; $lon = $gym['lon']; + + // Get the address. + $addr = get_address($lat, $lon); + + // Get full address - Street #, ZIP District + $fullAddress = ""; + $fullAddress .= (!empty($addr['street']) ? $addr['street'] : ""); + $fullAddress .= (!empty($addr['street_number']) ? " " . $addr['street_number'] : ""); + $fullAddress .= (!empty($fullAddress) ? ", " : ""); + $fullAddress .= (!empty($addr['postal_code']) ? $addr['postal_code'] . " " : ""); + $fullAddress .= (!empty($addr['district']) ? $addr['district'] : ""); + + // Fallback: Get address from database + if(empty($fullAddress)) { + $fullAddress = $gym['address']; + } debug_log('Gym ID: ' . $gym_id); debug_log('Gym Name: ' . $gym_name); debug_log('Gym Address: ' . $fullAddress); From 9a7c0ab41332fe6267ad4ed97eda3b3e804b8dd8 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 21 Dec 2017 12:35:56 +0100 Subject: [PATCH 143/225] Oops! Continue only if chat type is private, otherwise check administrators of groups/supergroups/channels --- logic.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/logic.php b/logic.php index 18e7e6f..1562d7c 100755 --- a/logic.php +++ b/logic.php @@ -29,8 +29,10 @@ function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = f $allow_access = true; break; } else { - // Result was ok, but access not granted. Continue then. - continue; + // Result was ok, but access not granted. Continue with next chat if type is private. + if ($chat_obj['result']['type'] == "private") { + continue; + } } } else { debug_log('Chat ' . $chat . ' does not exist! Continuing with next chat...'); From 7abdcb8a67adab841d5a0e1d64817b596a56c4fb Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sun, 24 Dec 2017 15:48:37 +0100 Subject: [PATCH 144/225] Update language.json Fixed here for NL regio. Translated the new items for the NL regio. --- language.json | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/language.json b/language.json index a8d8bf2..42191f3 100755 --- a/language.json +++ b/language.json @@ -45,7 +45,7 @@ "EN": "Raid done" }, "here" : { - "DE": "Ben er", + "NL": "Ben er", "DE": "Bin da", "EN": "Here" }, @@ -115,12 +115,12 @@ "EN": "Raid egg opens on" }, "raid_egg_opens_at" : { - "NL": "at", + "NL": "om", "DE": "um", "EN": "at" }, "raid_until" : { - "NL": "Raid until", + "NL": "Raid tot", "DE": "Raid bis", "EN": "Raid until" }, @@ -350,17 +350,17 @@ "EN": "First letter selected." }, "raid_creation_started_at" : { - "NL": "Raid creation was started at", + "NL": "Raid aanmaak is gestart om", "DE": "Das Raid wird angelegt seit", "EN": "Raid creation was started at" }, "raid_being_created_by_other_user" : { - "NL": "Another user is currently creating a raid for this gym:", + "NL": "Een andere gebruiker is een raid voor deze gym aan het maken:", "DE": "Ein Raid für diese Arena wird gerade angelegt von:", "EN": "Another user is currently creating a raid for this gym:" }, "raid_already_exists" : { - "NL": "Raid already exists!", + "NL": "Raid bestaat al!", "DE": "Raid existiert bereits!", "EN": "Raid already exists!" }, @@ -370,17 +370,17 @@ "EN": "Create Raid in" }, "raid_creation_in_progress_warning" : { - "NL": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!", + "NL": "Je kan een raid aanmaken, maar de huidig aangemaakte raid zal worden overscheven. Deze wijziging kunnen niet ongedaan gemaakt worden dit is NIET AAN TE RADEN!", "DE": "Das Raid kann weiter angelegt werden, aber dies wird das Raid welches gerade zeitgleich erstellt wird überschreiben und ist daher definitiv NICHT EMPFOHLEN!", "EN": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!" }, "raid_creation_in_progress" : { - "NL": "Raid creation in progress", + "NL": "Raid wordt momenteel aangemaakt", "DE": "Raid wird gerade erstellt", "EN": "Raid creation in progress" }, "select_raid_level_to_continue" : { - "NL": "To really continue, please select raid level", + "NL": "Om echt door te gaan, selecteer een raid level", "DE": "Um wirklich fortzufahren, bitte Raid Level auswählen", "EN": "To really continue, please select raid level" }, @@ -475,17 +475,17 @@ "EN": "In how many minutes does the raid begin?" }, "raid_starts_when_clocktime_view" : { - "NL": "Clock time view", + "NL": "klok", "DE": "Uhrzeit-Ansicht", "EN": "Clock time view" }, "raid_starts_when_minutes_view" : { - "NL": "Minutes view", + "NL": "Minuten", "DE": "Minuten-Ansicht", "EN": "Minutes view" }, "raid_starts_when_view_changed" : { - "NL": "View changed!", + "NL": "Overzicht verandert!", "DE": "Ansicht geändert!", "EN": "View changed!" }, @@ -495,17 +495,17 @@ "EN": "Raid is already active!" }, "raid_access_denied" : { - "NL": "You are not allowed to edit this raid!", + "NL": "Je hebt geen rechten om deze raid aan te passen!", "DE": "Sie haben keine Berechtigung dieses Raid zu bearbeiten!", "EN": "You are not allowed to edit this raid!" }, "no_active_raids_found" : { - "NL": "No active raids found in the system!", + "NL": "Geen actieve raids gevonden!", "DE": "Aktuell sind keine laufenden Raids im System!", "EN": "No active raids found in the system!" }, "expand" : { - "NL": "Expand", + "NL": "Uitklappen", "DE": "Ausklappen", "EN": "Expand" }, @@ -590,62 +590,62 @@ "EN": "Gym name updated." }, "mods_details" : { - "NL": "Select moderator for details:", + "NL": "Selecteer moderator voor meer informatie:", "DE": "Für Details Moderator auswählen:", "EN": "Select moderator for details:" }, "mods_add_new" : { - "NL": "Add new moderator:", + "NL": "Nieuwe moderator toevoegen:", "DE": "Neuen Moderator hinzufügen:", "EN": "Add new moderator:" }, "mods_delete" : { - "NL": "Delete moderator:", + "NL": "Moderator verwijderen:", "DE": "Moderator löschen:", "EN": "Delete moderator:" }, "mods_list_of_all" : { - "NL": "List of all moderators.", + "NL": "Lijst met alle moderators.", "DE": "Liste aller Moderatoren.", "EN": "List of all moderators." }, "mods_list_add_delete" : { - "NL": "List, add or remove moderators", + "NL": "Lijst, toevoegen of verwijderen van moderators", "DE": "Moderatoren anzeigen, hinzufügen oder löschen", "EN": "List, add or remove moderators" }, "mods_not_found" : { - "NL": "Error! No moderators or users found!", + "NL": "Error! Geen Moderator of gebruiker gevonden!", "DE": "Fehler! Keine Moderatoren oder Benutzer gefunden!", "EN": "Error! No moderators or users found!" }, "mods_saved_mod" : { - "NL": "Moderator saved!", + "NL": "Moderator opgeslagen!", "DE": "Moderator gespeichert!", "EN": "Moderator saved!" }, "mods_delete_mod" : { - "NL": "Moderator deleted!", + "NL": "Moderator verwijderd!", "DE": "Moderator gelöscht!", "EN": "Moderator deleted!" }, "mods_info_about_mod" : { - "NL": "Info about this moderator:", + "NL": "Informatie over deze moderator:", "DE": "Infos zum diesem Moderator:", "EN": "Info about this moderator:" }, "list" : { - "NL": "List", + "NL": "Lijst", "DE": "Anzeigen", "EN": "List" }, "add" : { - "NL": "Add", + "NL": "Toevoegen", "DE": "Hinzufügen", "EN": "Add" }, "delete" : { - "NL": "Delete", + "NL": "Verwijder", "DE": "Löschen", "EN": "Delete" } From c30882347fa0f405a893d8a7a4c4f7a2ab06c582 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 26 Dec 2017 13:09:06 +0100 Subject: [PATCH 145/225] Improved logic to allow start_time being a part of the voting times, added the missing space in raid message --- logic.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/logic.php b/logic.php index 1562d7c..a5ea355 100755 --- a/logic.php +++ b/logic.php @@ -1017,14 +1017,20 @@ function keys_vote($raid) $timePerSlot = 60*RAID_SLOTS; $timeBeforeEnd = 60*RAID_LAST_START; $col = 1; + // Old stuff, left for possible future use or in case of bugs: //for ($i = ceil($now / $timePerSlot) * $timePerSlot; $i <= ($end_time - $timeBeforeEnd); $i = $i + $timePerSlot) { - for ($i = ceil($start_time / $timePerSlot) * $timePerSlot; $i <= ($end_time - $timeBeforeEnd); $i = $i + $timePerSlot) { + //for ($i = ceil($start_time / $timePerSlot) * $timePerSlot; $i <= ($end_time - $timeBeforeEnd); $i = $i + $timePerSlot) { + + // Make start_time a possible vote_time: + // start_time minus 60 for a voting option e.g. 13:30 when an egg opens right at 13:30. Without minus 60, the first voting option would be 13:45 for example (assuming RAID_SLOTS = 15) + for ($i = ceil(($start_time - 60) / $timePerSlot) * $timePerSlot; $i <= ($end_time - $timeBeforeEnd); $i = $i + $timePerSlot) { if ($col++ >= 4) { $keys[] = $keys_time; $keys_time = []; $col = 1; } + // Plus 60 seconds, so vote button for e.g. 10:00 will disappear after 10:00:59 / at 10:01:00 and not right after 09:59:59 / at 10:00:00 if (($i + 60) > $now) { // Display vote buttons for now + 1 additional minute @@ -1325,7 +1331,7 @@ function show_raid_poll($raid) if ($weekday_now == $weekday_start) { $msg .= '' . getTranslation('raid_egg_opens') . ' ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; } else { - $msg .= '' . getTranslation('raid_egg_opens_day') . ' ' . $raid_day . ' ' . getTranslation('raid_egg_opens_at') . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; + $msg .= '' . getTranslation('raid_egg_opens_day') . ' ' . $raid_day . ' ' . getTranslation('raid_egg_opens_at') . ' ' . unix2tz($raid['ts_start'], $raid['timezone']) . '' . CR; } // Raid has started and active or already ended From 0dea0585f94c760e3788dde93703ffefd2f50efa Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 26 Dec 2017 13:10:50 +0100 Subject: [PATCH 146/225] Fixed copy/paste error in address, Added check for ex-raid so a Mewtwo won't get updated to Level 5 Egg to avoid people coming to an ex-raid without ex-raid pass --- commands/raid.php | 50 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index 35309c9..6c26bdd 100755 --- a/commands/raid.php +++ b/commands/raid.php @@ -58,7 +58,7 @@ $address = ""; $address .= (!empty($addr['street']) ? $addr['street'] : ""); $address .= (!empty($addr['street_number']) ? " " . $addr['street_number'] : ""); - $address .= (!empty($fullAddress) ? ", " : ""); + $address .= (!empty($addr) ? ", " : ""); $address .= (!empty($addr['postal_code']) ? $addr['postal_code'] . " " : ""); $address .= (!empty($addr['district']) ? $addr['district'] : ""); } else { @@ -72,19 +72,45 @@ $countdown = $data[8]; } -// Insert new raid or update existing raid? +// Insert new raid or update existing raid/ex-raid? $raid_id = raid_duplication_check($name,($endtime + $countdown)); +$ex_raid = false; + +if ($raid_id > 0) { + // Make sure it's not an Ex-Raid before updating the pokemon. + $pokemonlist = $GLOBALS['pokemon']; + foreach($pokemonlist as $level => $levelmons) { + if($level == "X") { + foreach($levelmons as $key => $pokemon) { + if(strtolower($pokemon) == strtolower($boss)) { + $ex_raid = true; + debug_log('Ex-raid pokemon detected: ' . $boss); + break 2; + } + } + } + } -if ($raid_id > 0){ - // Update pokemon and team in raids table. - my_query( - " - UPDATE raids - SET pokemon = '{$db->real_escape_string($boss)}', - gym_team = '{$db->real_escape_string($team)}' - WHERE id = {$raid_id} - " - ); + if ($ex_raid) { + // Ex-Raid! Update only team in raids table. + my_query( + " + UPDATE raids + SET gym_team = '{$db->real_escape_string($team)}' + WHERE id = {$raid_id} + " + ); + } else { + // Update pokemon and team in raids table. + my_query( + " + UPDATE raids + SET pokemon = '{$db->real_escape_string($boss)}', + gym_team = '{$db->real_escape_string($team)}' + WHERE id = {$raid_id} + " + ); + } // Debug log debug_log('Updated raid ID: ' . $raid_id); From d7874103d20426302c29c40558ec05ed957403b6 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 27 Dec 2017 14:11:06 +0100 Subject: [PATCH 147/225] Improved bot_access_check function to allow easier debugging and ensure proper checking for access, always return true when bot is not restricted --- logic.php | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/logic.php b/logic.php index a5ea355..539f78b 100755 --- a/logic.php +++ b/logic.php @@ -14,23 +14,40 @@ function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = f $all_chats .= !empty(BOT_ADMINS) ? BOT_ADMINS . ',' : ''; $all_chats .= ($access_type == BOT_ADMINS) ? '' : $access_type; + // Make sure all_chats does not end with , + $all_chats = rtrim($all_chats,','); + + // Get telegram ID to check access from $update - either messagem callback_query or inline_query + $update_type = ''; + $update_type = !empty($update['message']['from']['id']) ? 'message' : $update_type; + $update_type = (empty($update_type) && !empty($update['callback_query']['from']['id'])) ? 'callback_query' : $update_type; + $update_type = (empty($update_type) && !empty($update['inline_query']['from']['id'])) ? 'inline_query' : $update_type; + $update_id = $update[$update_type]['from']['id']; + // Check each admin chat defined in $access_type + debug_log('Telegram message type: ' . $update_type); + debug_log('Checking access for ID: ' . $update_id); + debug_log('Checking these chats now: ' . $all_chats); $chats = explode(',', $all_chats); foreach($chats as $chat) { // Get chat object - $chat_obj = get_chat($chat); debug_log("Getting chat object for '" . $chat . "'"); + $chat_obj = get_chat($chat); // Check chat object for proper response. if ($chat_obj['ok'] == true) { + debug_log('Proper chat object received, continuing with access check.'); $allow_access = false; // ID matching $chat and private chat type? - if ($chat_obj['result']['id'] == $update['message']['from']['id'] && $chat_obj['result']['type'] == "private") { + //if ($chat_obj['result']['id'] == ($update['message']['from']['id'] || $update['callback_query']['from']['id']) && $chat_obj['result']['type'] == "private") { + if ($chat_obj['result']['id'] == $update_id && $chat_obj['result']['type'] == "private") { + debug_log('Positive result on access check!'); $allow_access = true; break; } else { // Result was ok, but access not granted. Continue with next chat if type is private. if ($chat_obj['result']['type'] == "private") { + debug_log('Negative result on access check! Continuing with next chat...'); continue; } } @@ -43,14 +60,16 @@ function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = f $chat_obj = ''; // Get administrators from chat - $response = get_admins($chat); debug_log("Getting administrators from chat '" . $chat . "'"); + $chat_obj = get_admins($chat); // Make sure we get a proper response - if ($response['ok'] == true) { - foreach($response['result'] as $admin) { + if ($chat_obj['ok'] == true) { + foreach($chat_obj['result'] as $admin) { // If user is found as administrator allow access to the bot - if ($admin['user']['id'] == $update['message']['from']['id'] || $admin['user']['id'] == $update['inline_query']['from']['id']) { + // if ($admin['user']['id'] == $update['message']['from']['id'] || $admin['user']['id'] == $update['inline_query']['from']['id']) { + if ($admin['user']['id'] == $update_id) { + debug_log('Positive result on access check!'); $allow_access = true; break 2; } @@ -58,21 +77,11 @@ function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = f } } - // Prepare logging of username, first_name and/or id + // Prepare logging of id, username and/or first_name $msg = ''; - if(!empty($chat_obj['result']['id'])) { - $msg .= !empty($chat_obj['result']['id']) ? "Id: " . $chat_obj['result']['id'] . CR : ''; - $msg .= !empty($chat_obj['result']['username']) ? "Username: " . $chat_obj['result']['username'] . CR : ''; - $msg .= !empty($chat_obj['result']['first_name']) ? "First Name: " . $chat_obj['result']['first_name'] . CR : ''; - } else if (!empty($update['message']['from']['id'])) { - $msg .= !empty($update['message']['from']['id']) ? "Id: " . $update['message']['from']['id'] . CR : ''; - $msg .= !empty($update['message']['from']['username']) ? "Username: " . $update['message']['from']['username'] . CR : ''; - $msg .= !empty($update['message']['from']['first_name']) ? "First Name: " . $update['message']['from']['first_name'] . CR : ''; - } else if (!empty($update['inline_query']['from']['id'])) { - $msg .= !empty($update['inline_query']['from']['id']) ? "Id: " . $update['inline_query']['from']['id'] . CR : ''; - $msg .= !empty($update['inline_query']['from']['username']) ? "Username: " . $update['inline_query']['from']['username'] . CR : ''; - $msg .= !empty($update['inline_query']['from']['first_name']) ? "First Name: " . $update['inline_query']['from']['first_name'] . CR : ''; - } + $msg .= !empty($update[$update_type]['from']['id']) ? "Id: " . $update[$update_type]['from']['id'] . CR : ''; + $msg .= !empty($update[$update_type]['from']['username']) ? "Username: " . $update[$update_type]['from']['username'] . CR : ''; + $msg .= !empty($update[$update_type]['from']['first_name']) ? "First Name: " . $update[$update_type]['from']['first_name'] . CR : ''; // Allow or deny access to the bot and log result if ($allow_access && !$return_result) { @@ -95,6 +104,7 @@ function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = f $msg .= !empty($update['message']['from']['username']) ? "Username: " . $update['message']['from']['username'] . CR : ''; $msg .= !empty($update['message']['from']['first_name']) ? "First Name: " . $update['message']['from']['first_name'] . CR : ''; debug_log("Bot access is not restricted! Allowing access for user: " . CR . $msg); + return true; } } From 88286458c427c3a986f6020181d53f96ab9764dc Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 27 Dec 2017 15:27:10 +0100 Subject: [PATCH 148/225] Allow moderators to overwrite a raid which is in creation, not only admins. Reworked the raid_access_check to return either true or false when requested --- logic.php | 43 +++++++++++++++++++++++++++++++---------- modules/raid_create.php | 19 +++++++++++------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/logic.php b/logic.php index 539f78b..cf2b5a6 100755 --- a/logic.php +++ b/logic.php @@ -114,8 +114,11 @@ function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = f * @param $data * @return bool */ -function raid_access_check($update, $data) +function raid_access_check($update, $data, $return_result = false) { + // Default: Deny access to raids + $raid_access = false; + // Build query. $rs = my_query( " @@ -142,17 +145,37 @@ function raid_access_check($update, $data) if (empty($row['0'])) { $admin_access = bot_access_check($update, BOT_ADMINS, true); - if (!$admin_access) { - $keys = []; - if (isset($update['callback_query']['inline_message_id'])) { - editMessageText($update['callback_query']['inline_message_id'], '' . getTranslation('raid_access_denied') . '', $keys); - } else { - editMessageText($update['callback_query']['message']['message_id'], '' . getTranslation('raid_access_denied') . '', $keys, $update['callback_query']['message']['chat']['id'], $keys); - } - answerCallbackQuery($update['callback_query']['id'], getTranslation('raid_access_denied')); - exit; + if ($admin_access) { + // Allow raid access + $raid_access = true; } + } else { + // Allow raid access + $raid_access = true; + } + } else { + // Allow raid access + $raid_access = true; + } + + // Allow or deny access to the raid and log result + if ($raid_access && !$return_result) { + debug_log("Allowing access to the raid"); + } else if ($raid_access && $return_result) { + debug_log("Allowing access to the raid"); + return $raid_access; + } else if (!$raid_access && $return_result) { + debug_log("Denying access to the raid"); + return $raid_access; + } else { + $keys = []; + if (isset($update['callback_query']['inline_message_id'])) { + editMessageText($update['callback_query']['inline_message_id'], '' . getTranslation('raid_access_denied') . '', $keys); + } else { + editMessageText($update['callback_query']['message']['message_id'], '' . getTranslation('raid_access_denied') . '', $keys, $update['callback_query']['message']['chat']['id'], $keys); } + answerCallbackQuery($update['callback_query']['id'], getTranslation('raid_access_denied')); + exit; } } diff --git a/modules/raid_create.php b/modules/raid_create.php index 6651aa5..835382c 100755 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -165,8 +165,18 @@ $access_msg_footer = ''; // Check access to overwrite raid. - $admin_access = bot_access_check($update, BOT_ADMINS, true); - if ($admin_access) { + $raid_access = raid_access_check($update, $raid, true); + if ($raid_access) { + // Update user_id and start_time to ensure correct time selection + $rs = my_query( + " + UPDATE raids + SET user_id = {$userid}, + start_time = NOW() + " + ); + + // Add message header, footer and keys $access_msg_header .= CR . EMOJI_WARN . "" . getTranslation('raid_creation_in_progress') . "" . EMOJI_WARN . CR; $access_msg_header .= CR . "" . getTranslation('raid_creation_in_progress_warning') . "" . CR . CR; $access_msg_footer .= CR . CR . getTranslation('select_raid_level_to_continue') . ':'; @@ -179,11 +189,6 @@ $msg = $access_msg_header . $msg_main . $access_msg_footer; } - // Build message string. - /* - $msg = ($raid_status == "start") ? (getTranslation('raid_being_created_by_other_user') . CR . get_user($raid['user_id'])) : (getTranslation('raid_already_exists') . CR . show_raid_poll_small($raid)); - */ - // Edit the message. edit_message($update, $msg, $keys); From 6ee3b965e840246796ebf348778953e0ef3cd7d4 Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sat, 6 Jan 2018 20:19:39 +0100 Subject: [PATCH 149/225] Update language.json Added Kyogre --- language.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/language.json b/language.json index 42191f3..c814bf3 100755 --- a/language.json +++ b/language.json @@ -229,6 +229,11 @@ "DE": "Groudon", "EN": "Groudon" }, + "kyogre" : { + "NL": "Kyogre", + "DE": "Kyogre", + "EN": "Kyogre" + }, "egg_5" : { "NL": "Level 5 Ei", "DE": "Level 5 Ei", From 6e1aa24441f86c13179a4b993eaed0c2a618694b Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sat, 6 Jan 2018 20:20:35 +0100 Subject: [PATCH 150/225] Update constants.php Added kyogre --- constants.php | 1 + 1 file changed, 1 insertion(+) diff --git a/constants.php b/constants.php index 4b97d8e..d165577 100755 --- a/constants.php +++ b/constants.php @@ -41,6 +41,7 @@ getTranslation('entei'), getTranslation('suicune'), getTranslation('groudon'), + getTranslation('kyogre'), getTranslation('egg_5') ), '4' => array( From 49ab83498ddae7f28b2ccb7f59435dad091f3c74 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 12 Jan 2018 16:46:07 +0100 Subject: [PATCH 151/225] Add overview table to sql file --- raid-pokemon-bot.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index e21415d..bcc3d77 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -53,6 +53,15 @@ CREATE TABLE `gyms` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; +/*Table structure for table `overview` */ + +CREATE TABLE `overview` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `chat_id` bigint(20) signed NOT NULL, + `message_id` bigint(20) unsigned NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; + /*Table structure for table `raids` */ CREATE TABLE `raids` ( From 4690b4866f0422851b7d82870bd27356df556843 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 12 Jan 2018 16:46:46 +0100 Subject: [PATCH 152/225] Kyogre --- constants.php | 1 + 1 file changed, 1 insertion(+) diff --git a/constants.php b/constants.php index 4b97d8e..d165577 100755 --- a/constants.php +++ b/constants.php @@ -41,6 +41,7 @@ getTranslation('entei'), getTranslation('suicune'), getTranslation('groudon'), + getTranslation('kyogre'), getTranslation('egg_5') ), '4' => array( From 8f8148ee18f44efba0725c4bb9dded452f373981 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 12 Jan 2018 16:47:11 +0100 Subject: [PATCH 153/225] New /list command file --- commands/list.php | 83 ++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 55 deletions(-) diff --git a/commands/list.php b/commands/list.php index 5878166..6a97adb 100644 --- a/commands/list.php +++ b/commands/list.php @@ -2,67 +2,40 @@ // Write to log. debug_log('LIST'); -// Build query. -$rs = my_query( - " - SELECT timezone - FROM raids - WHERE id = ( - SELECT raid_id - FROM attendance - WHERE user_id = {$update['message']['from']['id']} - ORDER BY id DESC LIMIT 1 - ) - " -); +// Check access - user must be admin! +bot_access_check($update, BOT_ADMINS); -// Get row. -$row = $rs->fetch_assoc(); +// Get the userid and chattype +$userid = $update['message']['from']['id']; +$chattype = $update['message']['chat']['type']; -// No data found. -if (!$row) { - //sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); - //exit; - $tz = TIMEZONE; -} else { - $tz = $row['timezone']; -} +// Init empty keys array. +$keys = array(); -// Build query. -$request = my_query( - " - SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(NOW()) AS ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids - WHERE end_time>NOW() - AND timezone='{$tz}' - ORDER BY end_time ASC LIMIT 20 - " -); - -while ($raid = $request->fetch_assoc()) { - if(!$raid) { - sendMessage($update['message']['from']['id'], '' . getTranslation('no_active_raids_found') . ''); - exit; - } - - // Create keys array. - $keys = [ +// Create keys array. +$keys = [ + [ + [ + 'text' => getTranslation('list'), + 'callback_data' => $userid . ',' . $chattype . ':list_raids:0' + ] + ], + [ + [ + 'text' => getTranslation('overview_share'), + 'callback_data' => '0:overview_share:0' + ], [ - [ - 'text' => getTranslation('expand'), - 'callback_data' => $raid['id'] . ':vote_refresh:0', - ] + 'text' => getTranslation('overview_delete'), + 'callback_data' => '0:overview_delete:0' ] - ]; + ] +]; - // Get message. - $msg = show_raid_poll_small($raid); +// Set message. +$msg = '' . getTranslation('raids_list_share_overview') . ':'; - // Send message. - send_message($update['message']['from']['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; From 8dd8633c019e760dd6dbb87beb01775fa2f307a2 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 12 Jan 2018 16:48:04 +0100 Subject: [PATCH 154/225] Disable telegram web_page_preview inside raid poll messages --- commands/raid.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/raid.php b/commands/raid.php index 6c26bdd..003c5ec 100755 --- a/commands/raid.php +++ b/commands/raid.php @@ -246,7 +246,7 @@ } // Send the message. - send_message($update['message']['chat']['id'], $text, $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); + send_message($update['message']['chat']['id'], $text, $keys, ['reply_to_message_id' => $reply_to, 'reply_markup' => ['selective' => true, 'one_time_keyboard' => true], 'disable_web_page_preview' => 'true']); } exit; From c75c62ba32a007328f1d3ec1e8a109fafd62bcd7 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 12 Jan 2018 16:48:54 +0100 Subject: [PATCH 155/225] Old /list command file, now module file - improved output a bit for sure :D --- modules/list_raids.php | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 modules/list_raids.php diff --git a/modules/list_raids.php b/modules/list_raids.php new file mode 100644 index 0000000..a45199a --- /dev/null +++ b/modules/list_raids.php @@ -0,0 +1,92 @@ +fetch_assoc(); + +// No data found. +if (!$row) { + //sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + //exit; + $tz = TIMEZONE; +} else { + $tz = $row['timezone']; +} + +// Build query. +$request = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE end_time>NOW() + AND timezone='{$tz}' + ORDER BY end_time ASC LIMIT 20 + " +); + +// Count results. +$count = 0; + +// Get raids. +while ($raid = $request->fetch_assoc()) { + + // Counter++ + $count = $count + 1; + + // Create keys array. + $keys = [ + [ + [ + 'text' => getTranslation('expand'), + 'callback_data' => $raid['id'] . ':vote_refresh:0', + ] + ] + ]; + + // Get message. + $msg = show_raid_poll_small($raid); + + // Send message. + send_message($update['callback_query']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); +} + +// Set message. +if($count == 0) { + //sendMessage($update['callback_query']['from']['id'], '' . getTranslation('no_active_raids_found') . ''); + $msg = '' . getTranslation('no_active_raids_found') . ''; +} else { + $msg = '' . getTranslation('list_all_active_raids') . ':'; +} + +// Set message. +$keys = []; + +// Edit message. +edit_message($update, $msg, $keys, false); + +// Build callback message string. +$callback_response = 'OK'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); + +exit; From cba3d049c775a39dc6944a5da671a986baa84ccf Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 12 Jan 2018 16:49:33 +0100 Subject: [PATCH 156/225] Language stuff for overview --- language.json | 136 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 108 insertions(+), 28 deletions(-) diff --git a/language.json b/language.json index a8d8bf2..486fa69 100755 --- a/language.json +++ b/language.json @@ -45,7 +45,7 @@ "EN": "Raid done" }, "here" : { - "DE": "Ben er", + "NL": "Ben er", "DE": "Bin da", "EN": "Here" }, @@ -115,12 +115,12 @@ "EN": "Raid egg opens on" }, "raid_egg_opens_at" : { - "NL": "at", + "NL": "om", "DE": "um", "EN": "at" }, "raid_until" : { - "NL": "Raid until", + "NL": "Raid tot", "DE": "Raid bis", "EN": "Raid until" }, @@ -229,6 +229,11 @@ "DE": "Groudon", "EN": "Groudon" }, + "kyogre" : { + "NL": "Kyogre", + "DE": "Kyogre", + "EN": "Kyogre" + }, "egg_5" : { "NL": "Level 5 Ei", "DE": "Level 5 Ei", @@ -350,17 +355,17 @@ "EN": "First letter selected." }, "raid_creation_started_at" : { - "NL": "Raid creation was started at", + "NL": "Raid aanmaak is gestart om", "DE": "Das Raid wird angelegt seit", "EN": "Raid creation was started at" }, "raid_being_created_by_other_user" : { - "NL": "Another user is currently creating a raid for this gym:", + "NL": "Een andere gebruiker is een raid voor deze gym aan het maken:", "DE": "Ein Raid für diese Arena wird gerade angelegt von:", "EN": "Another user is currently creating a raid for this gym:" }, "raid_already_exists" : { - "NL": "Raid already exists!", + "NL": "Raid bestaat al!", "DE": "Raid existiert bereits!", "EN": "Raid already exists!" }, @@ -370,17 +375,17 @@ "EN": "Create Raid in" }, "raid_creation_in_progress_warning" : { - "NL": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!", + "NL": "Je kan een raid aanmaken, maar de huidig aangemaakte raid zal worden overscheven. Deze wijziging kunnen niet ongedaan gemaakt worden dit is NIET AAN TE RADEN!", "DE": "Das Raid kann weiter angelegt werden, aber dies wird das Raid welches gerade zeitgleich erstellt wird überschreiben und ist daher definitiv NICHT EMPFOHLEN!", "EN": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!" }, "raid_creation_in_progress" : { - "NL": "Raid creation in progress", + "NL": "Raid wordt momenteel aangemaakt", "DE": "Raid wird gerade erstellt", "EN": "Raid creation in progress" }, "select_raid_level_to_continue" : { - "NL": "To really continue, please select raid level", + "NL": "Om echt door te gaan, selecteer een raid level", "DE": "Um wirklich fortzufahren, bitte Raid Level auswählen", "EN": "To really continue, please select raid level" }, @@ -434,6 +439,11 @@ "DE": "Teilen", "EN": "Share" }, + "share_with" : { + "NL": "Delen met", + "DE": "Teilen mit", + "EN": "Share with" + }, "set_gym_name_and_team" : { "NL": "Optioneel - Gym naam and Gym Team:", "DE": "Optional - Arena Name und Arena Team:", @@ -475,17 +485,17 @@ "EN": "In how many minutes does the raid begin?" }, "raid_starts_when_clocktime_view" : { - "NL": "Clock time view", + "NL": "klok", "DE": "Uhrzeit-Ansicht", "EN": "Clock time view" }, "raid_starts_when_minutes_view" : { - "NL": "Minutes view", + "NL": "Minuten", "DE": "Minuten-Ansicht", "EN": "Minutes view" }, "raid_starts_when_view_changed" : { - "NL": "View changed!", + "NL": "Overzicht verandert!", "DE": "Ansicht geändert!", "EN": "View changed!" }, @@ -495,17 +505,22 @@ "EN": "Raid is already active!" }, "raid_access_denied" : { - "NL": "You are not allowed to edit this raid!", + "NL": "Je hebt geen rechten om deze raid aan te passen!", "DE": "Sie haben keine Berechtigung dieses Raid zu bearbeiten!", "EN": "You are not allowed to edit this raid!" }, "no_active_raids_found" : { - "NL": "No active raids found in the system!", + "NL": "Geen actieve raids gevonden!", "DE": "Aktuell sind keine laufenden Raids im System!", "EN": "No active raids found in the system!" }, + "no_active_raids" : { + "NL": "Geen actieve raids!", + "DE": "Aktuell gibt es keine Raids!", + "EN": "No active raids currently!" + }, "expand" : { - "NL": "Expand", + "NL": "Uitklappen", "DE": "Ausklappen", "EN": "Expand" }, @@ -590,62 +605,127 @@ "EN": "Gym name updated." }, "mods_details" : { - "NL": "Select moderator for details:", + "NL": "Selecteer moderator voor meer informatie:", "DE": "Für Details Moderator auswählen:", "EN": "Select moderator for details:" }, "mods_add_new" : { - "NL": "Add new moderator:", + "NL": "Nieuwe moderator toevoegen:", "DE": "Neuen Moderator hinzufügen:", "EN": "Add new moderator:" }, "mods_delete" : { - "NL": "Delete moderator:", + "NL": "Moderator verwijderen:", "DE": "Moderator löschen:", "EN": "Delete moderator:" }, "mods_list_of_all" : { - "NL": "List of all moderators.", + "NL": "Lijst met alle moderators.", "DE": "Liste aller Moderatoren.", "EN": "List of all moderators." }, "mods_list_add_delete" : { - "NL": "List, add or remove moderators", + "NL": "Lijst, toevoegen of verwijderen van moderators", "DE": "Moderatoren anzeigen, hinzufügen oder löschen", "EN": "List, add or remove moderators" }, "mods_not_found" : { - "NL": "Error! No moderators or users found!", + "NL": "Error! Geen Moderator of gebruiker gevonden!", "DE": "Fehler! Keine Moderatoren oder Benutzer gefunden!", "EN": "Error! No moderators or users found!" }, "mods_saved_mod" : { - "NL": "Moderator saved!", + "NL": "Moderator opgeslagen!", "DE": "Moderator gespeichert!", "EN": "Moderator saved!" }, "mods_delete_mod" : { - "NL": "Moderator deleted!", + "NL": "Moderator verwijderd!", "DE": "Moderator gelöscht!", "EN": "Moderator deleted!" }, "mods_info_about_mod" : { - "NL": "Info about this moderator:", + "NL": "Informatie over deze moderator:", "DE": "Infos zum diesem Moderator:", "EN": "Info about this moderator:" }, + "overview_share" : { + "NL": "INSERT_TRANSLATION", + "DE": "Übersicht teilen", + "EN": "Share overview" + }, + "overview_delete" : { + "NL": "INSERT_TRANSLATION", + "DE": "Übersicht löschen", + "EN": "Delete overview" + }, + "raids_list_share_overview" : { + "NL": "INSERT_TRANSLATION", + "DE": "Aktive Raids als Liste anzeigen oder die Raid-Übersicht pro Chat teilen / löschen", + "EN": "Show active raids as list or share / delete the raid overview per chat" + }, + "list_all_active_raids" : { + "NL": "INSERT_TRANSLATION", + "DE": "Alle aktiven Raids", + "EN": "All active raids" + }, + "list_all_overviews" : { + "NL": "INSERT_TRANSLATION", + "DE": "Alle Raid-Übersichten", + "EN": "All raid overviews" + }, + "delete_raid_overview_for_chat" : { + "NL": "INSERT_TRANSLATION", + "DE": "Raid-Übersicht löschen für", + "EN": "Delete raid overview for" + }, + "no_overviews_found" : { + "NL": "INSERT_TRANSLATION", + "DE": "Keine Raid-Übersichten im System gefunden!", + "EN": "No raid overviews found in the system!" + }, + "overview_successfully_deleted" : { + "NL": "INSERT_TRANSLATION", + "DE": "Raid-Übersicht wurde erfolgreich gelöscht!", + "EN": "Raid overview was successfully deleted!" + }, + "overview_deletion_was_canceled" : { + "NL": "INSERT_TRANSLATION", + "DE": "Löschung der Raid-Übersicht wurde abgebrochen!", + "EN": "Deletion of the raid overview was canceled!" + }, + "raid_overview_for_chat" : { + "NL": "INSERT_TRANSLATION", + "DE": "Raid-Übersicht für", + "EN": "Overview of raids for" + }, + "successfully_shared" : { + "NL": "INSERT_TRANSLATION", + "DE": "Erfolgreich geteilt!", + "EN": "Successfully shared!" + }, + "yes" : { + "NL": "Ja", + "DE": "Ja", + "EN": "Yes" + }, + "no" : { + "NL": "Nee", + "DE": "Nein", + "EN": "No" + }, "list" : { - "NL": "List", + "NL": "Lijst", "DE": "Anzeigen", - "EN": "List" + "EN": "List" }, "add" : { - "NL": "Add", + "NL": "Toevoegen", "DE": "Hinzufügen", "EN": "Add" }, "delete" : { - "NL": "Delete", + "NL": "Verwijder", "DE": "Löschen", "EN": "Delete" } From bede818397d5db100dd4086befe9245b4a840e5a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Sun, 14 Jan 2018 23:04:26 +0100 Subject: [PATCH 157/225] Overview modules and logic Added an own cleanup logfile as cleanup cronjob can write quite a lot to the debug logfile, so I guess it's better to have an own cleanup logfile therefore. Removed an unnecessary whitespace in logic.php for the raid messages too. Thanks @klablabla for the NL translation! :) --- config.php.example | 1 + debug.php | 21 +- functions.php | 16 +- index.php | 4 +- language.json | 27 ++- logic.php | 377 ++++++++++++++++++++++++++++++++--- modules/overview_delete.php | 106 ++++++++++ modules/overview_refresh.php | 138 +++++++++++++ modules/overview_share.php | 125 ++++++++++++ 9 files changed, 765 insertions(+), 50 deletions(-) create mode 100644 modules/overview_delete.php create mode 100644 modules/overview_refresh.php create mode 100644 modules/overview_share.php diff --git a/config.php.example b/config.php.example index c5b7eab..a2b3bef 100755 --- a/config.php.example +++ b/config.php.example @@ -29,6 +29,7 @@ define ('RAID_POKEMON_DURATION_SHORT', '45'); //minutes till pokemon leave define ('RAID_DURATION_CLOCK_STYLE', true); // True: Clocktime style, e.g. "18:34" --- False: Minute style, e.g. "still 0:34" define('CLEANUP', false); // must be true for cleanup +define('CLEANUP_LOGFILE', '/var/log/tg-bots/dev-raid-bot-cleanup.log'); define('CLEANUP_SECRET', 'your-cleanup-secret/passphrase'); define('CLEANUP_TELEGRAM', true); define('CLEANUP_TIME_TG', '10'); // minutes after RAID ended diff --git a/debug.php b/debug.php index a81e32e..117b56a 100644 --- a/debug.php +++ b/debug.php @@ -35,7 +35,7 @@ function my_query($query) * @param $val * @param string $type */ -function debug_log($val, $type = '*') +function debug_log($val, $type = '*', $cleanup_log = false) { // Write to log only if debug is enabled. if (DEBUG === true) { @@ -56,7 +56,22 @@ function debug_log($val, $type = '*') if (gettype($val) != 'string') $val = var_export($val, 1); $rows = explode("\n", $val); foreach ($rows as $v) { - error_log('[' . $date . '][' . getmypid() . '] ' . $bl . $type . ' ' . $v . "\n", 3, CONFIG_LOGFILE); + if ($cleanup_log == true) { + error_log('[' . $date . '][' . getmypid() . '] ' . $bl . $type . ' ' . $v . "\n", 3, CLEANUP_LOGFILE); + } else { + error_log('[' . $date . '][' . getmypid() . '] ' . $bl . $type . ' ' . $v . "\n", 3, CONFIG_LOGFILE); + } } } -} \ No newline at end of file +} + +/** + * Write cleanup log. + * @param $val + * @param string $type + * @param bool $cleanup_log + */ +function cleanup_log($val, $type = '*') +{ + debug_log($val, $type, $cleanup_log = true); +} diff --git a/functions.php b/functions.php index 34044ef..2904290 100755 --- a/functions.php +++ b/functions.php @@ -70,7 +70,7 @@ function send_message($chat_id, $text = array(), $inline_keyboard = false, $merg debug_log($reply_json, '>'); // Send request to telegram api. - curl_json_request($reply_json); + return curl_json_request($reply_json); } /** @@ -504,6 +504,20 @@ function curl_json_request($json) debug_log('Missing input! Cannot call cleanup preparation!'); } } + + // Check if text starts with getTranslation('raid_overview_for_chat') and inline keyboard is empty + $translation = getTranslation('raid_overview_for_chat'); + $translation_length = strlen($translation); + $text = substr($response['result']['text'], 0, $translation_length); + if ($text == $translation && empty($json_message['reply_markup']['inline_keyboard'])) { + debug_log('Detected overview message!'); + debug_log('Chat_ID: ' . $chat_id); + debug_log('Message_ID: ' . $message_id); + + // Write raid overview data to database + debug_log('Adding overview info to database now!'); + insert_overview($chat_id, $message_id); + } } } diff --git a/index.php b/index.php index 0f17a6d..92de934 100755 --- a/index.php +++ b/index.php @@ -72,7 +72,7 @@ // Cleanup request received. if (isset($update['cleanup']) && CLEANUP == true) { - debug_log('Cleanup process request received...'); + cleanup_log('Cleanup process request received...'); // Check access to cleanup of bot if ($update['cleanup']['secret'] == CLEANUP_SECRET) { // Get telegram cleanup value if specified. @@ -88,7 +88,7 @@ $database = 2; } // Run cleanup - debug_log('Calling cleanup process now!'); + cleanup_log('Calling cleanup process now!'); run_cleanup($telegram, $database); } // Exit after cleanup diff --git a/language.json b/language.json index 486fa69..aa7a556 100755 --- a/language.json +++ b/language.json @@ -514,6 +514,11 @@ "DE": "Aktuell sind keine laufenden Raids im System!", "EN": "No active raids found in the system!" }, + "no_active_raids_shared" : { + "NL": "Geen van de actieve raid is gedeeld!", + "DE": "Keines der aktiven Raids wurde geteilt!", + "EN": "None of the active raids was shared!" + }, "no_active_raids" : { "NL": "Geen actieve raids!", "DE": "Aktuell gibt es keine Raids!", @@ -650,57 +655,57 @@ "EN": "Info about this moderator:" }, "overview_share" : { - "NL": "INSERT_TRANSLATION", + "NL": "Overzicht delen", "DE": "Übersicht teilen", "EN": "Share overview" }, "overview_delete" : { - "NL": "INSERT_TRANSLATION", + "NL": "Vewijder overzicht", "DE": "Übersicht löschen", "EN": "Delete overview" }, "raids_list_share_overview" : { - "NL": "INSERT_TRANSLATION", + "NL": "Geef de actieve raid weer als een lijst of deel / verwijder het raid overzicht", "DE": "Aktive Raids als Liste anzeigen oder die Raid-Übersicht pro Chat teilen / löschen", "EN": "Show active raids as list or share / delete the raid overview per chat" }, "list_all_active_raids" : { - "NL": "INSERT_TRANSLATION", + "NL": "Alle actieve raids", "DE": "Alle aktiven Raids", "EN": "All active raids" }, "list_all_overviews" : { - "NL": "INSERT_TRANSLATION", + "NL": "Totaal raid overzicht", "DE": "Alle Raid-Übersichten", "EN": "All raid overviews" }, "delete_raid_overview_for_chat" : { - "NL": "INSERT_TRANSLATION", + "NL": "Verwijder raid overzicht voor", "DE": "Raid-Übersicht löschen für", "EN": "Delete raid overview for" }, "no_overviews_found" : { - "NL": "INSERT_TRANSLATION", + "NL": "Geen raid overzicht gevonden in het systeem!", "DE": "Keine Raid-Übersichten im System gefunden!", "EN": "No raid overviews found in the system!" }, "overview_successfully_deleted" : { - "NL": "INSERT_TRANSLATION", + "NL": "Raid overzicht is succesvol verwijderd!", "DE": "Raid-Übersicht wurde erfolgreich gelöscht!", "EN": "Raid overview was successfully deleted!" }, "overview_deletion_was_canceled" : { - "NL": "INSERT_TRANSLATION", + "NL": "Het verwijderen van het raid overzicht is gestopt!", "DE": "Löschung der Raid-Übersicht wurde abgebrochen!", "EN": "Deletion of the raid overview was canceled!" }, "raid_overview_for_chat" : { - "NL": "INSERT_TRANSLATION", + "NL": "Raid overzicht voor", "DE": "Raid-Übersicht für", "EN": "Overview of raids for" }, "successfully_shared" : { - "NL": "INSERT_TRANSLATION", + "NL": "Succesvol gedeeld!", "DE": "Erfolgreich geteilt!", "EN": "Successfully shared!" }, diff --git a/logic.php b/logic.php index cf2b5a6..6aba282 100755 --- a/logic.php +++ b/logic.php @@ -770,8 +770,8 @@ function insert_cleanup($chat_id, $message_id, $raid_id) function run_cleanup ($telegram = 2, $database = 2) { // Check configuration, cleanup of telegram needs to happen before database cleanup! if (CLEANUP_TIME_TG > CLEANUP_TIME_DB) { - debug_log('Configuration issue! Cleanup time for telegram messages needs to be lower or equal to database cleanup time!'); - debug_log('Stopping cleanup process now!'); + cleanup_log('Configuration issue! Cleanup time for telegram messages needs to be lower or equal to database cleanup time!'); + cleanup_log('Stopping cleanup process now!'); exit; } @@ -809,7 +809,7 @@ function run_cleanup ($telegram = 2, $database = 2) { } // Write to log. - debug_log($cleanup_jobs); + cleanup_log($cleanup_jobs); // Init previous raid id. $prev_raid_id = "FIRST_RUN"; @@ -819,10 +819,10 @@ function run_cleanup ($telegram = 2, $database = 2) { $current_raid_id = ($row['raid_id'] == 0) ? $row['cleaned'] : $row['raid_id']; // Write to log. - debug_log("Cleanup ID: " . $row['id']); - debug_log("Chat ID: " . $row['chat_id']); - debug_log("Message ID: " . $row['message_id']); - debug_log("Raid ID: " . $row['raid_id']); + cleanup_log("Cleanup ID: " . $row['id']); + cleanup_log("Chat ID: " . $row['chat_id']); + cleanup_log("Message ID: " . $row['message_id']); + cleanup_log("Raid ID: " . $row['raid_id']); // Get raid data only when raid_id changed compared to previous run if ($prev_raid_id != $current_raid_id) { @@ -850,16 +850,17 @@ function run_cleanup ($telegram = 2, $database = 2) { $cleanup_time_db = 60*CLEANUP_TIME_DB; // Write times to log. - debug_log("Raid end time: " . unix2tz($end,$tz,"Y-m-d H:i:s")); - debug_log("Raid cleanup time: " . unix2tz(($end + $cleanup_time),$tz,"Y-m-d H:i:s")); - debug_log("Current time: " . unix2tz($now,$tz,"Y-m-d H:i:s")); + cleanup_log("Current time: " . unix2tz($now,$tz,"Y-m-d H:i:s")); + cleanup_log("Raid end time: " . unix2tz($end,$tz,"Y-m-d H:i:s")); + cleanup_log("Telegram cleanup time: " . unix2tz(($end + $cleanup_time_tg),$tz,"Y-m-d H:i:s")); + cleanup_log("Database cleanup time: " . unix2tz(($end + $cleanup_time_db),$tz,"Y-m-d H:i:s")); // Write unix timestamps to log. - debug_log("Unix timestamps:"); - debug_log("Raid end time: " . $end); - debug_log("Telegram cleanup time: " . ($end + $cleanup_time_tg)); - debug_log("Database cleanup time: " . ($end + $cleanup_time_db)); - debug_log("Current time: " . $now); + cleanup_log(CR . "Unix timestamps:"); + cleanup_log("Current time: " . $now); + cleanup_log("Raid end time: " . $end); + cleanup_log("Telegram cleanup time: " . ($end + $cleanup_time_tg)); + cleanup_log("Database cleanup time: " . ($end + $cleanup_time_db)); } // Time for telegram cleanup? @@ -867,10 +868,10 @@ function run_cleanup ($telegram = 2, $database = 2) { // Delete raid poll telegram message if not already deleted if ($telegram == 1 && $row['chat_id'] != 0 && $row['message_id'] != 0) { // Delete telegram message. - debug_log('Deleting telegram message ' . $row['message_id'] . ' from chat ' . $row['chat_id'] . ' for raid ' . $row['raid_id']); + cleanup_log('Deleting telegram message ' . $row['message_id'] . ' from chat ' . $row['chat_id'] . ' for raid ' . $row['raid_id']); delete_message($row['chat_id'], $row['message_id']); // Set database values of chat_id and message_id to 0 so we know telegram message was deleted already. - debug_log('Updating telegram cleanup inforamtion.'); + cleanup_log('Updating telegram cleanup inforamtion.'); my_query( " UPDATE cleanup @@ -881,13 +882,13 @@ function run_cleanup ($telegram = 2, $database = 2) { ); } else { if ($telegram == 1) { - debug_log('Telegram message is already deleted!'); + cleanup_log('Telegram message is already deleted!'); } else { - debug_log('Telegram cleanup was not triggered! Skipping...'); + cleanup_log('Telegram cleanup was not triggered! Skipping...'); } } } else { - debug_log('Skipping cleanup of telegram for this raid! Cleanup time has not yet come...'); + cleanup_log('Skipping cleanup of telegram for this raid! Cleanup time has not yet come...'); } // Time for database cleanup? @@ -896,7 +897,7 @@ function run_cleanup ($telegram = 2, $database = 2) { // Make sure to delete only once - raid may be in multiple channels/supergroups, but only 1 time in database if (($database == 1) && $row['raid_id'] != 0 && ($prev_raid_id != $current_raid_id)) { // Delete raid from attendance table. - debug_log('Deleting attendances for raid ' . $current_raid_id); + cleanup_log('Deleting attendances for raid ' . $current_raid_id); my_query( " DELETE FROM attendance @@ -906,7 +907,7 @@ function run_cleanup ($telegram = 2, $database = 2) { // Set database value of raid_id to 0 so we know attendance info was deleted already // Use raid_id in where clause since the same raid_id can in cleanup more than once - debug_log('Updating database cleanup inforamtion.'); + cleanup_log('Updating database cleanup inforamtion.'); my_query( " UPDATE cleanup @@ -917,9 +918,9 @@ function run_cleanup ($telegram = 2, $database = 2) { ); } else { if ($database == 1) { - debug_log('Attendances are already deleted!'); + cleanup_log('Attendances are already deleted!'); } else { - debug_log('Attendance cleanup was not triggered! Skipping...'); + cleanup_log('Attendance cleanup was not triggered! Skipping...'); } } @@ -927,7 +928,7 @@ function run_cleanup ($telegram = 2, $database = 2) { // In addition trigger deletion only when previous and current raid_id are different to avoid unnecessary sql queries if ($row['raid_id'] == 0 && $row['chat_id'] == 0 && $row['message_id'] == 0 && $row['cleaned'] != 0 && ($prev_raid_id != $current_raid_id)) { // Delete raid from raids table. - debug_log('Deleting raid ' . $row['cleaned'] . ' from database.'); + cleanup_log('Deleting raid ' . $row['cleaned'] . ' from database.'); my_query( " DELETE FROM raids @@ -936,7 +937,7 @@ function run_cleanup ($telegram = 2, $database = 2) { ); // Get all cleanup jobs which will be deleted now. - debug_log('Removing cleanup info from database:'); + cleanup_log('Removing cleanup info from database:'); $rs_cl = my_query( " SELECT * @@ -947,7 +948,7 @@ function run_cleanup ($telegram = 2, $database = 2) { // Log each cleanup ID which will be deleted. while($rs_cleanups = $rs_cl->fetch_assoc()) { - debug_log('Cleanup ID: ' . $rs_cleanups['id'] . ', Former Raid ID: ' . $rs_cleanups['cleaned']); + cleanup_log('Cleanup ID: ' . $rs_cleanups['id'] . ', Former Raid ID: ' . $rs_cleanups['cleaned']); } // Finally delete from cleanup table. @@ -959,13 +960,13 @@ function run_cleanup ($telegram = 2, $database = 2) { ); } else { if ($prev_raid_id != $current_raid_id) { - debug_log('Time for complete removal of raid from database has not yet come.'); + cleanup_log('Time for complete removal of raid from database has not yet come.'); } else { - debug_log('Complete removal of raid from database was already done!'); + cleanup_log('Complete removal of raid from database was already done!'); } } } else { - debug_log('Skipping cleanup of database for this raid! Cleanup time has not yet come...'); + cleanup_log('Skipping cleanup of database for this raid! Cleanup time has not yet come...'); } // Store current raid id as previous id for next loop @@ -973,7 +974,7 @@ function run_cleanup ($telegram = 2, $database = 2) { } // Write to log. - debug_log('Finished with cleanup process!'); + cleanup_log('Finished with cleanup process!'); } } @@ -1233,7 +1234,7 @@ function send_response_vote($update, $data, $new = false) } else { // Edit the message. - edit_message($update, $msg, $keys); + edit_message($update, $msg, $keys, ['disable_web_page_preview' => 'true']); // Change message string. $msg = getTranslation('vote_updated'); // Answer the callback. @@ -1243,6 +1244,316 @@ function send_response_vote($update, $data, $new = false) exit; } +/** + * Insert overview. + * @param $chat_id + * @param $message_id + */ +function insert_overview($chat_id, $message_id) +{ + global $db; + + // Build query to check if overview details are already in database or not + $rs = my_query( + " + SELECT COUNT(*) + FROM overview + WHERE chat_id = '{$chat_id}' + " + ); + + $row = $rs->fetch_row(); + + // Overview already in database or new + if (empty($row['0'])) { + // Build query for overview table to add overview info to database + debug_log('Adding new overview information to database overview list!'); + $rs = my_query( + " + INSERT INTO overview + SET chat_id = '{$chat_id}', + message_id = '{$message_id}' + " + ); + } else { + // Nothing to do - overview information is already in database. + debug_log('Overview information is already in database! Nothing to do...'); + } +} + +/** + * Delete overview. + * @param $chat_id + * @param $message_id + */ +function delete_overview($chat_id, $message_id) +{ + global $db; + + // Delete telegram message. + debug_log('Deleting overview telegram message ' . $message_id . ' from chat ' . $chat_id); + delete_message($chat_id, $message_id); + + // Delete overview from database. + debug_log('Deleting overview information from database for Chat_ID: ' . $chat_id); + $rs = my_query( + " + DELETE FROM overview + WHERE chat_id = '{$chat_id}' + " + ); +} + +/** + * Get overview data to Share or refresh. + * @param $update + * @param $chats_active + * @param $raids_active + * @param $action - refresh or share + * @param $chat_id + */ +function get_overview($update, $chats_active, $raids_active, $action = 'refresh', $chat_id = 0) +{ + // Add pseudo array for last run to active chats array + $last_run = array(); + $last_run[chat_id] = 'LAST_RUN'; + $chats_active[] = $last_run; + + // Init previous chat_id + $previous = 'FIRST_RUN'; + + // Any active raids currently? + if (empty($raids_active)) { + // Init keys. + $keys = array(); + $keys = []; + + // Refresh active overview messages with 'no_active_raids_currently' or send 'no_active_raids_found' message to user. + $rs = my_query( + " + SELECT * + FROM overview + " + ); + + // Refresh active overview messages. + while ($row_overview = $rs->fetch_assoc()) { + $chat_id = $row_overview['chat_id']; + $message_id = $row_overview['message_id']; + + // Get info about chat for title. + debug_log('Getting chat object for chat_id: ' . $row_overview['chat_id']); + $chat_obj = get_chat($row_overview['chat_id']); + $chat_title = ''; + + // Set title. + if ($chat_obj['ok'] == 'true') { + $chat_title = $chat_obj['result']['title']; + debug_log('Title of the chat: ' . $chat_obj['result']['title']); + } + + // Set the message. + $msg = '' . getTranslation('raid_overview_for_chat') . ' ' . $chat_title . ':' . CR . CR; + $msg .= getTranslation('no_active_raids'); + $msg .= CR . '' . getTranslation('updated') . ': ' . unix2tz(time(), TIMEZONE, 'H:i:s') . ''; + + // Edit the message, but disable the web preview! + debug_log('Updating overview:' . CR . 'Chat_ID: ' . $chat_id . CR . 'Message_ID: ' . $message_id); + editMessageText($message_id, $msg, $keys, $chat_id); + } + + // Triggered from user or cronjob? + if (!empty($update['callback_query']['id'])) { + // Send no active raids message to the user. + $msg = getTranslation('no_active_raids'); + + // Edit the message, but disable the web preview! + edit_message($update, $msg, $keys); + + // Answer the callback. + answerCallbackQuery($update['callback_query']['id'], $msg); + } + + // Exit here. + exit; + } + + // Share or refresh each chat. + foreach ($chats_active as $row) { + $current = $row['chat_id']; + + // Are any raids shared? + if ($previous == "FIRST_RUN" && $current == "LAST_RUN") { + // Send no active raids message to the user. + $msg = getTranslation('no_active_raids_shared'); + + // Edit the message, but disable the web preview! + edit_message($update, $msg, $keys); + + // Answer the callback. + answerCallbackQuery($update['callback_query']['id'], $msg); + } + + // Send message if not first run and previous not current + if ($previous !== 'FIRST_RUN' && $previous !== $current) { + // Add keys. + $keys = array(); + + // Add update timestamp to msg. + $msg .= '' . getTranslation('updated') . ': ' . unix2tz(time(), $tz, 'H:i:s') . ''; + + // Share or refresh? + if ($action == 'share') { + if ($chat_id == 0) { + // Make sure it's not already shared + $rs = my_query( + " + SELECT COUNT(*) + FROM overview + WHERE chat_id = '{$previous}' + " + ); + + $row = $rs->fetch_row(); + + if (empty($row['0'])) { + // Not shared yet - Share button + $keys[] = [ + [ + 'text' => getTranslation('share_with') . ' ' . $chat_obj['result']['title'], + 'callback_data' => '0:overview_share:' . $previous + ] + ]; + } else { + // Already shared - refresh button + $keys[] = [ + [ + 'text' => EMOJI_REFRESH, + 'callback_data' => '0:overview_refresh:' . $previous + ] + ]; + } + + // Send the message, but disable the web preview! + send_message($update['callback_query']['message']['chat']['id'], $msg, $keys, ['disable_web_page_preview' => 'true']); + + // Set the callback message and keys + $callback_keys = array(); + $callback_keys = []; + $callback_msg = '' . getTranslation('list_all_overviews') . ':'; + + // Edit the message. + edit_message($update, $callback_msg, $callback_keys); + + // Answer the callback. + answerCallbackQuery($update['callback_query']['id'], 'OK'); + } else { + // Shared overview + $keys = []; + + // Set callback message string. + $msg_callback = getTranslation('successfully_shared'); + + // Edit the message, but disable the web preview! + edit_message($update, $msg_callback, $keys, ['disable_web_page_preview' => 'true']); + + // Answer the callback. + answerCallbackQuery($update['callback_query']['id'], $msg_callback); + + // Send the message, but disable the web preview! + send_message($chat_id, $msg, $keys, ['disable_web_page_preview' => 'true']); + } + } else { + // Refresh overview messages. + $keys = []; + + // Get active overviews + $rs = my_query( + " + SELECT message_id + FROM overview + WHERE chat_id = '{$previous}' + " + ); + + // Edit text for all messages, but disable the web preview! + while ($row_msg_id = $rs->fetch_assoc()) { + // Set message_id. + $message_id = $row_msg_id['message_id']; + debug_log('Updating overview:' . CR . 'Chat_ID: ' . $previous . CR . 'Message_ID: ' . $message_id); + editMessageText($message_id, $msg, $keys, $previous, ['disable_web_page_preview' => 'true']); + } + + // Answer the callback. + answerCallbackQuery($update['callback_query']['id'], 'OK'); + } + } + + // End if last run + if ($current == 'LAST_RUN') { + break; + } + + // Create message for each raid_id + if($previous !== $current) { + // Get info about chat for username. + debug_log('Getting chat object for chat_id: ' . $row['chat_id']); + $chat_obj = get_chat($row['chat_id']); + $chat_username = ''; + + // Set username if available. + if ($chat_obj['ok'] == 'true' && isset($chat_obj['result']['username'])) { + $chat_username = $chat_obj['result']['username']; + debug_log('Username of the chat: ' . $chat_obj['result']['username']); + } + + $msg = '' . getTranslation('raid_overview_for_chat') . ' ' . $chat_obj['result']['title'] . ':' . CR . CR; + } + + // Set variables for easier message building. + $raid_id = $row['raid_id']; + $pokemon = $raids_active[$raid_id]['pokemon']; + $gym = $raids_active[$raid_id]['gym_name']; + $now = $raids_active[$raid_id]['ts_now']; + $tz = $raids_active[$raid_id]['timezone']; + $start_time = $raids_active[$raid_id]['ts_start']; + $time_left = floor($raids_active[$raid_id]['t_left'] / 60); + + // Build message and add each gym in this format - link gym_name to raid poll chat_id + message_id if possible + /* Example: + * Raid Overview from 18:18h + * + * Train Station Gym + * Raikou - still 0:24h + * + * Bus Station Gym + * Level 5 Egg opens up 18:41h + */ + // Gym name. + $msg .= !empty($chat_username) ? '' . htmlspecialchars($gym) . '' : $gym; + $msg .= CR; + + // Raid has not started yet - adjust time left message + if ($now < $start_time) { + $weekday_now = date('N', $now); + $weekday_start = date('N', $start_time); + $raid_day = weekday_number2name ($weekday_start); + if ($weekday_now == $weekday_start) { + $msg .= getTranslation('raid_egg_opens') . ' ' . unix2tz($start_time, $tz) . CR . CR; + } else { + $msg .= getTranslation('raid_egg_opens_day') . ' ' . $raid_day . ' ' . getTranslation('raid_egg_opens_at') . ' ' . unix2tz($start_time, $tz) . CR . CR; + } + + // Raid has started already + } else { + // Add time left message. + $msg .= $pokemon . ' — ' . getTranslation('still') . ' ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h' . CR . CR; + } + + // Prepare next iteration + $previous = $current; + } +} /** * Convert unix timestamp to time string by timezone settings. * @param $unix @@ -1350,7 +1661,7 @@ function show_raid_poll($raid) $time_left = floor($raid['t_left'] / 60); if ( strpos(str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) , '-' ) !== false ) { // $time_left = 'beendet'; <-- REPLACED BY $tl_msg, so if clause below is still working ($time_left < 0) - $tl_msg = ' ' . getTranslation('raid_done') . ''; + $tl_msg = '' . getTranslation('raid_done') . ''; } else { // Replace $time_left with $tl_msg too $tl_msg = ' — ' . getTranslation('still') . ' ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h'; diff --git a/modules/overview_delete.php b/modules/overview_delete.php new file mode 100644 index 0000000..ecf645f --- /dev/null +++ b/modules/overview_delete.php @@ -0,0 +1,106 @@ +fetch_assoc()) { + // Counter++ + $count = $count + 1; + + // Get info about chat for title. + debug_log('Getting chat object for chat_id: ' . $rowOverviews['chat_id']); + $chat_obj = get_chat($rowOverviews['chat_id']); + $chat_title = ''; + + // Set title. + if ($chat_obj['ok'] == 'true') { + $chat_title = $chat_obj['result']['title']; + debug_log('Title of the chat: ' . $chat_obj['result']['title']); + } + + // Build message string. + $msg = '' . getTranslation('delete_raid_overview_for_chat') . ' ' . $chat_title . '?'; + + // Set keys - Delete button. + $keys[] = [ + [ + 'text' => getTranslation('yes'), + 'callback_data' => '0:overview_delete:' . $rowOverviews['chat_id'] + ], + [ + 'text' => getTranslation('no'), + 'callback_data' => '0:overview_delete:1' + ] + ]; + + // Send the message, but disable the web preview! + send_message($update['callback_query']['message']['chat']['id'], $msg, $keys); + } + + // Set message. + if($count == 0) { + $callback_msg = '' . getTranslation('no_overviews_found') . ''; + } else { + $callback_msg = '' . getTranslation('list_all_overviews') . ':'; + } +} else if ($chat_id == 1) { + // Write to log. + debug_log('Deletion of the raid overview was canceled!'); + + // Set message. + $callback_msg = '' . getTranslation('overview_deletion_was_canceled') . ''; +} else { + // Write to log. + debug_log('Triggering deletion of overview for Chat_ID ' . $chat_id); + + // Get chat and message ids for overview. + $request_overviews = my_query( + " + SELECT * + FROM overview + WHERE chat_id = '{$chat_id}' + " + ); + + $overview = $request_overviews->fetch_assoc(); + + // Delete overview + delete_overview($overview['chat_id'], $overview['message_id']); + + // Set message. + $callback_msg = '' . getTranslation('overview_successfully_deleted') . ''; +} + +// Init keys. +$callback_keys = array(); + +// Set keys. +$callback_keys = []; + +// Edit message. +edit_message($update, $callback_msg, $callback_keys, false); + +// Build callback message string. +$callback_response = 'OK'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); diff --git a/modules/overview_refresh.php b/modules/overview_refresh.php new file mode 100644 index 0000000..340d14d --- /dev/null +++ b/modules/overview_refresh.php @@ -0,0 +1,138 @@ +fetch_assoc(); + + // No data found. + if (!$row) { + //sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + //exit; + $tz = TIMEZONE; + } else { + $tz = $row['timezone']; + } +} else { + $tz = TIMEZONE; +} + +// Get active raids. +$request_active_raids = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE end_time>NOW() + AND timezone='{$tz}' + ORDER BY end_time ASC + " +); + +// Count active raids. +$count_active_raids = 0; + +// Init empty active raids and raid_ids array. +$raids_active = array(); +$raid_ids_active = array(); + +// Get all active raids into array. +while ($rowRaids = $request_active_raids->fetch_assoc()) { + // Use current raid_id as key for raids array + $current_raid_id = $rowRaids['id']; + $raids_active[$current_raid_id] = $rowRaids; + + // Build array with raid_ids to query cleanup table later + $raid_ids_active[] = $rowRaids['id']; + + // Counter for active raids + $count_active_raids = $count_active_raids + 1; +} + +// Write to log. +debug_log('Active raids:'); +debug_log($raids_active); + +// Init empty active chats array. +$chats_active = array(); + +// Make sure we have active raids. +if ($count_active_raids > 0) { + // Implode raid_id's of all active raids. + $raid_ids_active = implode(',',$raid_ids_active); + + // Write to log. + debug_log('IDs of active raids:'); + debug_log($raid_ids_active); + + // Get all or specific overview + if ($chat_id == 0) { + $request_overviews = my_query( + " + SELECT chat_id + FROM overview + " + ); + } else { + $request_overviews = my_query( + " + SELECT chat_id + FROM overview + WHERE chat_id = '{$chat_id}' + " + ); + } + + while ($rowOverviews = $request_overviews->fetch_assoc()) { + // Set chat_id. + $chat_id = $rowOverviews['chat_id']; + + // Get chats. + $request_active_chats = my_query( + " + SELECT * + FROM cleanup + WHERE raid_id IN ({$raid_ids_active}) + AND chat_id = '{$chat_id}' + ORDER BY chat_id, FIELD(raid_id, {$raid_ids_active}) + " + ); + + // Get all chats. + while ($rowChats = $request_active_chats->fetch_assoc()) { + $chats_active[] = $rowChats; + } + } +} + +// Write to log. +debug_log('Active chats:'); +debug_log($chats_active); + +// Get raid overviews +get_overview($update, $chats_active, $raids_active, $action = 'refresh', $chat_id); +exit; diff --git a/modules/overview_share.php b/modules/overview_share.php new file mode 100644 index 0000000..9e59644 --- /dev/null +++ b/modules/overview_share.php @@ -0,0 +1,125 @@ +fetch_assoc(); + +// No data found. +if (!$row) { + //sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + //exit; + $tz = TIMEZONE; +} else { + $tz = $row['timezone']; +} + +// Get active raids. +$request_active_raids = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE end_time>NOW() + AND timezone='{$tz}' + ORDER BY end_time ASC + " +); + +// Count active raids. +$count_active_raids = 0; + +// Init empty active raids and raid_ids array. +$raids_active = array(); +$raid_ids_active = array(); + +// Get all active raids into array. +while ($rowRaids = $request_active_raids->fetch_assoc()) { + // Use current raid_id as key for raids array + $current_raid_id = $rowRaids['id']; + $raids_active[$current_raid_id] = $rowRaids; + + // Build array with raid_ids to query cleanup table later + $raid_ids_active[] = $rowRaids['id']; + + // Counter for active raids + $count_active_raids = $count_active_raids + 1; +} + +// Write to log. +debug_log('Active raids:'); +debug_log($raids_active); + +// Init empty active chats array. +$chats_active = array(); + +// Make sure we have active raids. +if ($count_active_raids > 0) { + // Implode raid_id's of all active raids. + $raid_ids_active = implode(',',$raid_ids_active); + + // Write to log. + debug_log('IDs of active raids:'); + debug_log($raid_ids_active); + + // Get chat for active raids. + if ($chat_id == 0) { + $request_active_chats = my_query( + " + SELECT * + FROM cleanup + WHERE raid_id IN ({$raid_ids_active}) + ORDER BY chat_id, FIELD(raid_id, {$raid_ids_active}) + " + ); + } else { + $request_active_chats = my_query( + " + SELECT * + FROM cleanup + WHERE raid_id IN ({$raid_ids_active}) + AND chat_id = '{$chat_id}' + ORDER BY chat_id, FIELD(raid_id, {$raid_ids_active}) + " + ); + } + + // Get all chats. + while ($rowChats = $request_active_chats->fetch_assoc()) { + $chats_active[] = $rowChats; + } +} + +// Write to log. +debug_log('Active chats:'); +debug_log($chats_active); + +// Get raid overviews +if ($chat_id == 0) { + get_overview($update, $chats_active, $raids_active, $action = 'share'); +} else { + get_overview($update, $chats_active, $raids_active, $action = 'share', $chat_id); +} +exit; From 4c335e5050b57051be6e8f20b2eb3f6bc946ed8b Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Sun, 14 Jan 2018 23:40:05 +0100 Subject: [PATCH 158/225] Beautify it! Add a whitespace :D --- logic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.php b/logic.php index 6aba282..80371ab 100755 --- a/logic.php +++ b/logic.php @@ -1355,7 +1355,7 @@ function get_overview($update, $chats_active, $raids_active, $action = 'refresh' // Set the message. $msg = '' . getTranslation('raid_overview_for_chat') . ' ' . $chat_title . ':' . CR . CR; $msg .= getTranslation('no_active_raids'); - $msg .= CR . '' . getTranslation('updated') . ': ' . unix2tz(time(), TIMEZONE, 'H:i:s') . ''; + $msg .= CR . CR . '' . getTranslation('updated') . ': ' . unix2tz(time(), TIMEZONE, 'H:i:s') . ''; // Edit the message, but disable the web preview! debug_log('Updating overview:' . CR . 'Chat_ID: ' . $chat_id . CR . 'Message_ID: ' . $message_id); From 433cd5a88c4d8a4c685073f8260d8d7f0615ccb8 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 15 Jan 2018 19:54:54 +0100 Subject: [PATCH 159/225] Added attendances (summarized for all timeslots) to the overview --- logic.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/logic.php b/logic.php index 80371ab..3363313 100755 --- a/logic.php +++ b/logic.php @@ -1550,6 +1550,55 @@ function get_overview($update, $chats_active, $raids_active, $action = 'refresh' $msg .= $pokemon . ' — ' . getTranslation('still') . ' ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h' . CR . CR; } + // Build query to add attendances to message. + $rs = my_query( + " + SELECT team, + COUNT(*) AS cnt, + SUM(extra_people) AS extra + FROM attendance + WHERE raid_id = {$raid_id} + AND (cancel = 0 OR cancel IS NULL) + AND (raid_done = 0 OR raid_done IS NULL) + GROUP BY team + " + ); + + $total = 0; + $total_extra = 0; + $sep = ''; + $msg_teams = ''; + + // Get attendances for each team and unknown + while ($row_att = $rs->fetch_assoc()) { + $sum = $row_att['cnt']; + + if ($sum == 0) continue; + + // Add to message. + $msg_teams .= $sep . $GLOBALS['teams'][$row_att['team']] . $sum; + $sep = ' '; + $total += $sum; + + if ($row_att['extra'] > 0) { + $total_extra += $row_att['extra']; + $total += $row_att['extra']; + } + } + + // Add team unknown count + if ($total_extra > 0) { + $msg_teams .= $sep . TEAM_UNKNOWN . $total_extra; + } + + // Add attendances to message if there are some + if ($total > 0) { + $msg .= EMOJI_GROUP . ' ' . $total . ' — ' . $msg_teams . CR; + } + + // Add CR to message now since we don't know if attendances got added or not + $msg .= CR; + // Prepare next iteration $previous = $current; } From 1405b5faa62c2e2d57b5d7d2cbaac46193f708ed Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Mon, 15 Jan 2018 22:25:11 +0100 Subject: [PATCH 160/225] Bug, didn't get translation. Bug, didn't get translation. --- modules/raid_by_gym_letter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/raid_by_gym_letter.php b/modules/raid_by_gym_letter.php index 0836f2a..13d162c 100755 --- a/modules/raid_by_gym_letter.php +++ b/modules/raid_by_gym_letter.php @@ -38,7 +38,7 @@ $keys = [ [ [ - 'text' => 'Not supported', + 'text' => getTranslation('not_supported'), 'callback_data' => 'edit:not_supported' ] ] From 607029f09f712605bef2c11f26340f31d95d55ab Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 16 Jan 2018 14:06:58 +0100 Subject: [PATCH 161/225] Oops... fix check to avoid updating of pokemon when they are in the ex-raid list --- commands/raid.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index 003c5ec..b3bc41c 100755 --- a/commands/raid.php +++ b/commands/raid.php @@ -77,14 +77,30 @@ $ex_raid = false; if ($raid_id > 0) { + // Get current pokemon from database for raid. + $rs_ex_raid = my_query( + " + SELECT pokemon + FROM raids + WHERE id = {$raid_id} + " + ); + + // Get row. + $row_ex_raid = $rs_ex_raid->fetch_assoc(); + $poke_name = $row_ex_raid['pokemon']; + debug_log('Comparing the current pokemon to pokemons from ex-raid list now...'); + debug_log('Current Pokemon in database for this raid: ' . $poke_name); + // Make sure it's not an Ex-Raid before updating the pokemon. $pokemonlist = $GLOBALS['pokemon']; foreach($pokemonlist as $level => $levelmons) { if($level == "X") { foreach($levelmons as $key => $pokemon) { - if(strtolower($pokemon) == strtolower($boss)) { + if(strtolower($pokemon) == strtolower($poke_name)) { $ex_raid = true; - debug_log('Ex-raid pokemon detected: ' . $boss); + debug_log('Current pokemon is an ex-raid pokemon: ' . $poke_name); + debug_log('Pokemon "' .$poke_name . '" will NOT be updated to "' . $boss . '"!'); break 2; } } @@ -102,6 +118,8 @@ ); } else { // Update pokemon and team in raids table. + debug_log('Current pokemon is NOT an ex-raid pokemon: ' . $poke_name); + debug_log('Pokemon "' .$poke_name . '" will be updated to "' . $boss . '"!'); my_query( " UPDATE raids From 5474ef3d9e7d32f360d6944a7a50d1e9562abf9c Mon Sep 17 00:00:00 2001 From: GabArcanjo <35526660+GabArcanjo@users.noreply.github.com> Date: Wed, 17 Jan 2018 13:14:57 -0200 Subject: [PATCH 162/225] Added "Portuguese - Brazilian" Language Hey, I've added the Portuguese Brazilian language to the bot. Tell me if anything is wrong on the code so I can fix it! Its a pleasure to help! Contact me on Telegram: @GabArcanjo --- language.json | 441 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 295 insertions(+), 146 deletions(-) diff --git a/language.json b/language.json index aa7a556..b814211 100755 --- a/language.json +++ b/language.json @@ -2,102 +2,123 @@ "5stars" : { "NL": "5 Sterren Raid", "DE": "5 Sterne Raid", - "EN": "5 Star Raid" + "EN": "5 Star Raid", + "PT-BR": "Raid nível 5" }, "4stars" : { "NL": "4 Sterren Raid", "DE": "4 Sterne Raid", - "EN": "4 Star Raid" + "EN": "4 Star Raid", + "PT-BR": "Raid nível 4" }, "3stars" : { "NL": "3 Sterren Raid", "DE": "3 Sterne Raid", - "EN": "3 Star Raid" + "EN": "3 Star Raid", + "PT-BR": "Raid nível 3" }, "2stars" : { "NL": "2 Sterren Raid", "DE": "2 Sterne Raid", - "EN": "2 Star Raid" + "EN": "2 Star Raid", + "PT-BR": "Raid nível 2" }, "1stars" : { "NL": "1 Sterren Raid", "DE": "1 Sterne Raid", - "EN": "1 Star Raid" + "EN": "1 Star Raid", + "PT-BR": "Raid nível 1" }, "back" : { "NL": "Terug", "DE": "Zurück", - "EN": "Back" + "EN": "Back", + "PT-BR": "Voltar" }, "next" : { "NL": "Next", "DE": "Weiter", - "EN": "Next" + "EN": "Next", + "PT-BR": "Próximo" }, "alone" : { "NL": "Alleen", "DE": "Alleine", - "EN": "Alone" + "EN": "Alone", + "PT-BR": "Sozinho" }, "raid_done" : { "NL": "Raid beëindigd", "DE": "Raid beendet.", - "EN": "Raid done" + "EN": "Raid done", + "PT-BR": "Raid completa" }, "here" : { "NL": "Ben er", "DE": "Bin da", - "EN": "Here" + "EN": "Here", + "PT-BR": "Aqui" + }, "done" : { "NL": "Klaar", "DE": "Fertig", - "EN": "Done" + "EN": "Done", + "PT-BR": "Feito" }, "cancellation" : { "NL": "Afwezig", "DE": "Absage", - "EN": "Cancellation" + "EN": "Cancellation", + "PT-BR": "Cancelada" }, "vote_updated" : { "NL": "Stem geüpdatet", "DE": "Abstimmung aktualisiert", - "EN": "Vote updated" + "EN": "Vote updated", + "PT-BR": "Votos atualizados" }, "monday" : { "NL": "Maandag", "DE": "Montag", - "EN": "Monday" + "EN": "Monday", + "PT-BR": "Segunda-feira" }, "tuesday" : { "NL": "Dinsdag", "DE": "Dienstag", - "EN": "Tuesday" + "EN": "Tuesday", + "PT-BR": "Terça-feira" }, "wensday" : { "NL": "Woensdag", "DE": "Mittwoch", - "EN": "Wednesday" + "EN": "Wednesday", + "PT-BR": "Quarta-feira" }, "thursday" : { "NL": "Donderdag", "DE": "Donnerstag", - "EN": "Thursday" + "EN": "Thursday", + "PT-BR": "Quinta-feira" }, "friday" : { "NL": "Vrijdag", "DE": "Freitag", - "EN": "Friday" + "EN": "Friday", + "PT-BR": "Sexta-feira" }, "saterday" : { "NL": "Zaterdag", "DE": "Samstag", - "EN": "Saturday" + "EN": "Saturday", + "PT-BR": "Sábado" }, "sunday" : { "NL": "Zondag", "DE": "Sonntag", - "EN": "Sunday" + "EN": "Sunday", + "PT-BR": "Domingo" }, "still" : { "NL": "nog", @@ -107,631 +128,759 @@ "raid_egg_opens" : { "NL": "Raid ei gaat open", "DE": "Raid-Ei öffnet sich um", - "EN": "Raid egg opens up" + "EN": "Raid egg opens up", + "PT-BR": "Ovo eclode" }, "raid_egg_opens_day" : { "NL": "Raid ei gaat open", "DE": "Raid-Ei öffnet sich am", - "EN": "Raid egg opens on" + "EN": "Raid egg opens on", + "PT-BR": "Ovo eclode em" }, "raid_egg_opens_at" : { "NL": "om", "DE": "um", - "EN": "at" + "EN": "at", + "PT-BR": "em" }, "raid_until" : { "NL": "Raid tot", "DE": "Raid bis", - "EN": "Raid until" + "EN": "Raid until", + "PT-BR": "Raid até" }, "exraid_pass" : { "NL": "DEELNAME IS ALLEEN MOGELIJK MET EX-RAID PASS", "DE": "TEILNAHME IST NUR MIT EX-RAID-PASS MÖGLICH", - "EN": "PARTICIPATION IS POSSIBLE ONLY WITH EX-RAID PASS" + "EN": "PARTICIPATION IS POSSIBLE ONLY WITH EX-RAID PASS", + "PT-BR": "PARTICIPAÇÃO APENAS COM PASSE EX" }, "no_participants_yet" : { "NL": "Nog geen deelnemers", "DE": "Noch keine Teilnehmer.", - "EN": "No participants yet" + "EN": "No participants yet", + "PT-BR": "Ainda sem participantes" }, "finished" : { "NL": "Klaar", "DE": "Fertig", - "EN": "Finished" + "EN": "Finished", + "PT-BR": "Finalizada" }, "cancel" : { "NL": "Annuleren", "DE": "Abgesagt", - "EN": "Cancel" + "EN": "Cancel", + "PT-BR": "Cancelar" }, "created_by" : { "NL": "Aangemaakt door", "DE": "Erstellt von", - "EN": "Created by" + "EN": "Created by", + "PT-BR": "Criada por" }, "updated" : { "NL": "Bijgewerkt", "DE": "Aktualisiert", - "EN": "Updated" + "EN": "Updated", + "PT-BR": "Atualizada" }, "from" : { "NL": "van", "DE": "von", - "EN": "from" + "EN": "from", + "PT-BR": "de" }, "to" : { "NL": "tot", "DE": "bis", - "EN": "to" + "EN": "to", + "PT-BR": "para" }, "no_participants" : { "NL": "Geen deelnemers", "DE": "Keine Teilnehmer", - "EN": "No participants" + "EN": "No participants", + "PT-BR": "Sem participantes" }, "mew" : { "NL": "Mew", "DE": "Mew", - "EN": "Mew" + "EN": "Mew", + "PT-BR": "Mew" }, "mewtwo" : { "NL": "Mewtwo", "DE": "Mewtu", - "EN": "Mewtwo" + "EN": "Mewtwo", + "PT-BR": "Mewtwo" }, "lugia" : { "NL": "Lugia", "DE": "Lugia", - "EN": "Lugia" + "EN": "Lugia", + "PT-BR": "Lugia" }, "zapdos" : { "NL": "Zapdos", "DE": "Zapdos", - "EN": "Zapdos" + "EN": "Zapdos", + "PT-BR": "Zapdos" }, "hooh" : { "NL": "Ho-oh", "DE": "Ho-oh", - "EN": "Ho-oh" + "EN": "Ho-oh", + "PT-BR": "Ho-oh" }, "celebi" : { "NL": "Celebi", "DE": "Celebi", - "EN": "Celebi" + "EN": "Celebi", + "PT-BR": "Celebi" }, "raikou" : { "NL": "Raikou", "DE": "Raikou", - "EN": "Raikou" + "EN": "Raikou", + "PT-BR": "Raikou" }, "entei" : { "NL": "Entei", "DE": "Entei", - "EN": "Entei" + "EN": "Entei", + "PT-BR": "Entei" }, "suicune" : { "NL": "Suicune", "DE": "Suicune", - "EN": "Suicune" + "EN": "Suicune", + "PT-BR": "Suicune" }, "moltres" : { "NL": "Moltres", "DE": "Lavados", - "EN": "Moltres" + "EN": "Moltres", + "PT-BR": "Moltres" }, "articuno" : { "NL": "Articuno", "DE": "Arktos", - "EN": "Articuno" + "EN": "Articuno", + "PT-BR": "Articuno" }, "groudon" : { "NL": "Groudon", "DE": "Groudon", - "EN": "Groudon" + "EN": "Groudon", + "PT-BR": "Groudon" }, "kyogre" : { "NL": "Kyogre", "DE": "Kyogre", - "EN": "Kyogre" + "EN": "Kyogre", + "PT-BR": "Kyogre" }, "egg_5" : { "NL": "Level 5 Ei", "DE": "Level 5 Ei", - "EN": "Level 5 Egg" + "EN": "Level 5 Egg", + "PT-BR": "Ovo de Nível 5" }, "egg_4" : { "NL": "Level 4 Ei", "DE": "Level 4 Ei", - "EN": "Level 4 Egg" + "EN": "Level 4 Egg", + "PT-BR": "Ovo de Nível 4" }, "egg_3" : { "NL": "Level 3 Ei", "DE": "Level 3 Ei", - "EN": "Level 3 Egg" + "EN": "Level 3 Egg", + "PT-BR": "Ovo de Nível 3" }, "lapras" : { "NL": "Lapras", "DE": "Lapras", - "EN": "Lapras" + "EN": "Lapras", + "PT-BR": "Lapras" }, "nidoqueen" : { "NL": "Nidoqueen", "DE": "Nidoqueen", - "EN": "Nidoqueen" + "EN": "Nidoqueen", + "PT-BR": "Nidoqueen" }, "nidoking" : { "NL": "Nidoking", "DE": "Nidoking", - "EN": "Nidoking" + "EN": "Nidoking", + "PT-BR": "Nidoking" }, "absol" : { "NL": "Absol", "DE": "Absol", - "EN": "Absol" + "EN": "Absol", + "PT-BR": "Absol" }, "tyranitar" : { "NL": "Tyranitar", "DE": "Despotar", - "EN": "Tyranitar" + "EN": "Tyranitar", + "PT-BR": "Tyranitar" }, "snorlax" : { "NL": "Snorlax", "DE": "Relaxo", - "EN": "Snorlax" + "EN": "Snorlax", + "PT-BR": "Snorlax" }, "golem" : { "NL": "Golem", "DE": "Geowaz", - "EN": "Golem" + "EN": "Golem", + "PT-BR": "Golem" }, "rhydon" : { "NL": "Rhydon", "DE": "Rizeros", - "EN": "Rhydon" + "EN": "Rhydon", + "PT-BR": "Rhydon" }, "porygon" : { "NL": "Porygon", "DE": "Porygon", - "EN": "Porygon" + "EN": "Porygon", + "PT-BR": "Porygon" }, "gengar" : { "NL": "Gengar", "DE": "Gengar", - "EN": "Gengar" + "EN": "Gengar", + "PT-BR": "Gengar" }, "poliwrath" : { "NL": "Poliwrath", "DE": "Quappo", - "EN": "Poliwrath" + "EN": "Poliwrath", + "PT-BR": "Poliwrath" }, "victreebel" : { "NL": "Victreebel", "DE": "Sarzenia", - "EN": "Victreebel" + "EN": "Victreebel", + "PT-BR": "Victreebel" }, "arcanine" : { "NL": "Arcanine", "DE": "Arkani", - "EN": "Arcanine" + "EN": "Arcanine", + "PT-BR": "Arcanine" }, "machamp" : { "NL": "Machamp", "DE": "Machomei", - "EN": "Machamp" + "EN": "Machamp", + "PT-BR": "Machamp" }, "alakazam" : { "NL": "Alakazam", "DE": "Simsala", - "EN": "Alakazam" + "EN": "Alakazam", + "PT-BR": "Alakazam" }, "scyther" : { "NL": "Scyther", "DE": "Sichlor", - "EN": "Scyther" + "EN": "Scyther", + "PT-BR": "Schyther" }, "omastar" : { "NL": "Omastar", "DE": "Amoroso", - "EN": "Omastar" + "EN": "Omastar", + "PT-BR": "Omastar" }, "ninetails" : { "NL": "Ninetails", "DE": "Vulnona", - "EN": "Ninetails" + "EN": "Ninetails", + "PT-BR": "Ninetails" }, "forest" : { "NL": "Ergens in het bos", "DE": "Irgendwo im Wald", - "EN": "Somewhere in the forest" + "EN": "Somewhere in the forest", + "PT-BR": "Em algum lugar na floresta" }, "select_gym_first_letter" : { "NL": "Selecteer alstublieft de eerste letter van de gym:", "DE": "Bitte Anfangsbuchstabe der Arena auswählen:", - "EN": "Please select the first letter of the gym:" + "EN": "Please select the first letter of the gym:", + "PT-BR": "Por favor escolha a primeira letra do ginásio:" }, "select_gym" : { "NL": "Beginletter geselecteerd.", "DE": "Anfangsbuchstabe ausgewählt.", - "EN": "First letter selected." + "EN": "First letter selected.", + "PT-BR": "Primeira letra escolhida.:" }, "raid_creation_started_at" : { "NL": "Raid aanmaak is gestart om", "DE": "Das Raid wird angelegt seit", - "EN": "Raid creation was started at" + "EN": "Raid creation was started at", + "PT-BR": "Criação da raid em" }, "raid_being_created_by_other_user" : { "NL": "Een andere gebruiker is een raid voor deze gym aan het maken:", "DE": "Ein Raid für diese Arena wird gerade angelegt von:", - "EN": "Another user is currently creating a raid for this gym:" + "EN": "Another user is currently creating a raid for this gym:", + "PT-BR": "Outro usuário está criando uma raid para este ginásio:" }, "raid_already_exists" : { "NL": "Raid bestaat al!", "DE": "Raid existiert bereits!", - "EN": "Raid already exists!" + "EN": "Raid already exists!", + "PT-BR": "A raid já existe!" }, "create_raid" : { "NL": "Begin Raid in", "DE": "Erstelle Raid in", - "EN": "Create Raid in" + "EN": "Create Raid in", + "PT-BR": "Criar raid em" }, "raid_creation_in_progress_warning" : { "NL": "Je kan een raid aanmaken, maar de huidig aangemaakte raid zal worden overscheven. Deze wijziging kunnen niet ongedaan gemaakt worden dit is NIET AAN TE RADEN!", "DE": "Das Raid kann weiter angelegt werden, aber dies wird das Raid welches gerade zeitgleich erstellt wird überschreiben und ist daher definitiv NICHT EMPFOHLEN!", - "EN": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!" + "EN": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!", + "PT-BR": "Você pode continuar a criar a raid, mas você substituirá outra raid que está sendo criada e isso NÃO É RECOMENDADO!" }, "raid_creation_in_progress" : { "NL": "Raid wordt momenteel aangemaakt", "DE": "Raid wird gerade erstellt", - "EN": "Raid creation in progress" + "EN": "Raid creation in progress", + "PT-BR": "Criação da raid em andamento" }, "select_raid_level_to_continue" : { "NL": "Om echt door te gaan, selecteer een raid level", "DE": "Um wirklich fortzufahren, bitte Raid Level auswählen", - "EN": "To really continue, please select raid level" + "EN": "To really continue, please select raid level", + "PT-BR": "Para continuar, escolha o nível da raid" }, "select_raid_level" : { "NL": "Selecteer Raid level", "DE": "Bitte Raid Level auswählen", - "EN": "Select raid level" + "EN": "Select raid level", + "PT-BR": "Escolha o nível da raid" }, "gym" : { "NL": "Gym", "DE": "Arena", - "EN": "Gym" + "EN": "Gym", + "PT-BR": "Ginásio" }, "gym_saved" : { "NL": "Gym opgeslagen.", "DE": "Arena gespeichert.", - "EN": "Gym saved." + "EN": "Gym saved.", + "PT-BR": "Ginásio salvo." }, "select_raid_boss" : { "NL": "Selecteer Raid baas", "DE": "Raid Boss auswählen", - "EN": "Select Raid boss" + "EN": "Select Raid boss", + "PT-BR": "Escolha o Pokémon chefe da raid" }, "select_pokemon" : { "NL": "Selecteer Pokemon", "DE": "Pokemon auswählen", - "EN": "Select Pokemon" + "EN": "Select Pokemon", + "PT-BR": "Escolha o Pokémon" }, "raid_saved" : { "NL": "Raid opgeslagen:", "DE": "Raid gespeichert:", - "EN": "Raid saved:" + "EN": "Raid saved:", + "PT-BR": "Raid salva:" + }, "raid_boss" : { "NL": "Raid baas", "DE": "Raid-Boss", - "EN": "Raid boss" + "EN": "Raid boss", + "PT-BR": "Chefe da raid" }, "raid_boss_saved" : { "NL": "Raid baas opgeslagen!", "DE": "Raid-Boss gespeichert!", - "EN": "Raid boss saved!" + "EN": "Raid boss saved!", + "PT-BR": "Chefe da raid salvo!" }, "not_supported" : { "NL": "Niet ondersteund", "DE": "Nicht unterstützt", - "EN": "Not supported" + "EN": "Not supported", + "PT-BR": "Não compatível" }, "share" : { "NL": "Delen", "DE": "Teilen", - "EN": "Share" + "EN": "Share", + "PT-BR": "Compartilhar" }, "share_with" : { "NL": "Delen met", "DE": "Teilen mit", - "EN": "Share with" + "EN": "Share with", + "PT-BR": "Compartilhar com" }, "set_gym_name_and_team" : { "NL": "Optioneel - Gym naam and Gym Team:", "DE": "Optional - Arena Name und Arena Team:", - "EN": "Optional - Gym name and Gym Team:" + "EN": "Optional - Gym name and Gym Team:", + "PT-BR": "Opcional - Nome do gínasio e nome do time" }, "set_gym_name_command" : { "NL": "/gym Naam van de Gym", "DE": "/gym Name der Arena", - "EN": "/gym Name of the Gym" + "EN": "/gym Name of the Gym", + "PT-BR": "/gym Nome do ginásio" }, "set_gym_team" : { "NL": "Optioneel - zet Gym en Team", "DE": "Optional - Arena Team setzen", - "EN": "Optional - set Gym and Team" + "EN": "Optional - set Gym and Team", + "PT-BR": "Opcional - escolha o gínasio e time" }, "set_gym_team_command" : { "NL": "/team Mystic/Valor/Instinct/Blauw/Rood/Geel", "DE": "/team Mystic/Valor/Instinct/Blau/Rot/Gelb", - "EN": "/team Mystic/Valor/Instinct/Blue/Red/Yellow" + "EN": "/team Mystic/Valor/Instinct/Blue/Red/Yellow", + "PT-BR": "/team Mystic/Valor/Instinct/Azul/Vermelho/Amarelo" }, "end_time" : { "NL": "Eindtijd gezet op ", "DE": "Ablaufzeit gesetzt auf ", - "EN": "Endtime set to " + "EN": "Endtime set to ", + "PT-BR": "Hora de término determinada para " + }, "minutes" : { "NL": "minuten", "DE": "Minuten", - "EN": "minutes" + "EN": "minutes", + "PT-BR": "minutos" }, "raid_starts_when" : { "NL": "Wanneer gaat het Raid ei open?", "DE": "Wann beginnt der Raid?", - "EN": "When will the Raid begin?" + "EN": "When will the Raid begin?", + "PT-BR": "Quando a raid irá começar?" }, "raid_starts_when_minutes" : { "NL": "Wanneer begint de Raid?", "DE": "In wie viel Minuten beginnt der Raid?", - "EN": "In how many minutes does the raid begin?" + "EN": "In how many minutes does the raid begin?", + "PT-BR": "Em quantos minutos a raid irá começar?" }, "raid_starts_when_clocktime_view" : { "NL": "klok", "DE": "Uhrzeit-Ansicht", - "EN": "Clock time view" + "EN": "Clock time view", + "PT-BR": "Ver horário" }, "raid_starts_when_minutes_view" : { "NL": "Minuten", "DE": "Minuten-Ansicht", - "EN": "Minutes view" + "EN": "Minutes view", + "PT-BR": "Ver minutos" }, "raid_starts_when_view_changed" : { "NL": "Overzicht verandert!", "DE": "Ansicht geändert!", - "EN": "View changed!" + "EN": "View changed!", + "PT-BR": "Visualização mudou!" }, "is_raid_active" : { "NL": "Raid is al actief!", "DE": "Raid läuft schon!", - "EN": "Raid is already active!" + "EN": "Raid is already active!", + "PT-BR": "A raid já está ativa!" }, "raid_access_denied" : { "NL": "Je hebt geen rechten om deze raid aan te passen!", "DE": "Sie haben keine Berechtigung dieses Raid zu bearbeiten!", - "EN": "You are not allowed to edit this raid!" + "EN": "You are not allowed to edit this raid!", + "PT-BR": "Você não tem permissão para editar esta raid!" }, "no_active_raids_found" : { "NL": "Geen actieve raids gevonden!", "DE": "Aktuell sind keine laufenden Raids im System!", - "EN": "No active raids found in the system!" + "EN": "No active raids found in the system!", + "PT-BR": "Nenhuma raid ativa encontrada no sistema!" }, "no_active_raids_shared" : { "NL": "Geen van de actieve raid is gedeeld!", "DE": "Keines der aktiven Raids wurde geteilt!", - "EN": "None of the active raids was shared!" + "EN": "None of the active raids was shared!", + "PT-BR": "Nenhuma das raids ativas foi compartilhada!" }, "no_active_raids" : { "NL": "Geen actieve raids!", "DE": "Aktuell gibt es keine Raids!", - "EN": "No active raids currently!" + "EN": "No active raids currently!", + "PT-BR": "Nenhuma raid ativa no momento!" }, "expand" : { "NL": "Uitklappen", "DE": "Ausklappen", - "EN": "Expand" + "EN": "Expand", + "PT-BR": "Expandir" }, "pokemon_saved" : { "NL": "Pokemon opgeslagen: ", "DE": "Pokemon gespeichert: ", - "EN": "Pokemon saved: " + "EN": "Pokemon saved: ", + "PT-BR": "Pokemon salvo " }, "how_long_raid" : { "NL": "Hoe lang duurt de Raid?", "DE": "Wie lange dauert der Raid?", - "EN": "How long will the raid last?" + "EN": "How long will the raid last?", + "PT-BR": "Quanto tempo a raid vai durar" }, "lead_time_set_to" : { "NL": "Doorlooptijd ingesteld op", "DE": "Vorlaufzeit gesetzt auf", - "EN": "Lead time set to" + "EN": "Lead time set to", + "PT-BR": "Tempo principal configurado para" }, "select_gym_name" : { "NL": "Selecteer Gym:", "DE": "Bitte Arena auswählen:", - "EN": "Select Gym:" + "EN": "Select Gym:", + "PT-BR": "Escolha o ginásio:" }, "here_we_go" : { "NL": "Hier gaan we!", "DE": "Los gehts!", - "EN": "Here we go!" + "EN": "Here we go!", + "PT-BR": "Bora arrasar!" }, "create_a_raid" : { "NL": "Maak een Raid", "DE": "Raid anlegen", - "EN": "Create a Raid" + "EN": "Create a Raid", + "PT-BR": "Criar a raid" }, "coordination_succes" : { "NL": "Coördinatie geslaagd!", "DE": "Koordinaten erfolgreich übermittelt!", - "EN": "Coordinates successfully submitted!" + "EN": "Coordinates successfully submitted!", + "PT-BR": "Coordenadas enviadas com sucesso!" }, "update_pokemon" : { "NL": "Pokemon vernieuwen", "DE": "Pokemon aktualisieren", - "EN": "Update Pokemon" + "EN": "Update Pokemon", + "PT-BR": "Atualizar Pokemon" }, "send_location" : { "NL": "Stuur me alsjeblieft eerst een locatie.", "DE": "Bitte sende mir zuerst einen Standort.", - "EN": "Please send me a location first." + "EN": "Please send me a location first.", + "PT-BR": "Por favor, antes me envie a localização." }, "raid_by_gym" : { "NL": "Of maak een raid door een Gym te selecteren:", "DE": "Oder lege ein Raid per Arena-Auswahl an:", - "EN": "Or make a raid per gym selection:" + "EN": "Or make a raid per gym selection:", + "PT-BR": "Ou escolha uma raid por ginásio:" }, "red" : { "NL": "rood", "DE": "rot", - "EN": "red" + "EN": "red", + "PT-BR": "vermelho" }, "yellow" : { "NL": "geel", "DE": "gelb", - "EN": "yellow" + "EN": "yellow", + "PT-BR": "amarelo" }, "blue" : { "NL": "blauw", "DE": "blau", - "EN": "blue" + "EN": "blue", + "PT-BR": "azul" }, "gym_team_set_to" : { "NL": "Gym Team gezet op:", "DE": "Arena Team gesetzt auf:", - "EN": "Gym Team set to:" + "EN": "Gym Team set to:", + "PT-BR": "Time do ginásio escolhido para" }, "invalid_team" : { "NL": "Ongeldige team naam: schrijf: Mystic, Valor, Instinct or Blauw, Rood, Geel ", "DE": "Ungültiger Team Name - schreibe: Mystic, Valor, Instinct oder Blau, Rot, Gelb", - "EN": "Invalid team name - write: Mystic, Valor, Instinct or Blue, Red, Yellow " + "EN": "Invalid team name - write: Mystic, Valor, Instinct or Blue, Red, Yellow ", + "PT-BR": "Nome de time inválido - escreva: Mystic, Valor, Instinct ou Blue, Red, Yellow" }, "gym_name_updated" : { "NL": "Gym naam aangepast.", "DE": "Der Arena Name wurde aktualisiert.", - "EN": "Gym name updated." + "EN": "Gym name updated.", + "PT-BR": "Nome do ginásio atualizado." }, "mods_details" : { "NL": "Selecteer moderator voor meer informatie:", "DE": "Für Details Moderator auswählen:", - "EN": "Select moderator for details:" + "EN": "Select moderator for details:", + "PT-BR": "Escolha moderador para detalhes:" }, "mods_add_new" : { "NL": "Nieuwe moderator toevoegen:", "DE": "Neuen Moderator hinzufügen:", - "EN": "Add new moderator:" + "EN": "Add new moderator:", + "PT-BR": "Adicionar novo moderador:" }, "mods_delete" : { "NL": "Moderator verwijderen:", "DE": "Moderator löschen:", - "EN": "Delete moderator:" + "EN": "Delete moderator:", + "PT-BR": "Excluir moderador:" }, "mods_list_of_all" : { "NL": "Lijst met alle moderators.", "DE": "Liste aller Moderatoren.", - "EN": "List of all moderators." + "EN": "List of all moderators.", + "PT-BR": "Lista de todos os moderadores." }, "mods_list_add_delete" : { "NL": "Lijst, toevoegen of verwijderen van moderators", "DE": "Moderatoren anzeigen, hinzufügen oder löschen", - "EN": "List, add or remove moderators" + "EN": "List, add or remove moderators", + "PT-BR": "Listar, adicionar ou remover moderadores" }, "mods_not_found" : { "NL": "Error! Geen Moderator of gebruiker gevonden!", "DE": "Fehler! Keine Moderatoren oder Benutzer gefunden!", - "EN": "Error! No moderators or users found!" + "EN": "Error! No moderators or users found!", + "PT-BR": "Erro! Nenhum moderador ou usuário encontrado!" }, "mods_saved_mod" : { "NL": "Moderator opgeslagen!", "DE": "Moderator gespeichert!", - "EN": "Moderator saved!" + "EN": "Moderator saved!", + "PT-BR": "Moderador salvo!" }, "mods_delete_mod" : { "NL": "Moderator verwijderd!", "DE": "Moderator gelöscht!", - "EN": "Moderator deleted!" + "EN": "Moderator deleted!", + "PT-BR": "Moderador excluído!" }, "mods_info_about_mod" : { "NL": "Informatie over deze moderator:", "DE": "Infos zum diesem Moderator:", - "EN": "Info about this moderator:" + "EN": "Info about this moderator:", + "PT-BR": "Informações sobre esse moderador:" }, "overview_share" : { "NL": "Overzicht delen", "DE": "Übersicht teilen", - "EN": "Share overview" + "EN": "Share overview", + "PT-BR": "Detalhes de compartilhamento" }, "overview_delete" : { "NL": "Vewijder overzicht", "DE": "Übersicht löschen", - "EN": "Delete overview" + "EN": "Delete overview", + "PT-BR": "Deletar detalhes" }, "raids_list_share_overview" : { "NL": "Geef de actieve raid weer als een lijst of deel / verwijder het raid overzicht", "DE": "Aktive Raids als Liste anzeigen oder die Raid-Übersicht pro Chat teilen / löschen", - "EN": "Show active raids as list or share / delete the raid overview per chat" + "EN": "Show active raids as list or share / delete the raid overview per chat", + "PT-BR": "Mostrar raids ativas como lista ou compartilhar / deletar detalhes de raid por chat" }, "list_all_active_raids" : { "NL": "Alle actieve raids", "DE": "Alle aktiven Raids", - "EN": "All active raids" + "EN": "All active raids", + "PT-BR": "Todas as raids ativas" }, "list_all_overviews" : { "NL": "Totaal raid overzicht", "DE": "Alle Raid-Übersichten", - "EN": "All raid overviews" + "EN": "All raid overviews", + "PT-BR": "Todos os detalhes de raid" }, "delete_raid_overview_for_chat" : { "NL": "Verwijder raid overzicht voor", "DE": "Raid-Übersicht löschen für", - "EN": "Delete raid overview for" + "EN": "Delete raid overview for", + "PT-BR": "Deletar detalhe de raid para" }, "no_overviews_found" : { "NL": "Geen raid overzicht gevonden in het systeem!", "DE": "Keine Raid-Übersichten im System gefunden!", - "EN": "No raid overviews found in the system!" + "EN": "No raid overviews found in the system!", + "PT-BR": "Nenhum detalhe de raid encontrado no sistema!" }, "overview_successfully_deleted" : { "NL": "Raid overzicht is succesvol verwijderd!", "DE": "Raid-Übersicht wurde erfolgreich gelöscht!", - "EN": "Raid overview was successfully deleted!" + "EN": "Raid overview was successfully deleted!", + "PT-BR": "Detalhe de raid deletado com sucesso!" }, "overview_deletion_was_canceled" : { "NL": "Het verwijderen van het raid overzicht is gestopt!", "DE": "Löschung der Raid-Übersicht wurde abgebrochen!", - "EN": "Deletion of the raid overview was canceled!" + "EN": "Deletion of the raid overview was canceled!", + "PT-BR": "O deletamento dos detalhes da raid foi cancelado!" }, "raid_overview_for_chat" : { "NL": "Raid overzicht voor", "DE": "Raid-Übersicht für", - "EN": "Overview of raids for" + "EN": "Overview of raids for", + "PT-BR": "Detalhes de raids para" }, "successfully_shared" : { "NL": "Succesvol gedeeld!", "DE": "Erfolgreich geteilt!", - "EN": "Successfully shared!" + "EN": "Successfully shared!", + "PT-BR": "Compartilhado com sucesso!" }, "yes" : { "NL": "Ja", "DE": "Ja", - "EN": "Yes" + "EN": "Yes", + "PT-BR": "Sim" }, "no" : { "NL": "Nee", "DE": "Nein", - "EN": "No" + "EN": "No", + "PT-BR": "Não" }, "list" : { "NL": "Lijst", "DE": "Anzeigen", - "EN": "List" + "EN": "List", + "PT-BR": "Lista" }, "add" : { "NL": "Toevoegen", "DE": "Hinzufügen", - "EN": "Add" + "EN": "Add", + "PT-BR": "Adicionar" }, "delete" : { "NL": "Verwijder", "DE": "Löschen", - "EN": "Delete" + "EN": "Delete", + "PT-BR": "Deletar" } } From 891a772e5fa74896a441e5d896aadbc1353ab96c Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 18 Jan 2018 09:59:44 +0100 Subject: [PATCH 163/225] Update README to include latest changes :) --- README.md | 68 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b6148c8..1cf2a57 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,13 @@ Edit config.php and set `CONFIG_LOGFILE` Start chat with https://t.me/BotFather and create bot token. -Bot Settings: Enable Inline mode, Allow Groups, Group Privacy off +Bot Settings: + - Enable Inline mode + - Allow Groups + - Group Privacy off Use https://www.miniwebtool.com/sha512-hash-generator/ and set `CONFIG_HASH` to hashed value of your token (make sure it is lowecase) -## Bot access - -Set `BOT_ACCESS` to the name (@Bot_Access_Groupname) or id (-100123456789) of one or multiple by comma separated groups, supergroups or channels. All administrators (not members!) will gain access to the bot. - -When no group, supergroup or channel is specified, the bot will allow everyone to use it (public access). - -Example for multiple access groups: `define('BOT_ACCESS', '@Bot_Access_Groupname,@Another_Bot_Access_Group,@Superadmins_Bot_Groups');` - ## Raid times There are several options to configure the times related to the raid polls: @@ -82,7 +77,23 @@ https://console.developers.google.com/apis/library/timezone-backend.googleapis.c https://console.developers.google.com/apis/library/geocoding-backend.googleapis.com -Finally check the dashboard again and make sure Google Maps Geocoding API and Google Maps Time Zone API are listed as enabled services. +Finally check the dashboard again and make sure Google Maps Geocoding API and Google Maps Time Zone API are listed as enabled services. + +## Raid overview + +The bot allows you to list all raids which got shared with one or more chats as a single raid overview message to quickly get an overview of all raids which are currently running and got shared in each chat. You can view and share raid overviews via the /list command - but only if some raids are currently active and if these active raids got shared to any chats! + +To keep this raid overview always up to date when you have it e.g. pinned inside your raid channel, you can setup a cronjob that updates the message by calling the overview_refresh module. + +You can either refresh all shared raid overview messages by calling + +`curl -k -d '{"callback_query":{"data":"0:overview_refresh:0"}}' https://localhost/bot_subdirectory/index.php?apikey=111111111:AABBccddEEFFggHHiijjKKLLmmnnOOPPqq` + +or just refresh the raid overview message you've shared with a specific chat (e.g. -100112233445): + +`curl -k -d '{"callback_query":{"data":"0:overview_refresh:-100112233445"}}' https://localhost/bot_subdirectory/index.php?apikey=111111111:AABBccddEEFFggHHiijjKKLLmmnnOOPPqq` + +To delete a shared raid overview message you can use the /list command too. ## Cleanup @@ -124,13 +135,32 @@ OR # Access permissions +## Public access + +When no telegram id, group, supergroup or channel is specified in `BOT_ADMINS` and/or `BOT_ACCESS`, the bot will allow everyone to use it (public access). + +Example for public access: `define('BOT_ACCESS', '');` + +## Restricted access + With BOT_ADMINS and BOT_ACCESS being used to restrict access, there are several access roles / types. When you do not configure BOT_ACCESS, everyone will have access to your bot (public access). -With your MAINTAINER_ID and as a member of BOT_ADMINS you have the permissions to do anything. **For performance improvements, it's recommended to add the MAINTAINER and all members of BOT_ADMINS as moderator via /mods command!** +Set `BOT_ADMINS` and `BOT_ACCESS` to the name (@Telegram_Groupname) or id (-100123456789) of one or multiple by comma separated individual telegram chat names/ids, groups, supergroups or channels. + +Please note, when you're setting groups, supergroups or channels only administrators (not members!) from these chats will gain access to the bot! So make sure this requirement is fulfilled or add their individual telegram usernames/ids instead. + +Example for restricted access: +`define('BOT_ADMINS', '@YOUR_USERNAME,111222333');` -As a member of BOT_ACCESS you can create raid polls, update your own raid polls' pokemon and change the gym team of your last raid poll. BOT_ACCESS members who are moderators can change the gym name and update raid polls' pokemon of others. +`define('BOT_ACCESS', '111222333,@Bot_Access_Groupname,-100112233445,@Superadmins_Bot_Groups');` -Telegram Users can only vote on raid polls, but have no access to other bot functions. +## Access overview + +With your `MAINTAINER_ID` and as a member of `BOT_ADMINS` you have the permissions to do anything. **For performance improvements, it's recommended to add the MAINTAINER and all members of BOT_ADMINS as moderator via /mods command!** + +As a member of `BOT_ACCESS` you can create raid polls, update your own raid polls' pokemon and change the gym team of your last raid poll. `BOT_ACCESS` members who are moderators too, can also change the gym name and update pokemon from other users raid polls. + +Telegram Users can only vote on raid polls, but have no access to other bot functions (unless you configured it for public access). | Access | Database | Raid poll | | | Pokemon | | Gym | | Moderators | | | Help | @@ -138,10 +168,16 @@ Telegram Users can only vote on raid polls, but have no access to other bot func | | | **Vote** | **Create** `/start`, `/raid`, `/new` | **List** `/list` | **All raid polls** `/pokemon` | **Own raid polls** `/pokemon` | **Name** `/gym` | **Team** `/team` | **List** `/mods` | **Add** `/mods` | **Delete** `/mods` | **Show** `/help` | | MAINTAINER_ID | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | | BOT_ADMINS | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | -| BOT_ACCESS | Moderator | Yes | Yes | Yes | Yes | Yes | Yes | Yes | | | | Yes | -| BOT_ACCESS | User | Yes | Yes | Yes | | Yes | | Yes | | | | Yes | +| BOT_ACCESS | Moderator | Yes | Yes | | Yes | Yes | Yes | Yes | | | | Yes | +| BOT_ACCESS | User | Yes | Yes | | | Yes | | Yes | | | | Yes | | Telegram | User | Yes | | | | | | | | | | | +# Updates + +Currently constantly new features, bug fixes and improvements are added to the bot. Since we do not have an update mechanism yet, when updating the bot, please always do the following: + - Add new config variables which got added to the config.php.example to your own config.php! + - If new tables and/or columns got added or changed inside raid-pokemon-bot.sql, please add/alter these tables/columns at your existing installation! + # Usage ## Bot commands @@ -194,7 +230,7 @@ Example input: `/new 52.514545,13.350095` #### Command: /list -The bot will send you a list of the last 20 active raids. +The bot will allow you to via a list of the last 20 active raids, share and delete all raids which got shared to channels as a raid overview. #### Command: /team From 8c5a2bc08004235286bbb757c0fafb42c1caefbf Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Thu, 18 Jan 2018 11:59:34 +0100 Subject: [PATCH 164/225] bug on row 535 was 5star had to be 1 star. We use the 1,2 egg for the EX triggers. --- logic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.php b/logic.php index 3363313..71cb088 100755 --- a/logic.php +++ b/logic.php @@ -532,7 +532,7 @@ function raid_edit_start_keys($id) 'callback_data' => $id . ':edit:2' ], [ - 'text' => getTranslation('5stars'), + 'text' => getTranslation('1stars'), 'callback_data' => $id . ':edit:1' ] */ ] From 1df89af78bbfe7f3f00385ddbadf509628d20ec4 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 19 Jan 2018 00:08:37 +0100 Subject: [PATCH 165/225] Improved query (now queries) for cleanup logic, fixed unnecessary callback answer triggered by cronjob and added delete_raid function in prepartion for adding command to delete raids --- logic.php | 85 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/logic.php b/logic.php index 3363313..35ce82c 100755 --- a/logic.php +++ b/logic.php @@ -792,13 +792,40 @@ function run_cleanup ($telegram = 2, $database = 2) { // Start cleanup when at least one parameter is set to trigger cleanup if ($telegram == 1 || $database == 1) { - // Get cleanup info. - $rs = my_query( - " - SELECT * - FROM cleanup - " - ); + // Query for telegram cleanup without database cleanup + if ($telegram == 1 && $database == 0) { + // Get cleanup info. + $rs = my_query( + " + SELECT * + FROM cleanup + WHERE chat_id <> 0 + ORDER BY id DESC + LIMIT 0, 100 + " + ); + // Query for database cleanup without telegram cleanup + } else if ($telegram == 0 && $database == 1) { + // Get cleanup info. + $rs = my_query( + " + SELECT * + FROM cleanup + WHERE chat_id = 0 + LIMIT 0, 100 + " + ); + // Query for telegram and database cleanup + } else { + // Get cleanup info. + $rs = my_query( + " + SELECT * + FROM cleanup + LIMIT 0, 100 + " + ); + } // Init empty cleanup jobs array. $cleanup_jobs = array(); @@ -1484,8 +1511,11 @@ function get_overview($update, $chats_active, $raids_active, $action = 'refresh' editMessageText($message_id, $msg, $keys, $previous, ['disable_web_page_preview' => 'true']); } - // Answer the callback. - answerCallbackQuery($update['callback_query']['id'], 'OK'); + // Triggered from user or cronjob? + if (!empty($update['callback_query']['id'])) { + // Answer the callback. + answerCallbackQuery($update['callback_query']['id'], 'OK'); + } } } @@ -1664,6 +1694,43 @@ function weekday_number2name ($weekdaynumber) return $weekday; } +/** + * Delete raid. + * @param $raid_id + */ +function delete_raid($raid_id) +{ + global $db; + + // Delete raid from cleanup table! + debug_log('Deleting raid ' . $raid_id ' from the cleanup table:'); + $rs_cleanup = my_query( + " + DELETE FROM raids + WHERE raid_id = '{$raid_id}' + OR cleaned = '{$raid_id}' + " + ); + + // Delete raid from attendance table! + debug_log('Deleting raid ' . $raid_id ' from the attendance table:'); + $rs_attendance = my_query( + " + DELETE FROM attendance + WHERE raid_id = '{$raid_id}' + " + ); + + // Delete raid from raid table! + debug_log('Deleting raid ' . $raid_id ' from the raid table:'); + $rs_raid = my_query( + " + DELETE FROM raids + WHERE id = '{$raid_id}' + " + ); +} + /** * Show raid poll. * @param $raid From 34b2df7988511728882c03ab3bbfdf63554a70b4 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 19 Jan 2018 10:03:06 +0100 Subject: [PATCH 166/225] Added cleanup check to my_query function to write cleanup sql stuff to separate cleanup file too for easier debugging --- debug.php | 14 +++++++++++--- logic.php | 26 +++++++++++++------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/debug.php b/debug.php index 117b56a..0e4eff2 100644 --- a/debug.php +++ b/debug.php @@ -15,16 +15,24 @@ function my_insert_id() * @param $query * @return bool|mysqli_result */ -function my_query($query) +function my_query($query, $cleanup_query = false) { global $db; - debug_log($query, '?'); + if ($cleanup_query == true) { + debug_log($query, '?', true); + } else { + debug_log($query, '?'); + } $res = $db->query($query); if ($db->error) { - debug_log($db->error, '!'); + if ($cleanup_query == true) { + debug_log($db->error, '!', true); + } else { + debug_log($db->error, '!'); + } } return $res; diff --git a/logic.php b/logic.php index 35ce82c..b167c0e 100755 --- a/logic.php +++ b/logic.php @@ -802,7 +802,7 @@ function run_cleanup ($telegram = 2, $database = 2) { WHERE chat_id <> 0 ORDER BY id DESC LIMIT 0, 100 - " + ", true ); // Query for database cleanup without telegram cleanup } else if ($telegram == 0 && $database == 1) { @@ -813,7 +813,7 @@ function run_cleanup ($telegram = 2, $database = 2) { FROM cleanup WHERE chat_id = 0 LIMIT 0, 100 - " + ", true ); // Query for telegram and database cleanup } else { @@ -823,7 +823,7 @@ function run_cleanup ($telegram = 2, $database = 2) { SELECT * FROM cleanup LIMIT 0, 100 - " + ", true ); } @@ -863,7 +863,7 @@ function run_cleanup ($telegram = 2, $database = 2) { UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left FROM raids WHERE id = {$current_raid_id} - " + ", true ); // Fetch raid data. @@ -905,7 +905,7 @@ function run_cleanup ($telegram = 2, $database = 2) { SET chat_id = 0, message_id = 0 WHERE id = {$row['id']} - " + ", true ); } else { if ($telegram == 1) { @@ -929,7 +929,7 @@ function run_cleanup ($telegram = 2, $database = 2) { " DELETE FROM attendance WHERE id = {$row['raid_id']} - " + ", true ); // Set database value of raid_id to 0 so we know attendance info was deleted already @@ -941,7 +941,7 @@ function run_cleanup ($telegram = 2, $database = 2) { SET raid_id = 0, cleaned = {$row['raid_id']} WHERE raid_id = {$row['raid_id']} - " + ", true ); } else { if ($database == 1) { @@ -960,7 +960,7 @@ function run_cleanup ($telegram = 2, $database = 2) { " DELETE FROM raids WHERE id = {$row['cleaned']} - " + ", true ); // Get all cleanup jobs which will be deleted now. @@ -970,7 +970,7 @@ function run_cleanup ($telegram = 2, $database = 2) { SELECT * FROM cleanup WHERE cleaned = {$row['cleaned']} - " + ", true ); // Log each cleanup ID which will be deleted. @@ -983,7 +983,7 @@ function run_cleanup ($telegram = 2, $database = 2) { " DELETE FROM cleanup WHERE cleaned = {$row['cleaned']} - " + ", true ); } else { if ($prev_raid_id != $current_raid_id) { @@ -1569,15 +1569,15 @@ function get_overview($update, $chats_active, $raids_active, $action = 'refresh' $weekday_start = date('N', $start_time); $raid_day = weekday_number2name ($weekday_start); if ($weekday_now == $weekday_start) { - $msg .= getTranslation('raid_egg_opens') . ' ' . unix2tz($start_time, $tz) . CR . CR; + $msg .= getTranslation('raid_egg_opens') . ' ' . unix2tz($start_time, $tz) . CR; } else { - $msg .= getTranslation('raid_egg_opens_day') . ' ' . $raid_day . ' ' . getTranslation('raid_egg_opens_at') . ' ' . unix2tz($start_time, $tz) . CR . CR; + $msg .= getTranslation('raid_egg_opens_day') . ' ' . $raid_day . ' ' . getTranslation('raid_egg_opens_at') . ' ' . unix2tz($start_time, $tz) . CR; } // Raid has started already } else { // Add time left message. - $msg .= $pokemon . ' — ' . getTranslation('still') . ' ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h' . CR . CR; + $msg .= $pokemon . ' — ' . getTranslation('still') . ' ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h' . CR; } // Build query to add attendances to message. From 0d1b98f9f00bf4551abe514929699b83d95b95ea Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Sun, 21 Jan 2018 12:25:08 +0100 Subject: [PATCH 167/225] Oops, forgot the dot --- logic.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/logic.php b/logic.php index b167c0e..0e6ecf2 100755 --- a/logic.php +++ b/logic.php @@ -1703,7 +1703,7 @@ function delete_raid($raid_id) global $db; // Delete raid from cleanup table! - debug_log('Deleting raid ' . $raid_id ' from the cleanup table:'); + debug_log('Deleting raid ' . $raid_id . ' from the cleanup table:'); $rs_cleanup = my_query( " DELETE FROM raids @@ -1713,7 +1713,7 @@ function delete_raid($raid_id) ); // Delete raid from attendance table! - debug_log('Deleting raid ' . $raid_id ' from the attendance table:'); + debug_log('Deleting raid ' . $raid_id . ' from the attendance table:'); $rs_attendance = my_query( " DELETE FROM attendance @@ -1722,7 +1722,7 @@ function delete_raid($raid_id) ); // Delete raid from raid table! - debug_log('Deleting raid ' . $raid_id ' from the raid table:'); + debug_log('Deleting raid ' . $raid_id . ' from the raid table:'); $rs_raid = my_query( " DELETE FROM raids From 00e5119d5fbe1ac990f2a4f1044d06bddb16aaa7 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 22 Jan 2018 16:05:53 +0100 Subject: [PATCH 168/225] Added new command /delete to delete raids --- commands/delete.php | 84 +++++++++++++++++++++++++++++++++++++++ modules/raids_delete.php | 86 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 commands/delete.php create mode 100644 modules/raids_delete.php diff --git a/commands/delete.php b/commands/delete.php new file mode 100644 index 0000000..c3029dc --- /dev/null +++ b/commands/delete.php @@ -0,0 +1,84 @@ +fetch_assoc(); + +// No data found. +if (!$row) { + //sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + //exit; + $tz = TIMEZONE; +} else { + $tz = $row['timezone']; +} + +// Build query. +$request = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE end_time>NOW() + AND timezone='{$tz}' + ORDER BY end_time ASC LIMIT 20 + " +); + +// Count results. +$count = 0; + +// Get raids. +while ($raid = $request->fetch_assoc()) { + + // Counter++ + $count = $count + 1; + + // Create keys array. + $keys = [ + [ + [ + 'text' => getTranslation('delete'), + 'callback_data' => $raid['id'] . ':raids_delete:0' + ] + ] + ]; + + // Get message. + $msg = show_raid_poll_small($raid); + + // Send message. + send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); +} + +// Send message if no active raids were found. +if($count == 0) { + // Set message. + $msg = '' . getTranslation('no_active_raids_found') . ''; + + // Send message. + sendMessage($update['message']['from']['id'], $msg); +} + +exit; diff --git a/modules/raids_delete.php b/modules/raids_delete.php new file mode 100644 index 0000000..1987930 --- /dev/null +++ b/modules/raids_delete.php @@ -0,0 +1,86 @@ + Confirmation required +// 1 -> Cancel deletion +// 2 -> Execute deletion +$action = $data['arg']; + +// Get the raid id. +$id = $data['id']; + +// Execute the action. +if ($action == 0) { + // Build query. + $request = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE id = '{$id}' + " + ); + + // Get raid. + $raid = $request->fetch_assoc(); + + // Write to log. + debug_log('Asking for confirmation to delete the following raid:'); + debug_log($raid); + + // Create keys array. + $keys = [ + [ + [ + 'text' => getTranslation('yes'), + 'callback_data' => $raid['id'] . ':raids_delete:2' + ], + [ + 'text' => getTranslation('no'), + 'callback_data' => $raid['id'] . ':raids_delete:1' + ] + ] + ]; + + // Set message. + $msg = EMOJI_WARN . ' ' . getTranslation('delete_this_raid') . ' ' . EMOJI_WARN . CR . CR; + $msg .= show_raid_poll_small($raid); +} else if ($action == 1) { + debug_log('Raid deletion for ' . $id . ' was canceled!'); + // Set message. + $msg = '' . getTranslation('raid_deletion_was_canceled') . ''; + + // Set keys. + $keys = []; +} else if ($action == 2) { + debug_log('Confirmation to delete raid ' . $id . ' was received!'); + // Set message. + $msg = getTranslation('raid_successfully_deleted'); + + // Set keys. + $keys = []; + + // Delete raid from database. + delete_raid($id); +} + +// Edit message. +edit_message($update, $msg, $keys, false); + +// Build callback message string. +$callback_response = 'OK'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); + +exit; From 55be57ee3b281e0f11bb46f4be958f183a4a4b58 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 22 Jan 2018 16:08:15 +0100 Subject: [PATCH 169/225] Added new /delete command to existing modules, improved /list and /pokemon to tell when no raids are active, added access check to overview stuff --- commands/list.php | 6 +-- commands/pokemon.php | 18 +++++++ modules/overview_delete.php | 3 ++ modules/overview_share.php | 3 ++ modules/raid_create.php | 6 +++ modules/raids_list.php | 104 ++++++++++++++++++++++++++++++++++++ 6 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 modules/raids_list.php diff --git a/commands/list.php b/commands/list.php index 6a97adb..d023ba5 100644 --- a/commands/list.php +++ b/commands/list.php @@ -2,8 +2,8 @@ // Write to log. debug_log('LIST'); -// Check access - user must be admin! -bot_access_check($update, BOT_ADMINS); +// Check access. +bot_access_check($update, BOT_ACCESS); // Get the userid and chattype $userid = $update['message']['from']['id']; @@ -17,7 +17,7 @@ [ [ 'text' => getTranslation('list'), - 'callback_data' => $userid . ',' . $chattype . ':list_raids:0' + 'callback_data' => $userid . ',' . $chattype . ':raids_list:0' ] ], [ diff --git a/commands/pokemon.php b/commands/pokemon.php index 6a0bbe4..112866c 100755 --- a/commands/pokemon.php +++ b/commands/pokemon.php @@ -2,6 +2,9 @@ // Write to log. debug_log('POKEMON'); +// Check access. +bot_access_check($update, BOT_ACCESS); + // Build query. $rs = my_query( " @@ -43,6 +46,9 @@ " ); +// Count results. +$count = 0; + while ($raid = $request->fetch_assoc()) { // Create keys array. $keys = [ @@ -54,6 +60,9 @@ ] ]; + // Counter++ + $count = $count + 1; + // Get message. $msg = show_raid_poll_small($raid); @@ -61,4 +70,13 @@ send_message($update['message']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); } +// Send message if no active raids were found. +if($count == 0) { + // Set message. + $msg = '' . getTranslation('no_active_raids_found') . ''; + + // Send message. + sendMessage($update['message']['from']['id'], $msg); +} + exit; diff --git a/modules/overview_delete.php b/modules/overview_delete.php index ecf645f..3db1193 100644 --- a/modules/overview_delete.php +++ b/modules/overview_delete.php @@ -7,6 +7,9 @@ $chat_id = 0; $chat_id = $data['arg']; +// Check access. +bot_access_check($update, BOT_ADMINS); + // Get all or specific overview if ($chat_id == 0) { $request_overviews = my_query( diff --git a/modules/overview_share.php b/modules/overview_share.php index 9e59644..89c9bfd 100644 --- a/modules/overview_share.php +++ b/modules/overview_share.php @@ -3,6 +3,9 @@ debug_log('OVERVIEW_SHARE'); debug_log($data); +// Check access. +bot_access_check($update, BOT_ADMINS); + // Get chat ID from data $chat_id = 0; $chat_id = $data['arg']; diff --git a/modules/raid_create.php b/modules/raid_create.php index 835382c..a174a94 100755 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -150,6 +150,12 @@ 'callback_data' => $raid['id'] . ':raid_edit_poke:' . $raid['pokemon'], ] ], + [ + [ + 'text' => getTranslation('delete'), + 'callback_data' => $raid['id'] . ':raids_delete:0' + ] + ], [ [ 'text' => getTranslation('share'), diff --git a/modules/raids_list.php b/modules/raids_list.php new file mode 100644 index 0000000..6f1885a --- /dev/null +++ b/modules/raids_list.php @@ -0,0 +1,104 @@ +fetch_assoc(); + +// No data found. +if (!$row) { + //sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); + //exit; + $tz = TIMEZONE; +} else { + $tz = $row['timezone']; +} + +// Build query. +$request = my_query( + " + SELECT *, + UNIX_TIMESTAMP(end_time) AS ts_end, + UNIX_TIMESTAMP(start_time) AS ts_start, + UNIX_TIMESTAMP(NOW()) AS ts_now, + UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left + FROM raids + WHERE end_time>NOW() + AND timezone='{$tz}' + ORDER BY end_time ASC LIMIT 20 + " +); + +// Count results. +$count = 0; + +// Get raids. +while ($raid = $request->fetch_assoc()) { + + // Counter++ + $count = $count + 1; + + // Create keys array. + $keys = [ + [ + [ + 'text' => getTranslation('expand'), + 'callback_data' => $raid['id'] . ':vote_refresh:0', + ] + ], + [ + [ + 'text' => getTranslation('update_pokemon'), + 'callback_data' => $raid['id'] . ':raid_edit_poke:' . $raid['pokemon'], + ] + ], + [ + [ + 'text' => getTranslation('delete'), + 'callback_data' => $raid['id'] . ':raids_delete:0' + ] + ] + ]; + + // Get message. + $msg = show_raid_poll_small($raid); + + // Send message. + send_message($update['callback_query']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); +} + +// Set message. +if($count == 0) { + //sendMessage($update['callback_query']['from']['id'], '' . getTranslation('no_active_raids_found') . ''); + $msg = '' . getTranslation('no_active_raids_found') . ''; +} else { + $msg = '' . getTranslation('list_all_active_raids') . ':'; +} + +// Set message. +$keys = []; + +// Edit message. +edit_message($update, $msg, $keys, false); + +// Build callback message string. +$callback_response = 'OK'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); + +exit; From 31a1751e3d82088953c66c38dbc60ddc283d4ee5 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 22 Jan 2018 16:09:12 +0100 Subject: [PATCH 170/225] Renamed to modules/raids_list.php since we now have modules/raids_delete.php too --- modules/list_raids.php | 92 ------------------------------------------ 1 file changed, 92 deletions(-) delete mode 100644 modules/list_raids.php diff --git a/modules/list_raids.php b/modules/list_raids.php deleted file mode 100644 index a45199a..0000000 --- a/modules/list_raids.php +++ /dev/null @@ -1,92 +0,0 @@ -fetch_assoc(); - -// No data found. -if (!$row) { - //sendMessage($update['message']['from']['id'], 'Can\'t determine your location, please participate in at least 1 raid'); - //exit; - $tz = TIMEZONE; -} else { - $tz = $row['timezone']; -} - -// Build query. -$request = my_query( - " - SELECT *, - UNIX_TIMESTAMP(end_time) AS ts_end, - UNIX_TIMESTAMP(start_time) AS ts_start, - UNIX_TIMESTAMP(NOW()) AS ts_now, - UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(NOW()) AS t_left - FROM raids - WHERE end_time>NOW() - AND timezone='{$tz}' - ORDER BY end_time ASC LIMIT 20 - " -); - -// Count results. -$count = 0; - -// Get raids. -while ($raid = $request->fetch_assoc()) { - - // Counter++ - $count = $count + 1; - - // Create keys array. - $keys = [ - [ - [ - 'text' => getTranslation('expand'), - 'callback_data' => $raid['id'] . ':vote_refresh:0', - ] - ] - ]; - - // Get message. - $msg = show_raid_poll_small($raid); - - // Send message. - send_message($update['callback_query']['from']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); -} - -// Set message. -if($count == 0) { - //sendMessage($update['callback_query']['from']['id'], '' . getTranslation('no_active_raids_found') . ''); - $msg = '' . getTranslation('no_active_raids_found') . ''; -} else { - $msg = '' . getTranslation('list_all_active_raids') . ':'; -} - -// Set message. -$keys = []; - -// Edit message. -edit_message($update, $msg, $keys, false); - -// Build callback message string. -$callback_response = 'OK'; - -// Answer callback. -answerCallbackQuery($update['callback_query']['id'], $callback_response); - -exit; From 38b69d1863e8340b42e598ee49bcde009e3fb12d Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 22 Jan 2018 16:09:34 +0100 Subject: [PATCH 171/225] Added language stuff to delete raids --- language.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/language.json b/language.json index b814211..4111cbe 100755 --- a/language.json +++ b/language.json @@ -607,6 +607,12 @@ "EN": "Raid is already active!", "PT-BR": "A raid já está ativa!" }, + "bot_access_denied" : { + "NL": "Je hebt geen toegang tot deze functie!", + "DE": "Sie haben keine Berechtigung diesen Befehl oder Bot zu nutzen!", + "EN": "You are not allowed to use this command or bot!", + "PT-BR": "Você não tem permissão para utilizar esse comando ou bot!" + }, "raid_access_denied" : { "NL": "Je hebt geen rechten om deze raid aan te passen!", "DE": "Sie haben keine Berechtigung dieses Raid zu bearbeiten!", @@ -853,6 +859,24 @@ "EN": "Successfully shared!", "PT-BR": "Compartilhado com sucesso!" }, + "delete_this_raid" : { + "NL": "Verwijder deze raid?", + "DE": "Dieses Raid wirklich löschen?", + "EN": "Really delete this raid?", + "PT-BR": "Realmente deletar esta raid?" + }, + "raid_deletion_was_canceled" : { + "NL": "Het verwijderen van het raid is gestopt!", + "DE": "Löschung des Raids wurde abgebrochen!", + "EN": "Deletion of the raid was canceled!", + "PT-BR": "O deletamento da raid foi cancelado!" + }, + "raid_successfully_deleted" : { + "NL": "Raid is succesvol verwijderd!", + "DE": "Raid wurde erfolgreich gelöscht!", + "EN": "Raid was successfully deleted!", + "PT-BR": "Raid deletado com sucesso!" + }, "yes" : { "NL": "Ja", "DE": "Ja", From bc4946739d532d4200e2004d1d24074aad60fbdc Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 22 Jan 2018 16:10:11 +0100 Subject: [PATCH 172/225] Added logic to delete a raid in telegram and the database, improved bot_access_check a bit --- logic.php | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/logic.php b/logic.php index 0e6ecf2..a92a2c1 100755 --- a/logic.php +++ b/logic.php @@ -94,8 +94,17 @@ function bot_access_check($update, $access_type = BOT_ACCESS, $return_result = f return $allow_access; } else { debug_log("Denying access to the bot for user:" . CR . $msg); - $response_msg = 'You are not allowed to use this command or bot!'; - sendMessage($update['message']['chat']['id'], $response_msg); + $response_msg = '' . getTranslation('bot_access_denied') . ''; + // Edit message or send new message based on value of $update_type + if ($update_type == 'callback_query') { + $keys = []; + // Edit message. + edit_message($update, $response_msg, $keys); + // Answer the callback. + answerCallbackQuery($update[$update_type]['id'], getTranslation('bot_access_denied')); + } else { + sendMessage($update[$update_type]['from']['id'], $response_msg); + } exit; } } else { @@ -532,7 +541,7 @@ function raid_edit_start_keys($id) 'callback_data' => $id . ':edit:2' ], [ - 'text' => getTranslation('5stars'), + 'text' => getTranslation('1stars'), 'callback_data' => $id . ':edit:1' ] */ ] @@ -1702,7 +1711,33 @@ function delete_raid($raid_id) { global $db; - // Delete raid from cleanup table! + // Delete telegram messages for raid. + $rs = my_query( + " + SELECT * + FROM cleanup + WHERE raid_id = '{$raid_id}' + AND chat_id <> 0 + " + ); + + // Counter + $counter = 0; + + // Delete every telegram message + while ($row = $rs->fetch_assoc()) { + // Delete telegram message. + debug_log('Deleting telegram message ' . $row['message_id'] . ' from chat ' . $row['chat_id'] . ' for raid ' . $row['raid_id']); + delete_message($row['chat_id'], $row['message_id']); + $counter = $counter + 1; + } + + // Nothing to delete on telegram. + if ($counter == 0) { + debug_log('Raid with ID ' . $raid_id . ' was not found in the cleanup table! Skipping deletion of telegram messages!'); + } + + // Delete raid from cleanup table. debug_log('Deleting raid ' . $raid_id . ' from the cleanup table:'); $rs_cleanup = my_query( " @@ -1712,7 +1747,7 @@ function delete_raid($raid_id) " ); - // Delete raid from attendance table! + // Delete raid from attendance table. debug_log('Deleting raid ' . $raid_id . ' from the attendance table:'); $rs_attendance = my_query( " @@ -1721,7 +1756,7 @@ function delete_raid($raid_id) " ); - // Delete raid from raid table! + // Delete raid from raid table. debug_log('Deleting raid ' . $raid_id . ' from the raid table:'); $rs_raid = my_query( " From c7eed006fcbc8a1a30128f47102a3e16fa30209d Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Mon, 22 Jan 2018 16:18:35 +0100 Subject: [PATCH 173/225] Forgot to add missing part of NL translation --- language.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language.json b/language.json index 4111cbe..f1fe684 100755 --- a/language.json +++ b/language.json @@ -608,7 +608,7 @@ "PT-BR": "A raid já está ativa!" }, "bot_access_denied" : { - "NL": "Je hebt geen toegang tot deze functie!", + "NL": "Je hebt geen toegang tot deze functie of bot!", "DE": "Sie haben keine Berechtigung diesen Befehl oder Bot zu nutzen!", "EN": "You are not allowed to use this command or bot!", "PT-BR": "Você não tem permissão para utilizar esse comando ou bot!" From e088b07600e82c3ca93ec0f848796282b76c10a5 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 22 Jan 2018 16:48:28 +0100 Subject: [PATCH 174/225] Update README to include /delete function :) --- README.md | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1cf2a57..6195a37 100644 --- a/README.md +++ b/README.md @@ -163,14 +163,28 @@ As a member of `BOT_ACCESS` you can create raid polls, update your own raid poll Telegram Users can only vote on raid polls, but have no access to other bot functions (unless you configured it for public access). -| Access | Database | Raid poll | | | Pokemon | | Gym | | Moderators | | | Help | -|---------------|-----------|-----------|--------------------------------------|------------------|-------------------------------|-------------------------------|-----------------|------------------|------------------|-----------------|--------------------|------------------| -| | | **Vote** | **Create** `/start`, `/raid`, `/new` | **List** `/list` | **All raid polls** `/pokemon` | **Own raid polls** `/pokemon` | **Name** `/gym` | **Team** `/team` | **List** `/mods` | **Add** `/mods` | **Delete** `/mods` | **Show** `/help` | -| MAINTAINER_ID | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | -| BOT_ADMINS | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | -| BOT_ACCESS | Moderator | Yes | Yes | | Yes | Yes | Yes | Yes | | | | Yes | -| BOT_ACCESS | User | Yes | Yes | | | Yes | | Yes | | | | Yes | -| Telegram | User | Yes | | | | | | | | | | | +| Access: | | | MAINTAINER_ID | BOT_ADMINS | BOT_ACCESS | BOT_ACCESS | Telegram | +|-----------|------------|----------------------------------|---------------|------------|------------|------------|----------| +| Database: | | | | | Moderator | User | User | +| | **Area** | **Action and /command** | | | | | | +| | Raid poll | Vote | Yes | Yes | Yes | Yes | Yes | +| | | Create `/start`, `/raid`, `/new` | Yes | Yes | Yes | Yes | | +| | | List `/list` | Yes | Yes | Yes | Yes | | +| | | Overview `/list` | Yes | Yes | | | | +| | | Delete ALL raid polls `/delete` | Yes | Yes | Yes | | | +| | | Delete OWN raid polls `/delete` | Yes | Yes | Yes | Yes | | +| | | | | | | | | +| | Pokemon | ALL raid polls `/pokemon` | Yes | Yes | Yes | | | +| | | OWN raid polls `/pokemon` | Yes | Yes | Yes | Yes | | +| | | | | | | | | +| | Gym | Name `/gym` | Yes | Yes | Yes | | | +| | | Team `/team` | Yes | Yes | Yes | Yes | | +| | | | | | | | | +| | Moderators | List `/mods` | Yes | Yes | | | | +| | | Add `/mods` | Yes | Yes | | | | +| | | Delete `/mods` | Yes | Yes | | | | +| | | | | | | | | +| | Help | Show `/help` | Yes | Yes | Yes | Yes | | # Updates @@ -216,7 +230,7 @@ Example input: `/raid Entei,52.514545,13.350095,60,Mystic,Siegessäule,Großer S Update pokemon of an existing raid poll. With this command you can change the pokemon raid boss from e.g. "Level 5 Egg" to "Lugia" once the egg has hatched. -You can only change the pokemon raid boss of raid polls you created yourself. You cannot modify the pokemon of raid polls from other bot users. +Based on your access to the bot, you may can only change the pokemon raid boss of raid polls you created yourself and cannot modify the pokemon of raid polls from other bot users. #### Command: /new @@ -233,6 +247,13 @@ Example input: `/new 52.514545,13.350095` The bot will allow you to via a list of the last 20 active raids, share and delete all raids which got shared to channels as a raid overview. +#### Command: /delete + +Delete an existing raid poll. With this command you can delete a raid poll from telegram and the database. Use with care! + +Based on your access to the bot, you may can only delete raid polls you created yourself and cannot delete raid polls from other bot users. + + #### Command: /team The bot will set the team to Mystic/Valor/Instinct for the last created raid based on your input. @@ -253,5 +274,4 @@ Check your bot logfile and other related log files, e.g. apache/httpd log, php l * New gyms: Adding gyms to database without creating a raid via /raid * Preferred pokemon raid boss: When multiple level 5 raids are available, e.g. Lugia and Zapdos, add buttons to tell that you're coming a) only if Lugia, b) only if Zapdos, c) independently of the pokemon -* Delete raids: Allow BOT_ADMINS to delete raids * Delete incomplete raids automatically: When a bot user starts to create a raid via /start, but does not finish the raid creation, incomplete raid data is stored in the raids table. A method to automatically delete them without interfering with raids just being created would be nice. From 99533642553092dce935b58bfee3bc0ed93d3a96 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 23 Jan 2018 16:23:45 +0100 Subject: [PATCH 175/225] Add new variables to restrict sharing of raids --- config.php.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config.php.example b/config.php.example index a2b3bef..c7c1dea 100755 --- a/config.php.example +++ b/config.php.example @@ -19,6 +19,10 @@ define('BOT_NAME', '@RaidPokemonBot'); define('BOT_ADMINS', ''); // optional define('BOT_ACCESS', ''); // optional +define('SHARE_MODERATORS', true); +define('SHARE_USERS', true); +define('SHARE_CHATS', ''); + define('RAID_LOCATION', false); // send location as message in addition to raid poll message define('RAID_SLOTS', '15'); // minutes define('RAID_LAST_START', '10'); // minutes before RAID ends From 1264e9e1cc212405ca98174ee8c0f018fddb30b5 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 23 Jan 2018 16:24:29 +0100 Subject: [PATCH 176/225] Add logic for the share keys --- logic.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/logic.php b/logic.php index a92a2c1..184d76e 100755 --- a/logic.php +++ b/logic.php @@ -695,6 +695,68 @@ function next_key($keys, $id, $action, $arg) return $keys; } +/** + * Share keys. + * @param $raid_id + * @param $user_id + * @return array + */ +function share_keys($raid_id, $user_id) +{ + // Moderator or not? + debug_log("Checking if user is moderator: " . $user_id); + $rs = my_query( + " + SELECT moderator + FROM users + WHERE user_id = {$user_id} + " + ); + + // Fetch user data. + $user = $rs->fetch_assoc(); + + // Check moderator status. + $mod = $user['moderator']; + debug_log('User is ' . (($mod == 1) ? '' : 'not ') . 'a moderator: ' . $user_id); + + // Add share button if not restricted. + if ((SHARE_MODERATORS == true && $mod == 1) || SHARE_USERS == true) { + debug_log('Adding general share key to inline keys'); + // Set the keys. + $keys[] = [ + [ + 'text' => getTranslation('share'), + 'switch_inline_query' => strval($raid_id) + ] + ]; + } + + // Add buttons for predefined sharing chats. + if (!empty(SHARE_CHATS)) { + // Add keys for each chat. + $chats = explode(',', SHARE_CHATS); + foreach($chats as $chat) { + // Get chat object + debug_log("Getting chat object for '" . $chat . "'"); + $chat_obj = get_chat($chat); + + // Check chat object for proper response. + if ($chat_obj['ok'] == true) { + debug_log('Proper chat object received, continuing to add key for this chat: ' . $chat_obj['result']['title']); + $keys[] = [ + [ + 'text' => getTranslation('share_with') . ' ' . $chat_obj['result']['title'], + 'callback_data' => $raid_id . ':raid_share:' . $chat + ] + ]; + } + } + } + + return $keys; +} + /** * Insert cleanup info to database. * @param $chat_id From 154aa32ac83d07630492242e8f6461f748517005 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 23 Jan 2018 16:26:55 +0100 Subject: [PATCH 177/225] Add new sharing keys, removed updating of raid user_id as a potential risk to take over raids ownership, added an abort button and some few cosmetic changes --- modules/raid_create.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/modules/raid_create.php b/modules/raid_create.php index a174a94..cccc3a4 100755 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -142,14 +142,11 @@ // Create the keys. if ($raid_status == "end") { $msg = getTranslation('raid_already_exists') . CR . show_raid_poll_small($raid); - // Update pokemon or share raid? + // Init keys. + $keys = array(); + + // Update pokemon and delete raid $keys = [ - [ - [ - 'text' => getTranslation('update_pokemon'), - 'callback_data' => $raid['id'] . ':raid_edit_poke:' . $raid['pokemon'], - ] - ], [ [ 'text' => getTranslation('delete'), @@ -158,14 +155,19 @@ ], [ [ - 'text' => getTranslation('share'), - 'switch_inline_query' => strval($raid['id']) + 'text' => getTranslation('update_pokemon'), + 'callback_data' => $raid['id'] . ':raid_edit_poke:' . $raid['pokemon'], ] ] ]; + + // Add keys to share. + $keys_share = share_keys($raid['id'], $userid); + $keys = array_merge($keys, $keys_share); } else { // Set message string - $msg_main = getTranslation('raid_being_created_by_other_user') . CR . get_user($raid['user_id']); + $msg_main = getTranslation('raid_being_created_by_other_user') . CR; + $msg_main .= getTranslation('gym') . ': ' . $raid['gym_name'] . CR . get_user($raid['user_id']); $msg_main .= getTranslation('raid_creation_started_at') . " " . unix2tz($raid['ts_start'], $raid['timezone']) . '.'; $access_msg_header = ''; $access_msg_footer = ''; @@ -177,8 +179,7 @@ $rs = my_query( " UPDATE raids - SET user_id = {$userid}, - start_time = NOW() + SET start_time = NOW() " ); @@ -187,6 +188,15 @@ $access_msg_header .= CR . "" . getTranslation('raid_creation_in_progress_warning') . "" . CR . CR; $access_msg_footer .= CR . CR . getTranslation('select_raid_level_to_continue') . ':'; $keys = raid_edit_start_keys($raid['id']); + $key_exit = [ + [ + [ + 'text' => getTranslation('abort'), + 'callback_data' => '0:exit:0' + ] + ] + ]; + $keys = array_merge($keys, $key_exit); } else { $keys = []; } From 3befaf74a0996785170f6a659de4f5aa2c9bca5a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 23 Jan 2018 16:27:36 +0100 Subject: [PATCH 178/225] Add module to exit the current process/action --- modules/exit.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 modules/exit.php diff --git a/modules/exit.php b/modules/exit.php new file mode 100644 index 0000000..32a386d --- /dev/null +++ b/modules/exit.php @@ -0,0 +1,19 @@ + Date: Tue, 23 Jan 2018 16:29:19 +0100 Subject: [PATCH 179/225] Add new sharing keys and delete key. Update user_id to make sure the right person is the raid creator/owner. --- modules/edit_left.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/edit_left.php b/modules/edit_left.php index f0cebe0..40b6228 100755 --- a/modules/edit_left.php +++ b/modules/edit_left.php @@ -10,26 +10,37 @@ // Set the id. $id = $data['id']; +// Set the user id. +$userid = $update['callback_query']['from']['id']; + // Build query. my_query( " UPDATE raids - SET end_time = DATE_ADD(start_time, INTERVAL {$data['arg']} MINUTE) + SET user_id = {$userid}, + end_time = DATE_ADD(start_time, INTERVAL {$data['arg']} MINUTE) WHERE id = {$id} " ); if ($update['message']['chat']['type'] == 'private' || $update['callback_query']['message']['chat']['type'] == 'private') { - // Set the keys. + // Init keys. + $keys = array(); + + // Add delete to keys. $keys = [ [ [ - 'text' => getTranslation('share'), - 'switch_inline_query' => strval($id) + 'text' => getTranslation('delete'), + 'callback_data' => $id . ':raids_delete:0' ] ] ]; + // Add keys to share. + $keys_share = share_keys($id, $userid); + $keys = array_merge($keys, $keys_share); + // Get raid times. $rs = my_query( " From 04fd07ca48ac25401b5bca3907a0b5dbbaf0579f Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 23 Jan 2018 16:30:18 +0100 Subject: [PATCH 180/225] Add module to share raids with a chat --- modules/raid_share.php | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 modules/raid_share.php diff --git a/modules/raid_share.php b/modules/raid_share.php new file mode 100755 index 0000000..137a50e --- /dev/null +++ b/modules/raid_share.php @@ -0,0 +1,48 @@ +fetch_assoc(); + +// Get text and keys. +$text = show_raid_poll($raid); +$keys = keys_vote($raid); + +// Send the message. +send_message($chat, $text, $keys, ['disable_web_page_preview' => 'true']); + +// Set callback keys and message +$callback_msg = getTranslation('successfully_shared'); + +// Edit message. +edit_message($update, $callback_msg, $callback_keys, false); + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_msg); + +exit; From 9ccc902a22016cb3db1c120516f12a42ec2892c9 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 23 Jan 2018 16:58:47 +0100 Subject: [PATCH 181/225] Added new sharing restrictions to readme --- README.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1cf2a57..fa0deaa 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,32 @@ Bot Settings: Use https://www.miniwebtool.com/sha512-hash-generator/ and set `CONFIG_HASH` to hashed value of your token (make sure it is lowecase) +## Sharing raids + +You can share raid polls wth any chat in Telegram via a share button. + +Sharing raid polls can be restricted, so only moderators or users or both can be allowed to share a raid poll. + +Therefore it is possible, via a comma-separated list, to specify the chats the raid polls can be shared with. + +A few examples: + +#### Restrict sharing for moderators and users to chats -100111222333 and @RaidChat + +`define('SHARE_MODERATORS', false);` + +`define('SHARE_USERS', false);` + +`define('SHARE_CHATS', '-100111222333,@RaidChat');` + +#### Allow moderators to share with any chat, restrict sharing for users to chat @RaidChat + +`define('SHARE_MODERATORS', true);` + +`define('SHARE_USERS', false);` + +`define('SHARE_CHATS', '@RaidChat');` + ## Raid times There are several options to configure the times related to the raid polls: @@ -163,14 +189,28 @@ As a member of `BOT_ACCESS` you can create raid polls, update your own raid poll Telegram Users can only vote on raid polls, but have no access to other bot functions (unless you configured it for public access). -| Access | Database | Raid poll | | | Pokemon | | Gym | | Moderators | | | Help | -|---------------|-----------|-----------|--------------------------------------|------------------|-------------------------------|-------------------------------|-----------------|------------------|------------------|-----------------|--------------------|------------------| -| | | **Vote** | **Create** `/start`, `/raid`, `/new` | **List** `/list` | **All raid polls** `/pokemon` | **Own raid polls** `/pokemon` | **Name** `/gym` | **Team** `/team` | **List** `/mods` | **Add** `/mods` | **Delete** `/mods` | **Show** `/help` | -| MAINTAINER_ID | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | -| BOT_ADMINS | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | -| BOT_ACCESS | Moderator | Yes | Yes | | Yes | Yes | Yes | Yes | | | | Yes | -| BOT_ACCESS | User | Yes | Yes | | | Yes | | Yes | | | | Yes | -| Telegram | User | Yes | | | | | | | | | | | +| Access: | | | MAINTAINER_ID | BOT_ADMINS | BOT_ACCESS | BOT_ACCESS | Telegram | +|-----------|------------|----------------------------------|---------------|------------|------------|------------|----------| +| Database: | | | | | Moderator | User | User | +| | **Area** | **Action and /command** | | | | | | +| | Raid poll | Vote | Yes | Yes | Yes | Yes | Yes | +| | | Create `/start`, `/raid`, `/new` | Yes | Yes | Yes | Yes | | +| | | List `/list` | Yes | Yes | Yes | Yes | | +| | | Overview `/list` | Yes | Yes | | | | +| | | Delete ALL raid polls `/delete` | Yes | Yes | Yes | | | +| | | Delete OWN raid polls `/delete` | Yes | Yes | Yes | Yes | | +| | | | | | | | | +| | Pokemon | ALL raid polls `/pokemon` | Yes | Yes | Yes | | | +| | | OWN raid polls `/pokemon` | Yes | Yes | Yes | Yes | | +| | | | | | | | | +| | Gym | Name `/gym` | Yes | Yes | Yes | | | +| | | Team `/team` | Yes | Yes | Yes | Yes | | +| | | | | | | | | +| | Moderators | List `/mods` | Yes | Yes | | | | +| | | Add `/mods` | Yes | Yes | | | | +| | | Delete `/mods` | Yes | Yes | | | | +| | | | | | | | | +| | Help | Show `/help` | Yes | Yes | Yes | Yes | | # Updates @@ -216,7 +256,7 @@ Example input: `/raid Entei,52.514545,13.350095,60,Mystic,Siegessäule,Großer S Update pokemon of an existing raid poll. With this command you can change the pokemon raid boss from e.g. "Level 5 Egg" to "Lugia" once the egg has hatched. -You can only change the pokemon raid boss of raid polls you created yourself. You cannot modify the pokemon of raid polls from other bot users. +Based on your access to the bot, you may can only change the pokemon raid boss of raid polls you created yourself and cannot modify the pokemon of raid polls from other bot users. #### Command: /new @@ -233,6 +273,13 @@ Example input: `/new 52.514545,13.350095` The bot will allow you to via a list of the last 20 active raids, share and delete all raids which got shared to channels as a raid overview. +#### Command: /delete + +Delete an existing raid poll. With this command you can delete a raid poll from telegram and the database. Use with care! + +Based on your access to the bot, you may can only delete raid polls you created yourself and cannot delete raid polls from other bot users. + + #### Command: /team The bot will set the team to Mystic/Valor/Instinct for the last created raid based on your input. @@ -253,5 +300,4 @@ Check your bot logfile and other related log files, e.g. apache/httpd log, php l * New gyms: Adding gyms to database without creating a raid via /raid * Preferred pokemon raid boss: When multiple level 5 raids are available, e.g. Lugia and Zapdos, add buttons to tell that you're coming a) only if Lugia, b) only if Zapdos, c) independently of the pokemon -* Delete raids: Allow BOT_ADMINS to delete raids * Delete incomplete raids automatically: When a bot user starts to create a raid via /start, but does not finish the raid creation, incomplete raid data is stored in the raids table. A method to automatically delete them without interfering with raids just being created would be nice. From dfdbe01cad11b913423c5f330af27dafd1048de0 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 23 Jan 2018 17:03:33 +0100 Subject: [PATCH 182/225] Buying an i :D --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa0deaa..b78ccb1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Use https://www.miniwebtool.com/sha512-hash-generator/ and set `CONFIG_HASH` to ## Sharing raids -You can share raid polls wth any chat in Telegram via a share button. +You can share raid polls with any chat in Telegram via a share button. Sharing raid polls can be restricted, so only moderators or users or both can be allowed to share a raid poll. From 14d562bae33c4e206b92939e709291c35c6885e8 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 23 Jan 2018 19:25:44 +0100 Subject: [PATCH 183/225] Add translations for the new sharing feature --- language.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/language.json b/language.json index f1fe684..67311a0 100755 --- a/language.json +++ b/language.json @@ -877,6 +877,12 @@ "EN": "Raid was successfully deleted!", "PT-BR": "Raid deletado com sucesso!" }, + "action_aborted" : { + "NL": "Het proces is afgebroken!", + "DE": "Der Vorgang wurde abgebrochen!", + "EN": "The process was aborted!", + "PT-BR": "O processo foi abortado!" + }, "yes" : { "NL": "Ja", "DE": "Ja", @@ -889,6 +895,12 @@ "EN": "No", "PT-BR": "Não" }, + "abort" : { + "NL": "Afbreken", + "DE": "Abbrechen", + "EN": "Abort", + "PT-BR": "Abortar" + }, "list" : { "NL": "Lijst", "DE": "Anzeigen", From 3c3d4fb5ad56e7c6d5baa80a4be55b640bee3d23 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 24 Jan 2018 01:23:29 +0100 Subject: [PATCH 184/225] Add Aggron as level 4 raid boss, fix two misspellings --- constants.php | 1 + language.json | 10 ++++++++-- logic.php | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/constants.php b/constants.php index d165577..44bd52a 100755 --- a/constants.php +++ b/constants.php @@ -55,6 +55,7 @@ getTranslation('rhydon'), getTranslation('golem'), getTranslation('absol'), + getTranslation('aggron'), getTranslation('egg_4') ), '3' => array( diff --git a/language.json b/language.json index 67311a0..9db436d 100755 --- a/language.json +++ b/language.json @@ -90,7 +90,7 @@ "EN": "Tuesday", "PT-BR": "Terça-feira" }, - "wensday" : { + "wednesday" : { "NL": "Woensdag", "DE": "Mittwoch", "EN": "Wednesday", @@ -108,7 +108,7 @@ "EN": "Friday", "PT-BR": "Sexta-feira" }, - "saterday" : { + "saturday" : { "NL": "Zaterdag", "DE": "Samstag", "EN": "Saturday", @@ -323,6 +323,12 @@ "EN": "Absol", "PT-BR": "Absol" }, + "aggron" : { + "NL": "Aggron", + "DE": "Stolloss", + "EN": "Aggron", + "PT-BR": "Aggron" + }, "tyranitar" : { "NL": "Tyranitar", "DE": "Despotar", diff --git a/logic.php b/logic.php index 184d76e..ae70cc2 100755 --- a/logic.php +++ b/logic.php @@ -1745,7 +1745,7 @@ function weekday_number2name ($weekdaynumber) $weekday = getTranslation('tuesday'); break; case 3: - $weekday = getTranslation('wensday'); + $weekday = getTranslation('wednesday'); break; case 4: $weekday = getTranslation('thursday'); @@ -1754,7 +1754,7 @@ function weekday_number2name ($weekdaynumber) $weekday = getTranslation('friday'); break; case 6: - $weekday = getTranslation('saterday'); + $weekday = getTranslation('saturday'); break; case 7: $weekday = getTranslation('sunday'); From b335c4a5e354b2f974b0d81b7492f5e461f9f789 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 24 Jan 2018 10:07:05 +0100 Subject: [PATCH 185/225] Add share buttons to /list command to re-share a raid poll --- modules/raids_list.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/raids_list.php b/modules/raids_list.php index 6f1885a..f5c8368 100644 --- a/modules/raids_list.php +++ b/modules/raids_list.php @@ -74,6 +74,10 @@ ] ]; + // Add keys to share. + $keys_share = share_keys($raid['id'], $update['callback_query']['from']['id']); + $keys = array_merge($keys, $keys_share); + // Get message. $msg = show_raid_poll_small($raid); From 915a89f5b2adffb2e3d3d958b3250ad053554c08 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 24 Jan 2018 10:13:47 +0100 Subject: [PATCH 186/225] Add message to cleanup_log if wrong secret was supplied --- index.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.php b/index.php index 92de934..0439d74 100755 --- a/index.php +++ b/index.php @@ -90,6 +90,8 @@ // Run cleanup cleanup_log('Calling cleanup process now!'); run_cleanup($telegram, $database); + } else { + cleanup_log('Error! Wrong cleanup secret supplied!', '!'); } // Exit after cleanup exit(); From 8fb6052f1417bcb7a5c019bce3e7728764a11514 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 24 Jan 2018 13:59:38 +0100 Subject: [PATCH 187/225] Added reply_to_message_id since we check for it to add raids to cleanup --- modules/raid_share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/raid_share.php b/modules/raid_share.php index 137a50e..b87ce79 100755 --- a/modules/raid_share.php +++ b/modules/raid_share.php @@ -34,7 +34,7 @@ $keys = keys_vote($raid); // Send the message. -send_message($chat, $text, $keys, ['disable_web_page_preview' => 'true']); +send_message($chat, $text, $keys, ['reply_to_message_id' => $chat, 'disable_web_page_preview' => 'true']); // Set callback keys and message $callback_msg = getTranslation('successfully_shared'); From 3091dad3657529611495a209506190e29e017239 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 24 Jan 2018 14:00:05 +0100 Subject: [PATCH 188/225] Some debugging improvements for the cleanup process --- functions.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 2904290..906d64d 100755 --- a/functions.php +++ b/functions.php @@ -476,7 +476,7 @@ function curl_json_request($json) debug_log('ERROR: ' . $json . "\n\n" . $json_response . "\n\n"); } else { // Result seems ok, get message_id and chat_id if supergroup or channel message - if ($response['result']['chat']['type'] == ("channel" || "supergroup")) { + if ($response['result']['chat']['type'] == "channel" || $response['result']['chat']['type'] == "supergroup") { // Init raid_id $raid_id = 0; @@ -487,6 +487,10 @@ function curl_json_request($json) // Get raid id from $json $json_message = json_decode($json, true); + // Write to log that message was shared with channel or supergroup + debug_log('Message was shared with ' . $response['result']['chat']['type'] . ' ' . $response['result']['chat']['title']); + debug_log('Checking input for cleanup info now...'); + // Check if callback_data is present to get the raid_id and reply_to_message_id is set to filter only raid messages if (!empty($json_message['reply_markup']['inline_keyboard']['0']['0']['callback_data']) && !empty($json_message['reply_to_message_id'])) { $split_callback_data = explode(':', $json_message['reply_markup']['inline_keyboard']['0']['0']['callback_data']); @@ -503,6 +507,8 @@ function curl_json_request($json) } else { debug_log('Missing input! Cannot call cleanup preparation!'); } + } else { + debug_log('No cleanup info found! Skipping cleanup preparation!'); } // Check if text starts with getTranslation('raid_overview_for_chat') and inline keyboard is empty From a12ec2bf80ca7cb969294464e588f60ddd2dcdab Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 24 Jan 2018 14:00:46 +0100 Subject: [PATCH 189/225] Two additional fixes --- commands/raid.php | 2 +- modules/vote.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/raid.php b/commands/raid.php index b3bc41c..50d4bcd 100755 --- a/commands/raid.php +++ b/commands/raid.php @@ -250,7 +250,7 @@ ]; // Send the message. - send_message($update['message']['chat']['id'], $text, $keys); + send_message($update['message']['chat']['id'], $text, $keys, ['disable_web_page_preview' => 'true']); } else { // Set reply to. diff --git a/modules/vote.php b/modules/vote.php index c2c93e3..d724a01 100644 --- a/modules/vote.php +++ b/modules/vote.php @@ -31,7 +31,7 @@ $extraPeople = intval($data['arg'] - 1); // Check if we found the users team. -$team = !empty($row['team']) ? "'" . $row['team'] . "'" : NULL; +$team = !empty($row['team']) ? "'" . $row['team'] . "'" : "NULL"; // Write to log. debug_log($row); From b32f0cd0333ba6444e8b93fde45ab8606ef25999 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 31 Jan 2018 13:52:21 +0100 Subject: [PATCH 190/225] Oops... Forgot where in sql statement. --- modules/raid_create.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/raid_create.php b/modules/raid_create.php index cccc3a4..005bfd6 100755 --- a/modules/raid_create.php +++ b/modules/raid_create.php @@ -180,6 +180,7 @@ " UPDATE raids SET start_time = NOW() + WHERE id = {$raid_id} " ); From 3a416723b72e11200f562b1d6587a65a583e65d7 Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Thu, 8 Feb 2018 17:52:42 +0100 Subject: [PATCH 191/225] Added all legendaries Added all legendaries --- language.json | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/language.json b/language.json index 9db436d..741c0e0 100755 --- a/language.json +++ b/language.json @@ -281,6 +281,54 @@ "EN": "Kyogre", "PT-BR": "Kyogre" }, + "rayquaza" : { + "NL": "Rayquaza", + "DE": "Rayquaza", + "EN": "Rayquaza", + "PT-BR": "Rayquaza" + }, + "latios" : { + "NL": "Latios", + "DE": "Latios", + "EN": "Latios", + "PT-BR": "Latios" + }, + "latias" : { + "NL": "Latias", + "DE": "Latias", + "EN": "Latias", + "PT-BR": "Latias" + }, + "deoxys" : { + "NL": "Deoxys", + "DE": "Deoxys", + "EN": "Deoxys", + "PT-BR": "Deoxys" + }, + "jirachi" : { + "NL": "Jirachi", + "DE": "Jirachi", + "EN": "Jirachi", + "PT-BR": "Jirachi" + }, + "regirock" : { + "NL": "Regirock", + "DE": "Regirock", + "EN": "Regirock", + "PT-BR": "Regirock" + }, + "regice" : { + "NL": "Regice", + "DE": "Regice", + "EN": "Regice", + "PT-BR": "Regice" + }, + "registeel" : { + "NL": "Registeel", + "DE": "Registeel", + "EN": "Registeel", + "PT-BR": "Registeel" + }, "egg_5" : { "NL": "Level 5 Ei", "DE": "Level 5 Ei", @@ -511,7 +559,7 @@ }, "raid_boss" : { - "NL": "Raid baas", + "NL": "#Raid baas", "DE": "Raid-Boss", "EN": "Raid boss", "PT-BR": "Chefe da raid" From 78a7e81bec94ad4f201dde45576b192c09661885 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Thu, 8 Feb 2018 20:05:54 +0100 Subject: [PATCH 192/225] Add Rayquaza Raid Boss --- constants.php | 1 + 1 file changed, 1 insertion(+) diff --git a/constants.php b/constants.php index 44bd52a..6542024 100755 --- a/constants.php +++ b/constants.php @@ -42,6 +42,7 @@ getTranslation('suicune'), getTranslation('groudon'), getTranslation('kyogre'), + getTranslation('rayquaza'), getTranslation('egg_5') ), '4' => array( From 72a86cd2a8dfad0fc6863118d41a8b1ed6b4ec99 Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Thu, 8 Feb 2018 20:27:05 +0100 Subject: [PATCH 193/225] Added Legendaries Added legendaries and disabled the Pokemon that are not in raids at the moment. --- constants.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/constants.php b/constants.php index 6542024..e82a8ca 100755 --- a/constants.php +++ b/constants.php @@ -29,20 +29,27 @@ getTranslation('mewtwo') ), '5' => array( - getTranslation('articuno'), - getTranslation('lugia'), - getTranslation('moltres'), - getTranslation('zapdos'), - getTranslation('mew'), +// getTranslation('articuno'), +// getTranslation('lugia'), +// getTranslation('moltres'), +// getTranslation('zapdos'), +// getTranslation('mew'), getTranslation('mewtwo'), - getTranslation('hooh'), - getTranslation('celebi'), - getTranslation('raikou'), - getTranslation('entei'), - getTranslation('suicune'), - getTranslation('groudon'), - getTranslation('kyogre'), +// getTranslation('hooh'), +// getTranslation('celebi'), +// getTranslation('raikou'), +// getTranslation('entei'), +// getTranslation('suicune'), +// getTranslation('groudon'), getTranslation('rayquaza'), + getTranslation('kyogre'), +// getTranslation('latios'), +// getTranslation('latias'), +// getTranslation('deoxys'), +// getTranslation('jirachi'), +// getTranslation('regirock'), +// getTranslation('regice'), +// getTranslation('registeel'), getTranslation('egg_5') ), '4' => array( From ea5d815c1f934c89101313dc2c2b8c93d06b7aff Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 9 Feb 2018 01:13:07 +0100 Subject: [PATCH 194/225] Added pokemon column to attendance --- constants.php | 31 +++++++++++++++++++------------ raid-pokemon-bot.sql | 1 + 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/constants.php b/constants.php index 6542024..e82a8ca 100755 --- a/constants.php +++ b/constants.php @@ -29,20 +29,27 @@ getTranslation('mewtwo') ), '5' => array( - getTranslation('articuno'), - getTranslation('lugia'), - getTranslation('moltres'), - getTranslation('zapdos'), - getTranslation('mew'), +// getTranslation('articuno'), +// getTranslation('lugia'), +// getTranslation('moltres'), +// getTranslation('zapdos'), +// getTranslation('mew'), getTranslation('mewtwo'), - getTranslation('hooh'), - getTranslation('celebi'), - getTranslation('raikou'), - getTranslation('entei'), - getTranslation('suicune'), - getTranslation('groudon'), - getTranslation('kyogre'), +// getTranslation('hooh'), +// getTranslation('celebi'), +// getTranslation('raikou'), +// getTranslation('entei'), +// getTranslation('suicune'), +// getTranslation('groudon'), getTranslation('rayquaza'), + getTranslation('kyogre'), +// getTranslation('latios'), +// getTranslation('latias'), +// getTranslation('deoxys'), +// getTranslation('jirachi'), +// getTranslation('regirock'), +// getTranslation('regice'), +// getTranslation('registeel'), getTranslation('egg_5') ), '4' => array( diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index bcc3d77..1d7a307 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -28,6 +28,7 @@ CREATE TABLE `attendance` ( `arrived` tinyint(1) unsigned DEFAULT 0, `raid_done` tinyint(1) unsigned DEFAULT 0, `cancel` tinyint(1) unsigned DEFAULT 0, + `pokemon` varchar(12) DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; From 79b44a033bba59a67638eb1bbb1c66dc92bdbb0b Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 9 Feb 2018 01:14:04 +0100 Subject: [PATCH 195/225] Added new file when voting for pokemon --- modules/vote_pokemon.php | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 modules/vote_pokemon.php diff --git a/modules/vote_pokemon.php b/modules/vote_pokemon.php new file mode 100644 index 0000000..5d1871b --- /dev/null +++ b/modules/vote_pokemon.php @@ -0,0 +1,63 @@ +fetch_assoc(); + +// Write to log. +debug_log($answer); + +// User has voted before. +if (!empty($answer)) { + // Update attendance. + my_query( + " + UPDATE attendance + SET pokemon = '{$db->real_escape_string($data['arg'])}' + WHERE raid_id = {$data['id']} + AND user_id = {$update['callback_query']['from']['id']} + " + ); + +// User has not voted before. +// Disabled since user shall vote for the time first! +/* +} else { + + // Get users data. + $rs = my_query( + " + SELECT * + FROM users + WHERE user_id = {$update['callback_query']['from']['id']} + " + ); + + // Get the row. + $row = $rs->fetch_assoc(); + + // Check if we found the users team. + $team = !empty($row['team']) ? "'" . $row['team'] . "'" : "NULL"; + + // Create attendance. + my_query( + " + INSERT INTO attendance + SET raid_id = {$data['id']}, + user_id = {$update['callback_query']['from']['id']}, + pokemon = '{$db->real_escape_string($data['arg'])}', + team = {$team} + " + ); +*/ +} +// Send vote response. +send_response_vote($update, $data); From 41d4943fd862cdb7e0e45b321e76d9d74a4e6982 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 9 Feb 2018 01:14:26 +0100 Subject: [PATCH 196/225] Added logic to vote for pokemon --- logic.php | 229 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 174 insertions(+), 55 deletions(-) diff --git a/logic.php b/logic.php index ae70cc2..ea4b6d6 100755 --- a/logic.php +++ b/logic.php @@ -1190,8 +1190,86 @@ function keys_vote($raid) } $keys[] = $keys_time; - } + // Init keys pokemon array. + $keys_poke = []; + + // Get current pokemon + $raid_pokemon = $raid['pokemon']; + + // Init raid level and level found + $raid_level = 0; + $level_found = false; + + // Ignore level X raid bosses + $ignore_X = []; + $X_list = $GLOBALS['pokemon']['X']; + foreach($X_list as $pokemon) { + $ignore_X[] = strtolower($pokemon); + debug_log('Adding pokemon to keys ignore list: ' . $pokemon); + } + + // Iterate thru the pokemon list to get raid level + $pokemonlist = $GLOBALS['pokemon']; + foreach($pokemonlist as $level => $levelmons) { + if($level == "X") continue; + //debug_log("Searching raid boss '" . $raid_pokemon . "' in level " . $level . " raids"); + // Compare pokemon by pokemon to get raid level + foreach($levelmons as $key => $pokemon) { + if(strtolower($raid_pokemon) == strtolower($pokemon)) { + $level_found = true; + $raid_level = $level; + //debug_log("Found raid boss '" . $pokemon . "' in level " . $level . " raids"); + break 2; + } + } + } + + // Add pokemon keys if we found the raid boss + if ($level_found) { + // Init counter and cols + $count = 0; + $col_poke = 1; + + foreach($pokemonlist as $level => $levelmons) { + if($level == $raid_level) { + foreach($levelmons as $key => $pokemon) { + // Ignore raid eggs and level X pokemon + if(strtolower($pokemon) == strtolower(getTranslation('egg_' . $level))) continue; + if(in_array(strtolower($pokemon), $ignore_X)) continue; + + // Not too many pokemon in a row + if ($col_poke++ >= 3) { + $keys[] = $keys_poke; + $keys_poke = []; + $col_poke = 1; + } + + // Add pokemon to keys + $keys_poke[] = array( + 'text' => $pokemon, + 'callback_data' => $raid['id'] . ':vote_pokemon:' . $pokemon + ); + + // Counter + $count = $count + 1; + } + } + } + + // Add pokemon keys if we have two or more pokemon + if($count >= 2) { + // Add button if raid boss does not matter + $keys_poke[] = array( + 'text' => getTranslation('any'), + 'callback_data' => $raid['id'] . ':vote_pokemon:0' + ); + + // Finally add pokemon to keys + $keys[] = $keys_poke; + } + } + } $keys[] = [ [ @@ -2010,84 +2088,125 @@ function show_raid_poll($raid) $msg .= CR; } - $user_rs = my_query( + // Get pokemon + $poke_rs = my_query( " SELECT * FROM attendance - WHERE UNIX_TIMESTAMP(attend_time) = {$ts['ts_att']} - AND raid_done != 1 - AND cancel != 1 - AND raid_id = {$raid['id']} - ORDER BY team ASC, arrived ASC + WHERE raid_id = {$raid['id']} + GROUP BY pokemon " ); - // Init empty attend users array. - $att_users = array(); - + // Init empty pokemon array. + $voted_poke = array(); + $count_poke = 0; - while ($rowUsers = $user_rs->fetch_assoc()) { - $att_users[] = $rowUsers; + // Count pokemons which users voted for. + while ($rowPoke = $poke_rs->fetch_assoc()) { + $voted_poke[] = $rowPoke; + $count_poke = $count_poke + 1; } - // Write to log. - debug_log($att_users); - - foreach ($att_users as $vv) { - // Write to log. - debug_log($vv['user_id']); - - // Get user data. - $rs = my_query( + // Get users for each pokemon. + foreach ($voted_poke as $pp) { + // Get users. + $user_rs = my_query( " - SELECT * - FROM users - WHERE user_id = {$vv['user_id']} + SELECT * + FROM attendance + WHERE UNIX_TIMESTAMP(attend_time) = {$ts['ts_att']} + AND raid_done != 1 + AND cancel != 1 + AND raid_id = {$raid['id']} + AND pokemon = '{$pp['pokemon']}' + ORDER BY team ASC, arrived ASC " ); - // Get the row. - $row = $rs->fetch_assoc(); - - // Always use name. - $name = '' . htmlspecialchars($row['name']) . ''; + // Init empty attend users array and counter. + $att_users = array(); + $cnt_users = 0; - // Unknown team. - if ($row['team'] === NULL) { - $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' '; + while ($rowUsers = $user_rs->fetch_assoc()) { + $att_users[] = $rowUsers; + $cnt_users = $cnt_users + 1; + } - // Known team. + if($cnt_users == 0) { + // No users voted for this pokemon, continue + continue; } else { - $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' '; + // Show any raid boss in message when we have more than 2 pokemon and pokemon is 0 + if($count_poke >= 2 && $pp['pokemon'] == '0') { + $msg .= '' . getTranslation('any_pokemon') . '' . CR; + // Show raid boss name in message when we have 1 or more pokemon and pokemon is NOT 0 + } else if($count_poke >= 1 && $pp['pokemon'] != '0') { + $msg .= '' . $pp['pokemon'] . '' . CR; + } + // Missing else since unnecessary: Hide raid boss name in message when we have just 1 pokemon which is 0 } - // Add level. - if ($row['level'] != 0) { - $msg .= ''.$row['level'].''; + // Write to log. + debug_log($att_users); + + foreach ($att_users as $vv) { + + // Write to log. + debug_log($vv['user_id']); + + // Get user data. + $rs = my_query( + " + SELECT * + FROM users + WHERE user_id = {$vv['user_id']} + " + ); + + // Get the row. + $row = $rs->fetch_assoc(); + + // Always use name. + $name = '' . htmlspecialchars($row['name']) . ''; + + // Unknown team. + if ($row['team'] === NULL) { + $msg .= ' └ ' . $GLOBALS['teams']['unknown'] . ' '; + + // Known team. + } else { + $msg .= ' └ ' . $GLOBALS['teams'][$row['team']] . ' '; + } + + // Add level. + if ($row['level'] != 0) { + $msg .= ''.$row['level'].''; + $msg .= ' '; + } + + // Add name. + $msg .= $name; $msg .= ' '; - } - // Add name. - $msg .= $name; - $msg .= ' '; + // Arrived. + if ($vv['arrived']) { + // No time is displayed, but undefined_index error in log, so changed it: + //$msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; + $msg .= '[' . getTranslation('here') . '] '; - // Arrived. - if ($vv['arrived']) { - // No time is displayed, but undefined_index error in log, so changed it: - //$msg .= '[Bin da' . unix2tz($vv['ts_att'], $raid['timezone']) . '] '; - $msg .= '[' . getTranslation('here') . '] '; + // Cancelled. + } else if ($vv['cancel']) { + $msg .= '[' . getTranslation('cancel') . '] '; + } - // Cancelled. - } else if ($vv['cancel']) { - $msg .= '[' . getTranslation('cancel') . '] '; - } + // Add extra people. + if ($vv['extra_people']) { + $msg .= '+' . $vv['extra_people']; + } - // Add extra people. - if ($vv['extra_people']) { - $msg .= '+' . $vv['extra_people']; + $msg .= CR; } - - $msg .= CR; } } From 5a9c6ff9189796305c074cf9e981db1102c2d77d Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 9 Feb 2018 01:15:41 +0100 Subject: [PATCH 197/225] Added translations for new pokemon voting feature. Maybe the whole file will be displayed as changed, since I changed the formatting from dos to unix as vim showed me that it is a dos file --- language.json | 1964 +++++++++++++++++++++++++------------------------ 1 file changed, 988 insertions(+), 976 deletions(-) diff --git a/language.json b/language.json index 741c0e0..c501973 100755 --- a/language.json +++ b/language.json @@ -1,976 +1,988 @@ -{ - "5stars" : { - "NL": "5 Sterren Raid", - "DE": "5 Sterne Raid", - "EN": "5 Star Raid", - "PT-BR": "Raid nível 5" - }, - "4stars" : { - "NL": "4 Sterren Raid", - "DE": "4 Sterne Raid", - "EN": "4 Star Raid", - "PT-BR": "Raid nível 4" - }, - "3stars" : { - "NL": "3 Sterren Raid", - "DE": "3 Sterne Raid", - "EN": "3 Star Raid", - "PT-BR": "Raid nível 3" - }, - "2stars" : { - "NL": "2 Sterren Raid", - "DE": "2 Sterne Raid", - "EN": "2 Star Raid", - "PT-BR": "Raid nível 2" - }, - "1stars" : { - "NL": "1 Sterren Raid", - "DE": "1 Sterne Raid", - "EN": "1 Star Raid", - "PT-BR": "Raid nível 1" - }, - "back" : { - "NL": "Terug", - "DE": "Zurück", - "EN": "Back", - "PT-BR": "Voltar" - }, - "next" : { - "NL": "Next", - "DE": "Weiter", - "EN": "Next", - "PT-BR": "Próximo" - }, - "alone" : { - "NL": "Alleen", - "DE": "Alleine", - "EN": "Alone", - "PT-BR": "Sozinho" - }, - "raid_done" : { - "NL": "Raid beëindigd", - "DE": "Raid beendet.", - "EN": "Raid done", - "PT-BR": "Raid completa" - }, - "here" : { - "NL": "Ben er", - "DE": "Bin da", - "EN": "Here", - "PT-BR": "Aqui" - - }, - "done" : { - "NL": "Klaar", - "DE": "Fertig", - "EN": "Done", - "PT-BR": "Feito" - }, - "cancellation" : { - "NL": "Afwezig", - "DE": "Absage", - "EN": "Cancellation", - "PT-BR": "Cancelada" - }, - "vote_updated" : { - "NL": "Stem geüpdatet", - "DE": "Abstimmung aktualisiert", - "EN": "Vote updated", - "PT-BR": "Votos atualizados" - }, - "monday" : { - "NL": "Maandag", - "DE": "Montag", - "EN": "Monday", - "PT-BR": "Segunda-feira" - }, - "tuesday" : { - "NL": "Dinsdag", - "DE": "Dienstag", - "EN": "Tuesday", - "PT-BR": "Terça-feira" - }, - "wednesday" : { - "NL": "Woensdag", - "DE": "Mittwoch", - "EN": "Wednesday", - "PT-BR": "Quarta-feira" - }, - "thursday" : { - "NL": "Donderdag", - "DE": "Donnerstag", - "EN": "Thursday", - "PT-BR": "Quinta-feira" - }, - "friday" : { - "NL": "Vrijdag", - "DE": "Freitag", - "EN": "Friday", - "PT-BR": "Sexta-feira" - }, - "saturday" : { - "NL": "Zaterdag", - "DE": "Samstag", - "EN": "Saturday", - "PT-BR": "Sábado" - }, - "sunday" : { - "NL": "Zondag", - "DE": "Sonntag", - "EN": "Sunday", - "PT-BR": "Domingo" - }, - "still" : { - "NL": "nog", - "DE": "noch", - "EN": "still" - }, - "raid_egg_opens" : { - "NL": "Raid ei gaat open", - "DE": "Raid-Ei öffnet sich um", - "EN": "Raid egg opens up", - "PT-BR": "Ovo eclode" - }, - "raid_egg_opens_day" : { - "NL": "Raid ei gaat open", - "DE": "Raid-Ei öffnet sich am", - "EN": "Raid egg opens on", - "PT-BR": "Ovo eclode em" - }, - "raid_egg_opens_at" : { - "NL": "om", - "DE": "um", - "EN": "at", - "PT-BR": "em" - }, - "raid_until" : { - "NL": "Raid tot", - "DE": "Raid bis", - "EN": "Raid until", - "PT-BR": "Raid até" - }, - "exraid_pass" : { - "NL": "DEELNAME IS ALLEEN MOGELIJK MET EX-RAID PASS", - "DE": "TEILNAHME IST NUR MIT EX-RAID-PASS MÖGLICH", - "EN": "PARTICIPATION IS POSSIBLE ONLY WITH EX-RAID PASS", - "PT-BR": "PARTICIPAÇÃO APENAS COM PASSE EX" - }, - "no_participants_yet" : { - "NL": "Nog geen deelnemers", - "DE": "Noch keine Teilnehmer.", - "EN": "No participants yet", - "PT-BR": "Ainda sem participantes" - }, - "finished" : { - "NL": "Klaar", - "DE": "Fertig", - "EN": "Finished", - "PT-BR": "Finalizada" - }, - "cancel" : { - "NL": "Annuleren", - "DE": "Abgesagt", - "EN": "Cancel", - "PT-BR": "Cancelar" - }, - "created_by" : { - "NL": "Aangemaakt door", - "DE": "Erstellt von", - "EN": "Created by", - "PT-BR": "Criada por" - }, - "updated" : { - "NL": "Bijgewerkt", - "DE": "Aktualisiert", - "EN": "Updated", - "PT-BR": "Atualizada" - }, - "from" : { - "NL": "van", - "DE": "von", - "EN": "from", - "PT-BR": "de" - }, - "to" : { - "NL": "tot", - "DE": "bis", - "EN": "to", - "PT-BR": "para" - }, - "no_participants" : { - "NL": "Geen deelnemers", - "DE": "Keine Teilnehmer", - "EN": "No participants", - "PT-BR": "Sem participantes" - }, - "mew" : { - "NL": "Mew", - "DE": "Mew", - "EN": "Mew", - "PT-BR": "Mew" - }, - "mewtwo" : { - "NL": "Mewtwo", - "DE": "Mewtu", - "EN": "Mewtwo", - "PT-BR": "Mewtwo" - }, - "lugia" : { - "NL": "Lugia", - "DE": "Lugia", - "EN": "Lugia", - "PT-BR": "Lugia" - }, - "zapdos" : { - "NL": "Zapdos", - "DE": "Zapdos", - "EN": "Zapdos", - "PT-BR": "Zapdos" - }, - "hooh" : { - "NL": "Ho-oh", - "DE": "Ho-oh", - "EN": "Ho-oh", - "PT-BR": "Ho-oh" - }, - "celebi" : { - "NL": "Celebi", - "DE": "Celebi", - "EN": "Celebi", - "PT-BR": "Celebi" - }, - "raikou" : { - "NL": "Raikou", - "DE": "Raikou", - "EN": "Raikou", - "PT-BR": "Raikou" - }, - "entei" : { - "NL": "Entei", - "DE": "Entei", - "EN": "Entei", - "PT-BR": "Entei" - }, - "suicune" : { - "NL": "Suicune", - "DE": "Suicune", - "EN": "Suicune", - "PT-BR": "Suicune" - }, - "moltres" : { - "NL": "Moltres", - "DE": "Lavados", - "EN": "Moltres", - "PT-BR": "Moltres" - }, - "articuno" : { - "NL": "Articuno", - "DE": "Arktos", - "EN": "Articuno", - "PT-BR": "Articuno" - }, - "groudon" : { - "NL": "Groudon", - "DE": "Groudon", - "EN": "Groudon", - "PT-BR": "Groudon" - }, - "kyogre" : { - "NL": "Kyogre", - "DE": "Kyogre", - "EN": "Kyogre", - "PT-BR": "Kyogre" - }, - "rayquaza" : { - "NL": "Rayquaza", - "DE": "Rayquaza", - "EN": "Rayquaza", - "PT-BR": "Rayquaza" - }, - "latios" : { - "NL": "Latios", - "DE": "Latios", - "EN": "Latios", - "PT-BR": "Latios" - }, - "latias" : { - "NL": "Latias", - "DE": "Latias", - "EN": "Latias", - "PT-BR": "Latias" - }, - "deoxys" : { - "NL": "Deoxys", - "DE": "Deoxys", - "EN": "Deoxys", - "PT-BR": "Deoxys" - }, - "jirachi" : { - "NL": "Jirachi", - "DE": "Jirachi", - "EN": "Jirachi", - "PT-BR": "Jirachi" - }, - "regirock" : { - "NL": "Regirock", - "DE": "Regirock", - "EN": "Regirock", - "PT-BR": "Regirock" - }, - "regice" : { - "NL": "Regice", - "DE": "Regice", - "EN": "Regice", - "PT-BR": "Regice" - }, - "registeel" : { - "NL": "Registeel", - "DE": "Registeel", - "EN": "Registeel", - "PT-BR": "Registeel" - }, - "egg_5" : { - "NL": "Level 5 Ei", - "DE": "Level 5 Ei", - "EN": "Level 5 Egg", - "PT-BR": "Ovo de Nível 5" - }, - "egg_4" : { - "NL": "Level 4 Ei", - "DE": "Level 4 Ei", - "EN": "Level 4 Egg", - "PT-BR": "Ovo de Nível 4" - }, - "egg_3" : { - "NL": "Level 3 Ei", - "DE": "Level 3 Ei", - "EN": "Level 3 Egg", - "PT-BR": "Ovo de Nível 3" - }, - "lapras" : { - "NL": "Lapras", - "DE": "Lapras", - "EN": "Lapras", - "PT-BR": "Lapras" - }, - "nidoqueen" : { - "NL": "Nidoqueen", - "DE": "Nidoqueen", - "EN": "Nidoqueen", - "PT-BR": "Nidoqueen" - }, - "nidoking" : { - "NL": "Nidoking", - "DE": "Nidoking", - "EN": "Nidoking", - "PT-BR": "Nidoking" - }, - "absol" : { - "NL": "Absol", - "DE": "Absol", - "EN": "Absol", - "PT-BR": "Absol" - }, - "aggron" : { - "NL": "Aggron", - "DE": "Stolloss", - "EN": "Aggron", - "PT-BR": "Aggron" - }, - "tyranitar" : { - "NL": "Tyranitar", - "DE": "Despotar", - "EN": "Tyranitar", - "PT-BR": "Tyranitar" - }, - "snorlax" : { - "NL": "Snorlax", - "DE": "Relaxo", - "EN": "Snorlax", - "PT-BR": "Snorlax" - }, - "golem" : { - "NL": "Golem", - "DE": "Geowaz", - "EN": "Golem", - "PT-BR": "Golem" - }, - "rhydon" : { - "NL": "Rhydon", - "DE": "Rizeros", - "EN": "Rhydon", - "PT-BR": "Rhydon" - }, - "porygon" : { - "NL": "Porygon", - "DE": "Porygon", - "EN": "Porygon", - "PT-BR": "Porygon" - }, - "gengar" : { - "NL": "Gengar", - "DE": "Gengar", - "EN": "Gengar", - "PT-BR": "Gengar" - }, - "poliwrath" : { - "NL": "Poliwrath", - "DE": "Quappo", - "EN": "Poliwrath", - "PT-BR": "Poliwrath" - }, - "victreebel" : { - "NL": "Victreebel", - "DE": "Sarzenia", - "EN": "Victreebel", - "PT-BR": "Victreebel" - }, - "arcanine" : { - "NL": "Arcanine", - "DE": "Arkani", - "EN": "Arcanine", - "PT-BR": "Arcanine" - }, - "machamp" : { - "NL": "Machamp", - "DE": "Machomei", - "EN": "Machamp", - "PT-BR": "Machamp" - }, - "alakazam" : { - "NL": "Alakazam", - "DE": "Simsala", - "EN": "Alakazam", - "PT-BR": "Alakazam" - }, - "scyther" : { - "NL": "Scyther", - "DE": "Sichlor", - "EN": "Scyther", - "PT-BR": "Schyther" - }, - "omastar" : { - "NL": "Omastar", - "DE": "Amoroso", - "EN": "Omastar", - "PT-BR": "Omastar" - }, - "ninetails" : { - "NL": "Ninetails", - "DE": "Vulnona", - "EN": "Ninetails", - "PT-BR": "Ninetails" - }, - "forest" : { - "NL": "Ergens in het bos", - "DE": "Irgendwo im Wald", - "EN": "Somewhere in the forest", - "PT-BR": "Em algum lugar na floresta" - }, - "select_gym_first_letter" : { - "NL": "Selecteer alstublieft de eerste letter van de gym:", - "DE": "Bitte Anfangsbuchstabe der Arena auswählen:", - "EN": "Please select the first letter of the gym:", - "PT-BR": "Por favor escolha a primeira letra do ginásio:" - }, - "select_gym" : { - "NL": "Beginletter geselecteerd.", - "DE": "Anfangsbuchstabe ausgewählt.", - "EN": "First letter selected.", - "PT-BR": "Primeira letra escolhida.:" - }, - "raid_creation_started_at" : { - "NL": "Raid aanmaak is gestart om", - "DE": "Das Raid wird angelegt seit", - "EN": "Raid creation was started at", - "PT-BR": "Criação da raid em" - }, - "raid_being_created_by_other_user" : { - "NL": "Een andere gebruiker is een raid voor deze gym aan het maken:", - "DE": "Ein Raid für diese Arena wird gerade angelegt von:", - "EN": "Another user is currently creating a raid for this gym:", - "PT-BR": "Outro usuário está criando uma raid para este ginásio:" - }, - "raid_already_exists" : { - "NL": "Raid bestaat al!", - "DE": "Raid existiert bereits!", - "EN": "Raid already exists!", - "PT-BR": "A raid já existe!" - }, - "create_raid" : { - "NL": "Begin Raid in", - "DE": "Erstelle Raid in", - "EN": "Create Raid in", - "PT-BR": "Criar raid em" - }, - "raid_creation_in_progress_warning" : { - "NL": "Je kan een raid aanmaken, maar de huidig aangemaakte raid zal worden overscheven. Deze wijziging kunnen niet ongedaan gemaakt worden dit is NIET AAN TE RADEN!", - "DE": "Das Raid kann weiter angelegt werden, aber dies wird das Raid welches gerade zeitgleich erstellt wird überschreiben und ist daher definitiv NICHT EMPFOHLEN!", - "EN": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!", - "PT-BR": "Você pode continuar a criar a raid, mas você substituirá outra raid que está sendo criada e isso NÃO É RECOMENDADO!" - }, - "raid_creation_in_progress" : { - "NL": "Raid wordt momenteel aangemaakt", - "DE": "Raid wird gerade erstellt", - "EN": "Raid creation in progress", - "PT-BR": "Criação da raid em andamento" - }, - "select_raid_level_to_continue" : { - "NL": "Om echt door te gaan, selecteer een raid level", - "DE": "Um wirklich fortzufahren, bitte Raid Level auswählen", - "EN": "To really continue, please select raid level", - "PT-BR": "Para continuar, escolha o nível da raid" - }, - "select_raid_level" : { - "NL": "Selecteer Raid level", - "DE": "Bitte Raid Level auswählen", - "EN": "Select raid level", - "PT-BR": "Escolha o nível da raid" - }, - "gym" : { - "NL": "Gym", - "DE": "Arena", - "EN": "Gym", - "PT-BR": "Ginásio" - }, - "gym_saved" : { - "NL": "Gym opgeslagen.", - "DE": "Arena gespeichert.", - "EN": "Gym saved.", - "PT-BR": "Ginásio salvo." - }, - "select_raid_boss" : { - "NL": "Selecteer Raid baas", - "DE": "Raid Boss auswählen", - "EN": "Select Raid boss", - "PT-BR": "Escolha o Pokémon chefe da raid" - }, - "select_pokemon" : { - "NL": "Selecteer Pokemon", - "DE": "Pokemon auswählen", - "EN": "Select Pokemon", - "PT-BR": "Escolha o Pokémon" - }, - "raid_saved" : { - "NL": "Raid opgeslagen:", - "DE": "Raid gespeichert:", - "EN": "Raid saved:", - "PT-BR": "Raid salva:" - - }, - "raid_boss" : { - "NL": "#Raid baas", - "DE": "Raid-Boss", - "EN": "Raid boss", - "PT-BR": "Chefe da raid" - }, - "raid_boss_saved" : { - "NL": "Raid baas opgeslagen!", - "DE": "Raid-Boss gespeichert!", - "EN": "Raid boss saved!", - "PT-BR": "Chefe da raid salvo!" - }, - "not_supported" : { - "NL": "Niet ondersteund", - "DE": "Nicht unterstützt", - "EN": "Not supported", - "PT-BR": "Não compatível" - }, - "share" : { - "NL": "Delen", - "DE": "Teilen", - "EN": "Share", - "PT-BR": "Compartilhar" - }, - "share_with" : { - "NL": "Delen met", - "DE": "Teilen mit", - "EN": "Share with", - "PT-BR": "Compartilhar com" - }, - "set_gym_name_and_team" : { - "NL": "Optioneel - Gym naam and Gym Team:", - "DE": "Optional - Arena Name und Arena Team:", - "EN": "Optional - Gym name and Gym Team:", - "PT-BR": "Opcional - Nome do gínasio e nome do time" - }, - "set_gym_name_command" : { - "NL": "/gym Naam van de Gym", - "DE": "/gym Name der Arena", - "EN": "/gym Name of the Gym", - "PT-BR": "/gym Nome do ginásio" - }, - "set_gym_team" : { - "NL": "Optioneel - zet Gym en Team", - "DE": "Optional - Arena Team setzen", - "EN": "Optional - set Gym and Team", - "PT-BR": "Opcional - escolha o gínasio e time" - }, - "set_gym_team_command" : { - "NL": "/team Mystic/Valor/Instinct/Blauw/Rood/Geel", - "DE": "/team Mystic/Valor/Instinct/Blau/Rot/Gelb", - "EN": "/team Mystic/Valor/Instinct/Blue/Red/Yellow", - "PT-BR": "/team Mystic/Valor/Instinct/Azul/Vermelho/Amarelo" - }, - "end_time" : { - "NL": "Eindtijd gezet op ", - "DE": "Ablaufzeit gesetzt auf ", - "EN": "Endtime set to ", - "PT-BR": "Hora de término determinada para " - - }, - "minutes" : { - "NL": "minuten", - "DE": "Minuten", - "EN": "minutes", - "PT-BR": "minutos" - }, - "raid_starts_when" : { - "NL": "Wanneer gaat het Raid ei open?", - "DE": "Wann beginnt der Raid?", - "EN": "When will the Raid begin?", - "PT-BR": "Quando a raid irá começar?" - }, - "raid_starts_when_minutes" : { - "NL": "Wanneer begint de Raid?", - "DE": "In wie viel Minuten beginnt der Raid?", - "EN": "In how many minutes does the raid begin?", - "PT-BR": "Em quantos minutos a raid irá começar?" - }, - "raid_starts_when_clocktime_view" : { - "NL": "klok", - "DE": "Uhrzeit-Ansicht", - "EN": "Clock time view", - "PT-BR": "Ver horário" - }, - "raid_starts_when_minutes_view" : { - "NL": "Minuten", - "DE": "Minuten-Ansicht", - "EN": "Minutes view", - "PT-BR": "Ver minutos" - }, - "raid_starts_when_view_changed" : { - "NL": "Overzicht verandert!", - "DE": "Ansicht geändert!", - "EN": "View changed!", - "PT-BR": "Visualização mudou!" - }, - "is_raid_active" : { - "NL": "Raid is al actief!", - "DE": "Raid läuft schon!", - "EN": "Raid is already active!", - "PT-BR": "A raid já está ativa!" - }, - "bot_access_denied" : { - "NL": "Je hebt geen toegang tot deze functie of bot!", - "DE": "Sie haben keine Berechtigung diesen Befehl oder Bot zu nutzen!", - "EN": "You are not allowed to use this command or bot!", - "PT-BR": "Você não tem permissão para utilizar esse comando ou bot!" - }, - "raid_access_denied" : { - "NL": "Je hebt geen rechten om deze raid aan te passen!", - "DE": "Sie haben keine Berechtigung dieses Raid zu bearbeiten!", - "EN": "You are not allowed to edit this raid!", - "PT-BR": "Você não tem permissão para editar esta raid!" - }, - "no_active_raids_found" : { - "NL": "Geen actieve raids gevonden!", - "DE": "Aktuell sind keine laufenden Raids im System!", - "EN": "No active raids found in the system!", - "PT-BR": "Nenhuma raid ativa encontrada no sistema!" - }, - "no_active_raids_shared" : { - "NL": "Geen van de actieve raid is gedeeld!", - "DE": "Keines der aktiven Raids wurde geteilt!", - "EN": "None of the active raids was shared!", - "PT-BR": "Nenhuma das raids ativas foi compartilhada!" - }, - "no_active_raids" : { - "NL": "Geen actieve raids!", - "DE": "Aktuell gibt es keine Raids!", - "EN": "No active raids currently!", - "PT-BR": "Nenhuma raid ativa no momento!" - }, - "expand" : { - "NL": "Uitklappen", - "DE": "Ausklappen", - "EN": "Expand", - "PT-BR": "Expandir" - }, - "pokemon_saved" : { - "NL": "Pokemon opgeslagen: ", - "DE": "Pokemon gespeichert: ", - "EN": "Pokemon saved: ", - "PT-BR": "Pokemon salvo " - }, - "how_long_raid" : { - "NL": "Hoe lang duurt de Raid?", - "DE": "Wie lange dauert der Raid?", - "EN": "How long will the raid last?", - "PT-BR": "Quanto tempo a raid vai durar" - }, - "lead_time_set_to" : { - "NL": "Doorlooptijd ingesteld op", - "DE": "Vorlaufzeit gesetzt auf", - "EN": "Lead time set to", - "PT-BR": "Tempo principal configurado para" - }, - "select_gym_name" : { - "NL": "Selecteer Gym:", - "DE": "Bitte Arena auswählen:", - "EN": "Select Gym:", - "PT-BR": "Escolha o ginásio:" - }, - "here_we_go" : { - "NL": "Hier gaan we!", - "DE": "Los gehts!", - "EN": "Here we go!", - "PT-BR": "Bora arrasar!" - }, - "create_a_raid" : { - "NL": "Maak een Raid", - "DE": "Raid anlegen", - "EN": "Create a Raid", - "PT-BR": "Criar a raid" - }, - "coordination_succes" : { - "NL": "Coördinatie geslaagd!", - "DE": "Koordinaten erfolgreich übermittelt!", - "EN": "Coordinates successfully submitted!", - "PT-BR": "Coordenadas enviadas com sucesso!" - }, - "update_pokemon" : { - "NL": "Pokemon vernieuwen", - "DE": "Pokemon aktualisieren", - "EN": "Update Pokemon", - "PT-BR": "Atualizar Pokemon" - }, - "send_location" : { - "NL": "Stuur me alsjeblieft eerst een locatie.", - "DE": "Bitte sende mir zuerst einen Standort.", - "EN": "Please send me a location first.", - "PT-BR": "Por favor, antes me envie a localização." - }, - "raid_by_gym" : { - "NL": "Of maak een raid door een Gym te selecteren:", - "DE": "Oder lege ein Raid per Arena-Auswahl an:", - "EN": "Or make a raid per gym selection:", - "PT-BR": "Ou escolha uma raid por ginásio:" - }, - "red" : { - "NL": "rood", - "DE": "rot", - "EN": "red", - "PT-BR": "vermelho" - }, - "yellow" : { - "NL": "geel", - "DE": "gelb", - "EN": "yellow", - "PT-BR": "amarelo" - }, - "blue" : { - "NL": "blauw", - "DE": "blau", - "EN": "blue", - "PT-BR": "azul" - }, - "gym_team_set_to" : { - "NL": "Gym Team gezet op:", - "DE": "Arena Team gesetzt auf:", - "EN": "Gym Team set to:", - "PT-BR": "Time do ginásio escolhido para" - }, - "invalid_team" : { - "NL": "Ongeldige team naam: schrijf: Mystic, Valor, Instinct or Blauw, Rood, Geel ", - "DE": "Ungültiger Team Name - schreibe: Mystic, Valor, Instinct oder Blau, Rot, Gelb", - "EN": "Invalid team name - write: Mystic, Valor, Instinct or Blue, Red, Yellow ", - "PT-BR": "Nome de time inválido - escreva: Mystic, Valor, Instinct ou Blue, Red, Yellow" - }, - "gym_name_updated" : { - "NL": "Gym naam aangepast.", - "DE": "Der Arena Name wurde aktualisiert.", - "EN": "Gym name updated.", - "PT-BR": "Nome do ginásio atualizado." - }, - "mods_details" : { - "NL": "Selecteer moderator voor meer informatie:", - "DE": "Für Details Moderator auswählen:", - "EN": "Select moderator for details:", - "PT-BR": "Escolha moderador para detalhes:" - }, - "mods_add_new" : { - "NL": "Nieuwe moderator toevoegen:", - "DE": "Neuen Moderator hinzufügen:", - "EN": "Add new moderator:", - "PT-BR": "Adicionar novo moderador:" - }, - "mods_delete" : { - "NL": "Moderator verwijderen:", - "DE": "Moderator löschen:", - "EN": "Delete moderator:", - "PT-BR": "Excluir moderador:" - }, - "mods_list_of_all" : { - "NL": "Lijst met alle moderators.", - "DE": "Liste aller Moderatoren.", - "EN": "List of all moderators.", - "PT-BR": "Lista de todos os moderadores." - }, - "mods_list_add_delete" : { - "NL": "Lijst, toevoegen of verwijderen van moderators", - "DE": "Moderatoren anzeigen, hinzufügen oder löschen", - "EN": "List, add or remove moderators", - "PT-BR": "Listar, adicionar ou remover moderadores" - }, - "mods_not_found" : { - "NL": "Error! Geen Moderator of gebruiker gevonden!", - "DE": "Fehler! Keine Moderatoren oder Benutzer gefunden!", - "EN": "Error! No moderators or users found!", - "PT-BR": "Erro! Nenhum moderador ou usuário encontrado!" - }, - "mods_saved_mod" : { - "NL": "Moderator opgeslagen!", - "DE": "Moderator gespeichert!", - "EN": "Moderator saved!", - "PT-BR": "Moderador salvo!" - }, - "mods_delete_mod" : { - "NL": "Moderator verwijderd!", - "DE": "Moderator gelöscht!", - "EN": "Moderator deleted!", - "PT-BR": "Moderador excluído!" - }, - "mods_info_about_mod" : { - "NL": "Informatie over deze moderator:", - "DE": "Infos zum diesem Moderator:", - "EN": "Info about this moderator:", - "PT-BR": "Informações sobre esse moderador:" - }, - "overview_share" : { - "NL": "Overzicht delen", - "DE": "Übersicht teilen", - "EN": "Share overview", - "PT-BR": "Detalhes de compartilhamento" - }, - "overview_delete" : { - "NL": "Vewijder overzicht", - "DE": "Übersicht löschen", - "EN": "Delete overview", - "PT-BR": "Deletar detalhes" - }, - "raids_list_share_overview" : { - "NL": "Geef de actieve raid weer als een lijst of deel / verwijder het raid overzicht", - "DE": "Aktive Raids als Liste anzeigen oder die Raid-Übersicht pro Chat teilen / löschen", - "EN": "Show active raids as list or share / delete the raid overview per chat", - "PT-BR": "Mostrar raids ativas como lista ou compartilhar / deletar detalhes de raid por chat" - }, - "list_all_active_raids" : { - "NL": "Alle actieve raids", - "DE": "Alle aktiven Raids", - "EN": "All active raids", - "PT-BR": "Todas as raids ativas" - }, - "list_all_overviews" : { - "NL": "Totaal raid overzicht", - "DE": "Alle Raid-Übersichten", - "EN": "All raid overviews", - "PT-BR": "Todos os detalhes de raid" - }, - "delete_raid_overview_for_chat" : { - "NL": "Verwijder raid overzicht voor", - "DE": "Raid-Übersicht löschen für", - "EN": "Delete raid overview for", - "PT-BR": "Deletar detalhe de raid para" - }, - "no_overviews_found" : { - "NL": "Geen raid overzicht gevonden in het systeem!", - "DE": "Keine Raid-Übersichten im System gefunden!", - "EN": "No raid overviews found in the system!", - "PT-BR": "Nenhum detalhe de raid encontrado no sistema!" - }, - "overview_successfully_deleted" : { - "NL": "Raid overzicht is succesvol verwijderd!", - "DE": "Raid-Übersicht wurde erfolgreich gelöscht!", - "EN": "Raid overview was successfully deleted!", - "PT-BR": "Detalhe de raid deletado com sucesso!" - }, - "overview_deletion_was_canceled" : { - "NL": "Het verwijderen van het raid overzicht is gestopt!", - "DE": "Löschung der Raid-Übersicht wurde abgebrochen!", - "EN": "Deletion of the raid overview was canceled!", - "PT-BR": "O deletamento dos detalhes da raid foi cancelado!" - }, - "raid_overview_for_chat" : { - "NL": "Raid overzicht voor", - "DE": "Raid-Übersicht für", - "EN": "Overview of raids for", - "PT-BR": "Detalhes de raids para" - }, - "successfully_shared" : { - "NL": "Succesvol gedeeld!", - "DE": "Erfolgreich geteilt!", - "EN": "Successfully shared!", - "PT-BR": "Compartilhado com sucesso!" - }, - "delete_this_raid" : { - "NL": "Verwijder deze raid?", - "DE": "Dieses Raid wirklich löschen?", - "EN": "Really delete this raid?", - "PT-BR": "Realmente deletar esta raid?" - }, - "raid_deletion_was_canceled" : { - "NL": "Het verwijderen van het raid is gestopt!", - "DE": "Löschung des Raids wurde abgebrochen!", - "EN": "Deletion of the raid was canceled!", - "PT-BR": "O deletamento da raid foi cancelado!" - }, - "raid_successfully_deleted" : { - "NL": "Raid is succesvol verwijderd!", - "DE": "Raid wurde erfolgreich gelöscht!", - "EN": "Raid was successfully deleted!", - "PT-BR": "Raid deletado com sucesso!" - }, - "action_aborted" : { - "NL": "Het proces is afgebroken!", - "DE": "Der Vorgang wurde abgebrochen!", - "EN": "The process was aborted!", - "PT-BR": "O processo foi abortado!" - }, - "yes" : { - "NL": "Ja", - "DE": "Ja", - "EN": "Yes", - "PT-BR": "Sim" - }, - "no" : { - "NL": "Nee", - "DE": "Nein", - "EN": "No", - "PT-BR": "Não" - }, - "abort" : { - "NL": "Afbreken", - "DE": "Abbrechen", - "EN": "Abort", - "PT-BR": "Abortar" - }, - "list" : { - "NL": "Lijst", - "DE": "Anzeigen", - "EN": "List", - "PT-BR": "Lista" - }, - "add" : { - "NL": "Toevoegen", - "DE": "Hinzufügen", - "EN": "Add", - "PT-BR": "Adicionar" - }, - "delete" : { - "NL": "Verwijder", - "DE": "Löschen", - "EN": "Delete", - "PT-BR": "Deletar" - } -} +{ + "5stars" : { + "NL": "5 Sterren Raid", + "DE": "5 Sterne Raid", + "EN": "5 Star Raid", + "PT-BR": "Raid nível 5" + }, + "4stars" : { + "NL": "4 Sterren Raid", + "DE": "4 Sterne Raid", + "EN": "4 Star Raid", + "PT-BR": "Raid nível 4" + }, + "3stars" : { + "NL": "3 Sterren Raid", + "DE": "3 Sterne Raid", + "EN": "3 Star Raid", + "PT-BR": "Raid nível 3" + }, + "2stars" : { + "NL": "2 Sterren Raid", + "DE": "2 Sterne Raid", + "EN": "2 Star Raid", + "PT-BR": "Raid nível 2" + }, + "1stars" : { + "NL": "1 Sterren Raid", + "DE": "1 Sterne Raid", + "EN": "1 Star Raid", + "PT-BR": "Raid nível 1" + }, + "back" : { + "NL": "Terug", + "DE": "Zurück", + "EN": "Back", + "PT-BR": "Voltar" + }, + "next" : { + "NL": "Next", + "DE": "Weiter", + "EN": "Next", + "PT-BR": "Próximo" + }, + "alone" : { + "NL": "Alleen", + "DE": "Alleine", + "EN": "Alone", + "PT-BR": "Sozinho" + }, + "raid_done" : { + "NL": "Raid beëindigd", + "DE": "Raid beendet.", + "EN": "Raid done", + "PT-BR": "Raid completa" + }, + "here" : { + "NL": "Ben er", + "DE": "Bin da", + "EN": "Here", + "PT-BR": "Aqui" + + }, + "done" : { + "NL": "Klaar", + "DE": "Fertig", + "EN": "Done", + "PT-BR": "Feito" + }, + "cancellation" : { + "NL": "Afwezig", + "DE": "Absage", + "EN": "Cancellation", + "PT-BR": "Cancelada" + }, + "vote_updated" : { + "NL": "Stem geüpdatet", + "DE": "Abstimmung aktualisiert", + "EN": "Vote updated", + "PT-BR": "Votos atualizados" + }, + "monday" : { + "NL": "Maandag", + "DE": "Montag", + "EN": "Monday", + "PT-BR": "Segunda-feira" + }, + "tuesday" : { + "NL": "Dinsdag", + "DE": "Dienstag", + "EN": "Tuesday", + "PT-BR": "Terça-feira" + }, + "wednesday" : { + "NL": "Woensdag", + "DE": "Mittwoch", + "EN": "Wednesday", + "PT-BR": "Quarta-feira" + }, + "thursday" : { + "NL": "Donderdag", + "DE": "Donnerstag", + "EN": "Thursday", + "PT-BR": "Quinta-feira" + }, + "friday" : { + "NL": "Vrijdag", + "DE": "Freitag", + "EN": "Friday", + "PT-BR": "Sexta-feira" + }, + "saturday" : { + "NL": "Zaterdag", + "DE": "Samstag", + "EN": "Saturday", + "PT-BR": "Sábado" + }, + "sunday" : { + "NL": "Zondag", + "DE": "Sonntag", + "EN": "Sunday", + "PT-BR": "Domingo" + }, + "still" : { + "NL": "nog", + "DE": "noch", + "EN": "still" + }, + "raid_egg_opens" : { + "NL": "Raid ei gaat open", + "DE": "Raid-Ei öffnet sich um", + "EN": "Raid egg opens up", + "PT-BR": "Ovo eclode" + }, + "raid_egg_opens_day" : { + "NL": "Raid ei gaat open", + "DE": "Raid-Ei öffnet sich am", + "EN": "Raid egg opens on", + "PT-BR": "Ovo eclode em" + }, + "raid_egg_opens_at" : { + "NL": "om", + "DE": "um", + "EN": "at", + "PT-BR": "em" + }, + "raid_until" : { + "NL": "Raid tot", + "DE": "Raid bis", + "EN": "Raid until", + "PT-BR": "Raid até" + }, + "exraid_pass" : { + "NL": "DEELNAME IS ALLEEN MOGELIJK MET EX-RAID PASS", + "DE": "TEILNAHME IST NUR MIT EX-RAID-PASS MÖGLICH", + "EN": "PARTICIPATION IS POSSIBLE ONLY WITH EX-RAID PASS", + "PT-BR": "PARTICIPAÇÃO APENAS COM PASSE EX" + }, + "no_participants_yet" : { + "NL": "Nog geen deelnemers", + "DE": "Noch keine Teilnehmer.", + "EN": "No participants yet", + "PT-BR": "Ainda sem participantes" + }, + "finished" : { + "NL": "Klaar", + "DE": "Fertig", + "EN": "Finished", + "PT-BR": "Finalizada" + }, + "cancel" : { + "NL": "Annuleren", + "DE": "Abgesagt", + "EN": "Cancel", + "PT-BR": "Cancelar" + }, + "created_by" : { + "NL": "Aangemaakt door", + "DE": "Erstellt von", + "EN": "Created by", + "PT-BR": "Criada por" + }, + "updated" : { + "NL": "Bijgewerkt", + "DE": "Aktualisiert", + "EN": "Updated", + "PT-BR": "Atualizada" + }, + "from" : { + "NL": "van", + "DE": "von", + "EN": "from", + "PT-BR": "de" + }, + "to" : { + "NL": "tot", + "DE": "bis", + "EN": "to", + "PT-BR": "para" + }, + "no_participants" : { + "NL": "Geen deelnemers", + "DE": "Keine Teilnehmer", + "EN": "No participants", + "PT-BR": "Sem participantes" + }, + "mew" : { + "NL": "Mew", + "DE": "Mew", + "EN": "Mew", + "PT-BR": "Mew" + }, + "mewtwo" : { + "NL": "Mewtwo", + "DE": "Mewtu", + "EN": "Mewtwo", + "PT-BR": "Mewtwo" + }, + "lugia" : { + "NL": "Lugia", + "DE": "Lugia", + "EN": "Lugia", + "PT-BR": "Lugia" + }, + "zapdos" : { + "NL": "Zapdos", + "DE": "Zapdos", + "EN": "Zapdos", + "PT-BR": "Zapdos" + }, + "hooh" : { + "NL": "Ho-oh", + "DE": "Ho-oh", + "EN": "Ho-oh", + "PT-BR": "Ho-oh" + }, + "celebi" : { + "NL": "Celebi", + "DE": "Celebi", + "EN": "Celebi", + "PT-BR": "Celebi" + }, + "raikou" : { + "NL": "Raikou", + "DE": "Raikou", + "EN": "Raikou", + "PT-BR": "Raikou" + }, + "entei" : { + "NL": "Entei", + "DE": "Entei", + "EN": "Entei", + "PT-BR": "Entei" + }, + "suicune" : { + "NL": "Suicune", + "DE": "Suicune", + "EN": "Suicune", + "PT-BR": "Suicune" + }, + "moltres" : { + "NL": "Moltres", + "DE": "Lavados", + "EN": "Moltres", + "PT-BR": "Moltres" + }, + "articuno" : { + "NL": "Articuno", + "DE": "Arktos", + "EN": "Articuno", + "PT-BR": "Articuno" + }, + "groudon" : { + "NL": "Groudon", + "DE": "Groudon", + "EN": "Groudon", + "PT-BR": "Groudon" + }, + "kyogre" : { + "NL": "Kyogre", + "DE": "Kyogre", + "EN": "Kyogre", + "PT-BR": "Kyogre" + }, + "rayquaza" : { + "NL": "Rayquaza", + "DE": "Rayquaza", + "EN": "Rayquaza", + "PT-BR": "Rayquaza" + }, + "latios" : { + "NL": "Latios", + "DE": "Latios", + "EN": "Latios", + "PT-BR": "Latios" + }, + "latias" : { + "NL": "Latias", + "DE": "Latias", + "EN": "Latias", + "PT-BR": "Latias" + }, + "deoxys" : { + "NL": "Deoxys", + "DE": "Deoxys", + "EN": "Deoxys", + "PT-BR": "Deoxys" + }, + "jirachi" : { + "NL": "Jirachi", + "DE": "Jirachi", + "EN": "Jirachi", + "PT-BR": "Jirachi" + }, + "regirock" : { + "NL": "Regirock", + "DE": "Regirock", + "EN": "Regirock", + "PT-BR": "Regirock" + }, + "regice" : { + "NL": "Regice", + "DE": "Regice", + "EN": "Regice", + "PT-BR": "Regice" + }, + "registeel" : { + "NL": "Registeel", + "DE": "Registeel", + "EN": "Registeel", + "PT-BR": "Registeel" + }, + "egg_5" : { + "NL": "Level 5 Ei", + "DE": "Level 5 Ei", + "EN": "Level 5 Egg", + "PT-BR": "Ovo de Nível 5" + }, + "egg_4" : { + "NL": "Level 4 Ei", + "DE": "Level 4 Ei", + "EN": "Level 4 Egg", + "PT-BR": "Ovo de Nível 4" + }, + "egg_3" : { + "NL": "Level 3 Ei", + "DE": "Level 3 Ei", + "EN": "Level 3 Egg", + "PT-BR": "Ovo de Nível 3" + }, + "lapras" : { + "NL": "Lapras", + "DE": "Lapras", + "EN": "Lapras", + "PT-BR": "Lapras" + }, + "nidoqueen" : { + "NL": "Nidoqueen", + "DE": "Nidoqueen", + "EN": "Nidoqueen", + "PT-BR": "Nidoqueen" + }, + "nidoking" : { + "NL": "Nidoking", + "DE": "Nidoking", + "EN": "Nidoking", + "PT-BR": "Nidoking" + }, + "absol" : { + "NL": "Absol", + "DE": "Absol", + "EN": "Absol", + "PT-BR": "Absol" + }, + "aggron" : { + "NL": "Aggron", + "DE": "Stolloss", + "EN": "Aggron", + "PT-BR": "Aggron" + }, + "tyranitar" : { + "NL": "Tyranitar", + "DE": "Despotar", + "EN": "Tyranitar", + "PT-BR": "Tyranitar" + }, + "snorlax" : { + "NL": "Snorlax", + "DE": "Relaxo", + "EN": "Snorlax", + "PT-BR": "Snorlax" + }, + "golem" : { + "NL": "Golem", + "DE": "Geowaz", + "EN": "Golem", + "PT-BR": "Golem" + }, + "rhydon" : { + "NL": "Rhydon", + "DE": "Rizeros", + "EN": "Rhydon", + "PT-BR": "Rhydon" + }, + "porygon" : { + "NL": "Porygon", + "DE": "Porygon", + "EN": "Porygon", + "PT-BR": "Porygon" + }, + "gengar" : { + "NL": "Gengar", + "DE": "Gengar", + "EN": "Gengar", + "PT-BR": "Gengar" + }, + "poliwrath" : { + "NL": "Poliwrath", + "DE": "Quappo", + "EN": "Poliwrath", + "PT-BR": "Poliwrath" + }, + "victreebel" : { + "NL": "Victreebel", + "DE": "Sarzenia", + "EN": "Victreebel", + "PT-BR": "Victreebel" + }, + "arcanine" : { + "NL": "Arcanine", + "DE": "Arkani", + "EN": "Arcanine", + "PT-BR": "Arcanine" + }, + "machamp" : { + "NL": "Machamp", + "DE": "Machomei", + "EN": "Machamp", + "PT-BR": "Machamp" + }, + "alakazam" : { + "NL": "Alakazam", + "DE": "Simsala", + "EN": "Alakazam", + "PT-BR": "Alakazam" + }, + "scyther" : { + "NL": "Scyther", + "DE": "Sichlor", + "EN": "Scyther", + "PT-BR": "Schyther" + }, + "omastar" : { + "NL": "Omastar", + "DE": "Amoroso", + "EN": "Omastar", + "PT-BR": "Omastar" + }, + "ninetails" : { + "NL": "Ninetails", + "DE": "Vulnona", + "EN": "Ninetails", + "PT-BR": "Ninetails" + }, + "forest" : { + "NL": "Ergens in het bos", + "DE": "Irgendwo im Wald", + "EN": "Somewhere in the forest", + "PT-BR": "Em algum lugar na floresta" + }, + "select_gym_first_letter" : { + "NL": "Selecteer alstublieft de eerste letter van de gym:", + "DE": "Bitte Anfangsbuchstabe der Arena auswählen:", + "EN": "Please select the first letter of the gym:", + "PT-BR": "Por favor escolha a primeira letra do ginásio:" + }, + "select_gym" : { + "NL": "Beginletter geselecteerd.", + "DE": "Anfangsbuchstabe ausgewählt.", + "EN": "First letter selected.", + "PT-BR": "Primeira letra escolhida.:" + }, + "raid_creation_started_at" : { + "NL": "Raid aanmaak is gestart om", + "DE": "Das Raid wird angelegt seit", + "EN": "Raid creation was started at", + "PT-BR": "Criação da raid em" + }, + "raid_being_created_by_other_user" : { + "NL": "Een andere gebruiker is een raid voor deze gym aan het maken:", + "DE": "Ein Raid für diese Arena wird gerade angelegt von:", + "EN": "Another user is currently creating a raid for this gym:", + "PT-BR": "Outro usuário está criando uma raid para este ginásio:" + }, + "raid_already_exists" : { + "NL": "Raid bestaat al!", + "DE": "Raid existiert bereits!", + "EN": "Raid already exists!", + "PT-BR": "A raid já existe!" + }, + "create_raid" : { + "NL": "Begin Raid in", + "DE": "Erstelle Raid in", + "EN": "Create Raid in", + "PT-BR": "Criar raid em" + }, + "raid_creation_in_progress_warning" : { + "NL": "Je kan een raid aanmaken, maar de huidig aangemaakte raid zal worden overscheven. Deze wijziging kunnen niet ongedaan gemaakt worden dit is NIET AAN TE RADEN!", + "DE": "Das Raid kann weiter angelegt werden, aber dies wird das Raid welches gerade zeitgleich erstellt wird überschreiben und ist daher definitiv NICHT EMPFOHLEN!", + "EN": "You can continue with the raid creation, but this will overwrite the raid which is concurrently being created and is definitely NOT RECOMMENDED!", + "PT-BR": "Você pode continuar a criar a raid, mas você substituirá outra raid que está sendo criada e isso NÃO É RECOMENDADO!" + }, + "raid_creation_in_progress" : { + "NL": "Raid wordt momenteel aangemaakt", + "DE": "Raid wird gerade erstellt", + "EN": "Raid creation in progress", + "PT-BR": "Criação da raid em andamento" + }, + "select_raid_level_to_continue" : { + "NL": "Om echt door te gaan, selecteer een raid level", + "DE": "Um wirklich fortzufahren, bitte Raid Level auswählen", + "EN": "To really continue, please select raid level", + "PT-BR": "Para continuar, escolha o nível da raid" + }, + "select_raid_level" : { + "NL": "Selecteer Raid level", + "DE": "Bitte Raid Level auswählen", + "EN": "Select raid level", + "PT-BR": "Escolha o nível da raid" + }, + "gym" : { + "NL": "Gym", + "DE": "Arena", + "EN": "Gym", + "PT-BR": "Ginásio" + }, + "gym_saved" : { + "NL": "Gym opgeslagen.", + "DE": "Arena gespeichert.", + "EN": "Gym saved.", + "PT-BR": "Ginásio salvo." + }, + "select_raid_boss" : { + "NL": "Selecteer Raid baas", + "DE": "Raid Boss auswählen", + "EN": "Select Raid boss", + "PT-BR": "Escolha o Pokémon chefe da raid" + }, + "select_pokemon" : { + "NL": "Selecteer Pokemon", + "DE": "Pokemon auswählen", + "EN": "Select Pokemon", + "PT-BR": "Escolha o Pokémon" + }, + "raid_saved" : { + "NL": "Raid opgeslagen:", + "DE": "Raid gespeichert:", + "EN": "Raid saved:", + "PT-BR": "Raid salva:" + + }, + "raid_boss" : { + "NL": "#Raid baas", + "DE": "Raid-Boss", + "EN": "Raid boss", + "PT-BR": "Chefe da raid" + }, + "raid_boss_saved" : { + "NL": "Raid baas opgeslagen!", + "DE": "Raid-Boss gespeichert!", + "EN": "Raid boss saved!", + "PT-BR": "Chefe da raid salvo!" + }, + "not_supported" : { + "NL": "Niet ondersteund", + "DE": "Nicht unterstützt", + "EN": "Not supported", + "PT-BR": "Não compatível" + }, + "share" : { + "NL": "Delen", + "DE": "Teilen", + "EN": "Share", + "PT-BR": "Compartilhar" + }, + "share_with" : { + "NL": "Delen met", + "DE": "Teilen mit", + "EN": "Share with", + "PT-BR": "Compartilhar com" + }, + "set_gym_name_and_team" : { + "NL": "Optioneel - Gym naam and Gym Team:", + "DE": "Optional - Arena Name und Arena Team:", + "EN": "Optional - Gym name and Gym Team:", + "PT-BR": "Opcional - Nome do gínasio e nome do time" + }, + "set_gym_name_command" : { + "NL": "/gym Naam van de Gym", + "DE": "/gym Name der Arena", + "EN": "/gym Name of the Gym", + "PT-BR": "/gym Nome do ginásio" + }, + "set_gym_team" : { + "NL": "Optioneel - zet Gym en Team", + "DE": "Optional - Arena Team setzen", + "EN": "Optional - set Gym and Team", + "PT-BR": "Opcional - escolha o gínasio e time" + }, + "set_gym_team_command" : { + "NL": "/team Mystic/Valor/Instinct/Blauw/Rood/Geel", + "DE": "/team Mystic/Valor/Instinct/Blau/Rot/Gelb", + "EN": "/team Mystic/Valor/Instinct/Blue/Red/Yellow", + "PT-BR": "/team Mystic/Valor/Instinct/Azul/Vermelho/Amarelo" + }, + "end_time" : { + "NL": "Eindtijd gezet op ", + "DE": "Ablaufzeit gesetzt auf ", + "EN": "Endtime set to ", + "PT-BR": "Hora de término determinada para " + + }, + "minutes" : { + "NL": "minuten", + "DE": "Minuten", + "EN": "minutes", + "PT-BR": "minutos" + }, + "raid_starts_when" : { + "NL": "Wanneer gaat het Raid ei open?", + "DE": "Wann beginnt der Raid?", + "EN": "When will the Raid begin?", + "PT-BR": "Quando a raid irá começar?" + }, + "raid_starts_when_minutes" : { + "NL": "Wanneer begint de Raid?", + "DE": "In wie viel Minuten beginnt der Raid?", + "EN": "In how many minutes does the raid begin?", + "PT-BR": "Em quantos minutos a raid irá começar?" + }, + "raid_starts_when_clocktime_view" : { + "NL": "klok", + "DE": "Uhrzeit-Ansicht", + "EN": "Clock time view", + "PT-BR": "Ver horário" + }, + "raid_starts_when_minutes_view" : { + "NL": "Minuten", + "DE": "Minuten-Ansicht", + "EN": "Minutes view", + "PT-BR": "Ver minutos" + }, + "raid_starts_when_view_changed" : { + "NL": "Overzicht verandert!", + "DE": "Ansicht geändert!", + "EN": "View changed!", + "PT-BR": "Visualização mudou!" + }, + "is_raid_active" : { + "NL": "Raid is al actief!", + "DE": "Raid läuft schon!", + "EN": "Raid is already active!", + "PT-BR": "A raid já está ativa!" + }, + "bot_access_denied" : { + "NL": "Je hebt geen toegang tot deze functie of bot!", + "DE": "Sie haben keine Berechtigung diesen Befehl oder Bot zu nutzen!", + "EN": "You are not allowed to use this command or bot!", + "PT-BR": "Você não tem permissão para utilizar esse comando ou bot!" + }, + "raid_access_denied" : { + "NL": "Je hebt geen rechten om deze raid aan te passen!", + "DE": "Sie haben keine Berechtigung dieses Raid zu bearbeiten!", + "EN": "You are not allowed to edit this raid!", + "PT-BR": "Você não tem permissão para editar esta raid!" + }, + "no_active_raids_found" : { + "NL": "Geen actieve raids gevonden!", + "DE": "Aktuell sind keine laufenden Raids im System!", + "EN": "No active raids found in the system!", + "PT-BR": "Nenhuma raid ativa encontrada no sistema!" + }, + "no_active_raids_shared" : { + "NL": "Geen van de actieve raid is gedeeld!", + "DE": "Keines der aktiven Raids wurde geteilt!", + "EN": "None of the active raids was shared!", + "PT-BR": "Nenhuma das raids ativas foi compartilhada!" + }, + "no_active_raids" : { + "NL": "Geen actieve raids!", + "DE": "Aktuell gibt es keine Raids!", + "EN": "No active raids currently!", + "PT-BR": "Nenhuma raid ativa no momento!" + }, + "expand" : { + "NL": "Uitklappen", + "DE": "Ausklappen", + "EN": "Expand", + "PT-BR": "Expandir" + }, + "pokemon_saved" : { + "NL": "Pokemon opgeslagen: ", + "DE": "Pokemon gespeichert: ", + "EN": "Pokemon saved: ", + "PT-BR": "Pokemon salvo " + }, + "how_long_raid" : { + "NL": "Hoe lang duurt de Raid?", + "DE": "Wie lange dauert der Raid?", + "EN": "How long will the raid last?", + "PT-BR": "Quanto tempo a raid vai durar" + }, + "lead_time_set_to" : { + "NL": "Doorlooptijd ingesteld op", + "DE": "Vorlaufzeit gesetzt auf", + "EN": "Lead time set to", + "PT-BR": "Tempo principal configurado para" + }, + "select_gym_name" : { + "NL": "Selecteer Gym:", + "DE": "Bitte Arena auswählen:", + "EN": "Select Gym:", + "PT-BR": "Escolha o ginásio:" + }, + "here_we_go" : { + "NL": "Hier gaan we!", + "DE": "Los gehts!", + "EN": "Here we go!", + "PT-BR": "Bora arrasar!" + }, + "create_a_raid" : { + "NL": "Maak een Raid", + "DE": "Raid anlegen", + "EN": "Create a Raid", + "PT-BR": "Criar a raid" + }, + "coordination_succes" : { + "NL": "Coördinatie geslaagd!", + "DE": "Koordinaten erfolgreich übermittelt!", + "EN": "Coordinates successfully submitted!", + "PT-BR": "Coordenadas enviadas com sucesso!" + }, + "update_pokemon" : { + "NL": "Pokemon vernieuwen", + "DE": "Pokemon aktualisieren", + "EN": "Update Pokemon", + "PT-BR": "Atualizar Pokemon" + }, + "send_location" : { + "NL": "Stuur me alsjeblieft eerst een locatie.", + "DE": "Bitte sende mir zuerst einen Standort.", + "EN": "Please send me a location first.", + "PT-BR": "Por favor, antes me envie a localização." + }, + "raid_by_gym" : { + "NL": "Of maak een raid door een Gym te selecteren:", + "DE": "Oder lege ein Raid per Arena-Auswahl an:", + "EN": "Or make a raid per gym selection:", + "PT-BR": "Ou escolha uma raid por ginásio:" + }, + "red" : { + "NL": "rood", + "DE": "rot", + "EN": "red", + "PT-BR": "vermelho" + }, + "yellow" : { + "NL": "geel", + "DE": "gelb", + "EN": "yellow", + "PT-BR": "amarelo" + }, + "blue" : { + "NL": "blauw", + "DE": "blau", + "EN": "blue", + "PT-BR": "azul" + }, + "gym_team_set_to" : { + "NL": "Gym Team gezet op:", + "DE": "Arena Team gesetzt auf:", + "EN": "Gym Team set to:", + "PT-BR": "Time do ginásio escolhido para" + }, + "invalid_team" : { + "NL": "Ongeldige team naam: schrijf: Mystic, Valor, Instinct or Blauw, Rood, Geel ", + "DE": "Ungültiger Team Name - schreibe: Mystic, Valor, Instinct oder Blau, Rot, Gelb", + "EN": "Invalid team name - write: Mystic, Valor, Instinct or Blue, Red, Yellow ", + "PT-BR": "Nome de time inválido - escreva: Mystic, Valor, Instinct ou Blue, Red, Yellow" + }, + "gym_name_updated" : { + "NL": "Gym naam aangepast.", + "DE": "Der Arena Name wurde aktualisiert.", + "EN": "Gym name updated.", + "PT-BR": "Nome do ginásio atualizado." + }, + "mods_details" : { + "NL": "Selecteer moderator voor meer informatie:", + "DE": "Für Details Moderator auswählen:", + "EN": "Select moderator for details:", + "PT-BR": "Escolha moderador para detalhes:" + }, + "mods_add_new" : { + "NL": "Nieuwe moderator toevoegen:", + "DE": "Neuen Moderator hinzufügen:", + "EN": "Add new moderator:", + "PT-BR": "Adicionar novo moderador:" + }, + "mods_delete" : { + "NL": "Moderator verwijderen:", + "DE": "Moderator löschen:", + "EN": "Delete moderator:", + "PT-BR": "Excluir moderador:" + }, + "mods_list_of_all" : { + "NL": "Lijst met alle moderators.", + "DE": "Liste aller Moderatoren.", + "EN": "List of all moderators.", + "PT-BR": "Lista de todos os moderadores." + }, + "mods_list_add_delete" : { + "NL": "Lijst, toevoegen of verwijderen van moderators", + "DE": "Moderatoren anzeigen, hinzufügen oder löschen", + "EN": "List, add or remove moderators", + "PT-BR": "Listar, adicionar ou remover moderadores" + }, + "mods_not_found" : { + "NL": "Error! Geen Moderator of gebruiker gevonden!", + "DE": "Fehler! Keine Moderatoren oder Benutzer gefunden!", + "EN": "Error! No moderators or users found!", + "PT-BR": "Erro! Nenhum moderador ou usuário encontrado!" + }, + "mods_saved_mod" : { + "NL": "Moderator opgeslagen!", + "DE": "Moderator gespeichert!", + "EN": "Moderator saved!", + "PT-BR": "Moderador salvo!" + }, + "mods_delete_mod" : { + "NL": "Moderator verwijderd!", + "DE": "Moderator gelöscht!", + "EN": "Moderator deleted!", + "PT-BR": "Moderador excluído!" + }, + "mods_info_about_mod" : { + "NL": "Informatie over deze moderator:", + "DE": "Infos zum diesem Moderator:", + "EN": "Info about this moderator:", + "PT-BR": "Informações sobre esse moderador:" + }, + "overview_share" : { + "NL": "Overzicht delen", + "DE": "Übersicht teilen", + "EN": "Share overview", + "PT-BR": "Detalhes de compartilhamento" + }, + "overview_delete" : { + "NL": "Vewijder overzicht", + "DE": "Übersicht löschen", + "EN": "Delete overview", + "PT-BR": "Deletar detalhes" + }, + "raids_list_share_overview" : { + "NL": "Geef de actieve raid weer als een lijst of deel / verwijder het raid overzicht", + "DE": "Aktive Raids als Liste anzeigen oder die Raid-Übersicht pro Chat teilen / löschen", + "EN": "Show active raids as list or share / delete the raid overview per chat", + "PT-BR": "Mostrar raids ativas como lista ou compartilhar / deletar detalhes de raid por chat" + }, + "list_all_active_raids" : { + "NL": "Alle actieve raids", + "DE": "Alle aktiven Raids", + "EN": "All active raids", + "PT-BR": "Todas as raids ativas" + }, + "list_all_overviews" : { + "NL": "Totaal raid overzicht", + "DE": "Alle Raid-Übersichten", + "EN": "All raid overviews", + "PT-BR": "Todos os detalhes de raid" + }, + "delete_raid_overview_for_chat" : { + "NL": "Verwijder raid overzicht voor", + "DE": "Raid-Übersicht löschen für", + "EN": "Delete raid overview for", + "PT-BR": "Deletar detalhe de raid para" + }, + "no_overviews_found" : { + "NL": "Geen raid overzicht gevonden in het systeem!", + "DE": "Keine Raid-Übersichten im System gefunden!", + "EN": "No raid overviews found in the system!", + "PT-BR": "Nenhum detalhe de raid encontrado no sistema!" + }, + "overview_successfully_deleted" : { + "NL": "Raid overzicht is succesvol verwijderd!", + "DE": "Raid-Übersicht wurde erfolgreich gelöscht!", + "EN": "Raid overview was successfully deleted!", + "PT-BR": "Detalhe de raid deletado com sucesso!" + }, + "overview_deletion_was_canceled" : { + "NL": "Het verwijderen van het raid overzicht is gestopt!", + "DE": "Löschung der Raid-Übersicht wurde abgebrochen!", + "EN": "Deletion of the raid overview was canceled!", + "PT-BR": "O deletamento dos detalhes da raid foi cancelado!" + }, + "raid_overview_for_chat" : { + "NL": "Raid overzicht voor", + "DE": "Raid-Übersicht für", + "EN": "Overview of raids for", + "PT-BR": "Detalhes de raids para" + }, + "successfully_shared" : { + "NL": "Succesvol gedeeld!", + "DE": "Erfolgreich geteilt!", + "EN": "Successfully shared!", + "PT-BR": "Compartilhado com sucesso!" + }, + "delete_this_raid" : { + "NL": "Verwijder deze raid?", + "DE": "Dieses Raid wirklich löschen?", + "EN": "Really delete this raid?", + "PT-BR": "Realmente deletar esta raid?" + }, + "raid_deletion_was_canceled" : { + "NL": "Het verwijderen van het raid is gestopt!", + "DE": "Löschung des Raids wurde abgebrochen!", + "EN": "Deletion of the raid was canceled!", + "PT-BR": "O deletamento da raid foi cancelado!" + }, + "raid_successfully_deleted" : { + "NL": "Raid is succesvol verwijderd!", + "DE": "Raid wurde erfolgreich gelöscht!", + "EN": "Raid was successfully deleted!", + "PT-BR": "Raid deletado com sucesso!" + }, + "action_aborted" : { + "NL": "Het proces is afgebroken!", + "DE": "Der Vorgang wurde abgebrochen!", + "EN": "The process was aborted!", + "PT-BR": "O processo foi abortado!" + }, + "any" : { + "NL": "Elk", + "DE": "Egal", + "EN": "Any", + "PT-BR": "Qualquer" + }, + "any_pokemon" : { + "NL": "Elke raid baas", + "DE": "Jeder Raid-Boss", + "EN": "Any raid boss", + "PT-BR": "Qualquer chefe da raid" + }, + "yes" : { + "NL": "Ja", + "DE": "Ja", + "EN": "Yes", + "PT-BR": "Sim" + }, + "no" : { + "NL": "Nee", + "DE": "Nein", + "EN": "No", + "PT-BR": "Não" + }, + "abort" : { + "NL": "Afbreken", + "DE": "Abbrechen", + "EN": "Abort", + "PT-BR": "Abortar" + }, + "list" : { + "NL": "Lijst", + "DE": "Anzeigen", + "EN": "List", + "PT-BR": "Lista" + }, + "add" : { + "NL": "Toevoegen", + "DE": "Hinzufügen", + "EN": "Add", + "PT-BR": "Adicionar" + }, + "delete" : { + "NL": "Verwijder", + "DE": "Löschen", + "EN": "Delete", + "PT-BR": "Deletar" + } +} From 7d3900f1ff7c5f1d8a6276d302cdb845c5c0cfb6 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 9 Feb 2018 10:38:19 +0100 Subject: [PATCH 198/225] Fix issue of wrong button layout, now 3 buttons for each row. Do not display pokemon buttons if pokemon is in level X and another level. --- logic.php | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/logic.php b/logic.php index ea4b6d6..9acfab7 100755 --- a/logic.php +++ b/logic.php @@ -1217,19 +1217,23 @@ function keys_vote($raid) // Compare pokemon by pokemon to get raid level foreach($levelmons as $key => $pokemon) { if(strtolower($raid_pokemon) == strtolower($pokemon)) { - $level_found = true; - $raid_level = $level; - //debug_log("Found raid boss '" . $pokemon . "' in level " . $level . " raids"); - break 2; + // Stop if pokemon is in level X too. + if(in_array(strtolower($raid_pokemon), $ignore_X)) { + break 2; + } else { + $level_found = true; + $raid_level = $level; + //debug_log("Found raid boss '" . $pokemon . "' in level " . $level . " raids"); + break 2; + } } } } // Add pokemon keys if we found the raid boss if ($level_found) { - // Init counter and cols + // Init counter. $count = 0; - $col_poke = 1; foreach($pokemonlist as $level => $levelmons) { if($level == $raid_level) { @@ -1238,13 +1242,6 @@ function keys_vote($raid) if(strtolower($pokemon) == strtolower(getTranslation('egg_' . $level))) continue; if(in_array(strtolower($pokemon), $ignore_X)) continue; - // Not too many pokemon in a row - if ($col_poke++ >= 3) { - $keys[] = $keys_poke; - $keys_poke = []; - $col_poke = 1; - } - // Add pokemon to keys $keys_poke[] = array( 'text' => $pokemon, @@ -1266,7 +1263,8 @@ function keys_vote($raid) ); // Finally add pokemon to keys - $keys[] = $keys_poke; + $keys_poke = inline_key_array($keys_poke, 3); + $keys = array_merge($keys, $keys_poke); } } } From 6c8a636cac3b765626a18c5a675443f5814afa3d Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sat, 10 Feb 2018 09:36:55 +0100 Subject: [PATCH 199/225] Added new T3/4 Added new T3/4 --- constants.php | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/constants.php b/constants.php index e82a8ca..2e86c2c 100755 --- a/constants.php +++ b/constants.php @@ -54,29 +54,25 @@ ), '4' => array( getTranslation('tyranitar'), - getTranslation('snorlax'), getTranslation('lapras'), - getTranslation('poliwrath'), - getTranslation('victreebel'), - getTranslation('nidoqueen'), - getTranslation('nidoking'), - getTranslation('rhydon'), - getTranslation('golem'), + getTranslation('snorlax'), + getTranslation('feraligatr'), getTranslation('absol'), getTranslation('aggron'), getTranslation('egg_4') ), '3' => array( - getTranslation('arcanine'), getTranslation('machamp'), - getTranslation('alakazam'), - getTranslation('gengar'), - getTranslation('scyther'), - getTranslation('porygon'), - getTranslation('omastar'), - getTranslation('ninetails'), + getTranslation('jynx'), + getTranslation('azumarill'), + getTranslation('piloswine'), getTranslation('egg_3') + ), + '2' => array( + getTranslation('egg_2') + ), + '1' => array( + getTranslation('egg_1') ) ); - From f30f9b3748d7472d7600285436f655171dc02aad Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sat, 10 Feb 2018 09:38:09 +0100 Subject: [PATCH 200/225] Added new T3/4 --- language.json | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/language.json b/language.json index c501973..95ec90e 100755 --- a/language.json +++ b/language.json @@ -328,6 +328,48 @@ "DE": "Registeel", "EN": "Registeel", "PT-BR": "Registeel" + }, + "jynx" : { + "NL": "Jynx", + "DE": "Jynx", + "EN": "Jynx", + "PT-BR": "Jynx" + }, + "azumarill" : { + "NL": "Azumarill", + "DE": "Azumarill", + "EN": "Azumarill", + "PT-BR": "Azumarill" + }, + "piloswine" : { + "NL": "Piloswine", + "DE": "Piloswine", + "EN": "Piloswine", + "PT-BR": "Piloswine" + }, + "salamence" : { + "NL": "Salamence", + "DE": "Salamence", + "EN": "Salamence", + "PT-BR": "Salamence" + }, + "feraligatr" : { + "NL": "Feraligatr", + "DE": "Feraligatr", + "EN": "Feraligatr", + "PT-BR": "Feraligatr" + }, + "meganium" : { + "NL": "Meganium", + "DE": "Meganium", + "EN": "Meganium", + "PT-BR": "Meganium" + }, + "typhlosion" : { + "NL": "Typhlosion", + "DE": "Typhlosion", + "EN": "Typhlosion", + "PT-BR": "Typhlosion" }, "egg_5" : { "NL": "Level 5 Ei", @@ -347,6 +389,18 @@ "EN": "Level 3 Egg", "PT-BR": "Ovo de Nível 3" }, + "egg_2" : { + "NL": "Level 2 Ei", + "DE": "Level 2 Ei", + "EN": "Level 2 Egg", + "PT-BR": "Ovo de Nível 2" + }, + "egg_1" : { + "NL": "Level 1 Ei", + "DE": "Level 1 Ei", + "EN": "Level 1 Egg", + "PT-BR": "Ovo de Nível 1" + }, "lapras" : { "NL": "Lapras", "DE": "Lapras", From e703767ad3aecf0757443d43fe95cdad838c6817 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 13 Feb 2018 22:17:22 +0100 Subject: [PATCH 201/225] Fix pokemon names as some are different in German --- language.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/language.json b/language.json index 95ec90e..6511ab5 100755 --- a/language.json +++ b/language.json @@ -331,7 +331,7 @@ }, "jynx" : { "NL": "Jynx", - "DE": "Jynx", + "DE": "Rossana", "EN": "Jynx", "PT-BR": "Jynx" }, @@ -341,33 +341,33 @@ "EN": "Azumarill", "PT-BR": "Azumarill" }, - "piloswine" : { + "piloswine" : { "NL": "Piloswine", - "DE": "Piloswine", + "DE": "Keifel", "EN": "Piloswine", "PT-BR": "Piloswine" }, - "salamence" : { + "salamence" : { "NL": "Salamence", - "DE": "Salamence", + "DE": "Brutalanda", "EN": "Salamence", "PT-BR": "Salamence" }, "feraligatr" : { "NL": "Feraligatr", - "DE": "Feraligatr", + "DE": "Impergator", "EN": "Feraligatr", "PT-BR": "Feraligatr" }, - "meganium" : { + "meganium" : { "NL": "Meganium", - "DE": "Meganium", + "DE": "Meganie", "EN": "Meganium", "PT-BR": "Meganium" }, "typhlosion" : { "NL": "Typhlosion", - "DE": "Typhlosion", + "DE": "Tornupto", "EN": "Typhlosion", "PT-BR": "Typhlosion" }, From 609f7a771e75e0f4f9abc9fb407cf38b1e6afb1a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Tue, 13 Feb 2018 22:19:48 +0100 Subject: [PATCH 202/225] Improve and fix issues with the new pokemon keys :) --- logic.php | 218 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 130 insertions(+), 88 deletions(-) diff --git a/logic.php b/logic.php index 9acfab7..b8c7f34 100755 --- a/logic.php +++ b/logic.php @@ -1230,8 +1230,47 @@ function keys_vote($raid) } } + // Get participants + $rs = my_query( + " + SELECT count(attend_time) AS count, + sum(pokemon = '0') AS count_any_pokemon, + sum(pokemon = '{$raid_pokemon}') AS count_raid_pokemon + FROM attendance + WHERE raid_id = {$raid['id']} + AND attend_time IS NOT NULL + AND raid_done != 1 + AND cancel != 1 + " + ); + + $row = $rs->fetch_assoc(); + + // Count participants and participants by pokemon + $count_pp = $row['count']; + $count_any_pokemon = $row['count_any_pokemon']; + $count_raid_pokemon = $row['count_raid_pokemon']; + + // Write to log. + debug_log('Participants for raid with ID ' . $raid['id'] . ': ' . $count_pp); + debug_log('Participants who voted for any pokemon: ' . $count_any_pokemon); + debug_log('Participants who voted for ' . $raid_pokemon . ': ' . $count_raid_pokemon); + + // Hide keys for specific cases + $show_keys = true; + // Make sure raid boss is not an egg + if (strtolower($raid_pokemon) != strtolower(getTranslation('egg_' . $level))) { + // Make sure we either have no participants + // OR all participants voted for "any" raid boss + // OR all participants voted for the hatched raid boss + // OR all participants voted for "any" or the hatched raid boss + if($count_pp == 0 || $count_pp == $count_any_pokemon || $count_pp == $count_raid_pokemon || $count_pp == ($count_any_pokemon + $count_raid_pokemon)) { + $show_keys = false; + } + } + // Add pokemon keys if we found the raid boss - if ($level_found) { + if ($level_found && $show_keys) { // Init counter. $count = 0; @@ -1727,50 +1766,33 @@ function get_overview($update, $chats_active, $raids_active, $action = 'refresh' $msg .= $pokemon . ' — ' . getTranslation('still') . ' ' . floor($time_left / 60) . ':' . str_pad($time_left % 60, 2, '0', STR_PAD_LEFT) . 'h' . CR; } - // Build query to add attendances to message. - $rs = my_query( + // Count attendances + $rs_att = my_query( " - SELECT team, - COUNT(*) AS cnt, - SUM(extra_people) AS extra - FROM attendance - WHERE raid_id = {$raid_id} - AND (cancel = 0 OR cancel IS NULL) - AND (raid_done = 0 OR raid_done IS NULL) - GROUP BY team + SELECT count(attend_time) AS count, + sum(team = 'mystic') AS count_mystic, + sum(team = 'valor') AS count_valor, + sum(team = 'instinct') AS count_instinct, + sum(team IS NULL) AS count_no_team, + sum(extra_people) AS extra + FROM attendance + WHERE raid_id = {$raid_id} + AND attend_time IS NOT NULL + AND raid_done != 1 + AND cancel != 1 " ); - $total = 0; - $total_extra = 0; - $sep = ''; - $msg_teams = ''; - - // Get attendances for each team and unknown - while ($row_att = $rs->fetch_assoc()) { - $sum = $row_att['cnt']; + $att = $rs_att->fetch_assoc(); - if ($sum == 0) continue; - - // Add to message. - $msg_teams .= $sep . $GLOBALS['teams'][$row_att['team']] . $sum; - $sep = ' '; - $total += $sum; - - if ($row_att['extra'] > 0) { - $total_extra += $row_att['extra']; - $total += $row_att['extra']; - } - } - - // Add team unknown count - if ($total_extra > 0) { - $msg_teams .= $sep . TEAM_UNKNOWN . $total_extra; - } - - // Add attendances to message if there are some - if ($total > 0) { - $msg .= EMOJI_GROUP . ' ' . $total . ' — ' . $msg_teams . CR; + // Add to message. + if ($att['count'] > 0) { + $msg .= EMOJI_GROUP . ' ' . ($att['count'] + $att['extra']) . ' — '; + $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'] + $att['extra']) > 0) ? TEAM_UNKNOWN . ($att['count_no_team'] + $att['extra']) : ''); + $msg .= CR; } // Add CR to message now since we don't know if attendances got added or not @@ -2052,6 +2074,8 @@ function show_raid_poll($raid) sum(team = 'instinct') AS count_instinct, sum(team IS NULL) AS count_no_team, sum(extra_people) AS extra, + sum(pokemon = '0') AS count_any_pokemon, + sum(pokemon = '{$raid['pokemon']}') AS count_raid_pokemon, attend_time FROM attendance WHERE raid_id = {$raid['id']} @@ -2098,12 +2122,10 @@ function show_raid_poll($raid) // Init empty pokemon array. $voted_poke = array(); - $count_poke = 0; // Count pokemons which users voted for. while ($rowPoke = $poke_rs->fetch_assoc()) { $voted_poke[] = $rowPoke; - $count_poke = $count_poke + 1; } // Get users for each pokemon. @@ -2122,27 +2144,60 @@ function show_raid_poll($raid) " ); - // Init empty attend users array and counter. + // Init empty attend users array. $att_users = array(); - $cnt_users = 0; while ($rowUsers = $user_rs->fetch_assoc()) { $att_users[] = $rowUsers; - $cnt_users = $cnt_users + 1; } - if($cnt_users == 0) { + // Get participants for voted time and pokemon. + $participants_rs = my_query( + " + SELECT count(attend_time) AS count, + sum(team = 'mystic') AS count_mystic, + sum(team = 'valor') AS count_valor, + sum(team = 'instinct') AS count_instinct, + sum(team IS NULL) AS count_no_team, + sum(extra_people) AS extra, + attend_time + FROM attendance + WHERE UNIX_TIMESTAMP(attend_time) = {$ts['ts_att']} + AND raid_done != 1 + AND cancel != 1 + AND raid_id = {$raid['id']} + AND pokemon = '{$pp['pokemon']}' + " + ); + + $row_pp = $participants_rs->fetch_assoc(); + + if($row_pp['count'] == 0) { // No users voted for this pokemon, continue continue; } else { - // Show any raid boss in message when we have more than 2 pokemon and pokemon is 0 - if($count_poke >= 2 && $pp['pokemon'] == '0') { - $msg .= '' . getTranslation('any_pokemon') . '' . CR; - // Show raid boss name in message when we have 1 or more pokemon and pokemon is NOT 0 - } else if($count_poke >= 1 && $pp['pokemon'] != '0') { - $msg .= '' . $pp['pokemon'] . '' . CR; + // Count all attendances, attendances for "any" pokemon and attendances for the raid boss + $count_pp = $ts['count']; + $count_any_pokemon = $ts['count_any_pokemon']; + $count_raid_pokemon = $ts['count_raid_pokemon']; + + // Write to log. + debug_log('Summary for timeslot: ' . unix2tz($ts['ts_att'], $raid['timezone'])); + debug_log('Participants for raid with ID ' . $raid['id'] . ': ' . $count_pp); + debug_log('Participants who voted for any pokemon: ' . $count_any_pokemon); + debug_log('Participants who voted for ' . $raid['pokemon'] . ': ' . $count_raid_pokemon); + + // Show attendances when multiple pokemon are selected, unless all attending users voted for the raid boss + any pokemon + if($count_pp != ($count_any_pokemon + $count_raid_pokemon)) { + // Add participants message. + $msg .= $pp['pokemon'] == '0' ? '' . getTranslation('any_pokemon') . '' : '' . $pp['pokemon'] . ''; + $msg .= ' [' . ($row_pp['count'] + $row_pp['extra']) . '] — '; + $msg .= (($row_pp['count_mystic'] > 0) ? TEAM_B . $row_pp['count_mystic'] . ' ' : ''); + $msg .= (($row_pp['count_valor'] > 0) ? TEAM_R . $row_pp['count_valor'] . ' ' : ''); + $msg .= (($row_pp['count_instinct'] > 0) ? TEAM_Y . $row_pp['count_instinct'] . ' ' : ''); + $msg .= ((($row_pp['count_no_team'] + $row_pp['extra']) > 0) ? TEAM_UNKNOWN . ($row_pp['count_no_team'] + $row_pp['extra']) : ''); + $msg .= CR; } - // Missing else since unnecessary: Hide raid boss name in message when we have just 1 pokemon which is 0 } // Write to log. @@ -2340,48 +2395,35 @@ function show_raid_poll_small($raid) $msg .= '' . $raid['address'] . '' . CR2; } - // Build query. + // Count attendances $rs = my_query( " - SELECT team, - COUNT(*) AS cnt, - SUM(extra_people) AS extra - FROM attendance - WHERE raid_id = {$raid['id']} - AND (cancel = 0 OR cancel IS NULL) - AND (raid_done = 0 OR raid_done IS NULL) - GROUP BY team + SELECT count(attend_time) AS count, + sum(team = 'mystic') AS count_mystic, + sum(team = 'valor') AS count_valor, + sum(team = 'instinct') AS count_instinct, + sum(team IS NULL) AS count_no_team, + sum(extra_people) AS extra + FROM attendance + WHERE raid_id = {$raid['id']} + AND attend_time IS NOT NULL + AND raid_done != 1 + AND cancel != 1 " ); - $total = 0; - $total_extra = 0; - $sep = ''; - $msg_teams = ''; - - while ($row = $rs->fetch_assoc()) { - $sum = $row['cnt']; - - if ($sum == 0) continue; - - // Add to message. - $msg_teams .= $sep . $GLOBALS['teams'][$row['team']] . ' ' . $sum; - $sep = ' '; - $total += $sum; - - if ($row['extra'] > 0) { - $total_extra += $row['extra']; - $total += $row['extra']; - } - } - if ($total_extra > 0) { - $msg_teams .= $sep . TEAM_UNKNOWN . ' ' . $total_extra; - } + $row = $rs->fetch_assoc(); - if (!$total) { - $msg .= getTranslation('no_participants') . CR; + // Add to message. + if ($row['count'] > 0) { + $msg .= EMOJI_GROUP . ' ' . ($row['count'] + $row['extra']) . ' — '; + $msg .= (($row['count_mystic'] > 0) ? TEAM_B . $row['count_mystic'] . ' ' : ''); + $msg .= (($row['count_valor'] > 0) ? TEAM_R . $row['count_valor'] . ' ' : ''); + $msg .= (($row['count_instinct'] > 0) ? TEAM_Y . $row['count_instinct'] . ' ' : ''); + $msg .= ((($row['count_no_team'] + $row['extra']) > 0) ? TEAM_UNKNOWN . ($row['count_no_team'] + $row['extra']) : ''); + $msg .= CR; } else { - $msg .= EMOJI_GROUP . ' ' . $total . ' — ' . $msg_teams; + $msg .= getTranslation('no_participants') . CR; } return $msg; From f01ef61dafadd721cb7a5bf78d70891c52af7a4e Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Fri, 16 Feb 2018 11:50:57 +0100 Subject: [PATCH 203/225] Switch gym selection and location at the start --- commands/start.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/start.php b/commands/start.php index 4bc69e6..e0c95a1 100755 --- a/commands/start.php +++ b/commands/start.php @@ -17,7 +17,7 @@ ]; // Set message. -$msg = '' . getTranslation('send_location') . '' . CR2 . CR . '' . getTranslation('raid_by_gym') . ''; +$msg = '' . getTranslation('raid_by_gym') . '' . CR2 . CR . '' . getTranslation('send_location') . ''; // Send message. send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); From 1a90c04c013895c3aac096d0ed9f5c7e4638bbc0 Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Fri, 16 Feb 2018 11:59:06 +0100 Subject: [PATCH 204/225] Update start.php --- commands/start.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/start.php b/commands/start.php index e0c95a1..9599dac 100755 --- a/commands/start.php +++ b/commands/start.php @@ -17,7 +17,7 @@ ]; // Set message. -$msg = '' . getTranslation('raid_by_gym') . '' . CR2 . CR . '' . getTranslation('send_location') . ''; +$msg = '' . getTranslation('raid_by_gym') . '' . CR2 . CR . getTranslation('send_location') ; // Send message. send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]); From f0526b7d0a11ee88e9f37603825350e1ef4f030d Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Fri, 16 Feb 2018 12:05:39 +0100 Subject: [PATCH 205/225] Update language.json --- language.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/language.json b/language.json index 6511ab5..9f8806e 100755 --- a/language.json +++ b/language.json @@ -800,17 +800,17 @@ "PT-BR": "Atualizar Pokemon" }, "send_location" : { - "NL": "Stuur me alsjeblieft eerst een locatie.", - "DE": "Bitte sende mir zuerst einen Standort.", - "EN": "Please send me a location first.", - "PT-BR": "Por favor, antes me envie a localização." - }, - "raid_by_gym" : { - "NL": "Of maak een raid door een Gym te selecteren:", - "DE": "Oder lege ein Raid per Arena-Auswahl an:", - "EN": "Or make a raid per gym selection:", - "PT-BR": "Ou escolha uma raid por ginásio:" - }, + "NL": "Of stuur me alsjeblieft een locatie:", + "DE": "Oder sende mir einen Standort:", + "EN": "Or send me a location:", + "PT-BR": "Por favor, antes me envie a localização:" + }, + "raid_by_gym" : { + "NL": "Maak een raid door een Gym te selecteren.", + "DE": "Lege ein Raid per Arena-Auswahl an.", + "EN": "Make a raid per gym selection.", + "PT-BR": "Ou escolha uma raid por ginásio." + }, "red" : { "NL": "rood", "DE": "rot", From 7e666c79911ff5c23f852c7c12b5e6ba93e752f4 Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Fri, 16 Feb 2018 13:37:15 +0100 Subject: [PATCH 206/225] Update constants.php --- constants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constants.php b/constants.php index 2e86c2c..bfed6b2 100755 --- a/constants.php +++ b/constants.php @@ -42,7 +42,7 @@ // getTranslation('suicune'), // getTranslation('groudon'), getTranslation('rayquaza'), - getTranslation('kyogre'), +// getTranslation('kyogre'), // getTranslation('latios'), // getTranslation('latias'), // getTranslation('deoxys'), From e7fbe65f11de2a4adcc89f1a1e775a02715b8c8a Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Sat, 17 Feb 2018 14:52:26 +0100 Subject: [PATCH 207/225] Comment the part with INSERT INTO ATTENDANCES sql query to avoid duplicate votes from the same person at the same raid --- modules/vote_team.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/vote_team.php b/modules/vote_team.php index 349637e..1a8f081 100644 --- a/modules/vote_team.php +++ b/modules/vote_team.php @@ -28,7 +28,8 @@ ); // User has not voted before. -} else { +// Do nothing to avoid that the same person appears twice in raid attendances when quickly pressing a team and a voting time button +/*} else { // Create attendance. my_query( " @@ -38,6 +39,7 @@ team = '{$data['arg']}' " ); +*/ } // Update users team. From d61d13e872fb3fd36e6831e739c7764a76f96406 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Mon, 19 Feb 2018 23:26:27 +0100 Subject: [PATCH 208/225] Fix connection on not well configures utf8 systems --- index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/index.php b/index.php index 0439d74..01fd271 100755 --- a/index.php +++ b/index.php @@ -55,6 +55,7 @@ // Establish mysql connection. $db = new mysqli('localhost', DB_USER, DB_PASSWORD, DB_NAME); +$db->set_charset('utf8'); // Error connecting to db. if ($db->connect_errno) { From 129d0826f6b58d072d0d91779e6be151aa365d17 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Tue, 20 Feb 2018 23:46:39 +0100 Subject: [PATCH 209/225] Define for database host --- config.php.example | 1 + index.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config.php.example b/config.php.example index c7c1dea..baf7724 100755 --- a/config.php.example +++ b/config.php.example @@ -9,6 +9,7 @@ define('DEBUG', true); define('CONFIG_LOGFILE', '/var/log/tg-bots/dev-raid-bot.log'); define('CONFIG_HASH', ' = hash(sha_512,tg_bot_key) '); +define('DB_HOST', 'localhost'); define('DB_NAME', 'your_database_name'); define('DB_USER', 'your_database_user'); define('DB_PASSWORD', 'your_database_password'); diff --git a/index.php b/index.php index 01fd271..5184eef 100755 --- a/index.php +++ b/index.php @@ -54,7 +54,7 @@ $command = NULL; // Establish mysql connection. -$db = new mysqli('localhost', DB_USER, DB_PASSWORD, DB_NAME); +$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $db->set_charset('utf8'); // Error connecting to db. From d7d28a8795e8a777f04f6a1233352dbc171793eb Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 21 Feb 2018 16:21:30 +0100 Subject: [PATCH 210/225] Add send_venue function, add detection to cleanup venue messages --- functions.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 906d64d..3564be5 100755 --- a/functions.php +++ b/functions.php @@ -112,6 +112,49 @@ function send_location($chat_id, $lat, $lon, $inline_keyboard = false) return curl_json_request($reply_json); } +/** + * Send venue. + * @param $chat_id + * @param $lat + * @param $lon + * @param $title + * @param $address + * @param bool $inline_keyboard + * @return mixed + */ +function send_venue($chat_id, $lat, $lon, $title, $address, $inline_keyboard = false) +{ + // Create reply content array. + $reply_content = [ + 'method' => 'sendVenue', + 'chat_id' => $chat_id, + 'latitude' => $lat, + 'longitude' => $lon, + 'title' => $title, + 'address' => $address + ]; + + // Write to log. + debug_log('KEYS'); + debug_log($inline_keyboard); + + if (is_array($inline_keyboard)) { + $reply_content['reply_markup'] = ['inline_keyboard' => $inline_keyboard]; + } + + // Encode data to json. + $reply_json = json_encode($reply_content); + + // Set header to json. + header('Content-Type: application/json'); + + // Write to log. + debug_log($reply_json, '>'); + + // Send request to telegram api and return response. + return curl_json_request($reply_json); +} + /** * Echo message. * @param $chat_id @@ -495,7 +538,16 @@ function curl_json_request($json) if (!empty($json_message['reply_markup']['inline_keyboard']['0']['0']['callback_data']) && !empty($json_message['reply_to_message_id'])) { $split_callback_data = explode(':', $json_message['reply_markup']['inline_keyboard']['0']['0']['callback_data']); $raid_id = $split_callback_data[0]; - debug_log('Found Raid_ID for cleanup preparation from callback_data!'); + + // Check if it's a venue and get raid id + } else if (!empty($response['result']['venue']['address'])) { + // Get raid_id from address. + $raid_id = substr(strrchr($response['result']['venue']['address'], "ID = "), 5); + } + + // Trigger Cleanup when raid_id was found + if ($raid_id != 0) { + debug_log('Found Raid_ID for cleanup preparation from callback_data or venue!'); debug_log('Raid_ID: ' . $raid_id); debug_log('Chat_ID: ' . $chat_id); debug_log('Message_ID: ' . $message_id); From c280c7a795293c1b7a1109b7f6c260e71cf3f778 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 21 Feb 2018 16:22:02 +0100 Subject: [PATCH 211/225] Switch from send_location to send_venue to include it in cleanup --- commands/raid.php | 3 ++- modules/raid_share.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/commands/raid.php b/commands/raid.php index 50d4bcd..aa9a7f2 100755 --- a/commands/raid.php +++ b/commands/raid.php @@ -227,7 +227,8 @@ if (RAID_LOCATION == true) { // Send location. - $loc = send_location($update['message']['chat']['id'], $raid['lat'], $raid['lon']); + //$loc = send_location($update['message']['chat']['id'], $raid['lat'], $raid['lon']); + $loc = send_venue($update['message']['chat']['id'], $raid['lat'], $raid['lon'], "", !empty($raid['address']) ? $raid['address'] . ', ID = ' . $raid['id'] : $raid['pokemon'] . ', ' . $raid['id']); // DO NOT REMOVE " ID = " --> NEEDED FOR CLEANUP PREPARATION! // Write to log. debug_log('location:'); diff --git a/modules/raid_share.php b/modules/raid_share.php index b87ce79..183a95b 100755 --- a/modules/raid_share.php +++ b/modules/raid_share.php @@ -36,6 +36,16 @@ // Send the message. send_message($chat, $text, $keys, ['reply_to_message_id' => $chat, 'disable_web_page_preview' => 'true']); +// Send location. +if (RAID_LOCATION == true) { + // Send location. + $loc = send_venue($chat, $raid['lat'], $raid['lon'], "", !empty($raid['address']) ? $raid['address'] . ', ID = ' . $raid['id'] : $raid['pokemon'] . ', ' . $raid['id']); // DO NOT REMOVE " ID = " --> NEEDED FOR CLEANUP PREPARATION! + + // Write to log. + debug_log('location:'); + debug_log($loc); +} + // Set callback keys and message $callback_msg = getTranslation('successfully_shared'); From 7c3f8d1449e0c15fcb6a5f4d71a1289aa215bd5b Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 21 Feb 2018 16:24:08 +0100 Subject: [PATCH 212/225] Remove 90% of keys, replace by short raid duration as default and expand key --- modules/edit_start.php | 70 +++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/modules/edit_start.php b/modules/edit_start.php index 0454f5e..3626cf1 100755 --- a/modules/edit_start.php +++ b/modules/edit_start.php @@ -10,36 +10,62 @@ // Set the id. $id = $data['id']; -if (true) { +// Set the arg. +$arg = $data['arg']; +$slot_switch = 0; +if (strpos($arg, ',') !== false) +{ + $args = explode(",", $arg); + $arg = $args[0]; + $slot_switch = $args[1]; + debug_log('More options got reqeusted for raid duration!'); + debug_log('Received argument and start_time in minutes: ' . $arg . ', ' . $slot_switch); +} - // Build query. - my_query( - " - UPDATE raids - SET start_time = DATE_ADD(start_time, INTERVAL {$data['arg']} MINUTE) - WHERE id = {$id} - " - ); +if (true || $arg == "more-options") { + if ($arg != "more-options") { + // Build query. + my_query( + " + UPDATE raids + SET start_time = DATE_ADD(start_time, INTERVAL {$arg} MINUTE) + WHERE id = {$id} + " + ); + } // Init empty keys array. $keys = array(); - // 1 Minute or 5 minute time slots - if ($data['arg'] == 0) { - $slotmax = RAID_POKEMON_DURATION_SHORT; - $slotsize = 1; + // Raid pokemon duration short or 1 Minute / 5 minute time slots + if($arg == "more-options") { + if ($slot_switch == 0) { + $slotmax = RAID_POKEMON_DURATION_SHORT; + $slotsize = 1; + } else { + $slotmax = RAID_POKEMON_DURATION_LONG; + $slotsize = 5; + } + + for ($i = $slotmax; $i >= 15; $i = $i - $slotsize) { + // Create the keys. + $keys[] = array( + // Just show the time, no text - not everyone has a phone or tablet with a large screen... + 'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), + 'callback_data' => $id . ':edit_left:' . $i + ); + } } else { - $slotmax = RAID_POKEMON_DURATION_LONG; - $slotsize = 5; - } + // Use raid pokemon duration short. + $keys[] = array( + 'text' => '0:' . RAID_POKEMON_DURATION_SHORT, + 'callback_data' => $id . ':edit_left:' . RAID_POKEMON_DURATION_SHORT + ); - for ($i = $slotmax; $i >= 15; $i = $i - $slotsize) { - // Create the keys. + // Button for more options. $keys[] = array( - // Just show the time, no text - not everyone has a phone or tablet with a large screen... - //'text' => 'noch ' . floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), - 'text' => floor($i / 60) . ':' . str_pad($i % 60, 2, '0', STR_PAD_LEFT), - 'callback_data' => $id . ':edit_left:' . $i + 'text' => getTranslation('expand'), + 'callback_data' => $id . ':edit_start:more-options,' . $arg ); } From 3a1fb37d3bc10989bcdc3a9bec6ebc0177967ce0 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Wed, 21 Feb 2018 16:25:04 +0100 Subject: [PATCH 213/225] Generate start keys for raid level by levels available in constants.php --- logic.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/logic.php b/logic.php index b8c7f34..81975ac 100755 --- a/logic.php +++ b/logic.php @@ -517,6 +517,24 @@ function inline_key_array($buttons, $columns) */ function raid_edit_start_keys($id) { + // Init empty keys array. + $keys = array(); + + // Create start keys based on levels in constants + $pokemonlist = $GLOBALS['pokemon']; + foreach($pokemonlist as $level => $levelmons) { + if($level == "X") continue; + $keys[] = array( + 'text' => getTranslation($level . 'stars'), + 'callback_data' => $id . ':edit:' . $level + ); + } + + // Get the inline key array. + $keys = inline_key_array($keys, 3); + +// OLD, static code: +/* $keys = [ [ [ @@ -533,8 +551,7 @@ function raid_edit_start_keys($id) 'text' => getTranslation('3stars'), 'callback_data' => $id . ':edit:3' ] -// No raids for level 2 or 1 -/* ], + ], [ [ 'text' => getTranslation('2stars'), @@ -544,8 +561,9 @@ function raid_edit_start_keys($id) 'text' => getTranslation('1stars'), 'callback_data' => $id . ':edit:1' ] -*/ ] + ] ]; +*/ return $keys; } From 9fe85e767758dfa7197362ecf54ff52b6e20e50b Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Fri, 23 Feb 2018 13:33:19 +0100 Subject: [PATCH 214/225] Change SQL to utf8mb4 for real unicoded formatting --- index.php | 2 +- raid-pokemon-bot.sql | 182 +++++++++++++++++++++++++++++-------------- 2 files changed, 125 insertions(+), 59 deletions(-) diff --git a/index.php b/index.php index 5184eef..3d69d48 100755 --- a/index.php +++ b/index.php @@ -55,7 +55,7 @@ // Establish mysql connection. $db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); -$db->set_charset('utf8'); +$db->set_charset('utf8mb4'); // Error connecting to db. if ($db->connect_errno) { diff --git a/raid-pokemon-bot.sql b/raid-pokemon-bot.sql index 1d7a307..64ccdaf 100644 --- a/raid-pokemon-bot.sql +++ b/raid-pokemon-bot.sql @@ -1,20 +1,33 @@ -/* -SQLyog Community v8.8 Beta2 -MySQL - 5.7.19-0ubuntu0.16.04.1 : Database - 437562092 -********************************************************************* -*/ +-- phpMyAdmin SQL Dump +-- version 4.2.12deb2+deb8u2 +-- http://www.phpmyadmin.net +-- +-- Host: localhost +-- Erstellungszeit: 23. Feb 2018 um 13:27 +-- Server Version: 5.5.58-0+deb8u1 +-- PHP-Version: 5.6.33-0+deb8u1 +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -/*!40101 SET SQL_MODE=''*/; +-- +-- Datenbank: `raidbot` +-- + +-- -------------------------------------------------------- -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -/*Table structure for table `attendance` */ +-- +-- Tabellenstruktur für Tabelle `attendance` +-- -CREATE TABLE `attendance` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, +CREATE TABLE IF NOT EXISTS `attendance` ( +`id` int(10) unsigned NOT NULL, `user_id` bigint(20) DEFAULT NULL, `raid_id` int(10) unsigned DEFAULT NULL, `attend_time` datetime DEFAULT NULL, @@ -25,48 +38,60 @@ CREATE TABLE `attendance` ( `extra_2_team` enum('mystic','valor','instinct') DEFAULT NULL, `extra_3_team` enum('mystic','valor','instinct') DEFAULT NULL, `extra_4_team` enum('mystic','valor','instinct') DEFAULT NULL, - `arrived` tinyint(1) unsigned DEFAULT 0, - `raid_done` tinyint(1) unsigned DEFAULT 0, - `cancel` tinyint(1) unsigned DEFAULT 0, - `pokemon` varchar(12) DEFAULT 0, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; + `arrived` tinyint(1) unsigned DEFAULT '0', + `raid_done` tinyint(1) unsigned DEFAULT '0', + `cancel` tinyint(1) unsigned DEFAULT '0', + `pokemon` varchar(12) DEFAULT '0' +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*Table structure for table `cleanup` */ +-- -------------------------------------------------------- -CREATE TABLE `cleanup` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, +-- +-- Tabellenstruktur für Tabelle `cleanup` +-- + +CREATE TABLE IF NOT EXISTS `cleanup` ( +`id` int(10) unsigned NOT NULL, `raid_id` int(10) unsigned NOT NULL, - `chat_id` bigint(20) signed NOT NULL, + `chat_id` bigint(20) NOT NULL, `message_id` bigint(20) unsigned NOT NULL, - `cleaned` int(10) unsigned DEFAULT 0, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; + `cleaned` int(10) unsigned DEFAULT '0' +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- -/*Table structure for table `gyms` */ +-- +-- Tabellenstruktur für Tabelle `gyms` +-- -CREATE TABLE `gyms` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, +CREATE TABLE IF NOT EXISTS `gyms` ( +`id` int(10) unsigned NOT NULL, `lat` varchar(11) DEFAULT NULL, `lon` varchar(11) DEFAULT NULL, `address` varchar(255) DEFAULT NULL, - `gym_name` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; + `gym_name` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*Table structure for table `overview` */ +-- -------------------------------------------------------- -CREATE TABLE `overview` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `chat_id` bigint(20) signed NOT NULL, - `message_id` bigint(20) unsigned NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; +-- +-- Tabellenstruktur für Tabelle `overview` +-- + +CREATE TABLE IF NOT EXISTS `overview` ( +`id` int(10) unsigned NOT NULL, + `chat_id` bigint(20) NOT NULL, + `message_id` bigint(20) unsigned NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*Table structure for table `raids` */ +-- -------------------------------------------------------- -CREATE TABLE `raids` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, +-- +-- Tabellenstruktur für Tabelle `raids` +-- + +CREATE TABLE IF NOT EXISTS `raids` ( +`id` int(10) unsigned NOT NULL, `user_id` bigint(20) DEFAULT NULL, `pokemon` varchar(12) DEFAULT NULL, `lat` varchar(11) DEFAULT NULL, @@ -76,29 +101,70 @@ CREATE TABLE `raids` ( `end_time` datetime DEFAULT NULL, `timezone` char(30) DEFAULT NULL, `address` varchar(255) DEFAULT NULL, - `gym_name` varchar(255) DEFAULT NULL, - `gym_team` enum('mystic','valor','instinct') DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; + `gym_name` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL, + `gym_team` enum('mystic','valor','instinct') DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- -/*Table structure for table `users` */ +-- +-- Tabellenstruktur für Tabelle `users` +-- -CREATE TABLE `users` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, +CREATE TABLE IF NOT EXISTS `users` ( +`id` int(10) unsigned NOT NULL, `user_id` bigint(20) DEFAULT NULL, - `nick` varchar(100) DEFAULT NULL, - `name` varchar(200) DEFAULT NULL, + `nick` varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL, + `name` varchar(200) CHARACTER SET utf8mb4 DEFAULT NULL, `team` enum('mystic','valor','instinct') DEFAULT NULL, `moderator` tinyint(1) unsigned DEFAULT NULL, `timezone` int(10) DEFAULT NULL, `lang` varchar(5) DEFAULT NULL, `alert_lat` varchar(12) DEFAULT NULL, `alert_lon` varchar(12) DEFAULT NULL, - `level` int(10) unsigned DEFAULT 0, - PRIMARY KEY (`id`), - UNIQUE KEY `i_userid` (`user_id`) -) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + `level` int(10) unsigned DEFAULT '0' +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Indizes der exportierten Tabellen +-- + +-- +-- Indizes für die Tabelle `attendance` +-- +ALTER TABLE `attendance` + ADD PRIMARY KEY (`id`), ADD KEY `raid_id` (`raid_id`); + +-- +-- Indizes für die Tabelle `cleanup` +-- +ALTER TABLE `cleanup` + ADD PRIMARY KEY (`id`); + +-- +-- Indizes für die Tabelle `gyms` +-- +ALTER TABLE `gyms` + ADD PRIMARY KEY (`id`); + +-- +-- Indizes für die Tabelle `overview` +-- +ALTER TABLE `overview` + ADD PRIMARY KEY (`id`); + +-- +-- Indizes für die Tabelle `raids` +-- +ALTER TABLE `raids` + ADD PRIMARY KEY (`id`), ADD KEY `end_time` (`end_time`), ADD KEY `user_id` (`user_id`); + +-- +-- Indizes für die Tabelle `users` +-- +ALTER TABLE `users` + ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `i_userid` (`user_id`); + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; From 9348ac23a92617982f291c2c504fb9eebffe3b70 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Fri, 23 Feb 2018 23:35:47 +0100 Subject: [PATCH 215/225] Insert Groudon and Kyogre as raid boss again --- constants.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/constants.php b/constants.php index bfed6b2..9bca4d5 100755 --- a/constants.php +++ b/constants.php @@ -40,9 +40,9 @@ // getTranslation('raikou'), // getTranslation('entei'), // getTranslation('suicune'), -// getTranslation('groudon'), + getTranslation('groudon'), getTranslation('rayquaza'), -// getTranslation('kyogre'), + getTranslation('kyogre'), // getTranslation('latios'), // getTranslation('latias'), // getTranslation('deoxys'), From 459efa4dab60ac9913653bd4cc3fdb201a912de9 Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Tue, 6 Mar 2018 11:48:26 +0100 Subject: [PATCH 216/225] Update raid bosses lvl5, lvl4 and lvl3 --- constants.php | 9 +++++++-- language.json | 28 ++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/constants.php b/constants.php index 9bca4d5..530cff9 100755 --- a/constants.php +++ b/constants.php @@ -40,9 +40,9 @@ // getTranslation('raikou'), // getTranslation('entei'), // getTranslation('suicune'), - getTranslation('groudon'), +// getTranslation('groudon'), getTranslation('rayquaza'), - getTranslation('kyogre'), +// getTranslation('kyogre'), // getTranslation('latios'), // getTranslation('latias'), // getTranslation('deoxys'), @@ -59,6 +59,7 @@ getTranslation('feraligatr'), getTranslation('absol'), getTranslation('aggron'), + getTranslation('charizard'), getTranslation('egg_4') ), '3' => array( @@ -66,6 +67,10 @@ getTranslation('jynx'), getTranslation('azumarill'), getTranslation('piloswine'), + getTranslation('starmie'), + getTranslation('aerodactyl'), + getTranslation('claydol'), + getTranslation('alakazam'), getTranslation('egg_3') ), '2' => array( diff --git a/language.json b/language.json index 9f8806e..656c486 100755 --- a/language.json +++ b/language.json @@ -485,12 +485,36 @@ "EN": "Arcanine", "PT-BR": "Arcanine" }, - "machamp" : { + "starmie" : { + "NL": "Starmie", + "DE": "Starmie", + "EN": "Starmie", + "PT-BR": "Starmie" + }, + "charizard" : { + "NL": "Charizard", + "DE": "Glurak", + "EN": "Charizard", + "PT-BR": "Charizard" + }, + "aerodactyl" : { + "NL": "Aerodactyl", + "DE": "Aerodactyl", + "EN": "Aerodactyl", + "PT-BR": "Aerodactyl" + }, + "claydol" : { + "NL": "Claydol", + "DE": "Lepumentas", + "EN": "Claydol", + "PT-BR": "Claydol" + }, + "machamp" : { "NL": "Machamp", "DE": "Machomei", "EN": "Machamp", "PT-BR": "Machamp" - }, + }, "alakazam" : { "NL": "Alakazam", "DE": "Simsala", From acdea863c07de96a23e8a988a49627fb36567d37 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 8 Mar 2018 21:18:28 +0100 Subject: [PATCH 217/225] Add phrases for new ex-raid selection, PT-BR still missing, but will get added once translation is there --- language.json | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/language.json b/language.json index 656c486..c1b645a 100755 --- a/language.json +++ b/language.json @@ -690,12 +690,35 @@ "EN": "/team Mystic/Valor/Instinct/Blue/Red/Yellow", "PT-BR": "/team Mystic/Valor/Instinct/Azul/Vermelho/Amarelo" }, + "start_date_time" : { + "NL": "Starttijd gezet op", + "DE": "Startzeit gesetzt auf", + "EN": "Starttime set to", + "PT-BR": "Hora de começar determinada para" + }, "end_time" : { "NL": "Eindtijd gezet op ", "DE": "Ablaufzeit gesetzt auf ", "EN": "Endtime set to ", "PT-BR": "Hora de término determinada para " - + }, + "raid_select_date" : { + "NL": "Selecteer de datum van de raid:", + "DE": "Datum des Raids auswählen:", + "EN": "Select the date of the raid:", + "PT-BR": "Select the date of the raid:" + }, + "raid_select_hour" : { + "NL": "Selecteer het uur van de raid:", + "DE": "Stunde des Raids auswählen:", + "EN": "Select the hour of the raid:", + "PT-BR": "Select the hour of the raid:" + }, + "raid_select_start_time" : { + "NL": "Selecteer de start tijd van de raid:", + "DE": "Startzeit des Raids auswählen:", + "EN": "Select the start time of the raid:", + "PT-BR": "Select the start time of the raid:" }, "minutes" : { "NL": "minuten", From 9ca3188cc6d8e1955fb3692cb9ccbfc51d14c8bf Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 8 Mar 2018 21:22:04 +0100 Subject: [PATCH 218/225] Fixed a few bugs --- logic.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/logic.php b/logic.php index 81975ac..e4b5b19 100755 --- a/logic.php +++ b/logic.php @@ -940,6 +940,33 @@ function run_cleanup ($telegram = 2, $database = 2) { cleanup_log("Message ID: " . $row['message_id']); cleanup_log("Raid ID: " . $row['raid_id']); + // Make sure raid exists + $rs = my_query( + " + SELECT UNIX_TIMESTAMP(end_time) AS ts_end + FROM raids + WHERE id = {$current_raid_id} + ", true + ); + $rr = $rs->fetch_row(); + + // No raid found - set cleanup to 0 and continue with next raid + if (empty($rr['0'])) { + cleanup_log('No raid found with ID: ' . $current_raid_id, '!'); + cleanup_log('Updating cleanup information.'); + my_query( + " + UPDATE cleanup + SET chat_id = 0, + message_id = 0 + WHERE id = {$row['id']} + ", true + ); + + // Continue with next raid + continue; + } + // Get raid data only when raid_id changed compared to previous run if ($prev_raid_id != $current_raid_id) { // Get the raid data by id. @@ -987,7 +1014,7 @@ function run_cleanup ($telegram = 2, $database = 2) { cleanup_log('Deleting telegram message ' . $row['message_id'] . ' from chat ' . $row['chat_id'] . ' for raid ' . $row['raid_id']); delete_message($row['chat_id'], $row['message_id']); // Set database values of chat_id and message_id to 0 so we know telegram message was deleted already. - cleanup_log('Updating telegram cleanup inforamtion.'); + cleanup_log('Updating telegram cleanup information.'); my_query( " UPDATE cleanup @@ -1023,7 +1050,7 @@ function run_cleanup ($telegram = 2, $database = 2) { // Set database value of raid_id to 0 so we know attendance info was deleted already // Use raid_id in where clause since the same raid_id can in cleanup more than once - cleanup_log('Updating database cleanup inforamtion.'); + cleanup_log('Updating database cleanup information.'); my_query( " UPDATE cleanup @@ -1919,7 +1946,7 @@ function delete_raid($raid_id) debug_log('Deleting raid ' . $raid_id . ' from the cleanup table:'); $rs_cleanup = my_query( " - DELETE FROM raids + DELETE FROM cleanup WHERE raid_id = '{$raid_id}' OR cleaned = '{$raid_id}' " From debf25254bd5f75c9d7abc225efa877ddc6168a5 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 8 Mar 2018 21:23:03 +0100 Subject: [PATCH 219/225] Modified edit_poke and edit_start to work with the new edit_date.php for ex-raid date and time selection --- modules/edit_poke.php | 60 +++++++++++++++++++++++++++++++++++------- modules/edit_start.php | 4 +-- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/modules/edit_poke.php b/modules/edit_poke.php index e1b9d33..553226a 100755 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -13,17 +13,57 @@ // Get the argument. $arg = $data['arg']; -if (true || $arg == "minutes" || $arg == "clocktime") { - if ($arg != "minutes" && $arg != "clocktime") { - // Update pokemon in the raid table. - my_query( - " - UPDATE raids - SET pokemon = '{$data['arg']}' - WHERE id = {$id} - " - ); +// Update pokemon in the raid table. +if ($arg != "minutes" && $arg != "clocktime") { + my_query( + " + UPDATE raids + SET pokemon = '{$data['arg']}' + WHERE id = {$id} + " + ); +} + +// Get pokemon of level X +$X_pokemons = []; +$X_list = $GLOBALS['pokemon']['X']; +foreach($X_list as $pokemon) { + $X_pokemons[] = strtolower($pokemon); + debug_log('Adding pokemon to list of ex-raid pokemon: ' . $pokemon); +} + +// Pokemon in level X? +if(in_array(strtolower($arg), $X_pokemons)) { + // Init empty keys array. + $keys = array(); + + // Not sure if necessary, leaving as comment + // Timezone - maybe there's a more elegant solution as date_default_timezone_set?! + //$tz = TIMEZONE; + //date_default_timezone_set($tz); + // Current and next month + $current_month = date('Y-m', strtotime('now')); + $current_month_name = date('F', strtotime('now')); + $next_month = date('Y-m', strtotime('first day of +1 months')); + $next_month_name = date('F', strtotime('first day of +1 months')); + + // Buttons for current and next month + $keys[] = array( + 'text' => $current_month_name . ' (' . $current_month . ')', + 'callback_data' => $id . ':edit_date:' . $current_month + ); + + $keys[] = array( + 'text' => $next_month_name . ' (' . $next_month . ')', + 'callback_data' => $id . ':edit_date:' . $next_month + ); + // Get the inline key array. + $keys = inline_key_array($keys, 2); + +// Pokemon not in level X? +} else if (true || $arg == "minutes" || $arg == "clocktime") { + if ($arg != "minutes" && $arg != "clocktime") { // Get default raid duration style from config if (RAID_DURATION_CLOCK_STYLE == true) { $arg = "clocktime"; diff --git a/modules/edit_start.php b/modules/edit_start.php index 3626cf1..e979a81 100755 --- a/modules/edit_start.php +++ b/modules/edit_start.php @@ -22,8 +22,8 @@ debug_log('Received argument and start_time in minutes: ' . $arg . ', ' . $slot_switch); } -if (true || $arg == "more-options") { - if ($arg != "more-options") { +if (true || $arg == "more-options" || $arg == "ex-raid") { + if ($arg != "more-options" && $arg !="ex-raid") { // Build query. my_query( " From 9d747f316bfc7ebd538a70888dfb4704a5229555 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Thu, 8 Mar 2018 21:23:32 +0100 Subject: [PATCH 220/225] Added edit_date to select date and time of an ex-raid :) --- modules/edit_date.php | 121 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 modules/edit_date.php diff --git a/modules/edit_date.php b/modules/edit_date.php new file mode 100755 index 0000000..a911e71 --- /dev/null +++ b/modules/edit_date.php @@ -0,0 +1,121 @@ +' . getTranslation('bot_access_denied') . ''; + sendMessage($update['callback_query']['from']['id'], $response_msg); + exit; +} + +// Set the id. +$id = $data['id']; + +// Get the argument. +$arg = $data['arg']; + +// Number of days in month +$days_in_month = date('t', strtotime($arg)); + +// Init empty keys array and set keys count. +$keys = array(); +$keys_count = 2; + +// Check amount of "-" in $arg to add day, hour and minute of ex-raid date +// Received: Year-Month / 1970-01 / 1x "-" +if(substr_count($arg, '-') == 1) { + debug_log('Generating buttons for each day in the given year and month: ' . $arg); + + // Formatting stuff. + $month = date('M', strtotime($arg)) . '.'; + $year = substr($arg, 0, 4); + + // Buttons for each day in the given month + for ($i = 1; $i <= $days_in_month; $i = $i + 1) { + // Create the keys. + $keys[] = array( + //'text' => $arg . '-' . str_pad($i, 2, '0', STR_PAD_LEFT), + 'text' => str_pad($i, 2, '0', STR_PAD_LEFT) . ' ' . $month . ' ' . $year, + 'callback_data' => $id . ':edit_date:' . $arg . '-' . str_pad($i, 2, '0', STR_PAD_LEFT) + ); + } + + //Set message + $msg = getTranslation('raid_select_date'); +// Received: Year-Month-Day / 1970-01-01 / 2x "-" +} else if (substr_count($arg, '-') == 2) { + debug_log('Generating buttons for each hour of the day'); + // Buttons for each hour + for ($i = 0; $i <= 23; $i = $i + 1) { + // Create the keys. + $keys[] = array( + // Just show the time, no text - not everyone has a phone or tablet with a large screen... + 'text' => str_pad($i, 2, '0', STR_PAD_LEFT) . ':xx', + 'callback_data' => $id . ':edit_date:' . $arg . ' ' . str_pad($i, 2, '0', STR_PAD_LEFT) . '-' + ); + } + // Set keys count and message. + $keys_count = 4; + $msg = getTranslation('raid_select_hour'); +// Received: Year-Month-Day Hour- / 1970-01-01 00- / 3x "-" +} else if (substr_count($arg, '-') == 3) { + debug_log('Generating buttons for minute of the hour'); + $hour = explode(" ", $arg); + $hour = $hour[1]; + // Buttons for each minute + for ($i = 0; $i <= 45; $i = $i + 15) { + // Create the keys. + $keys[] = array( + // Just show the time, no text - not everyone has a phone or tablet with a large screen... + 'text' => substr($hour, 0, -1) . ':' . str_pad($i, 2, '0', STR_PAD_LEFT), + 'callback_data' => $id . ':edit_date:' . $arg . str_pad($i, 2, '0', STR_PAD_LEFT) . '-00' + ); + } + // Set keys count and message. + $keys_count = 4; + $msg = getTranslation('raid_select_start_time'); +// Received: Year-Month-Day Hour-Minute-Second / 1970-01-01 00-00-00 / 4x "-" +} else if (substr_count($arg, '-') == 4) { + debug_log('Received the following date for the raid: ' . $arg); + debug_log('Formatting the date now properly...'); + // Replace last 2 occurences of "-" with ":" + $start_dt = explode(" ", $arg); + $date = $start_dt[0]; + $time = str_replace('-', ':', $start_dt[1]); + $start_date_time = $date . ' ' . $time; + debug_log('Writing the formatted date to the database now: ' . $start_date_time); + // Build query. + my_query( + " + UPDATE raids + SET start_time = '{$start_date_time}' + WHERE id = {$id} + " + ); + + // Adding button to continue with next step in raid creation + $keys[] = array( + 'text' => getTranslation('next'), + 'callback_data' => $id . ':edit_start:ex-raid' + ); + + // Set message. + $msg = getTranslation('start_date_time') . ': ' . $start_date_time . ''; +} + +// Get the inline key array. +$keys = inline_key_array($keys, $keys_count); + +// Edit the message. +edit_message($update, $msg, $keys); + +// Build callback message string. +$callback_response = 'OK'; + +// Answer callback. +answerCallbackQuery($update['callback_query']['id'], $callback_response); From c1d8c002182476a92c494a42514c76b5094f8204 Mon Sep 17 00:00:00 2001 From: Chefkeks Date: Fri, 9 Mar 2018 09:30:28 +0100 Subject: [PATCH 221/225] Added localized names for months --- language.json | 88 +++++++++++++++++++++++++++++++++++++++---- modules/edit_date.php | 6 +-- modules/edit_poke.php | 18 ++++++--- 3 files changed, 96 insertions(+), 16 deletions(-) diff --git a/language.json b/language.json index c1b645a..27f27e7 100755 --- a/language.json +++ b/language.json @@ -120,6 +120,78 @@ "EN": "Sunday", "PT-BR": "Domingo" }, + "month_01" : { + "NL": "Januari", + "DE": "Januar", + "EN": "January", + "PT-BR": "Janeiro" + }, + "month_02" : { + "NL": "Februari", + "DE": "Februar", + "EN": "February", + "PT-BR": "Fevereiro" + }, + "month_03" : { + "NL": "Maart", + "DE": "März", + "EN": "March", + "PT-BR": "Março" + }, + "month_04" : { + "NL": "April", + "DE": "April", + "EN": "April", + "PT-BR": "Abril" + }, + "month_05" : { + "NL": "Meer", + "DE": "Mai", + "EN": "May", + "PT-BR": "Mais" + }, + "month_06" : { + "NL": "Juni", + "DE": "Juni", + "EN": "June", + "PT-BR": "Junho" + }, + "month_07" : { + "NL": "Juli", + "DE": "Juli", + "EN": "July", + "PT-BR": "Julho" + }, + "month_08" : { + "NL": "Augustus", + "DE": "August", + "EN": "August", + "PT-BR": "Agosto" + }, + "month_09" : { + "NL": "September", + "DE": "September", + "EN": "September", + "PT-BR": "Setembro" + }, + "month_10" : { + "NL": "Oktober", + "DE": "Oktober", + "EN": "October", + "PT-BR": "Outubro" + }, + "month_11" : { + "NL": "November", + "DE": "November", + "EN": "November", + "PT-BR": "Novembro" + }, + "month_12" : { + "NL": "December", + "DE": "Dezember", + "EN": "December", + "PT-BR": "Dezembro" + }, "still" : { "NL": "nog", "DE": "noch", @@ -847,16 +919,16 @@ "PT-BR": "Atualizar Pokemon" }, "send_location" : { - "NL": "Of stuur me alsjeblieft een locatie:", - "DE": "Oder sende mir einen Standort:", - "EN": "Or send me a location:", - "PT-BR": "Por favor, antes me envie a localização:" + "NL": "Of stuur me alsjeblieft een locatie.", + "DE": "Oder sende mir einen Standort.", + "EN": "Or send me a location.", + "PT-BR": "Por favor, antes me envie a localização." }, "raid_by_gym" : { - "NL": "Maak een raid door een Gym te selecteren.", - "DE": "Lege ein Raid per Arena-Auswahl an.", - "EN": "Make a raid per gym selection.", - "PT-BR": "Ou escolha uma raid por ginásio." + "NL": "Maak een raid door een Gym te selecteren:", + "DE": "Lege ein Raid per Arena-Auswahl an:", + "EN": "Make a raid per gym selection:", + "PT-BR": "Ou escolha uma raid por ginásio:" }, "red" : { "NL": "rood", diff --git a/modules/edit_date.php b/modules/edit_date.php index a911e71..2c89aea 100755 --- a/modules/edit_date.php +++ b/modules/edit_date.php @@ -32,7 +32,7 @@ debug_log('Generating buttons for each day in the given year and month: ' . $arg); // Formatting stuff. - $month = date('M', strtotime($arg)) . '.'; + $month = substr($arg, -2); $year = substr($arg, 0, 4); // Buttons for each day in the given month @@ -40,7 +40,7 @@ // Create the keys. $keys[] = array( //'text' => $arg . '-' . str_pad($i, 2, '0', STR_PAD_LEFT), - 'text' => str_pad($i, 2, '0', STR_PAD_LEFT) . ' ' . $month . ' ' . $year, + 'text' => str_pad($i, 2, '0', STR_PAD_LEFT) . ' ' . getTranslation('month_' . $month) . ' ' . $year, 'callback_data' => $id . ':edit_date:' . $arg . '-' . str_pad($i, 2, '0', STR_PAD_LEFT) ); } @@ -105,7 +105,7 @@ ); // Set message. - $msg = getTranslation('start_date_time') . ': ' . $start_date_time . ''; + $msg = getTranslation('start_date_time') . ':' . CR .'' . $start_date_time . ''; } // Get the inline key array. diff --git a/modules/edit_poke.php b/modules/edit_poke.php index 553226a..ad922d0 100755 --- a/modules/edit_poke.php +++ b/modules/edit_poke.php @@ -42,20 +42,28 @@ //$tz = TIMEZONE; //date_default_timezone_set($tz); - // Current and next month + // Current month $current_month = date('Y-m', strtotime('now')); - $current_month_name = date('F', strtotime('now')); + //$current_month_name = date('F', strtotime('now')); + $current_month_name = getTranslation('month_' . substr($current_month, -2)); + $year_of_current_month_name = substr($current_month, 0, 4); + + // Next month $next_month = date('Y-m', strtotime('first day of +1 months')); - $next_month_name = date('F', strtotime('first day of +1 months')); + //$next_month_name = date('F', strtotime('first day of +1 months')); + $next_month_name = getTranslation('month_' . substr($next_month, -2)); + $year_of_next_month_name = substr($next_month, 0, 4); // Buttons for current and next month $keys[] = array( - 'text' => $current_month_name . ' (' . $current_month . ')', + //'text' => $current_month_name . ' (' . $current_month . ')', + 'text' => $current_month_name . ' ' . $year_of_current_month_name, 'callback_data' => $id . ':edit_date:' . $current_month ); $keys[] = array( - 'text' => $next_month_name . ' (' . $next_month . ')', + //'text' => $next_month_name . ' (' . $next_month . ')', + 'text' => $next_month_name . ' ' . $year_of_next_month_name, 'callback_data' => $id . ':edit_date:' . $next_month ); // Get the inline key array. From f4bafbe2a8513557fc10a920bbe9cca1251de63b Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Thu, 15 Mar 2018 17:37:15 +0100 Subject: [PATCH 222/225] Update constants.php --- constants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constants.php b/constants.php index 530cff9..4206040 100755 --- a/constants.php +++ b/constants.php @@ -30,7 +30,7 @@ ), '5' => array( // getTranslation('articuno'), -// getTranslation('lugia'), + getTranslation('lugia'), // getTranslation('moltres'), // getTranslation('zapdos'), // getTranslation('mew'), From 23424c7dbcdbcac38a7bf78e68dde522ad5b702c Mon Sep 17 00:00:00 2001 From: Florian Becker Date: Fri, 16 Mar 2018 11:10:30 +0100 Subject: [PATCH 223/225] Update constants.php --- constants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constants.php b/constants.php index 4206040..eb031db 100755 --- a/constants.php +++ b/constants.php @@ -41,7 +41,7 @@ // getTranslation('entei'), // getTranslation('suicune'), // getTranslation('groudon'), - getTranslation('rayquaza'), +// getTranslation('rayquaza'), // getTranslation('kyogre'), // getTranslation('latios'), // getTranslation('latias'), From d231ec7bb7b91b7170b0111c95fe80d50c0bd820 Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sat, 17 Mar 2018 10:34:36 +0100 Subject: [PATCH 224/225] Update raid bosses --- language.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/language.json b/language.json index 27f27e7..397a651 100755 --- a/language.json +++ b/language.json @@ -443,6 +443,12 @@ "EN": "Typhlosion", "PT-BR": "Typhlosion" }, + "jolteon" : { + "NL": "Jolteon", + "DE": "Blitza", + "EN": "Jolteon", + "PT-BR": "Jolteon" + }, "egg_5" : { "NL": "Level 5 Ei", "DE": "Level 5 Ei", From b41a4ed679ff4b162f1e32b25819694738abd8af Mon Sep 17 00:00:00 2001 From: klablabla <30940278+klablabla@users.noreply.github.com> Date: Sat, 17 Mar 2018 10:35:27 +0100 Subject: [PATCH 225/225] Update constants.php --- constants.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/constants.php b/constants.php index eb031db..c98adcb 100755 --- a/constants.php +++ b/constants.php @@ -54,23 +54,16 @@ ), '4' => array( getTranslation('tyranitar'), - getTranslation('lapras'), - getTranslation('snorlax'), - getTranslation('feraligatr'), getTranslation('absol'), getTranslation('aggron'), - getTranslation('charizard'), + getTranslation('golem'), getTranslation('egg_4') ), '3' => array( getTranslation('machamp'), getTranslation('jynx'), - getTranslation('azumarill'), - getTranslation('piloswine'), - getTranslation('starmie'), - getTranslation('aerodactyl'), - getTranslation('claydol'), - getTranslation('alakazam'), + getTranslation('jolteon'), + getTranslation('gengar'), getTranslation('egg_3') ), '2' => array(