Sun, 20 May 2007 06:19:49 +0000
merge of 'b98e72d4089afb8a1879e5fe9627cfb132ee88de'
and 'b2836a24d81e7a1bd1d21b3aea8794b094391344'
| 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 | |
| 12406 | 8 | # seanegan@gmail.com |
| 3706 | 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
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
23 | # |
|
6899
0387d73614d5
[gaim-migrate @ 7446]
Christian Hammond <chipx86@chipx86.com>
parents:
6593
diff
changeset
|
24 | # Updated by Christian Hammond, 20 August 2003 |
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
25 | # Changes: |
|
9986601866d5
[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 |
|
9986601866d5
[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 | ||
|
6529
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
45 | use Gaim; |
|
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
46 | |
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
47 | %PLUGIN_INFO = ( |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
48 | perl_api_version => 2, |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
49 | name => "Fortune Profile", |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
50 | version => "3.4", |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
51 | summary => "Sets your AIM profile to a fortune (with a header and footer of your choice).", |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
52 | description => "Sets your AIM profile to a fortune (with a header and footer of your choice).", |
| 12406 | 53 | author => "Sean Egan <seanegan\@gmail.com>", |
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
54 | url => "http://gaim.sf.net/", |
| 3706 | 55 | |
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
56 | load => "plugin_load" |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
57 | ); |
| 3706 | 58 | |
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
59 | sub plugin_init { |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
60 | return %PLUGIN_INFO; |
| 3706 | 61 | } |
| 62 | ||
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
63 | sub plugin_load { |
|
6529
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
64 | $plugin = shift; |
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
65 | |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
66 | $tab = " "; |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
67 | $tab = $tab . $tab . $tab . $tab; |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
68 | $nl = "<BR>"; |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
69 | |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
70 | $seconds = 30; # Delay before updating away messages. |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
71 | $max = 1020; # Max length of an profile. It should be |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
72 | # 1024, but I am being safe |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
73 | $pre_message = ""; # This gets added before the fortune |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
74 | |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
75 | $post_message =""; |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
76 | |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
77 | $len = 0; |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
78 | if ($pre_message ne "") { |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
79 | $len += length( $pre_message . "---$nl" ); |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
80 | } |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
81 | if ($post_message ne "") { |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
82 | $len += length("---$nl" . $post_message); |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
83 | } |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
84 | |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
85 | # Command to get dynamic message from |
|
6529
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
86 | $command = "fortune -sn " . ($max - $len); |
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
87 | |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
88 | # output the first message and start the timers... |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
89 | # This is done as a timeout to prevent attempts to set the |
|
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
90 | # profile before logging in. |
|
6593
8f73eb37a5cc
[gaim-migrate @ 7117]
Christian Hammond <chipx86@chipx86.com>
parents:
6529
diff
changeset
|
91 | Gaim::timeout_add($plugin, $seconds, \&update_away, 0); |
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
92 | } |
| 3706 | 93 | |
| 94 | sub update_away { | |
| 95 | # The fortunes are expanded into HTML (the tabs and newlines) which | |
| 96 | # causes the -s option of fortune to be a little bit meaningless. This | |
| 97 | # will loop until it gets a fortune of a good size (after expansion). | |
|
6519
9986601866d5
[gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents:
6125
diff
changeset
|
98 | |
| 3706 | 99 | do { |
| 100 | do { #It's a while loop because it doesn't always work for some reason | |
| 101 | $fortune = `$command`; | |
|
6125
0e8df445d9dc
[gaim-migrate @ 6599]
Mark Doliner <markdoliner@pidgin.im>
parents:
5487
diff
changeset
|
102 | if ($? == -1) { |
|
0e8df445d9dc
[gaim-migrate @ 6599]
Mark Doliner <markdoliner@pidgin.im>
parents:
5487
diff
changeset
|
103 | return; |
|
0e8df445d9dc
[gaim-migrate @ 6599]
Mark Doliner <markdoliner@pidgin.im>
parents:
5487
diff
changeset
|
104 | } |
| 3706 | 105 | } while ($fortune eq ""); |
| 106 | $fortune =~ s/\n/$nl/g; | |
| 107 | $fortune =~ s/\t/$tab/g; | |
| 108 | } while ((length($fortune) + $len ) > $max); | |
| 109 | ||
| 110 | $message = $fortune; | |
| 111 | if ($pre_message ne "") { | |
| 112 | $message = $pre_message . "---$nl" . $message; | |
| 113 | } | |
| 114 | if ($post_message ne "") { | |
| 115 | $message = $message . "---$nl" . $post_message ; | |
| 116 | } | |
| 117 | ||
|
6529
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
118 | foreach $account (Gaim::accounts()) { |
|
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
119 | if ($account->is_connected()) { |
|
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
120 | $account->set_user_info($message); |
|
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
121 | } |
|
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
122 | } |
|
5a0984a84166
[gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents:
6519
diff
changeset
|
123 | |
|
6593
8f73eb37a5cc
[gaim-migrate @ 7117]
Christian Hammond <chipx86@chipx86.com>
parents:
6529
diff
changeset
|
124 | Gaim::timeout_add($plugin, $seconds, \&update_away, 0); |
| 3706 | 125 | } |