html/twtopic.pl
1 use vars qw($VERSION %IRSSI);
2 use Irssi;
3 use Irssi::Irc;
4 use Irssi::TextUI;
5
6 $VERSION = '1.01';
7 %IRSSI = (
8 authors => 'John Engelbrecht',
9 contact => 'jengelbr@yahoo.com',
10 name => 'twtopic.pl',
11 description => 'Animated Topic bar.',
12 license => 'Public Domain',
13 changed => 'Sat Nov 20 14:15:18 CST 2004',
14 url => 'http://irssi.darktalker.net'."\n",
15 );
16
17 my $instrut =
18 ".--------------------------------------------------.\n".
19 "| 1.) shell> mkdir ~/.irssi/scripts |\n".
20 "| 2.) shell> cp twtopic.pl ~/.irssi/scripts/ |\n".
21 "| 3.) shell> mkdir ~/.irssi/scripts/autorun |\n".
22 "| 4.) shell> ln -s ~/.irssi/scripts/twtopic.pl \\ |\n".
23 "| ~/.irssi/scripts/autorun/twtopic.pl |\n".
24 "| 5.) /sbar topic remove topic |\n".
25 "| 6.) /sbar topic remove topic_empty |\n".
26 "| 7.) /sbar topic add -after topicbarstart |\n".
27 "| -priority 100 -alignment left twtopic |\n".
28 "| 9.) /toggle twtopic_instruct and last /save |\n".
29 "|--------------------------------------------------|\n".
30 "| Options: Default: |\n".
31 "| /set twtopic_refresh <speed> 150 |\n".
32 "| /set twtopic_size <size> 20 |\n".
33 "| /toggle twtopic_instruct |Startup instructions |\n".
34 "\`--------------------------------------------------'";
35
36
37 my $start_pos=0;
38 my $flipflop=0;
39 my @mirc_color_arr = ("\0031","\0035","\0033","\0037","\0032","\0036","\00310","\0030","\00314","\0034","\0039","\0038","\00312","\00313","\00311","\00315","\017");
40
41
42 sub setup {
43 my $time = Irssi::settings_get_int('twtopic_refresh');
44 Irssi::timeout_remove($timeout);
45 $timeout = Irssi::timeout_add($time, 'reload' , undef);
46 }
47
48 sub show {
49 my ($item, $get_size_only) = @_;
50 $text = get();
51 $text="[".$text."]";
52 $item->default_handler($get_size_only,$text, undef, 1);
53 }
54
55 sub get_topic {
56 $topic = "";
57 $name = Irssi::active_win()->{active}->{name};
58 $type = Irssi::active_win()->{active}->{type};
59 $name = "Status" if($name eq "");
60 if($name eq "Status") { return "Irssi website: http://www.irssi.org, Irssi IRC channel: #irssi @ irc://irc.freenode:6667, twtopic has been written by Tech Wizard"; }
61 if($type eq "QUERY") {
62 $text = "You are now talking too...... ".$name;
63 return $text;
64 }
65 $channel = Irssi::Irc::Server->channel_find($name);
66 $topic = $channel->{topic};
67 foreach (@mirc_color_arr) { $topic =~ s/$_//g; }
68 return $topic;
69 }
70
71 sub get {
72 $str=get_topic();
73 $str =~ s/(\00313)+//;
74 $str =~ s/(\002)+//;
75 $str =~ s/(\001)+//;
76 $extra_str= " ";
77 $size = Irssi::settings_get_int('twtopic_size');
78 if($str eq "") {
79 my $str = "=-=-=-=-= No Topic=-=-=-=-=-=-=-";
80 }
81 @str_arr = split //, $str;
82 my $total = $#str_arr;
83 $str=substr($extra_str,0,$size).$str.$extra_str;
84 $text = substr($str,$start_pos,$size);
85 if($start_pos > $total+$size) {
86 $start_pos=0;
87 }
88 if(!$flipflop) {
89 $flipflop=1;
90 return $text;
91 }
92 $start_pos++;
93 $flipflop=0;
94 return $text;
95 }
96
97 Irssi::statusbar_item_register('twtopic', '$0', 'show');
98 Irssi::signal_add('setup changed', 'setup');
99 Irssi::settings_add_int('tech_addon', 'twtopic_refresh', 150);
100 Irssi::settings_add_bool('tech_addon', 'twtopic_instruct', 1);
101 Irssi::settings_add_int('tech_addon', 'twtopic_size',20);
102 $timeout = Irssi::timeout_add(Irssi::settings_get_int('twtopic_refresh'), 'reload' , undef);
103 sub reload { Irssi::statusbar_items_redraw('twtopic'); }
104
105 if(Irssi::settings_get_bool('twtopic_instruct')) {
106 print $instrut;
107 }
108