Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Chatlogger for forum posting

Patch Lamington
Blumfield SLuburban
Join date: 2 Nov 2005
Posts: 188
01-28-2006 01:35
This is an unfinished script, posted just now as I wont have time to work on it for a while...
Listens to chat on channel 0, replays chat ready for cut and pasting into forum posts with colouring.

Needs more work :)
Could be re-written to use two lists instead of three.
Needs more colours.
Could use email instead of ownersay for replay.
Should inform all avatars that logging is in progress.
Could be more efficient.
Usual rules of TOS and common decency apply in using this, etc etc....

ps did send this to Library a couple of days ago, so apologies for cross-posting if it does appear there later.

CODE

list names;
list speech;
list colours=["002EB8","FF6633","006600","660066","660033","663300","1A9900","FF14B1","001A99","#B88A00"];
list unique_names;
integer listenID;

default
{
state_entry()
{
llSetText("This is a chat logger - currently only for testing",<0,0,0>,1.0);
integer i;
integer c;
for (i=0;i<llGetListLength(names);i++)
{
c = llListFindList(unique_names,llList2List(names,i,i));
while (c >= llGetListLength(colours))
c -= llGetListLength(colours);
llSetObjectName("" + llList2String(names,i) );
llOwnerSay( llList2String(speech,i) + "
" );
}
names = [];
speech = [];
unique_names = [];
llSetObjectName("Patch's Funky Chat Logger");
llOwnerSay("Free memory: " + (string)llGetFreeMemory() + "bytes");
}

on_rez(integer i)
{
//names = [];
//speech = [];
//unique_names = [];
llResetScript();
}

touch_start(integer total_number)
{
if (llDetectedKey(0) == llGetOwner() )
{
llOwnerSay("logging on!.");
state logging_chat;
}
}
}

state logging_chat
{
state_entry()
{
listenID = llListen(0,"",NULL_KEY,"");
}

on_rez(integer i)
{
//state default;
llOwnerSay("Logging still on!");
}

touch_start(integer total_number)
{
if (llDetectedKey(0) == llGetOwner() )
{
llSay(0, "chat logging now off - replaying log!.");
state default;
}
}

listen(integer channel, string name, key id, string message)
{
if (llGetFreeMemory() < 1000 )
{
if (llGetFreeMemory() < 200 )
{
llSay(0, "Chat log full. Stopping recording. Owner touch to playback.");
llListenRemove(listenID);
}
else if (llGetFreeMemory() > 800)
llOwnerSay("Chat log warning: Less than 1000 bytes remaining.");
}


if(llListFindList(unique_names,[name]) == -1)
{
unique_names += name;
}
names += name;
speech += message;
}

}
_____________________
Blumfield - a regular everyday kind of 'burb in an irregular world.
This notice brought to you by the Blumfield Visitors and Residents Bureau.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-28-2006 01:41
I'd have it dump to email and clear the log, rather than just stop - chat loggers can fill up very fast.

Also, is llGetFreeMemory reliable now to see if one is running out of memory? All the documentation I saw when checking it a while back said it wasn't and one should just cap list size instead.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
01-28-2006 04:36
I do one of these for another function and email it out as the length of the transcript reaches 3,500 characters (gives me a pad for the header and the previous line reaching 3,499 characters...

I do a different one with a catch to send if llGetFreeMemory gets too low and it seems to work OK in most circumstances - clearing the memory out and calling llGetFreeMemory may not be 100% reliable, but it's not totally borked either.
Patch Lamington
Blumfield SLuburban
Join date: 2 Nov 2005
Posts: 188
01-28-2006 05:43
From: Ordinal Malaprop
I'd have it dump to email and clear the log, rather than just stop - chat loggers can fill up very fast.


Aware of that. With email will the script delay mean that chat will be lost? Im aware workarounds, but as I said, not much time to work on it just now :-)

I will go back to it, probably next week, or week after.
_____________________
Blumfield - a regular everyday kind of 'burb in an irregular world.
This notice brought to you by the Blumfield Visitors and Residents Bureau.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-28-2006 06:13
From: Patch Lamington
Aware of that. With email will the script delay mean that chat will be lost? Im aware workarounds, but as I said, not much time to work on it just now :-)

I will go back to it, probably next week, or week after.

Potentially, yeah, I think, so you might want to use a separate server script to do that - one listen script that keeps a short list, and sends link messages to another script that handles more extensive logging and sending email. I think I've done this at some point. There's also the advantage that the email script will have a little more memory available to it.

Actually, that reminds me, I did say I'd make a chatlogger for someone myself, so I'll do that now.
Gwyneth Llewelyn
Winking Loudmouth
Join date: 31 Jul 2004
Posts: 1,336
Colourizing transcripts... but on PHP instead!
02-05-2006 09:25
Slightly off-topic, I used Ulrika's transcript colourizer to post transcripts online; it has the advantage of splitting up pieces of a transcript to properly format the code in "chunks" to be easily posted on the forums.

Alas, Ulrika's site has been down often, and yesterday I was desperate, so I thought to create my own PHP script instead. Feel free to use it; it's released on an "attribution" license of Creative Commons (do whatever you wish with it, but quote me ;) ).

I'm not a programmer, so I guess lots of things could be done more efficiently; you're welcome to laugh at my amateurish accomplishments :) If you don't have a webserver with PHP to try this out, you can test it here. Notice that you might need to tweak the CSS styles for your own purpose, but I guess the defaults will work well.

CODE
<!DOCTYPE html 
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="css/styles.css" type="text/css" media="all" />
<meta name="author" content="Gwyneth Llewelyn" />
<meta name="copyright" content="(cc) 2006 by Gwyneth Llewelyn. Some rights reserved." />
<title>Gwyn's Colourizer PHP Script</title>
</head>
<body>
<h1>Gwyn's Colourizer PHP Script</h1>

<?php

// Simple PHP colour-coding script for meeting transcripts
// (cc) 2006 by Gwyneth Llewelyn. Some rights reserved.
// Feel free to copy and improve upon it, and, if you're nice, mention my name or
// send me a donation of L$1 :)

if (!isset($text))
{
// No data yet, let's draw those nice forms and all!
?>
<form action="colour-code.php" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">Text to colourize:</td>
</tr>
<tr>
<td colspan="2">
<textarea name="text" rows="30" cols="100">Insert your transcript here.</textarea>
</td>
</tr>
<tr>
<td colspan="2">
Options:
</td>
</tr>
<tr>
<td>
Your Name: (replaces "You:")
</td>
<td>
<input type="text" name="You" size=32 value="Unknown Avatar" />
</td
</tr>
<tr>
<td>
Use bold for names?
</td>
<td>
<input type="checkbox" name="useBoldForNames" value="true" checked />
</td>
</tr>
<tr>
<td>
Use underline for names?
</td>
<td>
<input type="checkbox" name="useUnderlineForNames" value="true" />
</td>
</tr>
<tr>
<td>
Check SL forum post size limit?
</td>
<td>
<input type="checkbox" name="checkPostSizeLimit" value="true" checked />
</td>
</tr>
<tr>
<td>
Use vBulletin/phpBB/TikiWiki/HTML code?
</td>
<td>
<select name="phpBB">
<option selected value="1">vBulletin/phpBB</option>
<option value="0">HTML</option>
<option value="2">TikiWiki</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit" />
</td>
</tr>
</table>
</form>

<?
}
else
{
// Parameters to format names
/*
$useBoldForNames = true;
$useUnderlineForNames = true;
$checkPostSizeLimit = true; // this is to allow cutting the output for SL forum posts
$phpBB = true; // set it to FALSE to use plain HTML
$You = "Unknown Avatar";
*/

// A short list of colours. Add more for more fun!
if ($phpBB) // vBulletin/phpBB seem to allow for many colours
{
$colours = array("Black", "Sienna", "DarkOliveGreen", "DarkGreen", "DarkSlateBlue",
"Navy", "Indigo", "DarkSlateGray", "DarkRed", "DarkOrange",
"Olive", "Green", "Teal", "Blue", "SlateGray", "DimGray", "Red",
"SandyBrown", "YellowGreen", "SeaGreen", "MediumTurquoise",
"RoyalBlue", "Purple", "Gray", "Magenta", "Orange", "Yellow",
"Lime", "Cyan", "DeepSkyBlue", "DarkOrchid", "Silver", "Pink",
"Wheat", "LemonChiffon", "PaleGreen", "PaleTurquoise",
"LightBlue", "Plum", "White",
"#00CC00", "#3300CC", "#660000", "#66CCCC", "#996600", "#CC3366",
"#330000", "#FFCC00", "#663300", "#666699", "#FF9966", "#990033",
"#3366FF", "#FFCCCC", "#99FF00", "#33CCCC", "#330066", "#99FFCC");
}
else // standard HTML defines less colours
{
$colours = array("Black", "Silver", "Gray", "Maroon", "Red", "Purple",
"Fuchsia", "Green", "Lime", "Olive", "Yellow", "Navy",
"Blue", "Teal", "Aqua",
"#00CC00", "#3300CC", "#660000", "#66CCCC", "#996600", "#CC3366",
"#330000", "#FFCC00", "#663300", "#666699", "#FF9966", "#990033",
"#3366FF", "#FFCCCC", "#99FF00", "#33CCCC", "#330066", "#99FFCC");
}

$coloursTotal = count($colours);
$currentColour = 0;

// Tags - changes depending on if we're using phpBB, HTML or TikiWiki

//print("Style is: $phpBB<br \>\n");

switch ($phpBB)
{
case "1":
define("COLOR", "";);
define("ITALICS", "";);
define("BOLD", "";);
define("UNDERLINE", "";);
define("COLOR_END", "
");
define("ITALICS_END", "");
define("BOLD_END", "");
define("UNDERLINE_END", "");
define("HR", "");
define("LINE_END", "\n");
break;
case "2":
define("COLOR", "~~");
define("COLOR_END_BRACKET", ":");
define("ITALICS", "''");
define("BOLD", "__");
define("UNDERLINE", "===");
define("COLOR_END", "~~");
define("ITALICS_END", "''");
define("BOLD_END", "__");
define("UNDERLINE_END", "===");
define("HR", "---");
define("LINE_END", "\n");
break;
default:
define("COLOR", "<span style=\"color:");
define("COLOR_END_BRACKET", ";\">");
define("ITALICS", "<i>");
define("BOLD", "<b>");
define("UNDERLINE", "<u>");
define("COLOR_END", "</span>");
define("ITALICS_END", "</i>");
define("BOLD_END", "</b>");
define("UNDERLINE_END", "</u>");
define("HR", "<hr>");
define("LINE_END", "<br />\n");
break;
}

define("MAX_SIZE_PER_POST", 29000);

// array that links avatar name with one of the above colours
$avatarNamesColours = array("nobody" => "#000000");
$talkMode = true; // to handle /me'd text differently - italics, etc.

$byteCount = 0; // SL forum posts have a maximum of 30000 bytes
$chopBlockCount = 0;

// fix wrong values that come via form...

if ($useBoldForNames == "true") $useBoldForNames = true;
if ($useUnderlineForNames == "true") $useUnderlineForNames = true;

// start spewing out code...

if (!$phpBB) print("<div id=\"two-col\">\n");
if ($checkPostSizeLimit) // put blocks of chopped text inside textareas
print ("<form action=\"#\" method=\"post\">\n<textarea name=\"text-$chopBlockCount\" rows=\"10\" cols=\"100\" readonly>\n");

$lines = explode( "\n", $text);

foreach ($lines as $line)
{
$line = stripslashes(trim($line));
$line = ereg_replace("^You:", $You . ":", $line); // replace You by your avatar name

// split line into words separated by spaces to extract the avatar name easily
$words = explode(" ", $line);

// check if we're "talking" or /me'ing
$talkMode = (substr($words[1], -1) == ":");

// for convenience, get the first two words, aggregate them into an avatar
// name, and check if we have a ":" at the end or not
$avatarName = $words[0] . " " . trim($words[1], ":");

// see if we have a colour for it on our array avatarName/colour;
// if not, add to it
if (!isset($avatarNamesColours[$avatarName]))
{
// add a new colour to the array
$avatarNamesColours[$avatarName] = $colours[$currentColour];
// cycle to next available colour, or start from the beginning
$currentColour++; if ($currentColour > $coloursTotal) $currentColour = 0;
}

// now output a line
unset($words[0]); // these have the avatar name; discard them!
unset($words[1]);

$outputLine = COLOR . $avatarNamesColours[$avatarName] . COLOR_END_BRACKET
. ($talkMode ? "" : ITALICS)
. ($useBoldForNames & $talkMode ? BOLD : "")
. ($useUnderlineForNames & $talkMode ? UNDERLINE : "")
. $avatarName
. ($useUnderlineForNames & $talkMode ? UNDERLINE_END : "")
. ($useBoldForNames & $talkMode ? BOLD_END : "")
. ($talkMode ? ": ": " ")
. implode(" ", array_values($words))
. ($talkMode ? "" : ITALICS_END)
. COLOR_END . LINE_END;

// check if we have reached the limit for SL forum posts
if ($checkPostSizeLimit)
{
$byteCount += strlen($outputLine);

if ($byteCount >= MAX_SIZE_PER_POST)
{
print HR;
$chopBlockCount++;
// put blocks of chopped text inside textareas
print ("</textarea>\n<br />\n<textarea name=\"text-$chopBlockCount\" rows=\"10\" cols=\"100\" readonly>\n");
$byteCount = 0;
}
}
print $outputLine;
}
if ($checkPostSizeLimit) // put blocks of chopped text inside textareas
print ("</textarea>\n</form>\n");
if (!$phpBB) print("</div>\n");
}
?>
</body>
</html>


In the mean time, I just found out that Ulrika's website is up again! Ah well. Her script has a tiny bug dealing with the /me'd messages (which I handle differently), but it should actually work faster, since as I understand it, she does her programming in Perl, which should be much more efficient at dealing with string parsing.

EDIT 20060506: I had forgotten to post here the latest version, which adds TikiWiki colouring for those of you who need to post transcripts to Wikis.
_____________________