/var/www/www.irssi.org-old/scripts/html/away_verbose.pl
1 use Irssi;
2 use strict;
3 use vars qw($VERSION %IRSSI);
4
5 $VERSION = '0.0.7';
6 %IRSSI = (
7 authors => 'Wouter Coekaerts, Koenraad Heijlen',
8 contact => 'vipie@ulyssis.org, wouter@coekaerts.be',
9 name => 'away_verbose',
10 description => 'A verbose away script, displays a verbose away/back message in the channels you are in. BUT it can limit the channels (not spamming every channel!)',
11 license => 'GNU GPL version 2',
12 url => 'http://vipie.studentenweb.org/dev/irssi/',
13 changed => '2004-01-01'
14 );
15
16 #--------------------------------------------------------------------
17 # Changelog
18 #--------------------------------------------------------------------
19 #
20 # away_verbose.pl 0.7 (2004-01-01)
21 # * Wouter Coekaerts
22 # - don't hard code the command char
23 #
24 # away_verbose.pl 0.5 (2002-11-17)
25 # * James Seward
26 # - make regex case insensitive
27 #
28 #--------------------------------------------------------------------
29
30 #--------------------------------------------------------------------
31 # Public Variables
32 #--------------------------------------------------------------------
33 my $away_time_texts = "wk,wks,day,days,hr,hrs,min,mins,sec,secs";
34 my ($away_set, $away_time, $away_reason, $away_silent)=(0,0,"",0);
35 my %myHELP = ();
36
37
38 #--------------------------------------------------------------------
39 # Help function
40 #--------------------------------------------------------------------
41 sub cmd_help {
42 my ($about) = @_;
43
44 %myHELP = (
45 back => "
46 BACK
47
48 Away is unset, the time you were away is displayed in the channel with the reason.
49
50 like this: /me away_back_text_part1 <reason> away_back_text_part2 TIME
51
52 Currently it will display:
53 /me " . Irssi::settings_get_str('away_back_text_part1') . " Some Reason " . Irssi::settings_get_str('away_back_text_part2') . " " . &secs2text(10000) . "
54
55 You can change this by changing the settings (with /set setting_name):
56
57 * away_back_text_part1 (default: is back from)
58 * away_back_text_part2 (default: after)
59 * away_time_texts (default: wk,wks,day,days,hr,hrs,min,mins,sec,secs)
60
61 ",
62
63 gone => "
64 GONE <your away reason>
65
66 Sets you away with the given reason, and displays it publically on the allowed channels.
67
68 like this: /me away_gone_text <reason>
69
70 Currently it will display:
71 /me " . Irssi::settings_get_str('away_gone_text') . " Some Reason
72
73 You can change this by changing the settings (with /set setting_name):
74
75 * away_gone_text (default: is gone:)
76
77
78 How do I decide on which channels they away message is displayed?
79 -----------------------------------------------------------------
80
81 You set 2 settings: away_order_channels, away_allow_channels.
82
83 away_order_channels = [allow|exclude]
84 Should the channels be allowed or excluded using a regular expression. (exclude = all but the matching channels).
85
86 away_allow_channels = <regular expression>
87 The regular expression limiting the channels (eg 'linux|home' without the '').
88 ",
89
90 awe => "
91 AWE [<your away reason>]
92
93 When a reason is given, it acts as GONE
94 When no reason is supplied it acts as BACK.
95
96 SEE ALSO: HELP BACK, HELP GONE
97 ",
98
99 );
100
101 if ( $about =~ /(back|gone|awe)/i ) {
102 Irssi::print($myHELP{$1});
103 }
104 }
105
106
107 #--------------------------------------------------------------------
108 # Translate the number of seconds to a human readable format.
109 #--------------------------------------------------------------------
110 sub secs2text {
111 $away_time_texts = Irssi::settings_get_str('away_time_texts');
112 my ($secs) = @_;
113 my ($wk_,$wks_,$day_,$days_,$hr_,$hrs_,$min_,$mins_,$sec_,$secs_) = (0,1,2,3,4,5,6,7,8,9,10);
114 my @texts = split(/,/,$away_time_texts);
115 my $mins=int($secs/60); $secs -= ($mins*60);
116 my $hrs=int($mins/60); $mins -= ($hrs*60);
117 my $days=int($hrs/24); $hrs -= ($days*24);
118 my $wks=int($days/7); $days -= ($wks*7);
119 my $text = (($wks>0) ? (($wks>1) ? "$wks $texts[$wks_] " : "$wks $texts[$wk_] ") : "" );
120 $text .= (($days>0) ? (($days>1) ? "$days $texts[$days_] " : "$days $texts[$day_] ") : "" );
121 $text .= (($hrs>0) ? (($hrs>1) ? "$hrs $texts[$hrs_] " : "$hrs $texts[$hr_] ") : "" );
122 $text .= (($mins>0) ? (($mins>1) ? "$mins $texts[$mins_] " : "$mins $texts[$min_] ") : "" );
123 $text .= (($secs>0) ? (($secs>1) ? "$secs $texts[$secs_] " : "$secs $texts[$sec_] ") : "" );
124 $text =~ s/ $//;
125 return $text;
126 }
127
128 #--------------------------------------------------------------------
129 # Output the public away on all permitted channels.
130 #--------------------------------------------------------------------
131 sub away_describe_pub_channels {
132 my $away_allow_channels=Irssi::settings_get_str('away_allow_channels');
133 my $away_order_channels=Irssi::settings_get_str('away_order_channels');
134 my ($server,$text) = @_;
135 foreach my $server (Irssi::servers) {
136 foreach my $chan ($server->channels) {
137
138 if ((($server->{chatnet} .":". $chan->{name}) =~ /$away_allow_channels/i) != ($away_order_channels eq "exclude")) {
139 $server->command("DESCRIBE $chan->{name} $text");
140 }
141 }
142 }
143 }
144
145 #--------------------------------------------------------------------
146 # Set the away reason, and call the function to do the announce.
147 #--------------------------------------------------------------------
148 sub away_setaway {
149 my ($server, $reason)=@_;
150
151 my $away_gone_text=Irssi::settings_get_str('away_gone_text');
152
153 $server->command("AWAY " . $reason);
154 away_describe_pub_channels($server,"$away_gone_text $reason");
155 $away_time=time;
156 $away_reason=$reason;
157 $away_set=1;
158 }
159
160 #--------------------------------------------------------------------
161 # Remove the away reason, and call the function to do the announce.
162 #--------------------------------------------------------------------
163 sub away_back {
164 my($server)=@_;
165
166 my $away_back_text_part1=Irssi::settings_get_str('away_back_text_part1');
167 my $away_back_text_part2=Irssi::settings_get_str('away_back_text_part2');
168
169 if ( $away_set ) {
170 $server->command("AWAY");
171 away_describe_pub_channels($server,"$away_back_text_part1 $away_reason $away_back_text_part2 " . secs2text(time - $away_time));
172 $away_time=0;
173 $away_reason="";
174 $away_set=0;
175
176 } else {
177 Irssi::print("Don't use back if you are not away! OXYMORON");
178 Irssi::print("(ed. note) OXYMORON: a combination of contradictory or incongruous words (as cruel kindness)");
179 return;
180 }
181 }
182
183 #--------------------------------------------------------------------
184 # Defintion of /gone, /back and /awe
185 #--------------------------------------------------------------------
186 sub gone {
187 my ($args, $server, $item) = @_;
188 away_setaway($server,$args);
189 }
190
191 sub back {
192 my ($args, $server, $item) = @_;
193 away_back($server);
194 }
195
196 sub cmd_away {
197 my ($args, $server, $item) = @_;
198
199 if ( $args ) {
200 away_setaway($server,$args);
201 } else {
202 away_back($server);
203 }
204 }
205
206
207 #--------------------------------------------------------------------
208 # Irssi::Settings / Irssi::command_bind
209 #--------------------------------------------------------------------
210
211 Irssi::settings_add_str('away', 'away_allow_channels', "^\$");
212 Irssi::settings_add_str('away', 'away_order_channels', "exclude");
213 Irssi::settings_add_str('away', 'away_time_texts', $away_time_texts);
214
215 Irssi::settings_add_str('away', 'away_gone_text', "is gone:");
216 Irssi::settings_add_str('away', 'away_back_text_part1', "is back from");
217 Irssi::settings_add_str('away', 'away_back_text_part2', "after");
218
219 Irssi::command_bind("gone", "gone", "Advanced Away");
220 Irssi::command_bind("back", "back", "Advanced Away");
221 Irssi::command_bind("awe","cmd_away", "Advanced Away");
222
223 Irssi::command_bind("help","cmd_help", "Irssi commands");
224
225 #--------------------------------------------------------------------
226 # This text is printed at Load time.
227 #--------------------------------------------------------------------
228
229 Irssi::print("Use /back, /gone <reason>, or the toggle /awe [<reason>]");
230 Irssi::print("Use /away [<reason>] for silent away");
231 Irssi::print("Use /help back or gone or awe for more information.");
232
233
234 #- end