Wikipedia Script

Alphonse Kane

New member
Uses the visit_url function and several of the string handling routines to access Wikipedia and process the data. I use it as part of a chatbot script. Set it as the chatbotScript in your settings file, then have anyone send a private message to the bot. Whatever the message is, it will be looked up on wikipedia and formatted. I've had a few problems with it before, especially on articles with excessive HTML tags, and it doesn't always show the results rright. I tested it with the articles for "dance", "bookie" and "fish", and "bookie" showed up best.

Anyways, my primary motivation for this program was boredom.

Code:
void main(string sender, string message)
{
	string space = " ";
	string plus = "+";
	print("Formatting search...");
	message=replace_string(message,space,plus);
	print("Locating article...");
	string urlbase = "http://en.wikipedia.org/wiki/Special:Search?search=";
	string raw = visit_url(urlbase+message);
	int beginning=index_of(raw,"<p>");
	print("Clipping article...");
	raw=substring(raw,beginning,beginning+500);
	print("Formatting final response...");
	string working=raw;
	int incr=0;
	while (contains_text(working,"<") && (incr < 14))
	{
		if (contains_text(working,">"))
		{
			working=replace_string(working,substring(working,index_of(working,"<"),index_of(working,">")+1),"");
		}
		else
		{
			working=replace_string(working,substring(working,index_of(working,"<")),"");
		}
		incr=incr+1;
	}
	if(contains_text(working,"Contents"))
	{
		working=replace_string(working,substring(working,index_of(working,"Contents")),"");
	}
	print("Sending clip...");
	chat_reply(message+": "+working);
	print("Done.");
}
 
Top