GambleBot!

Rahmuss

Member
slyz - Thanks for the help. I'm still trying to really learn the RegExes, I can see how they can be very helpful with a bot. I hope I can get other things to work just as well.

Theraze - Yep, that's probably true. Most likely no one would use "D"; but who knows, if that wasn't in there some frustrated English major may be cursing at his computer because it's not working. :D
 

Theraze

Active member
slyz... one issue with what you posted is that you only return a single result, which may be useful in some cases, but won't allow for actual use in dice games. If you wanted to do Yahtzee or Zonk/Farkle, as standard pure d6 examples, you need to know what each die had, not just the total of all the dice. If you try to run a PnP game through chat, you need to know whether your d10/d20/dwhatever rolls are a success or not, not just what their total is...
 

Rahmuss

Member
Does this work?:

Code:
void main( string sender , string message )  {

    string text = message;
    matcher dice_matcher = create_matcher( "\\b(\\d+)[dD](\\d+)\\b", text); 

    if ( text.contains_text( "roll" ) && dice_matcher.find() )  {
        int num = dice_matcher.group( 1 ).to_int();
        int faces = dice_matcher.group( 2 ).to_int();
        int result = 0;

        if ( faces == 0 )  {
	    abort( "0-faced die do not exist in an Euclidian paradigm." );
	    chat_clan("Nice try small fry.  There are no 0-sided die silly.");
        }
        if ( faces == 1 )  {
	    abort( "1-faced die do not exist in an Euclidian paradigm." );
	    chat_clan("Oooo, wow, that would give some... uhm... interesting results.  Try again.");
        }
        if ( num == 0 )  {
	    abort( "Not throwing any die will NOT give a random result, you know." );
	    chat_clan("Ok, so you actually don't want me to roll any die?");
        }
        chat_clan( "Rolling " + num + " d" + faces + " ..." );
        for i from 1 to num  {
	    result = random( faces ) + 1;
        print( "Result: "+ result );
        }
    }
    else  { 
        print( "Usage: 'roll <xxx>d<yyy>' where xxx is the number of yyy-faced die to roll." ); 
    }
}
 

Theraze

Active member
First comment... reverse chat_clan and aborts... once you've aborted, that's it, so the chats never happen.

Second, you'll want to display each result as it happens, not just the total.

Third, just noticed this... faces should probably match on group 3. Group 2 is probably the [dD] match, and you don't want it to have "d" faces... Possibly I'm wrong on this, but I've had issues with regexps in the past where I did things like that.

Edit: Try this:
PHP:
void main( string sender , string message )  {
 string text = message;
 matcher dice_matcher = create_matcher( "\\b(\\d+)[dD](\\d+)\\b", text); 
 if ( text.contains_text( "roll" ) && dice_matcher.find() )  {
  int num = dice_matcher.group( 1 ).to_int();
  int faces = dice_matcher.group( 2 ).to_int();
  string result;
  if ( faces == 0 )  {
   chat_private( sender, "Nice try small fry.  There are no 0-sided die silly.");
   return;
  }
  if ( faces == 1 )  {
   chat_private( sender, "Oooo, wow, that would give some... uhm... interesting results.  Try again.");
   return;
  }
  if ( num == 0 )  {
   chat_private( sender, "Ok, so you actually don't want me to roll any die?");
   return;
  }
  chat_clan( "Rolling " + num + " d" + faces + " ..." );
  for i from 1 to num  {
   result.append(to_string(random( faces ) + 1) + (i == num) ? "" : ", "));
   chat_clan( "Result: "+ result );
  }
 }
 else  { 
  chat_private( sender, "Usage: 'roll <xxx>d<yyy>' where xxx is the number of yyy-faced die to roll." );
 }
}

Edit2: Technically, 1 sided dice do exist... they're called balls. Same side always ends up regardless how many times you throw it. Unless you manage to make it invert, the outside always end facing up... wacky objects that they are.
 
Last edited:

slyz

Developer
Sorry Theraze, I didn't notice your ninja edit =)

Oh, and I added the aborts in my snippet, but you're probably better off sending a message and then exiting (just replace the abort( "message" ); with return; ).

And [] isn't a capture group, so you should keep "int faces = dice_matcher.group( 2 ).to_int();"
 
Last edited:

Theraze

Active member
Ah... yeah, I think I'd done ([dD]) or something like that instead. Okay, edited above to set back to group 2 matching, left my incorrect pondering in the thread since, hey, it makes more sense if you can read it all in context. :D

Edit: Tweaked above code to not abort, but return instead. Also set it to chat_private if roll fails, and chat_clan if results happen. Getting gCLI logs on the chatbot doesn't really help the requestor know how they did. :)
 
Last edited:

Rahmuss

Member
Theraze - Thanks again for the help. I tried to change it so that it didn't total the results, did I do it wrong? If so, then how should I code it?
What does print() do instead of chat_clan()? It seems like print() would either just display to the CLI or it might try to print it into any chat channel that you're in; but I thought it only worked for clan chat now???
 

Rahmuss

Member
Thanks Winterbay, maybe it would be a good idea to keep a log of the rolls just in case there is a dispute. Though a timestamp may be needed. Oh, that reminds me. Anyone know how if there is a kind of pause() function?

EDIT: wait(30); ???
 

Theraze

Active member
True... your version did display every roll with "Result: 1" "Result: 5" and so on. Not really good though if you have someone roll 500 dice.

Print only displays to gCLI and log, as Winterbay said. So nobody but the person running the bot would see it, and they would only see it if they actually go to check. Better to print out what you're sending instead of each roll individually.

Yes, wait(30) would pause for 30 seconds. Or you can use waitq if you'd like a silent delay. Just remember that while it's paused, I don't think anything will happen... so even if someone else sends another message, it'll wait for that to finish up before moving on.
 

Rahmuss

Member
Theraze - I already got the main gamble bot script from mredge73, so this is just an additional part for the chat bot to roll regular die for anything that our clan might need. I'll probably put a limit so that they cannot do more than 10 die or something. Anyway, thanks again for all the help.
 

Theraze

Active member
Yes... I don't think you want to put a wait timer in there, since his only wait is when the bot is shutting down. But maybe I'm misunderstanding the way that chatbots run, and putting in waits won't screw up additional processing. :)
 

Rahmuss

Member
Not sure where else to ask these two questions, so I'll just ask here.

I can get the messages into the PMlog.txt file and I can open the file and see what's in there; but can I have my bot spit out one or more lines from the log? Here is what I tried:

Code:
void main( string sender , string message )  {
	print("Incoming message from " +sender+ " saying:  "+message,"olive");	
	string text = message;

	record note  {
		string sender;
		string message;
	}
	[int] PMlog;

	File_to_Map("PMlog.txt",PMlog);
	int newPM= count(PMlog);
	PMlog[newPM].sender= sender;
	PMlog[newPM].message= message;
	Map_to_File(PMlog,"PMlog.txt");	
	talkint = newPM;

	if (text.contains_text( "talk" ))  {
		for i from 0 to talkint  {
		chat_private(sender, PMlog[i] + " :: ";
	}
}

My second question is, how do I get it to clear the file so that it's empty when I log in. I want to be able to spit out everything that was said; but only what's been logged in that file from the time I logged in. So if I log off at rollover, and log back in, I want the file to start from scratch, or else have some way of only printing what has been done since the time I logged in.
 

Winterbay

Active member
That last part should be possible by doing a file_to_map on a empty variable in your logout script I guess.
 

StDoodle

Minion
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.
 
Last edited:

Rahmuss

Member
StDoodle - What I'm trying to do is basically setup a log so that people can leave a message for anyone in the clan. We don't want tons of clan announcements made; but we want these short messages available upon request. It actually won't be all PMs to the bot, it will only be PMs which contain a key word.

And thanks for the help on that second question as well. I'll have to see how that works.
 

StDoodle

Minion
Are you asking for a message board functionality, where all messages are given to everyone? Or more of a "delayed PM" functionality, where you can leave messages for offline clannies? Or both? If you let me know, I'd be happy to edit that functionality in there. (Desired format for messages of ea. kind would be needed.)
 

mredge73

Member
unofficial release

Gamblebot.ash
Preliminary chat support for Rolling the Dice
dice roll stole from this thread, chat bot stuff was imported from my bot. I haven't completely cleaned it up but it does work as is.

publicroll xx[dD]yy will display results in both the clan channel and PM
roll xx[dD]yy will PM the person asking for the roll

Requires PM logger.
 

Attachments

  • GambleBot.ash
    15 KB · Views: 28
  • PMlogger.ash
    476 bytes · Views: 23
Last edited:

mredge73

Member
Rahmuss
I have implemented a note taking feature as well on my clan bot.
It is pretty easy, give me a while and I may be able to build an example.
 

Rahmuss

Member
It will be all messages sent to the chatbot that day with the special key word. So this is what would happen:

/msg clanchatbot keyword Tell clan this.
... an hour later...
/msg clanchatbot newmessages

clanchatbot: Tell clan this
(this would be to the clan chat window).

Usually we'd get maybe 2 or 3 messages a day, though on a busy day with a lot of things going on that need to be coordinated we may have as many as 10 messages.

EDIT: mredge73 - Great! Thanks for the update. That'll make it easier for me to incorporate it all.
 
Last edited:
Top