Commits

Daniel Leining committed 2b6d836

moved actions to Sentinal::IRC::Actions

Comments (0)

Files changed (3)

lib/Sentinal/IRC.pm

 package Sentinal::IRC;
 
 use IO::Socket::IP;
-use base qw(Sentinal::IRC::Channel Sentinal::IRC::User);
+use base qw(Sentinal::IRC::Actions Sentinal::IRC::Channel);
 use Sentinal::IRC::Channel;
 
 our %channels;
 sub start {
 	my $irc = shift;
 	if ($irc->{socket}->connect()) {
-		$irc->sendraw("USER $irc->{ident} 0 * :$irc->{realname}");
-		$irc->sendraw("NICK $irc->{nick}");
+		$irc->raw("USER $irc->{ident} 0 * :$irc->{realname}");
+		$irc->raw("NICK $irc->{nick}");
 		return 1;
 	}
 	else {
 	}
 	$irc->fire("raw", $content);
 	if ($content =~ m/PING :(.+)/) {
-		$irc->sendraw("PONG :$1");
+		$irc->raw("PONG :$1");
 		return 1;
 	}
 	elsif ($content =~ m{^:([^ ]+) ([0-9]+) (.+)}) {
 	$irc->notice($target, "VERSION $irc->{version}");
 }
 
-sub privmsg {
-	my ($irc, $target, $msg) = @_;
-	$irc->sendraw("PRIVMSG $target :$msg");
-	return 1;
-}
-sub notice {
-	my ($irc, $target, $msg) = @_;
-	$irc->sendraw("NOTICE $target :$msg");
-	return 1;
-}
-
-sub nick {
-	my ($irc, $newnick) = @_;
-	if (!$newnick) {
-		return 0;
-	}
-	$irc->sendraw("NICK $newnick");
-	return 1;
-}
-
-sub cjoin {
-	my ($irc, $target) = @_;
-	if (!$target) {
-		return 0;
-	}
-	$irc->sendraw("JOIN $target");
-	return 1;
-}
-
-
-sub sendraw {
-	my ($irc, $msg) = @_;
-	if (!$msg) {
-		return 0;
-	}
-	my $sock = $irc->{socket};
-	print $sock $msg . "\n";
-	return 1;
-}
-
 1;
 __END__
 

lib/Sentinal/IRC/Actions.pm

 package Sentinal::IRC::Actions;
 
 sub privmsg {
-	
+	my ($irc, $target, $msg) = @_;
+	if (!$target || !$msg) {
+		return 0;
+	}
+	$irc->raw("PRIVMSG $target :$msg");
 }
 
 sub notice {
-	
+	my ($irc, $target, $msg) = @_;
+	if (!$target || !$msg) {
+		return 0;
+	}
+	$irc->raw("NOTICE $target :$msg");
 }
 
 sub join {
-	
+	my ($irc, $target) = @_;
+	if (!$target) {
+		return 0;
+	}
+	$irc->raw("JOIN $target");
 }
 
 sub part {
-	
+	my ($irc, $target) = @_;
+	if (!$target) {
+		return 0;
+	}
+	$irc->raw("PART $target");
 }
 
 sub nick {
-	
+	my ($irc, $newnick) = @_;
+	if (!$newnick) {
+		return 0;
+	}
+	$irc->raw("NICK $newnick");
 }
 
 sub raw {
-	
-}
+	my ($irc, $msg) = @_;
+		if (!$msg) {
+		return 0;
+	}
+	my $sock = $irc->{socket};
+	print $sock $msg . "\n";
+	return 1;
+}
+
+1;
 		my @ok = split ' ', $msg;
 		if ($ok[0] eq '.e' || $ok[0] eq '.eval') {
 			shift @ok;
-			my $k = eval join ' ', @ok;
+			my $k2 = eval join ' ', @ok;
 			if ($@) {
 				$irc->privmsg($target, "ERROR: " . $@);
 			}
 			else {
-				my @j = split(/\R/, $k);
+				my @j = split(/\R/, $k2);
 				foreach (@j) {
 					$irc->privmsg($target, "$nick: $_")
 				}  
 
 sub on_connected {
 	my $irc = shift;
-	$irc->cjoin('#home');
+	$irc->join('#home');
 	
 }