User:Petan-Bot/source/9

public ref class task_7 : t { public: void Init {		TLog(6, "Initialising task #7"); active = true; TLog(6, "OK"); }	int Do {		Thread::Sleep(40000); PageList ^list; list = gcnew PageList(enwiki); String ^ pn; Page ^ user; String ^ token; String ^ talk; String ^ check1; String ^ check2; Page ^ prt; Log("Loading"); list->FillFromCategory("AfC submissions in userspace"); for each (Page^ sb in list) {		pn = sb->title; sb->Load; check1 = sb->text; talk = sb->title; talk = System::Text::RegularExpressions::Regex("User:").Replace(talk, "User talk:"); talk = System::Text::RegularExpressions::Regex("\\/.*").Replace(talk, ""); pn = System::Text::RegularExpressions::Regex("^User\\:.*\\/").Replace(pn, ""); Log(pn); try {		prt = gcnew Page(enwiki, "Wikipedia talk:Articles for creation/" + pn); prt->Load; if ( (pn->Contains("Wikipedia talk:") != true ) && (pn->Contains("Articles for") != true ) && (pn->Contains("User:") != true ) && ("" == prt->text)) {			token = enwiki->GetPageHTM(enwiki->indexPath + "api.php?action=query&titles=" + System::Web::HttpUtility::UrlEncode(sb->title) +"&format=xml&prop=info&intoken=move"); token = System::Text::RegularExpressions::Regex::Match(token, "movetoken=\\\".*\\\"")->Value; token = token->Replace("movetoken=", ""); token = token->Replace("\"", "");			Log(enwiki->PostDataAndGetResultHTM(enwiki->indexPath + "api.php?action=move", "from="+ System::Web::HttpUtility::UrlEncode(sb->title) +	"&to=" +  System::Web::HttpUtility::UrlEncode("Wikipedia talk:Articles for creation/" + pn) + "&token="+ System::Web::HttpUtility::UrlEncode(token) +"&reason=Moving to " + System::Web::HttpUtility::UrlEncode("AFC space (bot)")  ));			delete prt;			prt = gcnew Page (enwiki, "Wikipedia talk:Articles for creation/" + pn);			prt->Load;			check2=prt->text;			if ( check2 == check1 ) //the page has been moved				//Wikipedia:Bots/Requests_for_approval/Petan-Bot_task9			{			user = gcnew Page(enwiki, talk);			user->Load;			user->text = user->text + "\n\n"+ sb->title + "\n";			user->Save(user->text, "Informing user about the move (task 9)", false); delete user; if (prt->text->Contains("{{Userspace draft")) {				//prt->text->Replace("{{userspacedraft}}", "");

prt->text=System::Text::RegularExpressions::Regex("{{\\s*Userspace\\sdraft.*}}").Replace(prt->text, "");

prt->Save(prt->text, "Removing {{UserSpace}} (task9)", false); }			}		} 		}		catch (Exception ^ px) {		}		delete prt; Thread::Sleep(12000); }		return 2; } };