Joined: 01 Jan 2004 Posts: 233 Location: The Netherlands
Posted: Fri Jan 02, 2004 10:44 pm Post subject:
Ok,
i've downloaded (shame shame ) this code from Wiredbots and it contains 3 files to use 'messaging' so that you can leave a message for someone (email-addy based)
The original code was intended to give a message to the user if they have a message but it looks like even IF you delete he keeps telling you to check your messages because you have a new one...
That's why i removed (commented) that part of the code (it was a handler)
But now i'd like to have it back and to act a bit different.
I want it this way: If a user gets a msg he gets 1 (one) message and after that he won't be notified - unless he gets another message.
I think it is possible.. It's a bit like the 'silence' command posted on this board.. After the msg was sent the bot sets '$sentnotif 1; ' and that if $sentnotif = 1; he won't reply and if it is $sentnotif=0; he does..
Is this possible? If so: how ? What do i have to change?
Here's the code:
Read Messages:
Code:
<br />sub rm {<br />open (FILE, "./logs/messages/$victim.txt");<br />my @msgs = <FILE>;<br />close (FILE);<br />$end = ("Here are all your messages:\n @msgs\n End of messages");<br />return $end;<br />}<br />1;<br />
Leave Messages:
Code:
sub lm {<br /><br />#get ours arrays sorted<br /><br />$timestamp = (scalar localtime);<br /><br />$adminonly = 0;<br /><br />#open the admin txt <br />open (FILE, "admin.txt");<br />$admin = <FILE>;<br />close(FILE);<br /><br /> $victim = shift;<br /> $msg = shift;<br /> <br /> # get vars after split<br /> ($note, $what) = split(/ /, $msg, 2);<br /> ($from, $to) = split(/>/, $what, 2);<br /> <br /> if ($from eq "" || $to eq "") {<br /> $reply = "You can leave a message for"<br /> ." other users by typing "<br /> ."!lm user> message so"<br /> ."!lm jij @ hotmail.com > you rock"<br /> ." would leave a message for " <br /> ."jij @ hotmail.com with the message "<br /> ."you rock\n";<br /> }<br />elsif($adminonly == 1 && $victim ne "$admin") {<br /><br /> $reply = "Sorry, This is for administrators";<br /><br /> #otherwise, leave the message <br /> } else { <br /> $cfgln = "[$victim said:] $to ";<br /> $filename = "$from.txt";<br /> open (DATA, ">>logs/messages/$filename");<br /> print DATA "$cfgln at [$timestamp on $datestamp]\n";<br /> close (DATA);<br /> open (DATA, ">>logs/messages/locks/$victim.lck");<br /> print DATA "1";<br /> close (DATA);<br /> $reply = "Message stored!";<br />}<br /><br />return $reply;<br />}<br />1;
Delete messages:
Code:
sub delmess {<br /><br />$adminonly = 0;<br />$reply = "4If you don't want them deleted, then don't delete them!!";<br /><br />#open admin yada yada<br />open (FILE, "admin.txt");<br />$admin = <FILE>;<br />close(FILE);<br /><br />$victim = shift;<br />$msg = shift;<br /><br />($del, $conf) = split(/ /, $msg, 2);<br /><br />if ($conf eq "") {<br /> $reply = "You can use this to"<br /> ." delete your messages by typing "<br /> ."!delmess yes"<br /> ." if you do not include the yes"<br /> ." your messages will not be " <br /> ."deleted. And a note of caution, "<br /> ."once you delete them, they are gone!!";<br /><br />} <br />elsif($adminonly == 1 && $victim ne "$admin") {<br /><br /> $reply = "Sorry, This is for administrators";<br /><br /> #leave the message<br /> } else {<br /> if ($conf eq "yes") {<br /> $reply = "Messages deleted";<br /> unlink (FILE, "./logs/messages/$victim.txt");<br />}<br />elsif($adminonly == 1 && $victim ne "$admin") {<br /><br /> $reply = "Sorry, This is for administrators";<br />}<br /><br />return $reply;<br />}<br />}<br />1;<br />
This is the thing needed for that notification:
Code:
sub mess {<br /><br />$greet = "Attention $victim";<br /><br />if (!-e "./logs/messages/locks/$victim.lck") <br />{ <br />#$msgs = thought ();<br />#$msgs = mess ();<br />}<br />else <br />{<br />$msgs = "$greet, You have new messages on the bot.\n";<br />unlink (FILE, "./logs/messages/locks/$victim.lck");<br />}<br />$reply = $msgs;<br />return $reply;<br />}<br /><br />1;
Tnx
Btw: I modified it slightly _________________ Sypher
Developer of Codera
lol... the one WiredBots made was designed to work with MSN P2, that's why I updated the code to use a more recent module. So use the one from the "Downloads/Bots" forum here.