Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use utf8;
- use Date::Parse;
- use Irssi;
- use vars qw($VERSION %IRSSI);
- $VERSION = "1.0";
- %IRSSI = (
- authors => 'ed',
- contact => 'rizon.net',
- name => 'reminder',
- description => 'see name',
- license => 'GNU GPL v2 explicitly',
- url => 'http://r-a-d.io/ed/'
- );
- @rem = ();
- $remn = 0;
- use constant TIM => 0;
- use constant SRC => 1;
- use constant DST => 2;
- use constant CHN => 3;
- use constant MSG => 4;
- use constant HIL => 5;
- # tim, src, dst, chn, msg, hil
- sub state_save {
- return;
- }
- sub recase {
- my ($server, $target, $nock) = @_;
- my @li = ();
- my $ch = $server->channel_find($target);
- foreach my $dick ($ch->nicks())
- {
- $nick = $dick->{'nick'};
- if ($nock eq lc($nick))
- {
- return $nick;
- }
- }
- return '.';
- }
- sub event_privmsg {
- my ($server, $data, $nick, $mask, $target) =@_;
- my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
- $time = time();
- $nock = lc($nick);
- for ($n = 0; $n < $remn; $n += 6)
- {
- if ($time >= $rem[$n+TIM] &&
- (
- $rem[$n+HIL] == 1 ||
- $rem[$n+DST] eq $nock
- )
- )
- {
- $nuck = recase($server, $rem[$n+CHN], $rem[$n+DST]);
- $nuck = $nick if ($nuck eq '.' && $rem[$n+DST] eq $nock);
- #print "$rem[$n+TIM] - src:$rem[$n+SRC] - dst:$rem[$n+DST] - chn:$rem[$n+CHN] - msg:$rem[$n+MSG] - hil:$rem[$n+HIL] - nuck:$nuck";
- next if ($nuck eq '.');
- my $msg = "$nuck, ";
- if ($rem[$n+HIL] == 0)
- {
- $msg = "Oh, $nuck! ";
- }
- $from = $rem[$n+SRC];
- $from = 'you' if (lc($from) eq $rem[$n+DST]);
- $msg .= "$from wanted me to remind you ";
- $msg .= $rem[$n+MSG];
- $msgto = $rem[$n+CHN];
- print " -!- REMINDER -!- $msgto -> $msg";
- $server->command("msg $msgto $msg");
- splice(@rem, $n, 6);
- $remn = @rem;
- state_save();
- }
- }
- $do_t = 0; #target
- $do_a = 0; #argument
- $do_r = 0; #remind
- $do_h = 0; #hilight
- if ($text =~ /^-([^ ]*) ([^ ]*) ([^ ]*) (.*)/)
- {
- $do_r = 1 if ($1 eq 'remind' && $3 eq 'in');
- $do_r = 2 if ($1 eq 'remind' && $3 eq 'on');
- $do_h = 1 if ($1 eq 'hilight' && $3 eq 'in');
- $do_h = 2 if ($1 eq 'hilight' && $3 eq 'on');
- $do_t = lc($2);
- $do_a = $4;
- if ($do_t eq 'me')
- {
- $do_t = $nock;
- }
- }
- if ($do_r == 1 || $do_h == 1) #in
- {
- $dur = 0;
- while (1==1)
- {
- #print " -!- args: '$do_a'";
- if ($do_a =~ /^and /)
- {
- $do_a = substr $do_a, 4;
- next;
- }
- last if $do_a !~ /^([0-9][0-9]*) ([a-z][^ ]*) /;
- $num = $1;
- $den = $2;
- $do_a = substr $do_a, length($num) + length($den) + 2;
- $den =~ s/,$//;
- $den =~ s/s$//;
- $mul = 0;
- if ($den eq 'second') { $mul = 1; }
- if ($den eq 'minute') { $mul = 60; }
- if ($den eq 'hour') { $mul = 60*60; }
- if ($den eq 'day') { $mul = 60*60*24; }
- if ($den eq 'week') { $mul = 60*60*24*4; }
- if ($den eq 'month') { $mul = 60*60*24*30.43685; }
- if ($den eq 'year') { $mul = 60*60*24*365.2422; }
- if ($mul == 0)
- {
- $err = "Bad denominator: $den";
- print " -!- REMINDER -!- $err";
- $server->command("msg $target Oh dear. $err");
- return;
- }
- $dur += $mul * $num;
- }
- $dur = int($dur);
- $abs = $time + $dur;
- push(@rem, ($abs, $nick, $do_t, $target, $do_a, $do_h));
- $remn = @rem;
- @weekday = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
- ($gsec,$gmin,$ghour,$gday,$gmon,$gyear,$gwday,$gyday,$gdst) = gmtime($abs);
- $human = sprintf("%d-%02d-%02d (%s) %02d:%02d:%02d",
- $gyear + 1900, $gmon, $gday, $weekday[$gwday], $ghour, $gmin, $gsec
- );
- $prt = "よし! I'll remind ";
- $prt .= 'you' if ($do_t eq $nock);
- $prt .= $do_t if ($do_t ne $nock);
- $prt .= " about that on $human - in $dur seconds (☞゚∀゚)☞";
- $server->command("msg $target $prt");
- print " -!- REMINDER -!- $text";
- return;
- }
- }
- Irssi::signal_add('event privmsg', 'event_privmsg');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement