User Control Panel
Advertisements

HELP US, HELP YOU!

Saving Individual's Names
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Bot Depot Forum Index -> AIM Protocol & questions
View unanswered posts
Author Message
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Sat Dec 06, 2003 4:19 pm    Post subject: Reply with quote

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
Back to top
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Sat Dec 06, 2003 6:14 pm    Post subject: Reply with quote

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:

Code:
Name=Bill<br />Age=13<br />Sex=guy<br />Area=Florida<br />Color=blue


And then you'd need a sub to save the new data. It would be called like

Code:
$uservars{"name"} = "Bob";<br />$uservars{"age"} = "14";<br />SaveVars($victim,%uservars);


And would look something like

Code:
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.
Back to top
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Sun Dec 07, 2003 6:36 am    Post subject: Reply with quote

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
Back to top
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Sun Dec 07, 2003 1:37 pm    Post subject: Reply with quote

Try something like this:

Code:
# 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!";
Back to top
Rameses
Senior Member
Senior Member


Joined: 02 Feb 2004
Posts: 182

Reputation: 31.1Reputation: 31.1Reputation: 31.1

PostPosted: Wed Feb 04, 2004 1:03 am    Post subject: Reply with quote

Yup, I've done something very similar to this. I deleted it soon after, though, when people began naming themselves cuss words, hehe.. <_<
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Wed Feb 04, 2004 1:36 am    Post subject: Reply with quote

lol, in my recent bot I have it uses hashes.

Everytime I need a specific client's info I just call this:
&profile_get ($username, $messenger);

And then get data like this:
Code:
Name: $chaos->{users}->{$user}->{name}<br />Age: $chaos->{users}->{$user}->{age}<br />Gender: $chaos->{users}->{$user}->{sex}


A new user's default file looks like this:
Code:
permission=Client<br />messages=0<br />name=$username<br />age=undefined<br />sex=undefined<br />location=undefined<br />color=undefined<br />band=undefined<br />book=undefined<br />sexuality=heterosexual<br />job=undefined


And I just have the profile_get sub fill the hash with that information.

I also have a profile_send sub that replaces a single line in the profile.
&profile_send ($client, $messenger, "name", $new_name); for example.

It's really quite easy and efficient. I'll be releasing it soon here.

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
Drayshak
Young One
Young One


Joined: 06 Jan 2004
Posts: 93
Location: Nottinghamshire, UK
Reputation: 46.2Reputation: 46.2Reputation: 46.2Reputation: 46.2Reputation: 46.2
votes: 4

PostPosted: Wed Feb 04, 2004 4:01 pm    Post subject: Reply with quote

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?
Back to top
zander
God Like
God Like


Joined: 14 Jan 2004
Posts: 540
Location: england
Reputation: 66.6

PostPosted: Wed Feb 04, 2004 4:04 pm    Post subject: Reply with quote

would this be able to work for andromeda if it was edited or is it no possible?
Back to top
Drayshak
Young One
Young One


Joined: 06 Jan 2004
Posts: 93
Location: Nottinghamshire, UK
Reputation: 46.2Reputation: 46.2Reputation: 46.2Reputation: 46.2Reputation: 46.2
votes: 4

PostPosted: Wed Feb 04, 2004 4:05 pm    Post subject: Reply with quote

ive edited the command for andromeda use, BUT, i need to know how to get it to reply the stored name
Back to top
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Wed Feb 04, 2004 4:32 pm    Post subject: Reply with quote

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
Back to top
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Wed Feb 04, 2004 4:36 pm    Post subject: Reply with quote

where would this go on an andromeda bot?
Back to top
Drayshak
Young One
Young One


Joined: 06 Jan 2004
Posts: 93
Location: Nottinghamshire, UK
Reputation: 46.2Reputation: 46.2Reputation: 46.2Reputation: 46.2Reputation: 46.2
votes: 4

PostPosted: Wed Feb 04, 2004 5:57 pm    Post subject: Reply with quote

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
Back to top
Drayshak
Young One
Young One


Joined: 06 Jan 2004
Posts: 93
Location: Nottinghamshire, UK
Reputation: 46.2Reputation: 46.2Reputation: 46.2Reputation: 46.2Reputation: 46.2
votes: 4

PostPosted: Wed Feb 04, 2004 7:48 pm    Post subject: Reply with quote

ok i got it edited now, it works!!
Code:
<br />my $toprint = "\n";<br />my ($user,$msg, $msn) = (shift,shift, shift);<br />my $reply;<br /><br /><br />open (NAME, "clients/names.txt");<br />@names = <NAME>;<br />close(NAME);<br />chomp(@names);<br /><br /><br />my $nam = 0;<br /><br />foreach my $line (@names) {<br /> ($user,$name) = split(/\]\[/,$line);<br /><br /> if ($user eq $user) {<br /> @rname = split(/\|/,$name);<br /> $nam = 1;<br /> break;<br /> } <br />}<br /><br />if ($nam == 1) {<br /><br /><br /><br /> $reply = "Hi " . $rname [ int(rand(scalar(@rname))) ] . ", welcome back!";<br /><br />} else {<br /><br /><br /><br />  $reply = "Failed";<br />}<br /><br /><br /><br />return $reply;<br /><br />}<br />1;   
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Wed Feb 04, 2004 7:51 pm    Post subject: Reply with quote

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 Smile 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
Back to top
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Wed Feb 04, 2004 8:35 pm    Post subject: Reply with quote

"Oh...I wish I had a brain", says my bot. LOL

Maybe I should rename my bot "Scarecrow"

_________________
Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> AIM Protocol & questions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group