chatbotScript

Subsonice

New member
I'm trying to setup the most simple chatbot ever. It will evolve into something else later, but I'm just trying to get the most basic function to work.

Here's the script.ash:

void main(string sender, string message){
print(sender + ": " + message , "green");
}

So it's just logging the private message. I have chatbotScript=script.ash . I even have chatbotScriptExecuted=true, even though, looking at the source code, it's not even being used here. The script runs fine if I run it from the KolMafia gCLI, and I specify my own parameters, and logs the message in the gCLI.

But, it's not running when I receive a private message. The private message shows up in chat, and showing up in gCLI as a regular PM, but it's not running the script. Any ideas here?

Thanks.
 

StDoodle

Minion
try declaring
Code:
void main(string sender, string message, string channel) {
...
}

This will give you access to channel info, which will be empty for pm's.
 

Subsonice

New member
try declaring
Code:
void main(string sender, string message, string channel) {
...
}

This will give you access to channel info, which will be empty for pm's.

I tried this before, and just tried it again. It still doesn't respond to PMs. I'm not sure that if the problem is with the script, because I'm using a script that the wiki and other people have used, and it works fine for them, I suppose. When I run the script manually from KolMafia, it works fine. Something is not triggering the script to run. I'm using v14.6 on Windows XP.

Thanks for your response : )
 

slyz

Developer
Depending on your system, you might want to make sure that the name of the script file is in lower case too.

What does the gCLI say when you try "get chatbotScript"?
 

mredge73

Member
Extra simple logging script:

Code:
## Use this script by placing it in your scripts directory and typing "set chatbotScript=ChatLogger.ash" into the gCLI.
void main( string sender , string message, string channel )
{
    if (channel=="")
    {    
        channel="PM";
        print("Incoming PM from " +sender+ " saying:  "+message,"blue");    
    }    
    else
    {
        print("Listening to "+channel+", Incoming from: " +sender+ " saying:  "+message,"green");
    }
    record note
    {
        string sender;
        string message;
        string channel;
        int date;
    }[int] ChatLog;
    
    File_to_Map("ChatLog.txt",ChatLog);
    int NE= count(ChatLog);
    while (ChatLog[NE].sender != "") NE=NE+1;
    
    
    ChatLog[NE].sender= sender;
    ChatLog[NE].message= message;
    ChatLog[NE].channel= channel;
    ChatLog[NE].date= today_to_string().to_int();
    Map_to_File(ChatLog,"Chatlog.txt");    
}
Be sure to set it as your chatbotScript.
"set chatbotScript=ChatLogger.ash"

Note: Big "S"
 

Grotfang

Developer
I believe this issue has been corrected. For completionists out there, 14.6 came before some in-game changes were made to chat that broke our reception of them. Downloading a daily build resolved the issue.
 

Pazleysox

Member
Code:
    record note
    {
        string sender;
        string message;
        string channel;
        int date;
    }[int] ChatLog;
    
    File_to_Map("ChatLog.txt",ChatLog);
    int NE= count(ChatLog);
    while (ChatLog[NE].sender != "") NE=NE+1;
    
    
    ChatLog[NE].sender= sender;
    ChatLog[NE].message= message;
    ChatLog[NE].channel= channel;
    ChatLog[NE].date= today_to_string().to_int();
    Map_to_File(ChatLog,"Chatlog.txt");    
}
[/QUOTE]

Is there a way to set this to keep only the last 30 things said?
 
Is there a way to set this to keep only the last 30 things said?

Code:
record note
{
string sender;
string message;
string channel;
int date;
}[int] ChatLog;

File_to_Map("ChatLog.txt",ChatLog);
/*
int NE= count(ChatLog);
while (ChatLog[NE].sender != "") NE=NE+1;
*/
// Get the actual upper bound
int NE = 0;
foreach i in ChatLog {
NE = i; 
}


ChatLog[NE].sender= sender;
ChatLog[NE].message= message;
ChatLog[NE].channel= channel;
ChatLog[NE].date= today_to_string().to_int();

NE -= 30;
while( ChatLog contains NE ) {
remove ChatLog[NE];
NE -= 1;
}

Map_to_File(ChatLog,"Chatlog.txt");
}

Maybe not perfect and could possibly leave some orphans for manual cleanup but should generally do the trick.

edit: actually I just realized what I had was going to break it, that NE = count(ChatLog) is not going to work for long, so changed that. This will eventually break when you hit maxint. Didn't test, possible syntax errors. I don't know of any way to get the last or first entry in an int map except roundabout via foreach.
 
Last edited:
Top