annotate plugins/fortuneprofile.pl @ 5247:60983a46700e

[gaim-migrate @ 5618] (22:40:26) Paco-Paco: gaim_find_buddy was an O(n) search through the blist tree, this adds an auxilliary hash to bring that down to O(1) committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 28 Apr 2003 02:41:00 +0000
parents 6316a0a33680
children 3b0acfecf094
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
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41 $handle = GAIM::register("Fortune Profile", "3.2", "", "");
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`;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72 } while ($fortune eq "");
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
73 $fortune =~ s/\n/$nl/g;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
74 $fortune =~ s/\t/$tab/g;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 } while ((length($fortune) + $len ) > $max);
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
76
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77 $message = $fortune;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
78 if ($pre_message ne "") {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79 $message = $pre_message . "---$nl" . $message;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81 if ($post_message ne "") {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82 $message = $message . "---$nl" . $post_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
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
85 foreach $id (GAIM::get_info(1)) {GAIM::command("info", $id, $message);}
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86 GAIM::add_timeout_handler($handle, $seconds, "update_away");
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
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 sub description {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90 my($a, $b, $c, $d, $e, $f) = @_;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91 ("Fortune Profile", "3.2", "Sets your AIM profile to a fortune (with a header and footer of your choice).",
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
92 "Sean Egan &lt;bj91704\@binghamton.edu>", "http://gaim.sf.net/",
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 "/dev/null");
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 # output the first message and start the timers...
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 update_away();