Posted: Thu Jun 16, 2005 3:09 pm Post subject: Note Command NexusBot
Here is a note command made for Nexusbot. I can't really say I made it alone. Cer helped a LOT, and I asked a ton of questions here. But here it is. Make sure you have a folder called "notes" in your main bot directory.
Create Note:
Code:
sub create {
my ($self,$client,$msg,$listener) = @_;
if (!-d "./notes/$client") {
mkdir ("./notes/$client");
}
use strict;
use warnings;
my ($title, $note) = split(/:/, $msg, 2);
my $time = localtime();
open(FILE,">./notes/$client/$title.txt");
print FILE "$time\n\n$note\n";
close(FILE);
#$reply = "$title Created";
#return $reply;
}
1;
Open Note:
Code:
sub open {
my ($self,$client,$msg,$listener) = @_;
open (FILE, "./notes/$client/$msg.txt");
my @data = <FILE>;
close (FILE);
chomp @data; # removes \r's from each line
return join ("\n", @data);
$reply = "@data";
return $reply;
}
1;
Delete 1 Note:
Code:
sub delete {
my ($self,$client,$msg,$listener) = @_;
$myfile ="./notes/$client/$msg.txt";
unlink $myfile;
$reply = "$msg Deleted";
return $reply;
}
1;
Delete All Notes:
Code:
sub erase {
my ($self,$client,$msg,$listener) = @_;
sub note {
my ($self,$client,$msg,$listener) = @_;
$reply = "Note Centeral\n\nTo write a note to yourself, enter: !create NoteTitle:Note\nExamples:\n!create Remember:To walk the dog\n!create Call:Your mom 555-5555\n!create ToDo:Homework,baseball,study\n\nTo open a note, enter: !open NoteTitle\nExamples:\n!open Remember\n!open Call\n!open ToDo\n\nTo delete a note, enter: !delete NoteTitle\nExamples:\n!delete Remember\n!delete Call\n!delete ToDo\n\nTo delete all your notes, enter: !erase\nExamples:\n!erase\n\nTo list all your notes, enter: !view\nExamples:\n!view\n\nTo send a note to someone else, enter: !send ScreenName:NoteTitle:Note\nExamples:\n!send JohnDoe64:Remember:To walk the dog\n!send TimJohnson22:Call:Your mom\n!send FredSmith58:ToDo:Homework,baseball,study\n\nTo get back here, enter: !note\nExamples:\n!note";
return $reply
}
1;
Send Note to other People:
Code:
sub send {
my ($self,$client,$msg,$listener) = @_;
my ($user, $title, $note) = split /:/, $msg, 3;
if (!-d "./notes/$user") {
mkdir ("./notes/$user");
}
use strict;
use warnings;
my $time = localtime();
open(FILE,">./notes/$user/$client.$title.txt");
print FILE "$time\n\n$note\n";
close(FILE);
}
1;
Some of the commands are missing a reply from the bot. I was having problems, and getting errors. If you want to add it in, post the code here.
Ideas For Improvement:
1: Print the Note
Print the Note, and JUST the note from the printer of the client
If you have other ideas for improvement, post them here.
Last edited by Cheater on Mon Jun 27, 2005 9:48 pm; edited 1 time in total
Thanks once again Cer. I'm glad you didn't just make it for me. Even if I had to ask a million questions to make it, I still learned a lot (and made my bot better).
Once again X-Worm, this was the first real command I made, and I am no longer working on it. Feel free to edit it and make your own version, but please stop posting about it