Mercurial > pidgin
annotate plugins/fortuneprofile.pl @ 6526:e162c765fe21
[gaim-migrate @ 7043]
And do it correctly, because crashing isn't in style anymore.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Wed, 20 Aug 2003 10:47:41 +0000 |
| parents | 7f0fffa1077b |
| children | e4e87ffd9f14 |
| rev | line source |
|---|---|
| 3706 | 1 # FORTUNE PROFILE |
| 2 # | |
| 3 # Sets your AIM profile to a fortune (with a header and footer of your | |
| 4 # choice). | |
| 5 # | |
| 6 | |
| 7 # By Sean Egan | |
| 8 # bj91704@binghamton.edu | |
| 9 # AIM: SeanEgn | |
| 10 # | |
| 11 # Updated by Nathan Conrad, 31 January 2002 | |
| 12 # Changes: | |
| 13 # * Fortunes have HTML tabs and newlines | |
| 14 # AIM: t98502 | |
| 15 # ICQ: 16106363 | |
| 16 # | |
| 17 # Updated by Mark Doliner, 15 October 2002 | |
| 18 # Changes: | |
| 19 # * Modified to work with the changed perl interface of gaim 0.60 | |
| 20 # * Fixed a bug where your info would be set to nothing if you had | |
| 21 # no pre and no post message | |
| 22 # AIM: lbdash | |
|
6519
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
23 # |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
24 # Updated by Christian Hammond, 20 August 2002 |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
25 # Changes: |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
26 # * Modified to work with the changed perl interface of gaim 0.68 |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
27 # AIM: ChipX86 |
| 3706 | 28 |
| 29 # Copyright (C) 2001 Sean Egan | |
| 30 | |
| 31 # This program is free software; you can redistribute it and/or modify | |
| 32 # it under the terms of the GNU General Public License as published by | |
| 33 # the Free Software Foundation; either version 2 of the License, or | |
| 34 # (at your option) any later version. | |
| 35 # | |
| 36 # This program is distributed in the hope that it will be useful, | |
| 37 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 38 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 39 # GNU General Public License for more details. | |
| 40 # | |
| 41 # You should have received a copy of the GNU General Public License | |
| 42 # along with this program; if not, write to the Free Software | |
| 43 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 44 | |
|
6519
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
45 %PLUGIN_INFO = ( |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
46 perl_api_version => 2, |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
47 name => "Fortune Profile", |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
48 version => "3.4", |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
49 summary => "Sets your AIM profile to a fortune (with a header and footer of your choice).", |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
50 description => "Sets your AIM profile to a fortune (with a header and footer of your choice).", |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
51 author => "Sean Egan <bj91704\@binghamton.edu>", |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
52 url => "http://gaim.sf.net/", |
| 3706 | 53 |
|
6519
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
54 load => "plugin_load" |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
55 ); |
| 3706 | 56 |
|
6519
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
57 sub plugin_init { |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
58 return %PLUGIN_INFO; |
| 3706 | 59 } |
| 60 | |
|
6519
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
61 sub plugin_load { |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
62 my $plugin = shift; |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
63 |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
64 $tab = " "; |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
65 $tab = $tab . $tab . $tab . $tab; |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
66 $nl = "<BR>"; |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
67 |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
68 $seconds = 30; # Delay before updating away messages. |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
69 $max = 1020; # Max length of an profile. It should be |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
70 # 1024, but I am being safe |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
71 $pre_message = ""; # This gets added before the fortune |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
72 |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
73 $post_message =""; |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
74 |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
75 $len = 0; |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
76 if ($pre_message ne "") { |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
77 $len += length( $pre_message . "---$nl" ); |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
78 } |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
79 if ($post_message ne "") { |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
80 $len += length("---$nl" . $post_message); |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
81 } |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
82 |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
83 # Command to get dynamic message from |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
84 $command = "fortune -sn " . ($max - $len); |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
85 |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
86 # output the first message and start the timers... |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
87 # This is done as a timeout to prevent attempts to set the |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
88 # profile before logging in. |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
89 Gaim::timeout_add($plugin, $seconds, "update_away"); |
|
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
90 } |
| 3706 | 91 |
| 92 sub update_away { | |
| 93 # The fortunes are expanded into HTML (the tabs and newlines) which | |
| 94 # causes the -s option of fortune to be a little bit meaningless. This | |
| 95 # will loop until it gets a fortune of a good size (after expansion). | |
|
6519
7f0fffa1077b
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
96 |
| 3706 | 97 do { |
| 98 do { #It's a while loop because it doesn't always work for some reason | |
| 99 $fortune = `$command`; | |
| 6125 | 100 if ($? == -1) { |
| 101 return; | |
| 102 } | |
| 3706 | 103 } while ($fortune eq ""); |
| 104 $fortune =~ s/\n/$nl/g; | |
| 105 $fortune =~ s/\t/$tab/g; | |
| 106 } while ((length($fortune) + $len ) > $max); | |
| 107 | |
| 108 $message = $fortune; | |
| 109 if ($pre_message ne "") { | |
| 110 $message = $pre_message . "---$nl" . $message; | |
| 111 } | |
| 112 if ($post_message ne "") { | |
| 113 $message = $message . "---$nl" . $post_message ; | |
| 114 } | |
| 115 | |
| 116 foreach $id (GAIM::get_info(1)) {GAIM::command("info", $id, $message);} | |
| 117 GAIM::add_timeout_handler($handle, $seconds, "update_away"); | |
| 118 } | |
| 119 | |
| 120 |
