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