Commit 0ee4f6de authored by GROSS-AMBLARD David's avatar GROSS-AMBLARD David
Browse files

Adds bots to users (add NBBOTS in config.php - see config.php.example).

Reset will populate these bots, named Allgaier<num>.
parent 5686f650
......@@ -102,6 +102,40 @@ function executeSqlFile($file_name, $conn){
}
}
/**
* createBots
* create an armada of bots as users
* @param $conn: a valid PDO connection
* @param $nbbots: the number of bots to create
*/
function createBots($conn,$nbbots){
$namePrefix="Allgaier";
$conn->query("delete from Skills where iduser in (select id from Users where name like '$namePrefix%')");
$conn->query("delete from UserProfile where id in (select id from Users where name like '$namePrefix%')");
$conn->query("delete from Users where name like '$namePrefix%'");
for($i=1;$i<=NBBOTS;$i++){
$botname="$namePrefix$i";
$pwd="bot";
$stmt = $conn->prepare("insert into Users(name,hashed_password) values(:name,:pwd)");
$stmt->bindParam(':name', $botname, PDO::PARAM_STR);
$stmt->bindParam(':pwd', $pwd, PDO::PARAM_STR);
$pwd=password_hash($pwd, PASSWORD_DEFAULT);
$stmt->execute();
$stmt = $conn->prepare("select * from Users where name=:username");
$stmt->bindParam(':username', $botname, PDO::PARAM_STR);
$stmt->execute();
$result =$stmt->setFetchMode(PDO::FETCH_ASSOC);
$line=$stmt->fetch();
$id=$line['id'];
// Any user has the "common knowledge" skill
$conn->query("insert into Skills values ($id,1,100)");
$conn->query("insert into UserProfile values ($id,'I am a bot and proud of it.',365,0)");
}
}
/**
* nextTaskFromArtifact
*
......@@ -282,7 +316,7 @@ function insertTaskFeedback($conn, $idtask, $feedbackText, $targetTable)
"idtask" => $idtask,
"text" => $feedbackText,
"iduser" => $user
));// or die(mysql_error());
));
}
/**
......
......@@ -34,5 +34,7 @@ define("DEBUG",false);
define("WIRKPROJECTENDPOINT","https://api.wirk.io/v1_0/AppProject");
define("WIRKTASKLINEENDPOINT","https://api.wirk.io/v1_0/TaskLine");
// Bot parameters
define("NBBOTS",10);
?>
......@@ -132,6 +132,7 @@ switch ($mode) {
case "restart":
restart($conn);
initialize($conn);
createBots($conn,NBBOTS);
showTasks($conn);
break;
case "showState":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment