annotate plugins/fortuneprofile.pl @ 6395:0587dd97f700

[gaim-migrate @ 6900] we can't use the display pref to check for whether to update or not because if we have the pref off, then the icon changes, and then we turn on the pref, we'd still have the initial icon. yeah. hey, it made sense in _my_ head. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Wed, 06 Aug 2003 18:22:05 +0000
parents e8204ffce9f8
children 7f0fffa1077b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 # FORTUNE PROFILE
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 # Sets your AIM profile to a fortune (with a header and footer of your
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 # choice).
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 # By Sean Egan
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
8 # bj91704@binghamton.edu
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9 # AIM: SeanEgn
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 # Updated by Nathan Conrad, 31 January 2002
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 # Changes:
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 # * Fortunes have HTML tabs and newlines
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 # AIM: t98502
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 # ICQ: 16106363
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 # Updated by Mark Doliner, 15 October 2002
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 # Changes:
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 # * Modified to work with the changed perl interface of gaim 0.60
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20 # * Fixed a bug where your info would be set to nothing if you had
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 # no pre and no post message
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22 # AIM: lbdash
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
24 # Copyright (C) 2001 Sean Egan
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
25
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
26 # This program is free software; you can redistribute it and/or modify
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
27 # it under the terms of the GNU General Public License as published by
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
28 # the Free Software Foundation; either version 2 of the License, or
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
29 # (at your option) any later version.
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 # This program is distributed in the hope that it will be useful,
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34 # GNU General Public License for more details.
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36 # You should have received a copy of the GNU General Public License
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 # along with this program; if not, write to the Free Software
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
38 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
39
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
40
6125
e8204ffce9f8 [gaim-migrate @ 6599]
Mark Doliner <mark@kingant.net>
parents: 5487
diff changeset
41 $handle = GAIM::register("Fortune Profile", "3.3", "", "");
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
43 $tab = "&nbsp;";
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44 $tab = $tab . $tab . $tab . $tab;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
45 $nl = "<BR>";
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46
4603
6316a0a33680 [gaim-migrate @ 4890]
Mark Doliner <mark@kingant.net>
parents: 3706
diff changeset
47 $seconds = 30; # Delay before updating away messages.
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
48 $max = 1020; # Max length of an profile. It should be
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
49 # 1024, but I am being safe
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50 $pre_message = ""; # This gets added before the fortune
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
51
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
52 $post_message ="";
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
54 $len = 0;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55 if ($pre_message ne "") {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 $len += length( $pre_message . "---$nl" );
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 if ($post_message ne "") {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 $len += length("---$nl" . $post_message);
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62 $command = "fortune -sn " . ($max - $len); # Command to get dynamic message from
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64 sub update_away {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
65 # The fortunes are expanded into HTML (the tabs and newlines) which
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 # causes the -s option of fortune to be a little bit meaningless. This
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 # will loop until it gets a fortune of a good size (after expansion).
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69 do {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
70 do { #It's a while loop because it doesn't always work for some reason
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
71 $fortune = `$command`;
6125
e8204ffce9f8 [gaim-migrate @ 6599]
Mark Doliner <mark@kingant.net>
parents: 5487
diff changeset
72 if ($? == -1) {
e8204ffce9f8 [gaim-migrate @ 6599]
Mark Doliner <mark@kingant.net>
parents: 5487
diff changeset
73 return;
e8204ffce9f8 [gaim-migrate @ 6599]
Mark Doliner <mark@kingant.net>
parents: 5487
diff changeset
74 }
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 } while ($fortune eq "");
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
76 $fortune =~ s/\n/$nl/g;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77 $fortune =~ s/\t/$tab/g;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
78 } while ((length($fortune) + $len ) > $max);
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 $message = $fortune;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81 if ($pre_message ne "") {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82 $message = $pre_message . "---$nl" . $message;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
84 if ($post_message ne "") {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
85 $message = $message . "---$nl" . $post_message ;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
87
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
88 foreach $id (GAIM::get_info(1)) {GAIM::command("info", $id, $message);}
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 GAIM::add_timeout_handler($handle, $seconds, "update_away");
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
92 sub description {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 my($a, $b, $c, $d, $e, $f) = @_;
6125
e8204ffce9f8 [gaim-migrate @ 6599]
Mark Doliner <mark@kingant.net>
parents: 5487
diff changeset
94 ("Fortune Profile", "3.3", "Sets your AIM profile to a fortune (with a header and footer of your choice).",
e8204ffce9f8 [gaim-migrate @ 6599]
Mark Doliner <mark@kingant.net>
parents: 5487
diff changeset
95 "Sean Egan <bj91704\@binghamton.edu>", "http://gaim.sf.net/",
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 "/dev/null");
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 # output the first message and start the timers...
5487
3b0acfecf094 [gaim-migrate @ 5883]
Sean Egan <seanegan@gmail.com>
parents: 4603
diff changeset
100 # This is done as a timeout to prevent attempts to set the profile before logging in.
3b0acfecf094 [gaim-migrate @ 5883]
Sean Egan <seanegan@gmail.com>
parents: 4603
diff changeset
101 GAIM::add_timeout_handler($handle, $seconds, "update_away");