<commit_before><?php
ini_set('display_errors','1'); error_reporting(E_ALL);
include('config.php');
if(!defined('TOKEN')) {
   echo "Define a token in config.php:<br>\n<br>\n";
   echo "<pre>   define('TOKEN', '123456:<KEY>');</pre><br>\n<br>\n<br>\n";
}
if (!isset($_SQL)) {
   echo "Set the sql data in config.php:<br>\n<br>\n";
   echo "<pre>   \$_SQL = Array(
      'host' => 'localhost',
      'dbName' => 'corewarsbot',
      'user' => 'corewarsbot',
      'pw' => 'password'
   );</pre>";
}
if (!defined('TOKEN') || !isset($_SQL)) {
   exit();
}
require_once('db.php');


if (isset($_GET['setHook'])) {
   echo sendApiRequest('setwebhook', array('url' => $botHook));
   exit;
}

$_IN = file_get_contents("php://input");
$update = json_decode($_IN, true);

if (isset($update['inline_query'])) {
   $inline_query = $update['inline_query'];
   $ans = array(
         'inline_query_id' => $inline_query['id'],
         'results' => json_encode(array(
            array(
               'type' => 'article',
               'id' => "1",
               'title' => 'This is not working yet',
               'message_text' => 'This is not working yet!!!'
            )
         ))
      );
   
   $r = sendApiRequest('answerInlineQuery', $ans);
   //sendMsg($inline_query['from']['id'], "Search detected!: \n" . $r);
} else if (isset($update['message'])) {
   $update = $update['message'];
   
   if (false && !in_array($update['from']['id'], $admins)) { // Remove the "false && " to set maintenance mode
      sendMsg($update['from']['id'], "Maintenance!", false);
      exit;
   }

   if (!isset($update['text'])) {
      logToFile(json_encode($update)); // Debug!
      exit;
   }
   $user = getUserById($update['from']['id']);

   if ($update['text'] == '/register') {
      if ($user !== false) {
         sendMsg($user['id'], 'It seems you are alerady registered!', false);
      } else {
         addUserToDB(array('id' => $update['from']['id'], 'username' => $update['from']['username']));
         $user = getUserById($update['from']['id']);
         if ($user['id'] == $update['from']['id']) {
            sendMsg($user['id'], "Registered! You can now add warriors!!!\n(You are not participating. To participate, /participate )", false);
         } else {
            sendMsg($user['id'], 'Something wrong happened...', false);
         }
      }
      exit;
   }

   if ($user === false) {
      sendMsg($update['from']['id'], 'You are not registered... If you want, yo can /register', false);
      exit;
   }

   $userState = json_decode($user['state'], true);
   
   if ($update['text'] == '/cancel') {
      updateUserState($user, json_encode(array('state' => 'none')));
      sendMsg($user['id'], "Cancelling...", false);
      exit();
   }
   if ($userState['state'] == 'none') {
      if ($update['text'] == '/sendwarrior') {
         updateUserState($user, json_encode(array('state' => 'sendWarrior')));
         sendMsg($user['id'], "Warrior name:", false);
      } else if ($update['text'] == '/help') {
         sendMsg($user['id'], "Once you are registered you can submit warriors with /sendwarrior\nIf you want, you can /participate or /retreat for the following tournaments.\nWhen you participate, your fighter (choose with /choosewarrior ) will fight in the core of the next tournaments.\nTournaments happen from time to time, you will be notified of the results.\nThis bot is in *alpha*!\n(No tournaments scheduled)", false);
      } else if ($update['text'] == '/commands') {
         sendMsg($user['id'],
            "/register - Become a member to participate\n".
            "/help - Do I have to explain what this is for?\n".
            "/sendwarrior - send a new warrior\n".
            "/getwarrior - If you want to take a look to the code of one of your warriors....\n".
            "/score - shows your score\n".
            "/participate - from now on, your choosen warrior will fight!\n".
            "/retreat - from now on, you wont participate\n".
            "/choosewarrior - choose one of your warriors for the fight!\n".
            "/deletewarrior - delete one of your warriors\n".
            "/cancel - cancels operation\n".
            "/commands - get a list of all available commands\n",
            false);
      } else if ($update['text'] == '/score') {
         sendMsg($user['id'], 'Your score is '.$user['score']);
      } else if ($update['text'] == '/participate') {
         updateUserParticipation($user, true);
         sendMsg($user['id'], "From now on, your figther *will* participate in the tournaments!\n You can add more warrior if you like... /sendwarrior", false);
      } else if ($update['text'] == '/retreat') {
         updateUserParticipation($user, false);
         sendMsg($user['id'], "From now on, your figther *will NOT* participate in the tournaments!", false);
      } else if ($update['text'] == '/getwarrior') {
         $warriorsAsKeyboard = getWarriorsFromUserAsKeyboard($user['id']);
         array_push($warriorsAsKeyboard, array('/cancel'));
         sendMsg($user['id'], "Choose a warrior (select one from the list or input its id)", $warriorsAsKeyboard);
         updateUserState($user, json_encode(array('state' => 'getWarrior')));
      } else if ($update['text'] == '/choosewarrior') {
         $warriorsAsKeyboard = getWarriorsFromUserAsKeyboard($user['id']);
         array_push($warriorsAsKeyboard, array('/cancel'));
         sendMsg($user['id'], "Choose a warrior (select one from the list or input its id)", $warriorsAsKeyboard);
         updateUserState($user, json_encode(array('state' => 'chooseWarrior')));
      } else if ($update['text'] == '/deletewarrior') {
         $warriorsAsKeyboard = getWarriorsFromUserAsKeyboard($user['id']);
         array_push($warriorsAsKeyboard, array('/cancel'));
         sendMsg($user['id'], "Choose a warrior (select one from the list or input its id)", $warriorsAsKeyboard);
         updateUserState($user, json_encode(array('state' => 'deleteWarrior')));
      } else if (explode(" ", $update['text'])[0] == '/sim') {
         if (!in_array($update['from']['id'], $admins)) {
            sendMsg($update['from']['id'], "You are not the boss", array(array('I am not the boss', 'I am not the boss'),array('I am not the boss', 'I am not the boss')));
            exit;
         }
         $c = explode(" ", $update['text']);<commit_msg>Updated /help command. Not it is organized in several lines and it shows the /commands command.<commit_after><?php
ini_set('display_errors','1'); error_reporting(E_ALL);
include('config.php');
if(!defined('TOKEN')) {
   echo "Define a token in config.php:<br>\n<br>\n";
   echo "<pre>   define('TOKEN', '<KEY>');</pre><br>\n<br>\n<br>\n";
}
if (!isset($_SQL)) {
   echo "Set the sql data in config.php:<br>\n<br>\n";
   echo "<pre>   \$_SQL = Array(
      'host' => 'localhost',
      'dbName' => 'corewarsbot',
      'user' => 'corewarsbot',
      'pw' => 'password'
   );</pre>";
}
if (!defined('TOKEN') || !isset($_SQL)) {
   exit();
}
require_once('db.php');


if (isset($_GET['setHook'])) {
   echo sendApiRequest('setwebhook', array('url' => $botHook));
   exit;
}

$_IN = file_get_contents("php://input");
$update = json_decode($_IN, true);

if (isset($update['inline_query'])) {
   $inline_query = $update['inline_query'];
   $ans = array(
         'inline_query_id' => $inline_query['id'],
         'results' => json_encode(array(
            array(
               'type' => 'article',
               'id' => "1",
               'title' => 'This is not working yet',
               'message_text' => 'This is not working yet!!!'
            )
         ))
      );
   
   $r = sendApiRequest('answerInlineQuery', $ans);
   //sendMsg($inline_query['from']['id'], "Search detected!: \n" . $r);
} else if (isset($update['message'])) {
   $update = $update['message'];
   
   if (false && !in_array($update['from']['id'], $admins)) { // Remove the "false && " to set maintenance mode
      sendMsg($update['from']['id'], "Maintenance!", false);
      exit;
   }

   if (!isset($update['text'])) {
      logToFile(json_encode($update)); // Debug!
      exit;
   }
   $user = getUserById($update['from']['id']);

   if ($update['text'] == '/register') {
      if ($user !== false) {
         sendMsg($user['id'], 'It seems you are alerady registered!', false);
      } else {
         addUserToDB(array('id' => $update['from']['id'], 'username' => $update['from']['username']));
         $user = getUserById($update['from']['id']);
         if ($user['id'] == $update['from']['id']) {
            sendMsg($user['id'], "Registered! You can now add warriors!!!\n(You are not participating. To participate, /participate )", false);
         } else {
            sendMsg($user['id'], 'Something wrong happened...', false);
         }
      }
      exit;
   }

   if ($user === false) {
      sendMsg($update['from']['id'], 'You are not registered... If you want, yo can /register', false);
      exit;
   }

   $userState = json_decode($user['state'], true);
   
   if ($update['text'] == '/cancel') {
      updateUserState($user, json_encode(array('state' => 'none')));
      sendMsg($user['id'], "Cancelling...", false);
      exit();
   }
   if ($userState['state'] == 'none') {
      if ($update['text'] == '/sendwarrior') {
         updateUserState($user, json_encode(array('state' => 'sendWarrior')));
         sendMsg($user['id'], "Warrior name:", false);
      } else if ($update['text'] == '/help') {
         sendMsg($user['id'], 
            "Once you are registered you can submit warriors with /sendwarrior\n".
            "If you want, you can /participate or /retreat for the following tournaments.\n".
            "When you participate, your fighter (choose with /choosewarrior ) will fight in the core of the next tournaments.\n".
            "Tournaments happen from time to time, you will be notified of the results.\n".
            "Full list of /commands here!\n".
            "This bot is in *alpha*!\n".
            "(No tournaments scheduled)",
         false);
      } else if ($update['text'] == '/commands') {
         sendMsg($user['id'],
            "/register - Become a member to participate\n".
            "/help - Do I have to explain what this is for?\n".
            "/sendwarrior - send a new warrior\n".
            "/getwarrior - If you want to take a look to the code of one of your warriors....\n".
            "/score - shows your score\n".
            "/participate - from now on, your choosen warrior will fight!\n".
            "/retreat - from now on, you wont participate\n".
            "/choosewarrior - choose one of your warriors for the fight!\n".
            "/deletewarrior - delete one of your warriors\n".
            "/cancel - cancels operation\n".
            "/commands - get a list of all available commands\n",
         false);
      } else if ($update['text'] == '/score') {
         sendMsg($user['id'], 'Your score is '.$user['score']);
      } else if ($update['text'] == '/participate') {
         updateUserParticipation($user, true);
         sendMsg($user['id'], "From now on, your figther *will* participate in the tournaments!\n You can add more warrior if you like... /sendwarrior", false);
      } else if ($update['text'] == '/retreat') {
         updateUserParticipation($user, false);
         sendMsg($user['id'], "From now on, your figther *will NOT* participate in the tournaments!", false);
      } else if ($update['text'] == '/getwarrior') {
         $warriorsAsKeyboard = getWarriorsFromUserAsKeyboard($user['id']);
         array_push($warriorsAsKeyboard, array('/cancel'));
         sendMsg($user['id'], "Choose a warrior (select one from the list or input its id)", $warriorsAsKeyboard);
         updateUserState($user, json_encode(array('state' => 'getWarrior')));
      } else if ($update['text'] == '/choosewarrior') {
         $warriorsAsKeyboard = getWarriorsFromUserAsKeyboard($user['id']);
         array_push($warriorsAsKeyboard, array('/cancel'));
         sendMsg($user['id'], "Choose a warrior (select one from the list or input its id)", $warriorsAsKeyboard);
         updateUserState($user, json_encode(array('state' => 'chooseWarrior')));
      } else if ($update['text'] == '/deletewarrior') {
         $warriorsAsKeyboard = getWarriorsFromUserAsKeyboard($user['id']);
         array_push($warriorsAsKeyboard, array('/cancel'));
         sendMsg($user['id'], "Choose a warrior (select one from the list or input its id)", $warriorsAsKeyboard);
         updateUserState($user, json_encode(array('state' => 'deleteWarrior')));
      } else if (explode(" ", $update['text'])[0] == '/sim') {
         if (!in_array($update['from']['id'], $admins)) {
            sendMsg($update['from']['id'], "You are not the boss", array(array('I am not the boss', 'I am not the boss'),array('I am not the boss', 'I am not the boss')));
            exit;
         }
         $c = explode(" ", $update['text']);
{'fraction_non_alphanumeric': 0.18901404104304892, 'fraction_numerical': 0.0009257830581700355, 'mean_word_length': 2.8869565217391306, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1236324', 'n_tokens_mistral': 3853, 'n_tokens_neox': 3817, 'n_words': 1064}