Yeah, I've done that many, many times. Just declare a map of the same format as you normally save (or really any map format should work), and then do map_to_file() before actually putting any data in the map. Just make sure that when you go to turn the file back into a map, you check to see if it has data with count() first.
Edit to answer your first question:
That script of yours has several issues. Please take a look at this...
PHP:
record note {
string sender;
string message;
string timestamp;
};
void main(string sender, string message) {
note [int] pm_log;
//load previous
if (! file_to_map("PMlog.txt", pm_log)) abort("Unable to load previous.");
//add this message to map
pm_log[count(pm_log)] = new note(sender, message, now_to_string("20110130 05:16:02");
//save updated map
if (! map_to_file(pm_log, "PMlog.txt")) abort("Unable to save pm log.");
if (contains_text(message, "talk")) {
//not sure what's going on; see below
}
}
Regarding the comment of "not sure what's going on":
It looks like you're saying that if you receive a pm with the text "talk" in it, you want to send a separate private message to the sender copying every single pm you've received since the log was cleared? That doesn't seem right... for one, sharing others' pm's is generally frowned on pretty heavily. For two, it could be quite spammy. If you have a different goal in mind, please feel free to let me know and I'd be happy to help. But I'm not assisting with anything that spammy and likely to be frowned on by TPTB.
Edit 2 regarding the second question, partially answered above:
Put the following in your login script:
PHP:
record note {
string sender;
string message;
string timestamp;
};
note [int] clearthem;
if (!get_property("_chatLogCleared").to_boolean()) {
if (map_to_file(clearthem, "PMlog.txt") {
set_property("_chatLogCleared","true");
} else {
abort("Unable to clear chat log; do so manually now!");
}
}
The property will get cleared automatically by mafia on your first login of the day, so if your chatbot gets halted & restarted for any reason, you'll still keep the day's log saved.