I know there are probably easier ways in doing this...but I started a sub that is supposed to save the name of an individual in a list referencing their name with their screenname.
This is the code in on_im.pl that has the bot check if it knows the individual:
Code:
if ($msg =~ /^(Howdy|Anybody|Hello|Hi|Hey|Yo|How's it going|Hows it going|Whats up|What up|What's up|Help)$/i) {<br /> $reply = names($victim,$msg);<br />}
I know this works because I've "peppered" the sub names() code with print commands.
This is the sub names() in file names.pl
Code:
sub names {<br /><br /> my $victim = shift;<br /><br /> open (NAME, "names.txt");<br /> @names = <NAME>;<br /> close(NAME);<br /> chomp(@names);<br /><br />print "Opening sub names\n";<br /><br /> foreach my $line (@names) {<br /> ($sn,$name) = split(/\]\[/,$line);<br /><br />print "Checking victim against list of names\n";<br /><br /> if ($sn eq $victim) {<br /> @rname = split(/\|/,$name);<br /> my $reply = "Hi " . $rname [ int(rand(scalar(@rname))) ] . ", welcome back! <br>Start by typing MENU.";<br /><br />print "Found person\n\n";<br /><br /> $found = 1;<br /> break;<br /> } else {<br /><br />print "Couldn't find person\n\n";<br /><br /> my $reply = "Hello. I'm here to help you with your programming questions. <br>Start by typing \"My name is \" followed by what you'ld like me to call you.";<br /> $found = 1;<br /> }<br /> }<br /><br /> return $reply,$found;<br /><br />}<br />1;
The problem is...is that the bot doesn't reply with the suggest $reply...it replies "1" _________________ Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
I've been doing this kind of thing with my bots for a while, but I've put in a lot more variables that the bot can learn. Here's something that might be in the on_im sub:
Code:
%uservars = UserVars($victim);<br />if ($msg =~ /who am i|what is my name/i) {<br /> $reply = "You are $uservars{'name'}!";<br />}<br />elsif ($msg =~ /how old am i|what is my age/i) {<br /> $reply = "You told me you were $uservars{'age'} years old.";<br />}<br />#and so-on
And here would be the UserVars sub
Code:
sub UserVars {<br /> my $victim = shift;<br /><br /> # Declare the hash.<br /> my %uservars;<br /><br /> # Open their file.<br /> open (VARS, "./clients/$victim.txt");<br /> my @vars = <VARS>;<br /> close (VARS);<br /><br /> # Go through the file.<br /> foreach $line (@vars) {<br /> chomp $line;<br /> my ($what,$is) = split(/=/, $line, 2);<br /> $what = lc($what);<br /><br /> # And add it to the hash.<br /> $uservars{$what} = $is;<br /> }<br /><br /> # Now we have the hash looking something like this...<br /> # %uservars = (<br /> # name => "Bill",<br /> # age => "13",<br /> # sex => "guy",<br /> # area => "Florida",<br /> # color => "blue",<br /> # );<br /><br /> # Return %uservars.<br /> return %uservars;<br />}
And then the basic uservars file would look like this:
sub SaveVars {<br /> my ($victim,%uservars) = (shift,shift);<br /><br /> # Open a template of what variables should exist<br /> # and which ones shouldn't.<br /> open (TMP, "./clients/_template.txt"); # use _ to make it unique<br /> my @template = <TMP>;<br /> chomp @template;<br /> close (TMP);<br /><br /> # Write over the client's data to make any changes necessary.<br /> open (DAT, ">./clients/$victim.txt");<br /> # Go on a foreach loop for the template data.<br /> foreach $line (@template) {<br /> my ($what,$is) = split(/=/, $line, 2);<br /> my $lc_what = lc($what);<br /> print DAT ($what . "=" . $uservars{$lc_what} . "\n");<br /> }<br /> close (DAT); #Close the data file.<br />}
Well, that's the basic idea. I haven't tested that exact code out, in some places you might need to refer to %uservars and $uservars in the returning and shifting parts, but I dunno. You'd have to test it.
thanks Nate for the idea with hashes...but after a few hours of getting no where...& not understanding how to make the hashes work...i got the original codes to work
my issue now...is that I have another sub, that allows the person to enter their name by saying "My name is ..."
Code:
sub addname {<br /><br /> my $victim = shift;<br /> my $msg = shift;<br /><br /> $msg =~ s/My name is //ig;<br /> my $rname = $msg;<br /><br /> open (NAME, "clients/names.txt");<br /> @names = <NAME>;<br /> close(NAME);<br /> chomp(@names);<br /><br />print "Opening names list\n";<br /><br /> for($i=0;$i<scalar(@names);$i++) {<br /> ($sn,$namea) = split(/\]\[/,$names[$i]);<br /> if ($sn eq $victim) {<br /> delete $names[$i];<br /> open (FILE1, ">clients/names.txt");<br /> foreach $item (@names) {<br /> print FILE1 "$item\n";<br /> }<br /> close(FILE1);<br /><br />print "Deleted previous saved name for $victim\n";<br /><br /> open (FILE2, ">>clients/names.txt");<br /> print FILE2 "$victim][$rname\n";<br /> close(FILE2);<br /><br />print "Added new name for $victim\n";<br /><br /> my $reply = "Thank you...$rname has now been saved as your name.";<br /><br /> } else {<br /><br />print "Opening names list\n";<br /><br /> open (FILE3, ">>clients/names.txt");<br /> print FILE3 "$victim][$rname\n";<br /> close(FILE3);<br /><br /> print "$victim name is $rname.\n";<br /><br /> my $reply = "Thank you...$rname has been saved as your name";<br /><br /><br /> return $reply;<br /><br />}<br />1;
The issue i'm having with this code ... is that every time someone says "My name is..." the bot adds a new "line" to the names.txt with the related $victim][$rname
What i want it to do...is that if the person already has a listing in the file...the bot erases the value and replaces it
Quote:
BigTony][JoeDirt
is replaced with
Quote:
BigTony][Anthony
_________________ Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
# See if they already have a name.<br />my $found = 0;<br />open (EXIST, "names.txt");<br />my @exist = <EXIST>;<br />close (EXIST);<br />foreach $item (@exist) {<br /> chomp $item;<br /> ($sn,$name) = split(/\]\[/, $item);<br /> if ($sn eq $victim) {<br /> $found = 1;<br /> }<br />}<br /><br /># If their name isn't in the list, add to the list.<br />if ($found == 0) {<br /> open (NEWITM, ">>names.txt");<br /> print NEWITM "\n" . $victim . "][" . $name;<br /> close (NEWITM);<br />}<br />else {<br /> # If they already have a name, change it.<br /> my $finished;<br /> foreach $item (@exist) { # use the exist list from before<br /> chomp $item;<br /> ($sn,$name) = split(/\]\[/, $item);<br /> if ($sn eq $victim) {<br /> $item = ($victim . "][" . $name);<br /> }<br /> $finished .= "$item\n";<br /> }<br /><br /> # Now $finished would be the entire content of the file, with<br /> # the one line changed for this person's new name.<br /><br /> open (EDITED, ">names.txt");<br /> print EDITED $finished;<br /> close (EDITED);<br />}<br />$reply = "Thanks, I will call you $name from now on!";
Joined: 06 Jan 2004 Posts: 93 Location: Nottinghamshire, UK votes: 4
Posted: Wed Feb 04, 2004 4:01 pm Post subject:
i edited this for msn, and it works and stores users emails and users chosen names, but how do *lazy* read and take the chosename bit for eg mine stores l33tchrono945@hotmail.com][Chrono945 when i type !name Chrono945 but how do i get it to reply your name in the menu, like how do *lazy* open the file and take that little Chrono945 bit from the txt file names?
Well, this is what I have to retrieve the stored name, when an individual says Hello (or any other greeting I have set).
Code:
######################################<br /># #<br /># ## #<br /># ########### # # #<br /># # # # #<br /># # ### # ### #<br /># # # # # #<br /># # ### # #<br /># # # # # #<br /># # ########## #<br /># # #<br /># ########### #<br /># #<br /># @-Squared Productions #<br /># #<br />######################################<br /><br />sub hinames {<br /><br /> my $toprint = "\n";<br /> my ($victim,$msg,$aim) = (shift,shift,shift);<br /> my $reply;<br /> my $sn = $screenname;<br /><br /> open (NAME, "clients/names.txt");<br /> @names = <NAME>;<br /> close(NAME);<br /> chomp(@names);<br /><br />$toprint .= "Opening sub names\n";<br />$toprint .= "Checking victim against list of names\n";<br /><br /> my $nam = 0;<br /><br /> foreach my $line (@names) {<br /> ($scrn,$name) = split(/\]\[/,$line);<br /><br /> if ($scrn eq $victim) {<br /> @rname = split(/\|/,$name);<br /> $nam = 1;<br /> break;<br /> } <br /> }<br /><br /> if ($nam == 1) {<br /><br />$toprint .= "Found person\n\n";<br /><br /> $reply = "Hi " . $rname [ int(rand(scalar(@rname))) ] . ", welcome back! <br>Start by typing <a href=\"aim:goim?screenname=$sn&message=MENU\">MENU</a>.";<br /><br /> } else {<br /><br />$toprint .= "Couldn't find person\n\n";<br /><br /> $reply = "Hello, I am $sn. I'm here to help you with your programming questions. <br>Start by typing \"My name is \" followed by what you'ld like me to call you. For example: My name is Anthony";<br /><br /> }<br /><br /> &print($toprint);<br /><br /> return $reply;<br /><br />}<br />1;
It kind of does two things...it checks if the person has a stored name. If they do, it says hello with the name. If they don't, it "sends" them to the "addname" function.
EDITED: Sorry...this is for my bot...someone will have to convert it for Andromeda. _________________ Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
Joined: 06 Jan 2004 Posts: 93 Location: Nottinghamshire, UK votes: 4
Posted: Wed Feb 04, 2004 5:57 pm Post subject:
hmmm you store screenname and a name to be called:( mine stores a username and a name to be called lol converting from aim to msn including diff bot to andromeda hard lol but am cracking on with it, can i have sum help? mine stores $user] [$msg
Joined: 03 May 2006 Posts: 2292 Location: Colorado
Posted: Wed Feb 04, 2004 7:51 pm Post subject:
Daz: With Andromeda you don't need to worry about files at all. Just save the name you want to use in $bot->{users}->{$user}->{name} = "Eric"; Easy as pie Of course learning names and other info would be best implemented as part of the brian and not as commands. _________________ Eric256
Proud previous owner and current admin of Bot-depot.com