-
Notifications
You must be signed in to change notification settings - Fork 234
/
autoreminder.pl
147 lines (127 loc) · 4.11 KB
/
autoreminder.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#####################
#
# irssi autoreminder script.
# Copyright (C) Terry Lewis
# Terry Lewis <mrkennie@kryogenic.co.uk>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#####################
#
# Auto reminder script for irssi
# This is really a first attempt at an irssi script,
# really more of a hack I suppose, to auto remind
# someone at certain intervals.
# It will not remind at every interval defined, so its
# kinda less annoying, but hopefully effective.
#
# To start:
# /start <nick> <"reminder message"> [interval]
# (<> = required, [] = optional)
# reminder Message must use "" parenthasis.
#
# to stop reminding use /stop
#
# I know the code is not fantastic but I will appreciate
# any patches for improvements, just mail them to me if
# you do improve it :)
#
# I use a rather nice script called cron.pl by Piotr
# Krukowiecki which I found at http://www.irssi.org/scripts/
# so I can start and stop the script at certain times.
# I hope someone finds this useful, Enjoy =)
#
#####################
use strict;
use vars qw($VERSION %IRSSI);
use Irssi;
$VERSION = '0.01';
%IRSSI = (
authors => 'Terry Lewis',
contact => 'terry@kryogenic.co.uk',
name => 'Auto Reminder',
description => 'This script ' .
'Reminds people ' .
'to do stuff! :)',
license => 'GPLv2',
);
my($timeout_tag, $timeout, $state, @opts, $date, @time, @hour, $start_hour, $end_hour);
#default state 0 meaning we are not started yet
$state = 0;
# /start <nick> <"message"> [interval]
sub cmd_start {
if($state != 1){
my($data,$server,$channel) = @_;
@opts = split(/\s\B\"(.*)\b\"/, $data);
if($opts[0] ne ''){
if($opts[1] ne ''){
if($opts[0] =~ /\s/g){
Irssi::print("Invalid username");
}elsif($opts[1] eq ''){
Irssi::print("You must type a message to send");
}else{
$state = 1;
if($opts[2] =~ /[0-9]/g){
$opts[2] =~ s/\s//g;
$timeout = $opts[2];
timeout_init($timeout);
}else{
Irssi::print("Invalid interval value, using defaults (15mins)") unless $opts[2] eq '';
$timeout = "900000";
timeout_init($timeout);
}
Irssi::print "Bugging $opts[0] with message \"$opts[1]\" every \"$timeout ms\"";
}
}else{
Irssi::print ("Usage: /start nick \"bug_msg\" [interval] (interval is optional)");
}
}else{
Irssi::print ("Usage: /start nick \"bug_msg\" [interval] (interval is optional)");
}
}else{
Irssi::print "Already started";
}
}
# /stop
sub cmd_stop {
if($state == 1){
$state = 0;
Irssi::print "No longer bugging $opts[0]";
Irssi::timeout_remove($timeout_tag);
$timeout_tag = undef;
}else{
Irssi::print "Not started";
}
}
sub timeout_init {
if($state == 1){
Irssi::timeout_remove($timeout_tag);
$timeout_tag = undef;
$timeout_tag = Irssi::timeout_add($timeout, "remind_them", "");
}
}
sub remind_them {
if($state == 1){
my (@servers) = Irssi::servers();
# make it random, so we dont remind at every defined interval
my $time = rand()*3;
if($time < 1){
$servers[0]->command("MSG $opts[0] Hi, this is an automated reminder, $opts[1]");
}
timeout_init($timeout);
}
}
Irssi::command_bind('start', \&cmd_start);
Irssi::command_bind('stop', \&cmd_stop);