#!/usr/bin/perl # Based upon the JinglyBOT module by Matthew Sibson # Ported to PogoBOT by Tim Retout use warnings; use strict; use IO::Socket::INET; $/ = "\r\n"; my $socket = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => 3009, Proto => 'tcp', ) or die "Couldn't open socket: $!"; print "Registering 28hr.\n"; print $socket "REG 28hr\n"; while (<$socket>) { chomp; print "Received $_\n"; next unless (/^28hr/); my $reply = get_28hr(); # Put the reply after the second field, removing the first field. s/^([^\t]*\t)([^\t]*)/$2 $reply/ || next; print "Saying ", $_, "\n"; print $socket $_, "\n"; } sub get_28hr { my @time = localtime; my $dayOfWeek = $time[6] - 1; my $second = $time[0]; my $minute = $time[1]; my $hour = $time[2]; my $totalHour = (($dayOfWeek * 24) + $hour); my $hour28 = $totalHour % 28; my $day28 = int($totalHour / 28); my $timeString = sprintf("%02d:%02d:%02d", $hour28, $minute, $second); # Hacky hacky five dollar my @days = ( 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', ); return "\$NICK: The time, by the 28 hour clock, is $timeString and it is $days[$day28]."; }