I've been working on a bot script for my clan for some time now, and I keep getting stuck on KMail parsing - not on how I can parse it, but on what would be the most optimal/efficent way to go about it.
Right now, it is built with recursion, so it will parse 10 KMails at the same time (or however many are in the inbox). They're returned into 10 Maps.
The problem is, I would like to build a functionally-similar parser that can be called from a "library", and I was wondering how I should go about it.
Can you program a function to return a map? If so, how should I organize it to pull in multiple KMails? Also (I haven't worked with Javascript), how can I delete messages?
Right now, the code is:
But that seems unnecessarily messy. So, I'll be working on revising it. Just wondering what the most efficent way to organize it would be...
Right now, it is built with recursion, so it will parse 10 KMails at the same time (or however many are in the inbox). They're returned into 10 Maps.
The problem is, I would like to build a functionally-similar parser that can be called from a "library", and I was wondering how I should go about it.
Can you program a function to return a map? If so, how should I organize it to pull in multiple KMails? Also (I haven't worked with Javascript), how can I delete messages?
Right now, the code is:
Code:
# kmail_message1[1] = "This is the Player ID#";
# kmail_message1[2] = "this is the Username";
# kmail_message1[3] = "This is the timestamp";
# kmail_message1[4] = "This is the message";
void kmail_extractor()
{
messages_html = visit_url( "messages.php" );
# Now we do the do-once parsing of the pwd value
sewerpackbot_pwd_start = index_of( messages_html , "name=pwd value=\"" ) + 16;
sewerpackbot_pwd_end = index_of( messages_html , "\"><input type=hidden", sewerpackbot_pwd_start );
print( sewerpackbot_pwd );
kmail_recursion_counter = 1;
while( kmail_extraction_termination != 1 )
{
# Extraction of the selected message's data follows. MESSAGE_SKIP is a value that is ajusted to enable the recursion.
kmail_playerid_start = index_of( messages_html , "showplayer.php?who=" , message_skip ) + 19;
kmail_playerid_end = index_of( messages_html , ">" , kmail_playerid_start ) - 1;
if( kmail_playerid_start >= kmail_playerid_end )
{
print( "The KMail extractor has failed while attempting to extract the PlayerID" );
#FIGURE OUT WHAT TO DO HERE TO RECTIFY PROBLEM
}
kmail_playerid = substring( messages_html , kmail_playerid_start , kmail_playerid_end );
print( kmail_playerid );
kmail_username_start = kmail_playerid_end + 1;
kmail_username_end = index_of( messages_html , "</a>" , kmail_username_start );
kmail_username = substring( messages_html , kmail_username_start , kmail_username_end );
print( kmail_username );
kmail_timestamp_start = index_of( messages_html , "</b><!--" , message_skip ) + 8;
kmail_timestamp_end = index_of( messages_html , "--><br><blockquote>" , kmail_timestamp_start );
kmail_timestamp = substring( messages_html , kmail_timestamp_start , kmail_timestamp_end );
print( kmail_timestamp );
kmail_message_start = index_of( messages_html, "--><br><blockquote>" , message_skip ) + 19;
kmail_message_end = index_of( messages_html, "</blockquote></td", kmail_message_start );
kmail_message = substring( messages_html, kmail_message_start, kmail_message_end );
print( kmail_message );
message_skip = index_of( messages_html , kmail_message_end , "<input type=checkbox name=" );
#SOME SORT OF ERROR PROTECTION NECESSARY HERE!
if ( kmail_recursion_counter == 1 )
{
kmail_message1[1] = kmail_playerid;
kmail_message1[2] = kmail_username
kmail_message1[3] = kmail_timestamp;
kmail_message1[4] = kmail_message;
}
if ( kmail_recursion_counter == 2 )
{
kmail_message2[1] = kmail_playerid;
kmail_message2[2] = kmail_username
kmail_message2[3] = kmail_timestamp;
kmail_message2[4] = kmail_message;
}
if ( kmail_recursion_counter == 3 )
{
kmail_message3[1] = kmail_playerid;
kmail_message3[2] = kmail_username
kmail_message3[3] = kmail_timestamp;
kmail_message3[4] = kmail_message;
}
if ( kmail_recursion_counter == 4 )
{
kmail_message4[1] = kmail_playerid;
kmail_message4[2] = kmail_username
kmail_message4[3] = kmail_timestamp;
kmail_message4[4] = kmail_message;
}
if ( kmail_recursion_counter == 5 )
{
kmail_message5[1] = kmail_playerid;
kmail_message5[2] = kmail_username
kmail_message5[3] = kmail_timestamp;
kmail_message5[4] = kmail_message;
}
if ( kmail_recursion_counter == 6 )
{
kmail_message6[1] = kmail_playerid;
kmail_message6[2] = kmail_username
kmail_message6[3] = kmail_timestamp;
kmail_message6[4] = kmail_message;
}
if ( kmail_recursion_counter == 7 )
{
kmail_message7[1] = kmail_playerid;
kmail_message7[2] = kmail_username
kmail_message7[3] = kmail_timestamp;
kmail_message7[4] = kmail_message;
}
if ( kmail_recursion_counter == 8 )
{
kmail_message8[1] = kmail_playerid;
kmail_message8[2] = kmail_username
kmail_message8[3] = kmail_timestamp;
kmail_message8[4] = kmail_message;
}
if ( kmail_recursion_counter == 9 )
{
kmail_message9[1] = kmail_playerid;
kmail_message9[2] = kmail_username
kmail_message9[3] = kmail_timestamp;
kmail_message9[4] = kmail_message;
}
if ( kmail_recursion_counter == 10 )
{
kmail_message10[1] = kmail_playerid;
kmail_message10[2] = kmail_username
kmail_message10[3] = kmail_timestamp;
kmail_message10[4] = kmail_message;
}
kmail_recursion_counter = kmail_recursion_counter + 1;
if( kmail_recursion_counter == 11 )
{
kmail_extraction_termination = 1;
}
}
}
But that seems unnecessarily messy. So, I'll be working on revising it. Just wondering what the most efficent way to organize it would be...
Last edited: