archive

- Random tools & helpful resources for IRC
git clone git://git.acid.vegas/archive.git
Log | Files | Refs | Archive

commit 997720c5d48f1a804930964973833e71bc93a6fe
parent 447473022880eedb21585b99550d77e702c75343
Author: acidvegas <acid.vegas@acid.vegas>
Date: Tue, 12 Sep 2023 15:47:16 -0400

moved stuff around

Diffstat:
Mart/irc2ansi.py | 5+++--
Abots/blackhole/README.md | 16++++++++++++++++
Abots/blackhole/blackhole/.irssi/certs/.gitignore | 5+++++
Abots/blackhole/blackhole/.irssi/config | 181+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/default.theme | 533+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/logs/.gitignore | 5+++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/awl.pl | 2552+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/chansort.pl | 44++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/dispatch.pl | 14++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/limit.pl | 33+++++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/masshlkick.pl | 31+++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/nickcolor.pl | 146+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/rejoin.pl | 32++++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/timer.pl | 175+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/trigger.pl | 1248+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/unfuck.pl | 15+++++++++++++++
Abots/blackhole/blackhole/.irssi/scripts/autorun/voicer.pl | 28++++++++++++++++++++++++++++
Abots/blackhole/blackhole/.irssi/startup | 1+
Abots/blackhole/blackhole/.irssi/triggers | 9+++++++++
Abots/blackhole/honeypot/.irssi/config | 178+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/honeypot/.irssi/default.theme | 533+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/honeypot/.irssi/scripts/autorun/awl.pl | 2552+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/honeypot/.irssi/scripts/autorun/chansort.pl | 44++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/honeypot/.irssi/scripts/autorun/dispatch.pl | 14++++++++++++++
Abots/blackhole/honeypot/.irssi/scripts/autorun/killreconnect.pl | 13+++++++++++++
Abots/blackhole/honeypot/.irssi/scripts/autorun/nickcolor.pl | 146+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/honeypot/.irssi/scripts/autorun/rejoin.pl | 32++++++++++++++++++++++++++++++++
Abots/blackhole/honeypot/.irssi/scripts/autorun/trigger.pl | 1248+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abots/blackhole/honeypot/.irssi/scripts/autorun/unfuck.pl | 15+++++++++++++++
Abots/blackhole/honeypot/.irssi/triggers | 3+++
Abots/hugecock.py | 278+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Defkh.py | 68--------------------------------------------------------------------
Rhueg-hexchat.pl -> scripts/hexchat/hueg.pl | 0
Ascripts/irssi/antifuckyou.pl | 21+++++++++++++++++++++
Ascripts/irssi/fuckyou.pl | 38++++++++++++++++++++++++++++++++++++++
Ascripts/irssi/takeover.pl | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/irssi/v.pl | 17+++++++++++++++++
Rweechat-scripts/antifuck.pl -> scripts/weechat/antifuck.pl | 0
Rweechat-scripts/banner.pl -> scripts/weechat/banner.pl | 0
Rweechat-scripts/colo.py -> scripts/weechat/colo.py | 0
Rweechat-scripts/coloconv.pl -> scripts/weechat/coloconv.pl | 0
Rweechat-scripts/hueg.pl -> scripts/weechat/hueg.pl | 0
Rweechat-scripts/masshl.py -> scripts/weechat/masshl.py | 0
Rweechat-scripts/parrot.pl -> scripts/weechat/parrot.pl | 0
Rweechat-scripts/play.pl -> scripts/weechat/play.pl | 0
Rweechat-scripts/prismx.py -> scripts/weechat/prismx.py | 0
Rweechat-scripts/sighup.pl -> scripts/weechat/sighup.pl | 0
Rweechat-scripts/snomasks.pl -> scripts/weechat/snomasks.pl | 0
Rweechat-scripts/whoishex.pl -> scripts/weechat/whoishex.pl | 0

49 files changed, 10266 insertions(+), 70 deletions(-)

diff --git a/art/irc2ansi.py b/art/irc2ansi.py
@@ -84,8 +84,9 @@ if __name__ == '__main__':
 				with open(path, 'rb') as art_file:
 					data = art_file.read()
 					enc  = chardet.detect(data)['encoding']
-					for line in IRC2ANSI(data.decode(enc)).split('\n'):
-						print(line)
+					lines = IRC2ANSI(data.decode(enc)).split('\n')
+					for line in lines:
+						print(line + ' ' + str(len(line)))
 						time.sleep(0.05)
 
 			if os.path.isdir(option):
diff --git a/bots/blackhole/README.md b/bots/blackhole/README.md
@@ -0,0 +1,15 @@
+# blackhole
+A bot mitigation system for the Internet Relay Chat (IRC) protocol.
+
+###### Information
+The entire blackhole system works on IRSSI connections across different boxes.
+
+The honeypot connections will message the blackhole connection the nick of anyone who does a CTCP, DCC, INVITE, or Private Message.
+
+The blackhole bot will kill anyone who triggers the honeypots, it will also kick anyone who masshilights or hilights a honeypot.
+
+Honeypot nicks and hosts need to be added to the 'triggers' file and reloaded on the blackhole connection.
+
+Make sure you do `chmod -w triggers` on the honypot's `triggers` file to prevent accidental removal of triggers.
+
+You can change the `/timer add limit 300 /alimit` line in the blackhole startup file to `/timer add limit 300 /acslimit` to use ChanServs mode lock feature.
+\ No newline at end of file
diff --git a/bots/blackhole/blackhole/.irssi/certs/.gitignore b/bots/blackhole/blackhole/.irssi/certs/.gitignore
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
+\ No newline at end of file
diff --git a/bots/blackhole/blackhole/.irssi/config b/bots/blackhole/blackhole/.irssi/config
@@ -0,0 +1,181 @@
+servers = (
+  { address = "localhost"; chatnet = "supernets"; port = "6697"; autoconnect = "no"; use_ssl = "yes";  ssl_cert = "~/.irssi/certs/blackhole.pem"; }
+);
+
+chatnets = {
+  supernets = { type = "IRC"; autosendcmd = "/^msg nickserv identify CHANGEME; wait 2000; /^oper blackhole *"; };
+};
+
+channels = (
+  { name = "#christ";    chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#dev";       chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#help";      chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#pumpcoin";  chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#scroll";    chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#superbowl"; chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#tor";       chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#tunes";     chatnet = "supernets"; autojoin = "yes"; }
+);
+
+aliases = {
+  alimit         = "foreach channel /limit";
+  acslimit       = "foreach channel /cslimit";
+  blackhole_kick = "eval KICK $0 $1 \00308,04          E N T E R   T H E   V O I D          \017";
+  blackhole_kill = "eval KILL $0 \00308,04          E N T E R   T H E   V O I D          \017";
+  wc             = "window close";
+};
+
+statusbar = {
+  items = {
+    barstart = "{sbstart}";
+    barend = "{sbend}";
+    topicbarstart = "{topicsbstart}";
+    topicbarend = "{topicsbend}";
+    time = "";
+    user = "";
+    window = "";
+    window_empty = "";
+    prompt = "{prompt $[.15]itemname@$tag}";
+    prompt_empty = "{prompt $winname}";
+    topic = " $topic";
+    topic_empty = "";
+    act = "";
+    lag = "";
+    more = "-- more --";
+  };
+  default = {
+    window = {
+      disabled = "yes";
+      type = "window";
+      placement = "bottom";
+      position = "1";
+      visible = "active";
+      items = {
+        barstart = { priority = "100"; };
+        time = { };
+        user = { };
+        window = { };
+        window_empty = { };
+        lag = { priority = "-1"; };
+        more = { priority = "-1"; alignment = "right"; };
+        barend = { priority = "100"; alignment = "right"; };
+      };
+    };
+    window_inact = {
+      type = "window";
+      placement = "bottom";
+      position = "1";
+      visible = "inactive";
+      items = {
+        barstart = { priority = "100"; };
+        window = { };
+        window_empty = { };
+        more = { priority = "-1"; alignment = "right"; };
+        barend = { priority = "100"; alignment = "right"; };
+      };
+      disabled = "yes";
+    };
+    prompt = {
+      type = "root";
+      placement = "bottom";
+      position = "100";
+      visible = "always";
+      items = {
+        prompt = { priority = "-1"; };
+        prompt_empty = { priority = "-1"; };
+        colours = { alignment = "right"; };
+        input = { priority = "10"; };
+      };
+    };
+    topic = {
+      type = "root";
+      placement = "top";
+      position = "1";
+      visible = "always";
+      items = {
+        topicbarstart = { priority = "100"; };
+        topic = { };
+        topic_empty = { };
+        topicbarend = { priority = "100"; alignment = "right"; };
+      };
+    };
+    inact = { items = { }; disabled = "yes"; };
+    awl_0 = {
+      items = {
+        barstart = { priority = "100"; };
+        awl_0 = { };
+        barend = { priority = "100"; alignment = "right"; };
+      };
+    };
+  };
+};
+
+settings = {
+  core = {
+    nick = "blackhole";
+    quit_message = "G-line: User has been permanently banned from this network.";
+    real_name = "ENTER THE VOID";
+    settings_autosave = "yes";
+    timestamp_format = "%I:%M";
+    user_name = "BL";
+    server_reconnect_time = "5min";
+    recode_fallback = "UTF-8";
+    recode_out_default_charset = "UTF-8";
+    recode_transliterate = "yes";
+    recode = "yes";
+    recode_autodetect_utf8 = "yes";
+    awaylog_level = "hilight";
+    awaylog_file = "~/.irssi/logs/away.log";
+  };
+  "fe-text" = { actlist_sort = "refnum"; };
+  "irc/core" = {
+    alternate_nick = "blackhole_";
+    channel_sync = "yes";
+    cmds_max_at_once = "0";
+    cmd_queue_speed = "0";
+    ctcp_version_reply = "?";
+    ctcp_userinfo_reply = "?";
+    max_ctcp_queue = "0";
+    part_message = "G-line: User has been permanently banned from this network.";
+    usermode = "+ix";
+    skip_motd = "yes";
+    ban_type = "host";
+    kick_first_on_kickban = "yes";
+  };
+  "irc/flood" = { flood_timecheck = "0"; flood_max_msgs = "0"; };
+  "fe-common/core" = {
+    show_names_on_join = "no";
+    beep_msg_level = "MSGS HILIGHT";
+    term_charset = "UTF-8";
+    max_command_history = "25";
+    autolog_path = "~/.irssi/logs/$tag/$0.log";
+    autocreate_query_level = "MSGS";
+    activity_hilight_level = "MSGS";
+    beep_when_away = "no";
+    beep_when_window_active = "no";
+    hilight_level = "PUBLIC";
+  };
+  "perl/core/scripts" = {
+    nickcolor_colors = "3 5 6 7 10 11 12 13 14";
+    awl_shared_sbar = "OFF";
+    awl_block = "-14";
+    awl_viewer = "no";
+    awl_prefer_name = "yes";
+    awl_sbar_maxlength = "yes";
+    chansort_autosort = "yes";
+    awl_mouse = "yes";
+  };
+};
+
+windows = { 1 = { immortal = "yes"; name = "status"; level = "ALL"; }; };
+mainwindows = { 1 = { first_line = "7"; lines = "13"; }; };
+logs = { };
+keyboard = ( 
+  { key = "meta-[M"; id = "command"; data = "mouse_xterm"; }
+);
+ignores = (
+  { mask = "*!*@services.supernets.org"; level = "CRAP MSGS PUBLICS NOTICES SNOTES CTCPS ACTIONS MODES TOPICS WALLOPS INVITES NICKS DCC DCCMSGS CLIENTNOTICES CLIENTCRAP CLIENTERRORS HILIGHTS"; servertag = "supernets"; },
+  { mask = "*!*@super.nets";             level = "CRAP MSGS PUBLICS NOTICES SNOTES CTCPS ACTIONS MODES TOPICS WALLOPS INVITES NICKS DCC DCCMSGS CLIENTNOTICES CLIENTCRAP CLIENTERRORS HILIGHTS"; servertag = "supernets"; },
+  { mask = "*!*@super.nets.bot";         level = "CRAP MSGS PUBLICS NOTICES SNOTES CTCPS ACTIONS MODES TOPICS WALLOPS INVITES NICKS DCC DCCMSGS CLIENTNOTICES CLIENTCRAP CLIENTERRORS HILIGHTS"; servertag = "supernets"; },
+  { mask = "*!*@super.nets.link";        level = "CRAP MSGS PUBLICS NOTICES SNOTES CTCPS ACTIONS MODES TOPICS WALLOPS INVITES NICKS DCC DCCMSGS CLIENTNOTICES CLIENTCRAP CLIENTERRORS HILIGHTS"; servertag = "supernets"; }
+);
diff --git a/bots/blackhole/blackhole/.irssi/default.theme b/bots/blackhole/blackhole/.irssi/default.theme
@@ -0,0 +1,533 @@
+default_color = "-1";
+info_eol = "false";
+replaces = { "[]=" = "%K$*%n"; "<>=" = "%K$*%n"; };
+abstracts = {
+  line_start = "";
+  timestamp = "[$*]";
+  hilight = "%_$*%_";
+  error = "%R$*%n";
+  channel = "%_%b$*%_%w";
+  nick = "%_$*%_";
+  nickhost = "[$*]";
+  server = "%_$*%_";
+  comment = "[$*]";
+  reason = "{comment $*}";
+  mode = "{comment $*}";
+  channick_hilight = "%b$*%n";
+  chanhost_hilight = "{nickhost %b$*%n}";
+  channick = "%_$*%_";
+  chanhost = "{nickhost $*}";
+  channelhilight = "%b$*%n";
+  ban = "%c$*%n";
+  msgnick = "%K<%n$0$1-%K>%n %|";
+  ownmsgnick = "{msgnick $0 $1-}";
+  ownnick = "%_$*%n";
+  pubmsgnick = "{msgnick $0 $1-}";
+  pubnick = "%N$*%n";
+  pubmsgmenick = "{msgnick $0 $1-}";
+  menick = "%Y$*%n";
+  pubmsghinick = "{msgnick $0$1$2-%n}";
+  msgchannel = "%K:%c$*%n";
+  privmsg = "[%R$0%K(%r$1-%K)%n] ";
+  ownprivmsg = "[%r$0%K(%R$1-%K)%n] ";
+  ownprivmsgnick = "{msgnick  $*}";
+  ownprivnick = "%_$*%n";
+  privmsgnick = "{msgnick  %R$*%n}";
+  action_core = "%_ * $*%n";
+  action = "{action_core $*} ";
+  ownaction = "{action $*}";
+  ownaction_target = "{action_core $0}%K:%c$1%n ";
+  pvtaction = "%_ (*) $*%n ";
+  pvtaction_query = "{action $*}";
+  pubaction = "{action $*}";
+  whois = "%# $[8]0 : $1-";
+  ownnotice = "[%m$0%K]%n ";
+  notice = "[%m$*%K]%n ";
+  pubnotice_channel = "%K:%m$*";
+  pvtnotice_host = "%K(%m$*%K)";
+  servernotice = "%g!$*%n ";
+  ownctcp = "[%r$0%K(%R$1-%K)] ";
+  ctcp = "%g$*%n";
+  wallop = "%_$*%n: ";
+  wallop_nick = "%n$*";
+  wallop_action = "%_ * $*%n ";
+  netsplit = "%b$*%n";
+  netjoin = "%g$*%n";
+  names_prefix = "";
+  names_nick = "[%_$0%_$1-] ";
+  names_nick_op = "{names_nick $*}";
+  names_nick_halfop = "{names_nick $*}";
+  names_nick_voice = "{names_nick $*}";
+  names_users = "[%g$*%n]";
+  names_channel = "%G$*%n";
+  dcc = "%g$*%n";
+  dccfile = "%_$*%_";
+  dccownmsg = "[%r$0%K($1-%K)%n] ";
+  dccownnick = "%R$*%n";
+  dccownquerynick = "%_$*%n";
+  dccownaction = "{action $*}";
+  dccownaction_target = "{action_core $0}%K:%c$1%n ";
+  dccmsg = "[%G$1-%K(%g$0%K)%n] ";
+  dccquerynick = "%G$*%n";
+  dccaction = "%_ (*dcc*) $*%n %|";
+  sb_background = "%n%w";
+  sb_default_bg = "%n";
+  sb_prompt_bg = "%n";
+  sb_info_bg = "%n";
+  sb_topic_bg = "%n";
+  sbstart = "";
+  sbend = " ";
+  topicsbstart = "%_[IRSSI]%_{sbstart $*}";
+  topicsbend = "{sbend $*}";
+  prompt = "[%b$*%w] ";
+  sb = "%K[%n$*%K]%n";
+  sbmode = " %c+%n$*";
+  sbaway = " %GzZzZ%n";
+  sbservertag = ":$0";
+  sbnickmode = "$0";
+  sb_act_sep = "%c$*";
+  sb_act_text = "%W$*";
+  sb_act_msg = "%c$*";
+  sb_act_hilight = "%Y$*";
+  sb_act_hilight_color = "$0$1-%n";
+};
+formats = {
+  "fe-common/irc/dcc" = {
+    own_dcc = "{dccownmsg dcc {dccownnick $1}}$2";
+    own_dcc_action = "{dccownaction_target $0 $1}$2";
+    own_dcc_action_query = "{dccownaction $0}$2";
+    own_dcc_ctcp = "{ownctcp ctcp $0}$1 $2";
+    dcc_msg = "{dccmsg dcc $0}$1";
+    action_dcc = "{dccaction $0}$1";
+    action_dcc_query = "{dccaction $0}$1";
+    own_dcc_query = "{ownmsgnick {dccownquerynick $0}}$2";
+    dcc_msg_query = "{privmsgnick $0}$1";
+    dcc_ctcp = "{dcc >>> DCC CTCP {hilight $1} received from {hilight $0}: $2}";
+    dcc_chat = "{dcc DCC CHAT from {nick $0} [$1 port $2]}";
+    dcc_chat_channel = "{dcc DCC CHAT from {nick $0} [$1 port $2] requested in channel {channel $3}}";
+    dcc_chat_not_found = "{dcc No DCC CHAT connection open to {nick $0}}";
+    dcc_chat_connected = "{dcc DCC CHAT connection with {nick $0} [$1 port $2] established}";
+    dcc_chat_disconnected = "{dcc DCC lost chat to {nick $0}}";
+    dcc_send = "{dcc DCC SEND from {nick $0} [$1 port $2]: $3 [$4]}";
+    dcc_send_channel = "{dcc DCC SEND from {nick $0} [$1 port $2]: $3 [$4 bytes] requested in channel {channel $5}}";
+    dcc_send_exists = "{dcc DCC already sending file {dccfile $0} for {nick $1}}";
+    dcc_send_no_route = "{dcc DCC route lost to nick {nick $0} when trying to send file {dccfile $1}}";
+    dcc_send_not_found = "{dcc DCC not sending file {dccfile $1} to {nick $0}}";
+    dcc_send_file_open_error = "{dcc DCC can't open file {dccfile $0}: $1}";
+    dcc_send_connected = "{dcc DCC sending file {dccfile $0} for {nick $1} [$2 port $3]}";
+    dcc_send_complete = "{dcc DCC sent file {dccfile $0} [{hilight $1}] for {nick $2} in {hilight $3} [{hilight $4kB/s}]}";
+    dcc_send_aborted = "{dcc DCC aborted sending file {dccfile $0} for {nick $1}}";
+    dcc_get_not_found = "{dcc DCC no file offered by {nick $0}}";
+    dcc_get_connected = "{dcc DCC receiving file {dccfile $0} from {nick $1} [$2 port $3]}";
+    dcc_get_complete = "{dcc DCC received file {dccfile $0} [$1] from {nick $2} in {hilight $3} [$4kB/s]}";
+    dcc_get_aborted = "{dcc DCC aborted receiving file {dccfile $0} from {nick $1}}";
+    dcc_get_write_error = "{dcc DCC error writing to file {dccfile $0}: {comment $1}";
+    dcc_unknown_ctcp = "{dcc DCC unknown ctcp {hilight $0} from {nick $1} [$2]}";
+    dcc_unknown_reply = "{dcc DCC unknown reply {hilight $0} from {nick $1} [$2]}";
+    dcc_unknown_type = "{dcc DCC unknown type {hilight $0}}";
+    dcc_invalid_ctcp = "{dcc DCC received CTCP {hilight $0} with invalid parameters from {nick $1}}";
+    dcc_connect_error = "{dcc DCC can't connect to {hilight $0} port {hilight $1}}";
+    dcc_cant_create = "{dcc DCC can't create file {dccfile $0}: $1}";
+    dcc_rejected = "{dcc DCC $0 was rejected by {nick $1} [{hilight $2}]}";
+    dcc_request_send = "{dcc DCC $0 request sent to {nick $1}: $2";
+    dcc_close = "{dcc DCC $0 close for {nick $1} [{hilight $2}]}";
+    dcc_lowport = "{dcc Warning: Port sent with DCC request is a lowport ({hilight $0, $1}) - this isn't normal. It is possible the address/port is faked (or maybe someone is just trying to bypass firewall)}";
+    dcc_list_header = "{dcc DCC connections}";
+    dcc_list_line_chat = "{dcc  $0 $1}";
+    dcc_list_line_file = "{dcc  $0 $1: %|$2 of $3 ($4%%) - $5kB/s - ETA $7 - $6}";
+    dcc_list_line_queued_send = "{dcc   - $0 $2 (queued)}";
+    dcc_list_footer = "";
+    dcc_list_line_server = "{dcc  $0: Port($1) - Send($2) - Chat($3) - Fserve($4)}";
+    dcc_server_started = "{dcc  DCC SERVER started on port {hilight $0}}";
+    dcc_server_closed = "{dcc  DCC SERVER on port {hilight $0} closed}";
+  };
+  "fe-common/irc/notifylist" = {
+    notify_join = "{nick $0} [$1@$2] [{hilight $3}] has joined to $4";
+    notify_part = "{nick $0} has left $4";
+    notify_away = "{nick $0} [$5] [$1@$2] [{hilight $3}] is now away: $4";
+    notify_unaway = "{nick $0} [$4] [$1@$2] [{hilight $3}] is now unaway";
+    notify_online = "On $0: {hilight $1}";
+    notify_offline = "Offline: $0";
+    notify_list = "$0: $1 $2";
+    notify_list_empty = "The notify list is empty";
+  };
+  "fe-common/core" = {
+    line_start = "{line_start}";
+    #line_start_irssi = "{line_start}{hilight Irssi:} ";
+    line_start_irssi = "";
+    timestamp = "{timestamp $Z} ";
+    servertag = "[$0] ";
+    daychange = "Day changed to %%d %%b %%Y";
+    talking_with = "You are now talking with {nick $0}";
+    refnum_too_low = "Window number must be greater than 1";
+    error_server_sticky = "Window's server is sticky and it cannot be changed without -unsticky option";
+    set_server_sticky = "Window's server set sticky";
+    unset_server_sticky = "Window's server isn't sticky anymore";
+    window_name_not_unique = "Window names must be unique";
+    window_level = "Window level is now $0";
+    window_set_immortal = "Window is now immortal";
+    window_unset_immortal = "Window isn't immortal anymore";
+    window_immortal_error = "Window is immortal, if you really want to close it, say /WINDOW IMMORTAL OFF";
+    windowlist_header = "%#Ref Name                 Active item     Server          Level";
+    windowlist_line = "%#$[3]0 %|$[20]1 $[15]2 $[15]3 $4";
+    windowlist_footer = "";
+    windows_layout_saved = "Layout of windows is now remembered";
+    windows_layout_reset = "Layout of windows reset to defaults";
+    window_info_header = "";
+    window_info_footer = "";
+    window_info_refnum = "%#Window  : {hilight #$0}";
+    window_info_refnum_sticky = "%#Window  : {hilight #$0 (sticky)}";
+    window_info_name = "%#Name    : $0";
+    window_info_history = "%#History : $0";
+    window_info_immortal = "%#Immortal: yes";
+    window_info_size = "%#Size    : $0x$1";
+    window_info_level = "%#Level   : $0";
+    window_info_server = "%#Server  : $0";
+    window_info_server_sticky = "%#Server  : $0 (sticky)";
+    window_info_theme = "%#Theme   : $0$1";
+    window_info_bound_items_header = "%#Bounds  : {hilight Name                           Server tag}";
+    window_info_bound_item = "%#        : $[!30]0 $[!15]1 $2";
+    window_info_bound_items_footer = "";
+    window_info_items_header = "%#Items   : {hilight Name                           Server tag}";
+    window_info_item = "%# $[7]0: $[!30]1 $2";
+    window_info_items_footer = "";
+    looking_up = "Looking up {server $0}";
+    connecting = "Connecting to {server $0} [$1] port {hilight $2}";
+    reconnecting = "Reconnecting to {server $0} [$1] port {hilight $2} - use /RMRECONNS to abort";
+    connection_established = "Connection to {server $0} established";
+    cant_connect = "Unable to connect server {server $0} port {hilight $1} {reason $2}";
+    connection_lost = "Connection lost to {server $0}";
+    lag_disconnected = "No PONG reply from server {server $0} in $1 seconds, disconnecting";
+    disconnected = "Disconnected from {server $0} {reason $1}";
+    server_quit = "Disconnecting from server {server $0}: {reason $1}";
+    server_changed = "Changed to {hilight $2} server {server $1}";
+    unknown_server_tag = "Unknown server tag {server $0}";
+    no_connected_servers = "Not connected to any servers";
+    server_list = "{server $0}: $1:$2 ($3)";
+    server_lookup_list = "{server $0}: $1:$2 ($3) (connecting...)";
+    server_reconnect_list = "{server $0}: $1:$2 ($3) ($5 left before reconnecting)";
+    server_reconnect_removed = "Removed reconnection to server {server $0} port {hilight $1}";
+    server_reconnect_not_found = "Reconnection tag {server $0} not found";
+    setupserver_added = "Server {server $0} saved";
+    setupserver_removed = "Server {server $0} removed";
+    setupserver_not_found = "Server {server $0} not found";
+    your_nick = "Your nickname is {nick $0}";
+    join = "<%gJoin> {channick $0} {chanhost $1}";
+    part = "<%rPart> {channick $0} {chanhost $1} {reason $3}";
+    kick = "<%rKick> {channick $0} was kicked by {nick $2} {reason $3}";
+    quit = "<%rQuit> {channick $0} {chanhost $1} {reason $2}";
+    quit_once = "<%rQuit> {channel $3} {channick $0} {chanhost $1} {reason $2}";
+    invite = "{nick $0} invites you to {channel $1}";
+    not_invited = "You have not been invited to a channel!";
+    new_topic = "<%btopic> %b\"$2\"%w set by {nick $0}";
+    topic_unset = "Topic unset by {nick $0} on {channel $1}";
+    your_nick_changed = "<%bNick> You are now {nick $1}";
+    nick_changed = "<%bNick> {channick $0} is now {channick $1}";
+    talking_in = "You are now talking in {channel $0}";
+    not_in_channels = "You are not on any channels";
+    current_channel = "Current channel {channel $0}";
+    #names = "{names_users Users {names_channel $0}}";
+    names = "";
+    names_prefix = "%#{names_prefix $0}";
+    names_nick_op = "{names_nick_op $0 $1}";
+    names_nick_halfop = "{names_nick_halfop $0 $1}";
+    names_nick_voice = "{names_nick_voice $0 $1}";
+    names_nick = "{names_nick $0 $1}";
+    endofnames = "{channel $0} - Total of {hilight $1} nicks {comment {hilight $2} ops, {hilight $3} halfops, {hilight $4} voices, {hilight $5} normal}";
+    chanlist_header = "%#You are on the following channels:";
+    chanlist_line = "%#{channel $[-10]0} %|+$1 ($2): $3";
+    chansetup_not_found = "Channel {channel $0} not found";
+    chansetup_added = "Channel {channel $0} saved";
+    chansetup_removed = "Channel {channel $0} removed";
+    chansetup_header = "%#Channel         Network    Password   Settings";
+    chansetup_line = "%#{channel $[15]0} %|$[10]1 $[10]2 $3";
+    chansetup_footer = "";
+    own_msg = "{ownmsgnick $2 {ownnick $0}}$1";
+    own_msg_channel = "{ownmsgnick $3 {ownnick $0}{msgchannel $1}}$2";
+    own_msg_private = "{ownprivmsg msg $0}$1";
+    own_msg_private_query = "{ownprivmsgnick {ownprivnick $2}}$1";
+    pubmsg_me = "{pubmsgmenick $2 {menick $0}}$1";
+    pubmsg_me_channel = "{pubmsgmenick $3 {menick $0}{msgchannel $1}}$2";
+    pubmsg_hilight = "{pubmsghinick $0 $3 $1}$2";
+    pubmsg_hilight_channel = "{pubmsghinick $0 $4 $1{msgchannel $2}}$3";
+    pubmsg = "{pubmsgnick $2 {pubnick \00306$0}}$1";
+    pubmsg_channel = "{pubmsgnick $3 {pubnick $0}{msgchannel $1}}$2";
+    msg_private = "{privmsg $0 $1}$2";
+    msg_private_query = "{privmsgnick $0}$2";
+    no_msgs_got = "You have not received a message from anyone yet";
+    no_msgs_sent = "You have not sent a message to anyone yet";
+    query_start = "Starting query in {server $1} with {nick $0}";
+    query_stop = "Closing query with {nick $0}";
+    no_query = "No query with {nick $0}";
+    query_server_changed = "Query with {nick $0} changed to server {server $1}";
+    hilight_header = "%#Highlights:";
+    hilight_line = "%#$[-4]0 $1 $2 $3$4";
+    hilight_footer = "";
+    hilight_not_found = "Highlight not found: $0";
+    hilight_removed = "Highlight removed: $0";
+    alias_added = "Alias $0 added";
+    alias_removed = "Alias $0 removed";
+    alias_not_found = "No such alias: $0";
+    aliaslist_header = "%#Aliases:";
+    aliaslist_line = "%#$[10]0 $1";
+    aliaslist_footer = "";
+    log_opened = "Log file {hilight $0} opened";
+    log_closed = "Log file {hilight $0} closed";
+    log_create_failed = "Couldn't create log file {hilight $0}: $1";
+    log_locked = "Log file {hilight $0} is locked, probably by another running Irssi";
+    log_not_open = "Log file {hilight $0} not open";
+    log_started = "Started logging to file {hilight $0}";
+    log_stopped = "Stopped logging to file {hilight $0}";
+    log_list_header = "%#Logs:";
+    log_list = "%#$0 $1: $2 $3$4$5";
+    log_list_footer = "";
+    windowlog_file = "Window LOGFILE set to $0";
+    windowlog_file_logging = "Can't change window's logfile while log is on";
+    no_away_msgs = "No new messages in awaylog";
+    away_msgs = "{hilight $1} new messages in awaylog:";
+    module_header = "%#Module               Type    Submodules";
+    module_line = "%#$[!20]0 $[7]1 $2";
+    module_footer = "";
+    module_already_loaded = "Module {hilight $0/$1} already loaded";
+    module_not_loaded = "Module {hilight $0/$1} is not loaded";
+    module_load_error = "Error loading module {hilight $0/$1}: $2";
+    module_invalid = "{hilight $0/$1} isn't Irssi module";
+    module_loaded = "Loaded module {hilight $0/$1}";
+    module_unloaded = "Unloaded module {hilight $0/$1}";
+    command_unknown = "Unknown command: $0";
+    command_ambiguous = "Ambiguous command: $0";
+    option_unknown = "Unknown option: $0";
+    option_ambiguous = "Ambiguous option: $0";
+    option_missing_arg = "Missing required argument for: $0";
+    not_enough_params = "Not enough parameters given";
+    not_connected = "Not connected to server";
+    not_joined = "Not joined to any channel";
+    chan_not_found = "Not joined to such channel";
+    chan_not_synced = "Channel not fully synchronized yet, try again after a while";
+    illegal_proto = "Command isn't designed for the chat protocol of the active server";
+    not_good_idea = "Doing this is not a good idea. Add -YES option to command if you really mean it";
+    invalid_number = "Invalid number";
+    invalid_time = "Invalid timestamp";
+    invalid_level = "Invalid message level";
+    invalid_size = "Invalid size";
+    invalid_charset = "Invalid charset: $0";
+    eval_max_recurse = "/eval hit maximum recursion limit";
+    program_not_found = "Could not find file or file is not executable";
+    theme_saved = "Theme saved to $0";
+    theme_save_failed = "Error saving theme to $0: $1";
+    theme_not_found = "Theme {hilight $0} not found";
+    theme_changed = "Now using theme {hilight $0} ($1)";
+    window_theme = "Using theme {hilight $0} in this window";
+    window_theme_default = "No theme is set for this window";
+    window_theme_changed = "Now using theme {hilight $0} ($1) in this window";
+    window_theme_removed = "Removed theme from this window";
+    format_title = "%:[{hilight $0}] - [{hilight $1}]%:";
+    format_subtitle = "[{hilight $0}]";
+    format_item = "$0 = $1";
+    ignored = "Ignoring {hilight $1} from {nick $0}";
+    ignored_options = "Ignoring {hilight $1} from {nick $0} {comment $2}";
+    unignored = "Unignored {nick $0}";
+    ignore_not_found = "{nick $0} is not being ignored";
+    ignore_no_ignores = "There are no ignores";
+    ignore_header = "%#Ignore List:";
+    ignore_line = "%#$[-4]0 $1: $2 $3 $4";
+    ignore_footer = "";
+    not_channel_or_query = "The current window is not a channel or query window";
+    conversion_added = "Added {hilight $0}/{hilight $1} to conversion database";
+    conversion_removed = "Removed {hilight $0} from conversion database";
+    conversion_not_found = "{hilight $0} not found in conversion database";
+    conversion_no_translits = "Transliterations not supported in this system";
+    recode_header = "%#Target                         Character set";
+    recode_line = "%#%|$[!30]0 $1";
+    unknown_chat_protocol = "Unknown chat protocol: $0";
+    unknown_chatnet = "Unknown chat network: $0 (create it with /NETWORK ADD)";
+    not_toggle = "Value must be either ON, OFF or TOGGLE";
+    perl_error = "Perl error: $0";
+    bind_header = "%#Key                  Action";
+    bind_list = "%#$[!20]0 $1 $2";
+    bind_command_list = "$[!30]0 $1";
+    bind_footer = "";
+    bind_unknown_id = "Unknown bind action: $0";
+    config_saved = "Saved configuration to file $0";
+    config_reloaded = "Reloaded configuration";
+    config_modified = "Configuration file was modified since irssi was last started - do you want to overwrite the possible changes?";
+    glib_error = "{error $0} $1";
+    overwrite_config = "Overwrite config (y/N)?";
+    set_title = "[{hilight $0}]";
+    set_item = "$0 = $1";
+    set_unknown = "Unknown setting $0";
+    set_not_boolean = "Setting {hilight $0} isn't boolean, use /SET";
+    no_completions = "There's no completions";
+    completion_removed = "Removed completion $0";
+    completion_header = "%#Key        Value                                    Auto";
+    completion_line = "%#$[10]0 $[!40]1 $2";
+    completion_footer = "";
+  };
+  "fe-text" = {
+    lastlog_too_long = "/LASTLOG would print $0 lines. If you really want to print all these lines use -force option.";
+    lastlog_count = "{hilight Lastlog}: $0 lines";
+    lastlog_start = "{hilight Lastlog}:";
+    lastlog_end = "{hilight End of Lastlog}";
+    lastlog_separator = "--";
+    refnum_not_found = "Window number $0 not found";
+    window_too_small = "Not enough room to resize this window";
+    cant_hide_last = "You can't hide the last window";
+    cant_hide_sticky_windows = "You can't hide sticky windows (use /WINDOW STICK OFF)";
+    cant_show_sticky_windows = "You can't show sticky windows (use /WINDOW STICK OFF)";
+    window_not_sticky = "Window is not sticky";
+    window_set_sticky = "Window set sticky";
+    window_unset_sticky = "Window is not sticky anymore";
+    window_info_sticky = "%#Sticky  : $0";
+    window_info_scroll = "%#Scroll  : $0";
+    window_scroll = "Window scroll mode is now $0";
+    window_scroll_unknown = "Unknown scroll mode $0, must be ON, OFF or DEFAULT";
+    statusbar_list_header = "%#Name                           Type   Placement Position Visible";
+    statusbar_list_footer = "";
+    statusbar_list = "%#$[30]0 $[6]1 $[9]2 $[8]3 $4";
+    statusbar_info_name = "%#Statusbar: {hilight $0}";
+    statusbar_info_type = "%#Type     : $0";
+    statusbar_info_placement = "%#Placement: $0";
+    statusbar_info_position = "%#Position : $0";
+    statusbar_info_visible = "%#Visible  : $0";
+    statusbar_info_item_header = "%#Items    : Name                                Priority  Alignment";
+    statusbar_info_item_footer = "";
+    statusbar_info_item_name = "%#         : $[35]0 $[9]1 $2";
+    statusbar_not_found = "Statusbar doesn't exist: $0";
+    statusbar_item_not_found = "Statusbar item doesn't exist: $0";
+    statusbar_unknown_command = "Unknown statusbar command: $0";
+    statusbar_unknown_type = "Statusbar type must be 'window' or 'root'";
+    statusbar_unknown_placement = "Statusbar placement must be 'top' or 'bottom'";
+    statusbar_unknown_visibility = "Statusbar visibility must be 'always', 'active' or 'inactive'";
+    paste_warning = "Pasting $0 lines to $1. Press Ctrl-K if you wish to do this or Ctrl-C to cancel.";
+    paste_prompt = "Hit Ctrl-K to paste, Ctrl-C to abort?";
+  };
+  "fe-common/perl" = {
+    script_not_found = "Script {hilight $0} not found";
+    script_not_loaded = "Script {hilight $0} is not loaded";
+    script_loaded = "Loaded script {hilight $0}";
+    script_unloaded = "Unloaded script {hilight $0}";
+    no_scripts_loaded = "No scripts are loaded";
+    script_list_header = "%#Loaded scripts:";
+    script_list_line = "%#$[!15]0 $1";
+    script_list_footer = "";
+    script_error = "{error Error in script {hilight $0}:}";
+  };
+  "fe-common/irc" = {
+    netsplit = "{netsplit Netsplit} {server $0} <-> {server $1} quits: $2";
+    netsplit_more = "{netsplit Netsplit} {server $0} <-> {server $1} quits: $2 (+$3 more, use /NETSPLIT to show all of them)";
+    netsplit_join = "{netjoin Netsplit} over, joins: $0";
+    netsplit_join_more = "{netjoin Netsplit} over, joins: $0 (+$1 more)";
+    no_netsplits = "There are no net splits";
+    netsplits_header = "%#Nick      Channel    Server               Split server";
+    netsplits_line = "%#$[9]0 $[10]1 $[20]2 $3";
+    netsplits_footer = "";
+    network_added = "Network $0 saved";
+    network_removed = "Network $0 removed";
+    network_not_found = "Network $0 not found";
+    network_header = "%#Networks:";
+    network_line = "%#$0: $1";
+    network_footer = "";
+    setupserver_header = "%#Server               Port  Network    Settings";
+    setupserver_line = "%#%|$[!20]0 $[5]1 $[10]2 $3";
+    setupserver_footer = "";
+    joinerror_toomany = "Cannot join to channel {channel $0} (You have joined to too many channels)";
+    joinerror_full = "Cannot join to channel {channel $0} (Channel is full)";
+    joinerror_invite = "Cannot join to channel {channel $0} (You must be invited)";
+    joinerror_banned = "Cannot join to channel {channel $0} (You are banned)";
+    joinerror_bad_key = "Cannot join to channel {channel $0} (Bad channel key)";
+    joinerror_bad_mask = "Cannot join to channel {channel $0} (Bad channel mask)";
+    joinerror_unavail = "Cannot join to channel {channel $0} (Channel is temporarily unavailable)";
+    joinerror_duplicate = "Channel {channel $0} already exists - cannot create it";
+    channel_rejoin = "Channel {channel $0} is temporarily unavailable, this is normally because of netsplits. Irssi will now automatically try to rejoin back to this channel until the join is successful. Use /RMREJOINS command if you wish to abort this.";
+    inviting = "Inviting {nick $0} to {channel $1}";
+    channel_created = "Channel {channelhilight $0} created $1";
+    url = "Home page for {channelhilight $0}: $1";
+    topic = "";
+    no_topic = "";
+    topic_info = "";
+    chanmode_change = "<%bMode> {mode $1} by {nick $2}";
+    server_chanmode_change = "<{netsplit Mode}> {mode $1} by {nick $2}";
+    channel_mode = "mode/{channelhilight $0} {mode $1}";
+    bantype = "Ban type changed to {channel $0}";
+    no_bans = "No bans in channel {channel $0}";
+    banlist = "$0 - {channel $1}: ban {ban $2}";
+    banlist_long = "$0 - {channel $1}: ban {ban $2} {comment by {nick $3}, $4 secs ago}";
+    ebanlist = "{channel $0}: ban exception {ban $1}";
+    ebanlist_long = "{channel $0}: ban exception {ban $1} {comment by {nick $2}, $3 secs ago}";
+    no_invitelist = "Invite list is empty in channel {channel $0}";
+    invitelist = "{channel $0}: invite {ban $1}";
+    invitelist_long = "{channel $0}: invite {ban $1} {comment by {nick $2}, $3 secs ago}";
+    no_such_channel = "{channel $0}: No such channel";
+    channel_synced = "Join to {channel $0} was synced in {hilight $1} secs";
+    usermode_change = "Mode change {mode $0} for user {nick $1}";
+    user_mode = "Your user mode is {mode $0}";
+    away = "You have been marked as being away";
+    unaway = "You are no longer marked as being away";
+    nick_away = "{nick $0} is away: $1";
+    no_such_nick = "{nick $0}: No such nick/channel";
+    nick_in_use = "Nick {nick $0} is already in use";
+    nick_unavailable = "Nick {nick $0} is temporarily unavailable";
+    your_nick_owned = "Your nick is owned by {nick $3} {comment $1@$2}";
+    whois = "{nick $0} {nickhost $1@$2}%:{whois ircname $3}";
+    whowas = "{nick $0} {nickhost $1@$2}%:{whois was $3}";
+    whois_idle = "{whois idle %|$1 days $2 hours $3 mins $4 secs}";
+    whois_idle_signon = "{whois idle %|$1 days $2 hours $3 mins $4 secs {comment signon: $5}}";
+    whois_server = "{whois server %|$1 {comment $2}}";
+    whois_oper = "{whois  {hilight $1}}";
+    whois_modes = "{whois modes $1}";
+    whois_realhost = "{whois hostname $1-}";
+    whois_usermode = "{whois usermode $1}";
+    whois_channels = "{whois channels %|$1}";
+    whois_away = "{whois away %|$1}";
+    whois_special = "{whois  %|$1}";
+    whois_extra = "{whois account %|$1}";
+    end_of_whois = "End of WHOIS";
+    end_of_whowas = "End of WHOWAS";
+    whois_not_found = "There is no such nick $0";
+    who = "%#{channelhilight $[-10]0} %|{nick $[!9]1} $[!3]2 $[!2]3 $4@$5 {comment {hilight $6}}";
+    end_of_who = "End of /WHO list";
+    own_notice = "{ownnotice notice $0}$1";
+    own_action = "{ownaction $0}$1";
+    own_action_target = "{ownaction_target $0 $2}$1";
+    own_ctcp = "{ownctcp ctcp $0}$1 $2";
+    notice_server = "{servernotice $0}$1";
+    notice_public = "{notice $0{pubnotice_channel $1}}$2";
+    notice_private = "{notice $0{pvtnotice_host $1}}$2";
+    action_private = "{pvtaction $0}$2";
+    action_private_query = "{pvtaction_query $0}$2";
+    action_public = "{pubaction $0}$1";
+    action_public_channel = "{pubaction $0{msgchannel $1}}$2";
+    ctcp_reply = "CTCP {hilight $0} reply from {nick $1}: $2";
+    ctcp_reply_channel = "CTCP {hilight $0} reply from {nick $1} in channel {channel $3}: $2";
+    ctcp_ping_reply = "CTCP {hilight PING} reply from {nick $0}: $1.$[-3.0]2 seconds";
+    ctcp_requested = "{ctcp {hilight $0} {comment $1} requested CTCP {hilight $2} from {nick $4}}: $3";
+    ctcp_requested_unknown = "{ctcp {hilight $0} {comment $1} requested unknown CTCP {hilight $2} from {nick $4}}: $3";
+    online = "Users online: {hilight $0}";
+    pong = "PONG received from $0: $1";
+    wallops = "{wallop WALLOP {wallop_nick $0}} $1";
+    action_wallops = "{wallop WALLOP {wallop_action $0}} $1";
+    kill = "You were {error killed} by {nick $0} {nickhost $1} {reason $2} {comment Path: $3}";
+    kill_server = "You were {error killed} by {server $0} {reason $1} {comment Path: $2}";
+    error = "{error ERROR} $0";
+    unknown_mode = "Unknown mode character $0";
+    default_event = "$1";
+    default_event_server = "[$0] $1";
+    silenced = "Silenced {nick $0}";
+    unsilenced = "Unsilenced {nick $0}";
+    silence_line = "{nick $0}: silence {ban $1}";
+    ask_oper_pass = "Operator password:";
+    accept_list = "Accepted users: {hilight $0}";
+  };
+  "Irssi::Script::awl" = {
+    awl_display_nokey = "$N $H$C$S";
+    awl_display_key = "$Q $H$C$S";
+    awl_display_nokey_visible = "%2$N $H$C$";
+    awl_display_key_visible = "%2$Q $H$C$S";
+    awl_display_nokey_active = "%1$N $H$C$S";
+    awl_display_key_active = "%1$Q $H$C$S";
+    awl_display_header = "%8$C";
+    awl_separator = "|";
+    awl_separator2 = "|";
+    awl_viewer_item_bg = "%0%w";
+  };
+};
diff --git a/bots/blackhole/blackhole/.irssi/logs/.gitignore b/bots/blackhole/blackhole/.irssi/logs/.gitignore
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
+\ No newline at end of file
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/awl.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/awl.pl
@@ -0,0 +1,2552 @@
+use strict;
+use warnings;
+
+our $VERSION = '1.4'; # b46fded611292cb
+our %IRSSI = (
+    authors     => 'Nei',
+    contact     => 'Nei @ anti@conference.jabber.teamidiot.de',
+    url         => "http://anti.teamidiot.de/",
+    name        => 'adv_windowlist',
+    description => 'Adds a permanent advanced window list on the right or in a status bar.',
+    license     => 'GNU GPLv2 or later',
+   );
+
+# UPGRADE NOTE
+# ============
+# for users of 0.7 or earlier series, please note that appearance
+# settings have moved to /format, i.e. inside your theme!
+# the fifo (screen) has been replaced by an external viewer script
+
+# Usage
+# =====
+# copy the script to ~/.irssi/scripts/
+#
+# In irssi:
+#
+#		/run adv_windowlist
+#
+# In your shell (for example a tmux split):
+#
+#		perl ~/.irssi/scripts/adv_windowlist.pl
+#
+# To use sbar mode instead:
+#
+#		/toggle awl_viewer
+#
+# Hint: to get rid of the old [Act:] display
+#     /statusbar window remove act
+#
+# to get it back:
+#     /statusbar window add -after lag -priority 10 act
+
+# Options
+# =======
+# formats can be cleared with /format -delete
+#
+# /format awl_display_(no)key(_active|_visible) <string>
+# * string : Format String for one window. The following $'s are expanded:
+#     $C : Name
+#     $N : Number of the Window
+#     $Q : meta-Keymap
+#     $H : Start hilighting
+#     $S : Stop hilighting
+#         /+++++++++++++++++++++++++++++++++,
+#        | ****  I M P O R T A N T :  ****  |
+#        |                                  |
+#        | don't forget  to use  $S  if you |
+#        | used $H before!                  |
+#        |                                  |
+#        '+++++++++++++++++++++++++++++++++/
+#   key     : a key binding that goes to this window could be detected in /bind
+#   nokey   : no such key binding was detected
+#   active  : window would receive the input you are currently typing
+#   visible : window is also visible on screen but not active (a split window)
+#
+# /format awl_name_display <string>
+# * string : Format String for window names
+#     $0 : name as formatted by the settings
+#
+# /format awl_display_header <string>
+# * string : Format String for this header line. The following $'s are expanded:
+#     $C : network tag
+#
+# /format awl_separator(2) <string>
+# * string : Character to use between the channel entries
+# variant 2 can be used for alternating separators (only in status bar
+# without block display)
+#
+# /format awl_abbrev_chars <string>
+# * string : Character to use when shortening long names. The second character
+#   will be used if two blocks need to be filled.
+#
+# /format awl_title <string>
+# * string : Text to display in the title string or title bar
+#
+# /format awl_viewer_item_bg <string>
+# * string : Format String specifying the viewer's item background colour
+#
+# /set awl_prefer_name <ON|OFF>
+# * this setting decides whether awl will use the active_name (OFF) or the
+#   window name as the name/caption in awl_display_*.
+#   That way you can rename windows using /window name myownname.
+#
+# /set awl_hide_empty <num>
+# * if visible windows without items should be hidden from the window list
+# set it to 0 to show all windows
+#           1 to hide visible windows without items (negative exempt
+#           active window)
+#
+# /set awl_hide_data <num>
+# * num : hide the window if its data_level is below num
+# set it to 0 to basically disable this feature,
+#           1 if you don't want windows without activity to be shown
+#           2 to show only those windows with channel text or hilight
+#           3 to show only windows with hilight (negative exempt active window)
+#
+# /set awl_hide_name_data <num>
+# * num : hide the name of the window if its data_level is below num
+#   (only works in status bar without block display)
+# you will want to change your formats to add $H...$S around $Q or $N
+# if you plan to use this
+#
+# /set awl_maxlines <num>
+# * num : number of lines to use for the window list (0 to disable, negative
+#   lock)
+#
+# /set awl_maxcolumns <num>
+# * num : number of columns to use for the window list when using the
+#   tmux integration (0 to disable)
+#
+# /set awl_block <num>
+# * num : width of a column in viewer mode (negative values = block
+#   display in status bar mode)
+#         /+++++++++++++++++++++++++++++++++,
+#        | ******  W A R N I N G !  ******  |
+#        |                                  |
+#        | If  your  block  display  looks  |
+#        | DISTORTED,  you need to add the  |
+#        | following  line to your  .theme  |
+#        | file under                       |
+#        |     abstracts = {             :  |
+#        |                                  |
+#        |       sb_act_none = "%K$*";      |
+#        |                                  |
+#        '+++++++++++++++++++++++++++++++++/
+#
+# /set awl_sbar_maxlength <ON|OFF>
+# * if you enable the maxlength setting, the block width will be used as a
+#   maximum length for the non-block status bar mode too.
+#
+# /set awl_height_adjust <num>
+# * num : how many lines to leave empty in viewer mode
+#
+# /set awl_sort <-data_level|-last_line|refnum>
+# * you can change the window sort order with this variable
+#     -data_level : sort windows with hilight first
+#     -last_line  : sort windows in order of activity
+#     refnum      : sort windows by window number
+#     active/server/tag : sort by server name
+#   "-" reverses the sort order
+#   typechecks are supported via ::, e.g. active::Query or active::Irc::Query
+#   undefinedness can be checked with ~, e.g. ~active
+#   string comparison can be done with =, e.g. name=(status)
+#   to make sort case insensitive, use #i, e.g. name#i
+#   any key in the window hash can be tested, e.g. active/chat_type=XMPP
+#   multiple criteria can be separated with , or +, e.g. -data_level+-last_line
+#
+# /set awl_placement <top|bottom>
+# /set awl_position <num>
+# * these settings correspond to /statusbar because awl will create
+#   status bars for you
+# (see /help statusbar to learn more)
+#
+# /set awl_all_disable <ON|OFF>
+# * if you set awl_all_disable to ON, awl will also remove the
+#   last status bar it created if it is empty.
+#   As you might guess, this only makes sense with awl_hide_data > 0 ;)
+#
+# /set awl_viewer <ON|OFF>
+# * enable the external viewer script
+#
+# /set awl_viewer_launch <ON|OFF>
+# * try to auto-launch the viewer under tmux or with a shell command
+#   /awl restart is required all auto-launch related settings to take
+#   effect
+#
+# /set awl_viewer_tmux_position <left|top|right|bottom|custom>
+# * try to split in this direction when using tmux for the viewer
+#   custom : use custom_command setting
+#
+# /set awl_viewer_xwin_command <shell command>
+# * custom command to run in order to start the viewer when irssi is
+#   running under X
+#   %A  - gets replaced by the command to run the viewer
+#   %qA - additionally quote the command
+#
+# /set awl_viewer_custom_command <shell command>
+# * custom command to run in order to start the viewer
+#
+# /set awl_viewer_launch_env <string>
+# * specific environment settings for use on viewer auto-launch,
+#   without the AWL_ prefix
+#
+# /set awl_shared_sbar <left<right|OFF>
+# * share a status bar for the first awl item, you will need to manually
+#   /statusbar window add -after lag -priority 10 awl_shared
+#     left   : space in cells occupied on the left of status bar
+#     right  : space occupied on the right
+# Note: you need to replace "left" AND "right" with the appropriate numbers!
+#
+# /set awl_path <path>
+# * path to the file which the viewer script reads
+#
+# /set fancy_abbrev <no|head|strict|fancy>
+# * how to shorten too long names
+#     no     : shorten in the middle
+#     head   : always cut off the ends
+#     strict : shorten repeating substrings
+#     fancy  : combination of no+strict
+#
+# /set awl_custom_xform <perl code>
+# * specify a custom routine to transform window names
+#   example: s/^#// remove the #-mark of IRC channels
+#   the special flags $CHANNEL / $TAG / $QUERY / $NAME can be
+#   tested in conditionals
+#
+# /set awl_last_line_shade <timeout>
+# * set timeout to shade activity base colours, to enable
+#   you also need to add +-last_line to awl_sort
+#   (requires 256 colour support)
+#
+# /set awl_no_mode_hint <ON|OFF>
+# * whether to show the hint of running the viewer script in the
+#   status bar
+#
+# /set awl_mouse <ON|OFF>
+# * enable the terminal mouse in irssi
+# (use the awl-patched mouse.pl for gestures and commands if you need
+# them and disable mouse_escape)
+#
+# /set awl_mouse_offset <num>
+# * specifies where on the screen is the awl status bar
+#   (0 = on top/bottom, 1 = one additional line in between,
+#   e.g. prompt)
+#   you MUST set this correctly otherwise the mouse coordinates will
+#   be off
+#
+# /set mouse_scroll <num>
+# * how many lines the mouse wheel scrolls
+#
+# /set mouse_escape <num>
+# * seconds to disable the mouse, when not clicked on the windowlist
+#
+
+# Commands
+# ========
+# /awl redraw
+# * redraws the windowlist. There may be occasions where the
+#   windowlist can get destroyed so you can use this command to
+#   force a redraw.
+#
+# /awl restart
+# * restart the connection to the viewer script.
+
+# Viewer script
+# =============
+# When run from the command line, adv_windowlist acts as the viewer
+# script to be used together with the irssi script to display the
+# window list in a sidebar/terminal of its own.
+#
+# One optional parameter is accepted, the awl_path
+#
+# The viewer can be configured by three environment variables:
+#
+# AWL_HI9=1
+# * interpret %9 as high-intensity toggle instead of bold. This had
+#   been the default prior to version 0.9b8
+#
+# AWL_AUTOFOCUS=0
+# * disable auto-focus behaviour when activating a window
+#
+# AWL_NOTITLE=1
+# * disable the title bar
+
+# Nei =^.^= ( anti@conference.jabber.teamidiot.de )
+
+no warnings 'redefine';
+use constant IN_IRSSI => __PACKAGE__ ne 'main' || $ENV{IRSSI_MOCK};
+use constant SCRIPT_FILE => __FILE__;
+no if !IN_IRSSI, strict => (qw(subs refs));
+use if IN_IRSSI, Irssi => ();
+use if IN_IRSSI, 'Irssi::TextUI' => ();
+use v5.10;
+use Encode;
+use Storable ();
+use IO::Socket::UNIX;
+use List::Util qw(min max reduce);
+use Hash::Util qw(lock_keys);
+use Text::ParseWords qw(shellwords);
+
+BEGIN {
+    if ($] < 5.012) {
+	*CORE::GLOBAL::length = *CORE::GLOBAL::length = sub (_) {
+	    defined $_[0] ? CORE::length($_[0]) : undef
+	};
+	*Irssi::active_win = {}; # hide incorrect warning
+    }
+}
+
+unless (IN_IRSSI) {
+    local *_ = \@ARGV;
+    &AwlViewer::main;
+    exit;
+}
+
+
+use constant GLOB_QUEUE_TIMER => 100;
+
+our $BLOCK_ALL;  # localized blocker
+my @actString;   # status bar texts
+my @win_items;
+my $currentLines = 0;
+my %awins;
+my $globTime;    # timer to limit remake calls
+
+my %CHANGED;
+my $VIEWER_MODE;
+my $MOUSE_ON;
+my %mouse_coords;
+my %statusbars;
+my %S; # settings
+my $settings_str = '';
+my $window_sort_func;
+my $custom_xform;
+my ($sb_base_width, $sb_base_width_pre, $sb_base_width_post);
+my $print_text_activity;
+my $shade_line_timer;
+my ($screenHeight, $screenWidth);
+my %viewer;
+
+my (%keymap, %nummap, %wnmap, %specialmap, %wnmap_exp, %custom_key_map);
+my %banned_channels;
+my %abbrev_cache;
+
+use constant setc => 'awl';
+
+sub set ($) {
+    setc . '_' . $_[0]
+}
+
+sub add_statusbar {
+    for (@_) {
+	# add subs
+	my $l = set $_;
+	{
+	    my $close = $_;
+	    no strict 'refs';
+	    *{$l} = sub { awl($close, @_) };
+	}
+	Irssi::command("statusbar $l reset");
+	Irssi::command("statusbar $l enable");
+	if (lc $S{placement} eq 'top') {
+	    Irssi::command("statusbar $l placement top");
+	}
+	if (my $x = $S{position}) {
+	    Irssi::command("statusbar $l position $x");
+	}
+	Irssi::command("statusbar $l add -priority 100 -alignment left barstart");
+	Irssi::command("statusbar $l add $l");
+	Irssi::command("statusbar $l add -priority 100 -alignment right barend");
+	Irssi::command("statusbar $l disable");
+	Irssi::statusbar_item_register($l, '$0', $l);
+	$statusbars{$_} = 1;
+	Irssi::command("statusbar $l enable");
+    }
+}
+
+sub remove_statusbar {
+    for (@_) {
+	my $l = set $_;
+	Irssi::command("statusbar $l disable");
+	Irssi::command("statusbar $l reset");
+	Irssi::statusbar_item_unregister($l);
+	{
+	    no strict 'refs';
+	    undef &{$l};
+	}
+	delete $statusbars{$_};
+    }
+}
+
+my $awl_shared_empty = sub {
+    return if $BLOCK_ALL;
+    my ($item, $get_size_only) = @_;
+    $item->default_handler($get_size_only, '', '', 0);
+};
+
+sub syncLines {
+    my $maxLines = $S{maxlines};
+    my $newLines = ($maxLines > 0 and @actString > $maxLines) ?
+	$maxLines :
+    ($maxLines < 0) ?
+	-$maxLines :
+	    @actString;
+    $currentLines = 1 if !$currentLines && $S{shared_sbar};
+    if ($S{shared_sbar} && !$statusbars{shared}) {
+	my $l = set 'shared';
+	{
+	    no strict 'refs';
+	    *{$l} = sub {
+		return if $BLOCK_ALL;
+		my ($item, $get_size_only) = @_;
+
+		my $text = $actString[0];
+		my $title = _get_format(set 'title');
+		if (length $title) {
+		    $title =~ s{\\(.)|(.)}{
+			defined $2 ? quotemeta $2
+			    : $1 eq 'V' ? '\u'
+			    : $1 eq ':' ? quotemeta ':%n'
+			    : $1 =~ /^[uUFQE]$/ ? "\\$1"
+			    : quotemeta "\\$1"
+			}sge;
+		    $title = eval qq{"$title"};
+		    $title .= ' ';
+		}
+		my $pat = defined $text ? "{sb $title\$*}" : '{sb }';
+		$text //= '';
+		$item->default_handler($get_size_only, $pat, $text, 0);
+	    };
+	}
+	$statusbars{shared} = 1;
+	remove_statusbar (0) if $statusbars{0};
+    }
+    elsif ($statusbars{shared} && !$S{shared_sbar}) {
+	add_statusbar (0) if $currentLines && $newLines;
+	delete $statusbars{shared};
+	my $l = set 'shared';
+	{
+	    no strict 'refs';
+	    *{$l} = $awl_shared_empty;
+	}
+    }
+    if ($currentLines == $newLines) { return; }
+    elsif ($newLines > $currentLines) {
+	add_statusbar ($currentLines .. ($newLines - 1));
+    }
+    else {
+	remove_statusbar (reverse ($newLines .. ($currentLines - 1)));
+    }
+    $currentLines = $newLines;
+}
+
+sub awl {
+    return if $BLOCK_ALL;
+    my ($line, $item, $get_size_only) = @_;
+
+    my $text = $actString[$line];
+    my $pat = defined $text ? '{sb $*}' : '{sb }';
+    $text //= '';
+    $item->default_handler($get_size_only, $pat, $text, 0);
+}
+
+# remove old statusbars
+{ my %killBar;
+  sub get_old_status {
+      my ($textDest, $cont, $cont_stripped) = @_;
+      if ($textDest->{level} == 524288 and $textDest->{target} eq '' and !defined $textDest->{server}) {
+	  my $name = quotemeta(set '');
+	  if ($cont_stripped =~ m/^$name(\d+)\s/) { $killBar{$1} = 1; }
+	  Irssi::signal_stop;
+      }
+  }
+  sub killOldStatus {
+      %killBar = ();
+      Irssi::signal_add_first('print text' => 'get_old_status');
+      Irssi::command('statusbar');
+      Irssi::signal_remove('print text' => 'get_old_status');
+      remove_statusbar(keys %killBar);
+  }
+}
+
+sub _add_map {
+    my ($type, $target, $map) = @_;
+    ($type->{$target}) = sort { length $a <=> length $b || $a cmp $b }
+	$map, exists $type->{$target} ? $type->{$target} : ();
+}
+
+sub get_keymap {
+    my ($textDest, undef, $cont_stripped) = @_;
+    if ($textDest->{level} == 524288 and $textDest->{target} eq '' and !defined $textDest->{server}) {
+	my $one_meta_or_ctrl_key = qr/((?:meta-)*?)(?:(meta-|\^)(\S)|(\w+))/;
+	$cont_stripped = as_uni($cont_stripped);
+	if ($cont_stripped =~ m/((?:$one_meta_or_ctrl_key-)*$one_meta_or_ctrl_key)\s+(.*)$/) {
+	    my ($combo, $command) = ($1, $10);
+	    my $map = '';
+	    while ($combo =~ s/(?:-|^)$one_meta_or_ctrl_key$//) {
+		my ($level, $ctl, $key, $nkey) = ($1, $2, $3, $4);
+		my $numlevel = ($level =~ y/-//);
+		$ctl = '' if !$ctl || $ctl ne '^';
+		$map = ('-' x ($numlevel%2)) . ('+' x ($numlevel/2)) .
+		    $ctl . (defined $key ? $key : "\01$nkey\01") . $map;
+	    }
+	    for ($command) {
+		last unless length $map;
+		if (/^change_window (\d+)/i) {
+		    _add_map(\%nummap, $1, $map);
+		}
+		elsif (/^(?:command window goto|change_window) (\S+)/i) {
+		    my $window = $1;
+		    if ($window !~ /\D/) {
+			_add_map(\%nummap, $window, $map);
+		    }
+		    elsif (lc $window eq 'active') {
+			_add_map(\%specialmap, '_active', $map);
+		    }
+		    else {
+			_add_map(\%wnmap, $window, $map);
+		    }
+		}
+		elsif (/^(?:active_window|command (ack))/i) {
+		    _add_map(\%specialmap, '_active', $map);
+		    $viewer{use_ack} = !!$1;
+		}
+		elsif (/^command window last/i) {
+		    _add_map(\%specialmap, '_last', $map);
+		}
+		elsif (/^(?:upper_window|command window up)/i) {
+		    _add_map(\%specialmap, '_up', $map);
+		}
+		elsif (/^(?:lower_window|command window down)/i) {
+		    _add_map(\%specialmap, '_down', $map);
+		}
+		elsif (/^key\s+(\w+)/i) {
+		    $custom_key_map{$1} = $map;
+		}
+	    }
+	}
+	Irssi::signal_stop;
+    }
+}
+
+sub update_keymap {
+    %nummap = %wnmap = %specialmap = %custom_key_map = ();
+    Irssi::signal_remove('command bind' => 'watch_keymap');
+    Irssi::signal_add_first('print text' => 'get_keymap');
+    Irssi::command('bind');
+    Irssi::signal_remove('print text' => 'get_keymap');
+    for (keys %custom_key_map) {
+	if (exists $custom_key_map{$_} &&
+		$custom_key_map{$_} =~ s/\01(\w+)\01/exists $custom_key_map{$1} ? $custom_key_map{$1} : "\02"/ge) {
+	    if ($custom_key_map{$_} =~ /\02/) {
+		delete $custom_key_map{$_};
+	    }
+	    else {
+		redo;
+	    }
+	}
+    }
+    for my $keymap (\(%specialmap, %wnmap, %nummap)) {
+	for (keys %$keymap) {
+	    if ($keymap->{$_} =~ s/\01(\w+)\01/exists $custom_key_map{$1} ? $custom_key_map{$1} : "\02"/ge) {
+		if ($keymap->{$_} =~ /\02/) {
+		    delete $keymap->{$_};
+		}
+	    }
+	}
+    }
+    Irssi::signal_add('command bind' => 'watch_keymap');
+    delete $viewer{client_keymap};
+    &wl_changed;
+}
+
+# watch keymap changes
+sub watch_keymap {
+    Irssi::timeout_add_once(1000, 'update_keymap', undef);
+}
+
+{ my %strip_table = (
+    # fe-common::core::formats.c:format_expand_styles
+    #      delete                format_backs  format_fores bold_fores   other stuff
+    (map { $_ => '' } (split //, '04261537' .  'kbgcrmyw' . 'KBGCRMYW' . 'U9_8I:|FnN>#[' . 'pP')),
+    #      escape
+    (map { $_ => $_ } (split //, '{}%')),
+   );
+  sub ir_strip_codes { # strip %codes
+      my $o = shift;
+      $o =~ s/(%(%|Z.{6}|z.{6}|X..|x..|.))/exists $strip_table{$2} ? $strip_table{$2} :
+	  $2 =~ m{x(?:0[a-f]|[1-6][0-9a-z]|7[a-x])|z[0-9a-f]{6}}i ? '' : $1/gex;
+      $o
+  }
+}
+## ir_parse_special -- wrapper around parse_special
+## $i - input format
+## $args - array ref of arguments to format
+## $win - different target window (default current window)
+## $flags - different kind of escape flags (default 4|8)
+## returns formatted str
+sub ir_parse_special {
+    my $o;
+    my $i = shift;
+    my $args = shift // [];
+    y/ /\177/ for @$args; # hack to escape spaces
+    my $win = shift || Irssi::active_win;
+    my $flags = shift // 0x4|0x8;
+    my @cmd_args = ($i, (join ' ', @$args), $flags);
+    my $server = Irssi::active_server();
+    if (ref $win and ref $win->{active}) {
+	$o = $win->{active}->parse_special(@cmd_args);
+    }
+    elsif (ref $win and ref $win->{active_server}) {
+	$o = $win->{active_server}->parse_special(@cmd_args);
+    }
+    elsif (ref $server) {
+	$o =  $server->parse_special(@cmd_args);
+    }
+    else {
+	$o = &Irssi::parse_special(@cmd_args);
+    }
+    $o =~ y/\177/ /;
+    $o
+}
+
+sub sb_format_expand { # Irssi::current_theme->format_expand wrapper
+    Irssi::current_theme->format_expand(
+	$_[0],
+	(
+	    Irssi::EXPAND_FLAG_IGNORE_REPLACES
+		    |
+	    ($_[1] ? 0 : Irssi::EXPAND_FLAG_IGNORE_EMPTY)
+	)
+    )
+}
+
+{ my $term_type = Irssi::version > 20040819 ? 'term_charset' : 'term_type';
+  local $@;
+  eval { require Text::CharWidth; };
+  unless ($@) {
+      *screen_length = sub { Text::CharWidth::mbswidth($_[0]) };
+  }
+  else {
+      my $err = $@; chomp $err; $err =~ s/\sat .* line \d+\.$//;
+      #Irssi::print("%_$IRSSI{name}: warning:%_ Text::CharWidth module failed to load. Length calculation may be off! Error was:");
+      print "%_$IRSSI{name}:%_ $err";
+      *screen_length = sub {
+	  my $temp = shift;
+	  if (lc Irssi::settings_get_str($term_type) eq 'utf-8') {
+	      Encode::_utf8_on($temp);
+	  }
+	  length($temp)
+      };
+  }
+  sub as_uni {
+      no warnings 'utf8';
+      Encode::decode(Irssi::settings_get_str($term_type), $_[0], 0)
+  }
+  sub as_tc {
+      Encode::encode(Irssi::settings_get_str($term_type), $_[0], 0)
+  }
+}
+
+sub sb_length {
+    screen_length(ir_strip_codes($_[0]))
+}
+
+sub run_custom_xform {
+    local $@;
+    eval {
+	$custom_xform->()
+    };
+    if ($@) {
+	$@ =~ /^(.*)/;
+	print '%_'.(set 'custom_xform').'%_ died (disabling): '.$1;
+	$custom_xform = undef;
+    }
+}
+
+sub remove_uniform {
+    my $o = shift;
+    $o =~ s/^xmpp:(.*?[%@]).+\.[^.]+$/$1/ or
+	$o =~ s#^psyc://.+\.[^.]+/([@~].*)$#$1#;
+    if ($custom_xform) {
+	run_custom_xform() for $o;
+    }
+    $o
+}
+
+sub remove_uniform_vars {
+    my $win = shift;
+    my $name = __PACKAGE__ . '::custom_xform::' . $win->{active}{type}
+	if ref $win->{active} && $win->{active}{type};
+    no strict 'refs';
+    local ${$name} = 1 if $name;
+    remove_uniform(+shift);
+}
+
+sub lc1459 {
+    my $x = shift;
+    $x =~ y/][\\^/}{|~/;
+    lc $x
+}
+
+sub window_list {
+    sort $window_sort_func Irssi::windows;
+}
+
+sub _calculate_abbrev {
+    my ($wins, $abbrevList) = @_;
+    if ($S{fancy_abbrev} !~ /^(no|off|head)/i) {
+	my @nameList = map { ref $_ ? remove_uniform_vars($_, as_uni($_->get_active_name) // '') : '' } @$wins;
+	for (my $i = 0; $i < @nameList - 1; ++$i) {
+	    my ($x, $y) = ($nameList[$i], $nameList[$i + 1]);
+	    s/^[+#!=]// for $x, $y;
+	    my $res = exists $abbrev_cache{$x}{$y} ? $abbrev_cache{$x}{$y}
+		: $abbrev_cache{$x}{$y} = string_LCSS($x, $y);
+	    if (defined $res) {
+		for ($nameList[$i], $nameList[$i + 1]) {
+		    $abbrevList->{$_} //= int((index $_, $res) + (length $res) / 2);
+		}
+	    }
+	}
+    }
+}
+
+my %act_last_line_shades = (
+    r => [qw[ 50 40 30 20 ]],
+    g => [qw[ 1O 1I 1C 16 ]],
+    y => [qw[ 5O 4I 3C 26 ]],
+    b => [qw[ 15 14 13 12 ]],
+    m => [qw[ 54 43 32 21 ]],
+    c => [qw[ 1S 1L 1E 17 ]],
+    w => [qw[ 7W 7T 7Q 3E ]],
+    K => [qw[ 7M 7K 27 7H ]],
+    R => [qw[ 60 50 40 30 ]],
+    G => [qw[ 1U 1O 1I 1C ]],
+    Y => [qw[ 6U 5O 4I 3C ]],
+    B => [qw[ 2B 2A 29 28 ]],
+    M => [qw[ 65 54 43 32 ]],
+    C => [qw[ 1Z 1S 1L 1E ]],
+    W => [qw[ 6Z 5S 7R 7O ]],
+   );
+
+sub _format_display {
+    my (undef, $format, $cformat, $hilight, $name, $number, $key, $win) = @_;
+    if ($print_text_activity && $S{line_shade}) {
+	my @hilight_code = split /\177/, sb_format_expand("{$hilight \177}"), 2;
+	my $max_time = max(1, log($S{line_shade}) - log(1000));
+	my $time_delta = min(3, min($max_time, log(max(1, time - $win->{last_line}))) / $max_time * 3);
+	if ($hilight_code[0] =~ /%(.)/ && exists $act_last_line_shades{$1}) {
+	    $hilight = 'sb_act_hilight_color %X'.$act_last_line_shades{$1}[$time_delta];
+	}
+    }
+    $cformat = '$0' unless length $cformat;
+    my %map = ('$C' => $cformat, '$N' => '$1', '$Q' => '$2');
+    $format =~ s<(\$.)><$map{$1}//$1>ge;
+    $format =~ s<\$H((?:\$.|[^\$])*?)\$S><{$hilight $1%n}>g;
+    my @ret = ir_parse_special(sb_format_expand($format), [$name, $number, $key], $win);
+    @ret
+}
+
+sub _get_format {
+    Irssi::current_theme->get_format(__PACKAGE__, @_)
+}
+
+sub _calculate_items {
+    my ($wins, $abbrevList) = @_;
+
+    my $display_header = _get_format(set 'display_header');
+    my $name_format = _get_format(set 'name_display');
+    my $abbrev_chars = as_uni(_get_format(set 'abbrev_chars'));
+
+    my %displays;
+
+    my $active = Irssi::active_win;
+    @win_items = ();
+    %keymap = (%nummap, %wnmap_exp);
+
+    my ($numPad, $keyPad) = (0, 0);
+    if ($VIEWER_MODE or $S{block} < 0) {
+	$numPad = length((sort { length $b <=> length $a } keys %keymap)[0]) // 0;
+	$keyPad = length((sort { length $b <=> length $a } values %keymap)[0]) // 0;
+    }
+    my $last_net;
+    my ($abbrev1, $abbrev2) = $abbrev_chars =~ /(\X)(.*)/;
+    my @abbrev_chars = ('~', "\x{301c}");
+    unless (defined $abbrev1 && screen_length(as_tc($abbrev1)) == 1) { $abbrev1 = $abbrev_chars[0] }
+    unless (length $abbrev2) {
+	$abbrev2 = $abbrev1;
+	if ($abbrev1 eq $abbrev_chars[0]) {
+	    $abbrev2 = $abbrev_chars[1];
+	}
+	else {
+	    $abbrev2 = $abbrev1;
+	}
+    }
+    if (screen_length(as_tc($abbrev2)) == 1) {
+	$abbrev2 x= 2;
+    }
+    while (screen_length(as_tc($abbrev2)) > 2) {
+	chop $abbrev2;
+    }
+    unless (screen_length(as_tc($abbrev2)) == 2) {
+	$abbrev2 = $abbrev_chars[1];
+    }
+    for my $win (@$wins) {
+	my $global_tag_header_mode;
+
+	next unless ref $win;
+
+	my $backup_win = Storable::dclone($win);
+	delete $backup_win->{active} unless ref $backup_win->{active};
+
+	$global_tag_header_mode =
+	    $display_header && ($last_net // '') ne ($backup_win->{active}{server}{tag} // '');
+
+	if ($win->{data_level} < abs $S{hide_data}
+		&& ($win->{refnum} != $active->{refnum} || 0 <= $S{hide_data})) {
+	    next; }
+	elsif (exists $awins{$win->{refnum}} && $S{hide_empty} && !$win->items
+		&& ($win->{refnum} != $active->{refnum} || 0 <= $S{hide_empty})) {
+	    next; }
+
+	my $colour = $win->{hilight_color} // '';
+	my $hilight = do {
+	    if    ($win->{data_level} == 0) { 'sb_act_none'; }
+	    elsif ($win->{data_level} == 1) { 'sb_act_text'; }
+	    elsif ($win->{data_level} == 2) { 'sb_act_msg'; }
+	    elsif ($colour           ne '') { "sb_act_hilight_color $colour"; }
+	    elsif ($win->{data_level} == 3) { 'sb_act_hilight'; }
+	    else                            { 'sb_act_special'; }
+	};
+	my $number = $win->{refnum};
+
+	my ($name, $display, $cdisplay);
+	if ($global_tag_header_mode) {
+	    $display = $display_header;
+	    $name = as_uni($backup_win->{active}{server}{tag}) // '';
+	    if ($custom_xform) {
+		no strict 'refs';
+		local ${ __PACKAGE__ . '::custom_xform::TAG' } = 1;
+		run_custom_xform() for $name;
+	    }
+	}
+	else {
+	    my @display = ('display_nokey');
+	    if (defined $keymap{$number} and $keymap{$number} ne '') {
+		unshift @display, map { (my $cpy = $_) =~ s/_no/_/; $cpy } @display;
+	    }
+	    if (exists $awins{$number}) {
+		unshift @display, map { my $cpy = $_; $cpy .= '_visible'; $cpy } @display;
+	    }
+	    if ($active->{refnum} == $number) {
+		unshift @display, map { my $cpy = $_; $cpy .= '_active'; $cpy }
+		    grep { !/_visible$/ } @display;
+	    }
+	    $display = (grep { length $_ }
+			       map { $displays{$_} //= _get_format(set $_) }
+				   @display)[0];
+	    $cdisplay = $name_format;
+	    $name = as_uni($win->get_active_name) // '';
+	    $name = '*' if $S{banned_on} and exists $banned_channels{lc1459($name)};
+	    $name = remove_uniform_vars($win, $name) if $name ne '*';
+	    if ($name ne '*' and $win->{name} ne '' and $S{prefer_name}) {
+		$name = as_uni($win->{name});
+		if ($custom_xform) {
+		    no strict 'refs';
+		    local ${ __PACKAGE__ . '::custom_xform::NAME' } = 1;
+		    run_custom_xform() for $name;
+		}
+	    }
+
+	    if (!$VIEWER_MODE && $S{block} >= 0 && $S{hide_name}
+		&& $win->{data_level} < abs $S{hide_name}
+		&& ($win->{refnum} != $active->{refnum} || 0 <= $S{hide_name})) {
+		$name = '';
+		$cdisplay = '';
+	    }
+	}
+
+	$display = "$display%n";
+	my $num_ent = (' 'x max(0,$numPad - length $number)) . $number;
+	my $key_ent = exists $keymap{$number} ? ((' 'x max(0,$keyPad - length $keymap{$number})) . $keymap{$number}) : ' 'x$keyPad;
+	if ($VIEWER_MODE or $S{sbar_maxlen} or $S{block} < 0) {
+	    my $baseLength = sb_length(_format_display(
+		'', $display, $cdisplay, $hilight,
+		'x', # placeholder
+		$num_ent,
+		$key_ent,
+		$win)) - 1;
+	    my $diff = (abs $S{block}) - (screen_length(as_tc($name)) + $baseLength);
+	    if ($diff < 0) { # too long
+		my $screen_length = screen_length(as_tc($name));
+		if ((abs $diff) >= $screen_length) { $name = '' } # forget it
+		elsif ((abs $diff) + screen_length(as_tc(substr($name, 0, 1))) >= $screen_length) { $name = substr($name, 0, 1); }
+		else {
+		    my $ulen = length $name;
+		    my $middle2 = exists $abbrevList->{$name} ?
+			($S{fancy_strict}) ?
+			    2* $abbrevList->{$name} :
+			   (2*($abbrevList->{$name} + $ulen) / 3) :
+			       ($S{fancy_head}) ?
+				2*$ulen :
+				    $ulen;
+		    my $first = 1;
+		    while (length $name > 1) {
+			my $cp = $middle2 >= 0 ? $middle2/2 : -1; # clearing position
+			my $rm = 2;
+			# if character at end is wider than 1 cell -> replace it with ~
+			if (screen_length(as_tc(substr $name, $cp, 1)) > 1) {
+			    if ($first || $cp < 0) {
+				$rm = 1;
+				$first = undef;
+			    }
+			}
+			elsif ($cp < 0) { # elsif at end -> replace last 2 characters
+			    --$cp;
+			}
+			(substr $name, $cp, $rm) = $abbrev1;
+			if ($cp > -1 && $rm > 1) {
+			    --$middle2;
+			}
+			my $sl = screen_length(as_tc($name));
+			if ($sl + $baseLength < abs $S{block}) {
+			    (substr $name, ($middle2+1)/2, 1) = $abbrev2;
+			    last;
+			}
+			elsif ($sl + $baseLength == abs $S{block}) {
+			    last;
+			}
+		    }
+		}
+	    }
+	    elsif ($VIEWER_MODE or $S{block} < 0) {
+		$name .= (' ' x $diff);
+	    }
+	}
+
+	push @win_items, _format_display(
+	    '', $display, $cdisplay, $hilight,
+	    as_tc($name),
+	    $num_ent,
+	    as_tc($key_ent),
+	    $win);
+
+	if ($global_tag_header_mode) {
+	    $last_net = $backup_win->{active}{server}{tag};
+	    redo;
+	}
+
+	$mouse_coords{refnum}{$#win_items} = $number;
+    }
+}
+
+sub _spread_items {
+    my $width = [Irssi::windows]->[0]{width} - $sb_base_width - 1;
+    my @separator = _get_format(set 'separator');
+    if ($S{block} >= 0) {
+	my $sep2 = _get_format(set 'separator2');
+	push @separator, $sep2 if length $sep2 && $sep2 ne $separator[0];
+    }
+    $separator[0] .= '%n';
+    my @sepLen = map { sb_length($_) } @separator;
+
+    @actString = ();
+    my $curLine;
+    my $curLen = 0;
+    if ($S{shared_sbar}) {
+	$curLen += $S{shared_sbar}[0] + 2;
+	$width -= $S{shared_sbar}[2];
+    }
+    my $mouse_header_check = 0;
+    for my $it (@win_items) {
+	my $itemLen = sb_length($it);
+	if ($curLen) {
+	    if ($curLen + $itemLen + $sepLen[$mouse_header_check % @sepLen] > $width) {
+		$width += $S{shared_sbar}[2]
+		    if !@actString && $S{shared_sbar};
+		push @actString, $curLine;
+		$curLine = undef;
+		$curLen = 0;
+	    }
+	    elsif (defined $curLine) {
+		$curLine .= $separator[$mouse_header_check % @separator];
+		$curLen += $sepLen[$mouse_header_check % @sepLen];
+	    }
+	}
+	$curLine .= $it;
+	if (exists $mouse_coords{refnum}{$mouse_header_check}) {
+	    $mouse_coords{scalar @actString}{ $_ } = $mouse_coords{refnum}{$mouse_header_check}
+		for $curLen .. $curLen + $itemLen - 1;
+	}
+	$curLen += $itemLen;
+    }
+    continue {
+	++$mouse_header_check;
+    }
+    $curLen -= $S{shared_sbar}[0]
+	if !@actString && $S{shared_sbar};
+    push @actString, $curLine if $curLen;
+}
+
+sub remake {
+    my %abbrevList;
+    my @wins = window_list();
+    if ($VIEWER_MODE or $S{sbar_maxlen} or $S{block} < 0) {
+	_calculate_abbrev(\@wins, \%abbrevList);
+    }
+
+    %mouse_coords = ( refnum => +{} );
+    _calculate_items(\@wins, \%abbrevList);
+
+    unless ($VIEWER_MODE) {
+	_spread_items();
+
+	push @actString, undef unless @actString || $S{all_disable};
+    }
+}
+
+sub update_wl {
+    return if $BLOCK_ALL;
+    remake();
+
+    Irssi::statusbar_items_redraw(set $_) for keys %statusbars;
+
+    unless ($VIEWER_MODE) {
+	Irssi::timeout_add_once(100, 'syncLines', undef);
+    }
+    else {
+	syncViewer();
+    }
+}
+
+sub screenFullRedraw {
+    my ($window) = @_;
+    if (!ref $window or $window->{refnum} == Irssi::active_win->{refnum}) {
+	$viewer{fullRedraw} = 1 if $viewer{client};
+	$settings_str = '';
+	&setup_changed;
+    }
+}
+
+sub restartViewerServer {
+    if ($VIEWER_MODE) {
+	stop_viewer();
+	start_viewer();
+    }
+}
+
+sub _simple_quote {
+    my @r = map {
+	my $x = $_;
+	$x =~ s/'/'"'"'/g;
+	$x = "'$x'";
+    } @_;
+    wantarray ? @r : shift @r
+}
+
+sub _viewer_command_replace_format {
+    my ($ecmd, @args) = @_;
+    my $file = _simple_quote(SCRIPT_FILE());
+    my $path = _simple_quote($viewer{path});
+    my @env;
+    for my $env (shellwords($S{viewer_launch_env})) {
+	if ($env =~ /^(\w+)(?:=(.*))$/) {
+	    push @env, "AWL_$1=$2"
+	}
+    }
+    my $cmd = join ' ',
+	(@env ? ('env', _simple_quote(@env)) : ()),
+	'perl', $file, '-1', _simple_quote(@args), $path;
+    $ecmd =~ s{%(%|\w+)}{
+	my $sub = $1;
+	if ($sub eq '%') {
+	    '%'
+	}
+	elsif ($sub =~ /^(q*)A(.*)/) {
+	    my $ret = $cmd;
+	    for (1..length $1) {
+		$ret = _simple_quote($ret);
+	    }
+	    "$ret$2"
+	}
+	else {
+	    "%$sub"
+	}
+    }gex;
+    $ecmd
+}
+
+sub start_viewer {
+    unlink $viewer{path} if -S $viewer{path} || -p _;
+
+    $viewer{server} = IO::Socket::UNIX->new(
+	Type => SOCK_STREAM,
+	Local => $viewer{path},
+	Listen => 1
+       );
+    unless ($viewer{server}) {
+	$viewer{msg} = "Viewer: $!";
+	$viewer{retry} = Irssi::timeout_add_once(5000, 'retry_viewer', 1);
+	return;
+    }
+    $viewer{server}->blocking(0);
+    set_viewer_mode_hint();
+    $viewer{server_tag} = Irssi::input_add($viewer{server}->fileno, INPUT_READ, 'vi_connected', undef);
+
+    if ($S{viewer_launch}) {
+	if (length $ENV{TMUX_PANE} && length $ENV{TMUX} && lc $S{viewer_tmux_position} ne 'custom') {
+	    my $cmd = _viewer_command_replace_format('%qA', '-p', lc $S{viewer_tmux_position});
+	    Irssi::command("exec - tmux neww -d $cmd 2>&1 &");
+	}
+	elsif (length $ENV{WINDOWID} && length $ENV{DISPLAY} && length $S{viewer_xwin_command} && $S{viewer_xwin_command} =~ /\S/) {
+	    my $cmd = _viewer_command_replace_format($S{viewer_xwin_command});
+	    Irssi::command("exec - $cmd 2>&1 &");
+	}
+	elsif (length $S{viewer_custom_command} && $S{viewer_custom_command} =~ /\S/) {
+	    my $cmd = _viewer_command_replace_format($S{viewer_custom_command});
+	    Irssi::command("exec - $cmd 2>&1 &");
+	}
+    }
+}
+
+sub set_viewer_mode_hint {
+    return unless $viewer{server};
+    if ($S{no_mode_hint}) {
+	$viewer{msg} = undef;
+    }
+    else {
+	my ($name) = __PACKAGE__ =~ /::([^:]+)$/;
+	$viewer{msg} = "Run $name from the shell or switch to sbar mode";
+    }
+}
+
+sub retry_viewer {
+    start_viewer();
+}
+
+sub vi_close_client {
+    Irssi::input_remove(delete $viewer{client_tag}) if exists $viewer{client_tag};
+    $viewer{client}->close if $viewer{client};
+    delete $viewer{client};
+    delete $viewer{client_keymap};
+    delete $viewer{client_settings};
+    delete $viewer{client_env};
+    delete $viewer{fullRedraw};
+}
+
+sub vi_connected {
+    vi_close_client();
+    $viewer{client} = $viewer{server}->accept or return;
+    $viewer{client}->blocking(0);
+    $viewer{client_tag} = Irssi::input_add($viewer{client}->fileno, INPUT_READ, 'vi_clientinput', undef);
+    syncViewer();
+}
+
+use constant VIEWER_BLOCK_SIZE => 1024;
+sub vi_clientinput {
+    if ($viewer{client}->read(my $buf, VIEWER_BLOCK_SIZE)) {
+	$viewer{rcvbuf} .= $buf;
+	if ($viewer{rcvbuf} =~ s/^(?:(active|\d+)|(last|up|down))\n//igm) {
+	    if (defined $2) {
+		Irssi::command("window $2");
+	    }
+	    elsif (lc $1 eq 'active' && $viewer{use_ack}) {
+		Irssi::command("ack");
+	    }
+	    else {
+		Irssi::command("window goto $1");
+	    }
+	}
+    }
+    else {
+	vi_close_client();
+	Irssi::timeout_add_once(100, 'syncViewer', undef);
+    }
+}
+
+sub stop_viewer {
+    Irssi::timeout_remove(delete $viewer{retry}) if exists $viewer{retry};
+    vi_close_client();
+    Irssi::input_remove(delete $viewer{server_tag}) if exists $viewer{server_tag};
+    return unless $viewer{server};
+    $viewer{server}->close;
+    delete $viewer{server};
+}
+sub _encode_var {
+    my $str;
+    while (@_) {
+	my ($name, $var) = splice @_, 0, 2;
+	my $type = ref $var ? $var =~ /HASH/ ? 'map' : $var =~ /ARRAY/ ? 'list' : '' : '';
+	$str .= "\n\U$name$type\_begin\n";
+	if ($type eq 'map') {
+	    no warnings 'numeric';
+	    $str .= " $_\n ${$var}{$_}\n" for sort { $a <=> $b || $a cmp $b } keys %$var;
+	}
+	elsif ($type eq 'list') {
+	    $str .= " $_\n" for @$var;
+	}
+	else {
+	    $str .= " $var\n";
+	}
+	$str .= "\U$name$type\_end\n";
+    }
+    $str
+}
+sub syncViewer {
+    if ($viewer{client}) {
+	@actString = ();
+	if ($currentLines) {
+	    killOldStatus();
+	    $currentLines = 0;
+	}
+	my $str;
+	unless ($viewer{client_keymap}) {
+	    $str .= _encode_var('key', +{ %nummap, %specialmap });
+	    $viewer{client_keymap} = 1;
+	}
+	unless ($viewer{client_settings}) {
+	    $str .= _encode_var(
+		block => $S{block},
+		ha => $S{height_adjust},
+		mc => $S{maxcolumns},
+		ml => $S{maxlines},
+	       );
+	    $viewer{client_settings} = 1;
+	}
+	unless ($viewer{client_env}) {
+	    $str .= _encode_var(irssienv => +{
+		length $ENV{TMUX_PANE} && length $ENV{TMUX} ?
+		     (tmux_pane => $ENV{TMUX_PANE},
+		      tmux_srv => $ENV{TMUX}) : (),
+		length $ENV{WINDOWID} ?
+		     (xwinid => $ENV{WINDOWID}) : (),
+	       });
+	    $viewer{client_env} = 1;
+	}
+	my $separator = _get_format(set 'separator');
+	my $sepLen = sb_length($separator);
+	my $item_bg = _get_format(set 'viewer_item_bg');
+	my $title = _get_format(set 'title');
+	if (length $title) {
+	    $title =~ s{\\(.)|(.)}{
+		defined $2 ? quotemeta $2
+		    : $1 eq 'V' ? '\U'
+		    : $1 eq ':' ? quotemeta '%N'
+		    : $1 =~ /^[uUFQE]$/ ? "\\$1"
+		    : quotemeta "\\$1"
+		}sge;
+	    $title = eval qq{"$title"};
+	}
+	$str .= _encode_var(redraw => 1) if delete $viewer{fullRedraw};
+	$str .= _encode_var(separator => $separator,
+			    seplen => $sepLen,
+			    itembg => $item_bg,
+			    title => $title,
+			    mouse => $mouse_coords{refnum},
+			    key2 => \%wnmap_exp,
+			    win => \@win_items);
+
+	my $was = $viewer{client}->blocking(1);
+	$viewer{client}->print($str);
+	$viewer{client}->blocking($was);
+    }
+    elsif ($viewer{server}) {
+	if (defined $viewer{msg}) {
+	    @actString = ((uc setc()).": $viewer{msg}");
+	}
+	else {
+	    @actString = ();
+	}
+    }
+    elsif (defined $viewer{msg}) {
+	@actString = ((uc setc()).": $viewer{msg}");
+    }
+    if (@actString) {
+	Irssi::timeout_add_once(100, 'syncLines', undef);
+    }
+    elsif ($currentLines) {
+	killOldStatus();
+	$currentLines = 0;
+    }
+}
+
+sub reset_awl {
+    Irssi::timeout_remove($shade_line_timer) if $shade_line_timer; $shade_line_timer = undef;
+    my $was_sort = $S{sort} // '';
+    my $was_xform = $S{xform} // '';
+    my $was_shared = $S{shared_sbar};
+    my $was_no_hint = $S{no_mode_hint};
+    %S = (
+	sort	      => Irssi::settings_get_str( set 'sort'),
+	fancy_abbrev  => Irssi::settings_get_str('fancy_abbrev'),
+	xform	      => Irssi::settings_get_str( set 'custom_xform'),
+	block	      => Irssi::settings_get_int( set 'block'),
+	banned_on     => Irssi::settings_get_bool('banned_channels_on'),
+	prefer_name   => Irssi::settings_get_bool(set 'prefer_name'),
+	hide_data     => Irssi::settings_get_int( set 'hide_data'),
+	hide_name     => Irssi::settings_get_int( set 'hide_name_data'),
+	hide_empty    => Irssi::settings_get_int( set 'hide_empty'),
+	sbar_maxlen   => Irssi::settings_get_bool(set 'sbar_maxlength'),
+	placement     => Irssi::settings_get_str( set 'placement'),
+	position      => Irssi::settings_get_int( set 'position'),
+	maxlines      => Irssi::settings_get_int( set 'maxlines'),
+	maxcolumns    => Irssi::settings_get_int( set 'maxcolumns'),
+	all_disable   => Irssi::settings_get_bool(set 'all_disable'),
+	height_adjust => Irssi::settings_get_int( set 'height_adjust'),
+	mouse_offset  => Irssi::settings_get_int( set 'mouse_offset'),
+	mouse_scroll  => Irssi::settings_get_int( 'mouse_scroll'),
+	mouse_escape  => Irssi::settings_get_int( 'mouse_escape'),
+	line_shade    => Irssi::settings_get_time(set 'last_line_shade'),
+	no_mode_hint  => Irssi::settings_get_bool(set 'no_mode_hint'),
+	viewer_launch	      => Irssi::settings_get_bool(set 'viewer_launch'),
+	viewer_launch_env     => Irssi::settings_get_str(set 'viewer_launch_env'),
+	viewer_xwin_command   => Irssi::settings_get_str(set 'viewer_xwin_command'),
+	viewer_custom_command => Irssi::settings_get_str(set 'viewer_custom_command'),
+	viewer_tmux_position  => Irssi::settings_get_str(set 'viewer_tmux_position'),
+	);
+    $S{fancy_strict} = $S{fancy_abbrev} =~ /^strict/i;
+    $S{fancy_head} = $S{fancy_abbrev} =~ /^head/i;
+    my $shared = Irssi::settings_get_str(set 'shared_sbar');
+    if ($shared =~ /^(\d+)([<])(\d+)$/) {
+	$S{shared_sbar} = [$1, $2, $3];
+    }
+    else {
+	Irssi::settings_set_str(set 'shared_sbar', 'OFF');
+	$S{shared_sbar} = undef;
+    }
+    lock_keys(%S);
+    if ($was_sort ne $S{sort}) {
+	$print_text_activity = undef;
+	my @sort_order = grep { @$_ > 4 } map {
+	    s/^\s*//;
+	    my $reverse = s/^\W*\K[-!]//;
+	    my $undef_check = s/^\W*\K~// ? 1 : undef;
+	    my $equal_check = s/=(.*)\s?$// ? $1 : undef;
+	    s/\s*$//;
+	    my $ignore_case = s/#i$// ? 1 : undef;
+
+	    $print_text_activity = 1 if $_ eq 'last_line';
+
+	    my @path = split '/';
+	    my $class_check = @path && $path[-1] =~ s/(::.*)$// ? $1 : undef;
+
+	    [ $reverse ? -1 : 1, $undef_check, $equal_check, $class_check, $ignore_case, @path ]
+	} "$S{sort}," =~ /([^+,]*|[^+,]*=[^,]*?\s(?=\+)|[^+,]*=[^,]*)[+,]/g;
+	$window_sort_func = sub {
+	    no warnings qw(numeric uninitialized);
+	    for my $so (@sort_order) {
+		my @x = map {
+		    my $ret = 0;
+		    $_ = lc1459($_) if defined $_ && !ref $_ && $so->[4];
+		    $ret = $_ eq ($so->[4] ? lc1459($so->[2]) : $so->[2]) ? 1 : -1 if defined $so->[2];
+		    $ret = defined $_ ? ($ret || -3) : 3 if $so->[1];
+		    $ret = ref $_ && $_->isa('Irssi'.$so->[3]) ? 2 : ($ret || -2) if $so->[3];
+		    -$ret || $_
+		}
+		map {
+		    reduce { return unless ref $a; $a->{$b} } $_, @{$so}[5..$#$so]
+		} $a, $b;
+		return ((($x[0] <=> $x[1] || $x[0] cmp $x[1]) * $so->[0]) || next);
+	    }
+	    return ($a->{refnum} <=> $b->{refnum});
+	};
+    }
+    if ($was_xform ne $S{xform}) {
+	if ($S{xform} !~ /\S/) {
+	    $custom_xform = undef;
+	}
+	else {
+	    my $script_pkg = __PACKAGE__ . '::custom_xform';
+	    local $@;
+	    $custom_xform = eval qq{
+package $script_pkg;
+use strict;
+no warnings;
+our (\$QUERY, \$CHANNEL, \$TAG, \$NAME);
+return sub {
+# line 1 @{[ set 'custom_xform' ]}\n$S{xform}\n}};
+	    if ($@) {
+		$@ =~ /^(.*)/;
+		print '%_'.(set 'custom_xform').'%_ did not compile: '.$1;
+	    }
+	}
+    }
+
+    my $new_settings = join "\n", $VIEWER_MODE
+	 ? ("\\", $S{block}, $S{height_adjust}, $S{maxlines}, $S{maxcolumns})
+	 : ("!", $S{placement}, $S{position});
+
+    if ($settings_str ne $new_settings) {
+	@actString = ();
+	%abbrev_cache = ();
+	$currentLines = 0;
+	killOldStatus();
+	delete $viewer{client_settings};
+	$settings_str = $new_settings;
+    }
+
+    my $was_mouse_mode = $MOUSE_ON;
+    if ($MOUSE_ON = Irssi::settings_get_bool(set 'mouse') and !$was_mouse_mode) {
+	install_mouse();
+    }
+    elsif ($was_mouse_mode and !$MOUSE_ON) {
+	uninstall_mouse();
+    }
+
+    my $path = Irssi::settings_get_str(set 'path');
+    my $was_viewer_mode = $VIEWER_MODE;
+    if ($was_viewer_mode &&
+	defined $viewer{path} && $viewer{path} ne $path) {
+	stop_viewer();
+	$was_viewer_mode = 0;
+    }
+    elsif ($was_viewer_mode && $S{no_mode_hint} != $was_no_hint + 0) {
+	set_viewer_mode_hint();
+    }
+    $viewer{path} = $path;
+    if ($VIEWER_MODE = Irssi::settings_get_bool(set 'viewer') and !$was_viewer_mode) {
+	start_viewer();
+    }
+    elsif ($was_viewer_mode and !$VIEWER_MODE) {
+	stop_viewer();
+    }
+
+    %banned_channels = map { lc1459(to_uni($_)) => undef }
+	split ' ', Irssi::settings_get_str('banned_channels');
+
+    my @sb_base = split /\177/, sb_format_expand("{sbstart}{sb \177}{sbend}"), 2;
+    $sb_base_width_pre = sb_length($sb_base[0]);
+    $sb_base_width_post = max 0, sb_length($sb_base[1])-1;
+    $sb_base_width = $sb_base_width_pre + $sb_base_width_post;
+
+    if ($print_text_activity && $S{line_shade}) {
+	$shade_line_timer = Irssi::timeout_add(max(10 * GLOB_QUEUE_TIMER, 100*$S{line_shade}**(1/3)), 'wl_changed', undef);
+    }
+
+    $CHANGED{AWINS} = 1;
+}
+
+sub stop_mouse_tracking {
+    print STDERR "\e[?1005l\e[?1000l";
+}
+sub start_mouse_tracking {
+    print STDERR "\e[?1000h\e[?1005h";
+}
+sub install_mouse {
+    Irssi::command_bind('mouse_xterm' => 'mouse_xterm');
+    Irssi::command('^bind meta-[M command mouse_xterm');
+    Irssi::signal_add_first('gui key pressed' => 'mouse_key_hook');
+    start_mouse_tracking();
+}
+sub uninstall_mouse {
+    stop_mouse_tracking();
+    Irssi::signal_remove('gui key pressed' => 'mouse_key_hook');
+    Irssi::command('^bind -delete meta-[M');
+    Irssi::command_unbind('mouse_xterm' => 'mouse_xterm');
+}
+
+sub awl_mouse_event {
+    return if $VIEWER_MODE;
+    if ((($_[0] == 3 and $_[3] == 0)
+	     || $_[0] == 64 || $_[0] == 65) and
+	    $_[1] == $_[4] and $_[2] == $_[5]) {
+	my $top = lc $S{placement} eq 'top';
+	my ($pos, $line) = @_[1 .. 2];
+	unless ($top) {
+	    $line -= $screenHeight;
+	    $line += $currentLines;
+	    $line += $S{mouse_offset};
+	}
+	else {
+	    $line -= $S{mouse_offset};
+	}
+	$pos -= $sb_base_width_pre;
+	return if $line < 0 || $line >= $currentLines;
+	if ($_[0] == 64) {
+	    Irssi::command('window up');
+	}
+	elsif ($_[0] == 65) {
+	    Irssi::command('window down');
+	}
+	elsif (exists $mouse_coords{$line}{$pos}) {
+	    my $win = $mouse_coords{$line}{$pos};
+	    Irssi::command('window ' . $win);
+	}
+	Irssi::signal_stop;
+    }
+}
+
+sub mouse_scroll_event {
+    return unless $S{mouse_scroll};
+    if (($_[3] == 64 or $_[3] == 65) and
+	    $_[0] == $_[3] and $_[1] == $_[4] and $_[2] == $_[5]) {
+	my $cmd = 'scrollback goto ' . ($_[3] == 64 ? '-' : '+') . $S{mouse_scroll};
+	Irssi::active_win->command($cmd);
+	Irssi::signal_stop;
+    }
+    elsif ($_[0] == 64 or $_[0] == 65) {
+	Irssi::signal_stop;
+    }
+}
+
+sub mouse_escape {
+    return unless $S{mouse_escape} > 0;
+    if ($_[0] == 3) {
+	my $tm = $S{mouse_escape};
+	$tm *= 1000 if $tm < 1000;
+	stop_mouse_tracking();
+	Irssi::timeout_add_once($tm, 'start_mouse_tracking', undef);
+	Irssi::signal_stop;
+    }
+}
+
+sub UNLOAD {
+    @actString = ();
+    killOldStatus();
+    stop_viewer() if $VIEWER_MODE;
+    uninstall_mouse() if $MOUSE_ON;
+}
+
+sub addPrintTextHook { # update on print text
+    return unless defined $^S;
+    return if $BLOCK_ALL;
+    return unless $print_text_activity;
+    return if $_[0]->{level} == 262144 and $_[0]->{target} eq ''
+	and !defined($_[0]->{server});
+    &wl_changed;
+}
+
+sub block_event_window_change {
+    Irssi::signal_stop;
+}
+
+sub update_awins {
+    my @wins = Irssi::windows;
+    local $BLOCK_ALL = 1;
+    Irssi::signal_add_first('window changed' => 'block_event_window_change');
+    my $bwin =
+	my $awin = Irssi::active_win;
+    my $lwin;
+    my $defer_irssi_broken_last;
+    unless ($wins[0]{refnum} == $awin->{refnum}) {
+	# special case: more than 1 last win, so /win last;
+	# /win last doesn't come back to the current window. eg. after
+	# connect & autojoin; we can't handle this situation, bail out
+	$defer_irssi_broken_last = 1;
+    }
+    else {
+	$awin->command('window last');
+	$lwin = Irssi::active_win;
+	$lwin->command('window last');
+	$defer_irssi_broken_last = $lwin->{refnum} == $bwin->{refnum};
+    }
+    my $awin_counter = 0;
+    Irssi::signal_remove('window changed' => 'block_event_window_change');
+    unless ($defer_irssi_broken_last) {
+	# we need to keep the fe-windows code running here
+	Irssi::signal_add_priority('window changed' => 'block_event_window_change', -99);
+	%awins = %wnmap_exp = ();
+	do {
+	    Irssi::active_win->command('window up');
+	    $awin = Irssi::active_win;
+	    $awins{$awin->{refnum}} = undef;
+	    ++$awin_counter;
+	} until ($awin->{refnum} == $bwin->{refnum} || $awin_counter >= @wins);
+	Irssi::signal_remove('window changed' => 'block_event_window_change');
+
+	Irssi::signal_add_first('window changed' => 'block_event_window_change');
+	for my $key (keys %wnmap) {
+	    next unless Irssi::window_find_name($key) || Irssi::window_find_item($key);
+	    $awin->command("window goto $key");
+	    my $cwin = Irssi::active_win;
+	    $wnmap_exp{ $cwin->{refnum} } = $wnmap{$key};
+	    $cwin->command('window last')
+		if $cwin->{refnum} != $awin->{refnum};
+	}
+	for my $win (reverse @wins) { # restore original window order
+	    Irssi::active_win->command('window '.$win->{refnum});
+	}
+	$awin->command('window '.$lwin->{refnum}); # restore last win
+	Irssi::active_win->command('window last');
+	Irssi::signal_remove('window changed' => 'block_event_window_change');
+    }
+    $CHANGED{WL} = 1;
+}
+
+sub resizeTerm {
+    if (defined (my $r = `stty size 2>/dev/null`)) {
+	($screenHeight, $screenWidth) = split ' ', $r;
+	$CHANGED{SETUP} = 1;
+    }
+    else {
+	$CHANGED{SIZE} = 1;
+    }
+}
+
+sub awl_refresh {
+    $globTime = undef;
+    resizeTerm()   if delete $CHANGED{SIZE};
+    reset_awl()    if delete $CHANGED{SETUP};
+    update_awins() if delete $CHANGED{AWINS};
+    update_wl()    if delete $CHANGED{WL};
+}
+
+sub termsize_changed { $CHANGED{SIZE}  = 1; &queue_refresh; }
+sub setup_changed    { $CHANGED{SETUP} = 1; &queue_refresh; }
+sub awins_changed    { $CHANGED{AWINS} = 1; &queue_refresh; }
+sub wl_changed       { $CHANGED{WL}    = 1; &queue_refresh; }
+
+sub window_changed {
+    &awins_changed if $_[1];
+}
+
+sub queue_refresh {
+    return if $BLOCK_ALL;
+    Irssi::timeout_remove($globTime)
+	    if defined $globTime; # delay the update further
+    $globTime = Irssi::timeout_add_once(GLOB_QUEUE_TIMER, 'awl_refresh', undef);
+}
+
+sub awl_init {
+    termsize_changed();
+    update_keymap();
+}
+
+sub runsub {
+    my $cmd = shift;
+    sub {
+	my ($data, $server, $item) = @_;
+	Irssi::command_runsub($cmd, $data, $server, $item);
+    };
+}
+
+Irssi::signal_register({
+    'gui mouse' => [qw/int int int int int int/],
+   });
+{ my $broken_expandos = (Irssi::version >= 20081128 && Irssi::version < 20110210)
+      ? sub { my $x = shift; $x =~ s/\$\{cumode_space\}/ /; $x } : undef;
+  Irssi::theme_register([
+    map { $broken_expandos ? $broken_expandos->($_) : $_ }
+    set 'display_nokey'		=>   '$N${cumode_space}$H$C$S',
+    set 'display_key'		=>   '$Q${cumode_space}$H$C$S',
+    set 'display_nokey_visible' => '%2$N${cumode_space}$H$C$S',
+    set 'display_key_visible'	=> '%2$Q${cumode_space}$H$C$S',
+    set 'display_nokey_active'	=> '%1$N${cumode_space}$H$C$S',
+    set 'display_key_active'	=> '%1$Q${cumode_space}$H$C$S',
+    set 'display_header'	=> '%8$C|${N}',
+    set 'name_display'		=> '$0',
+    set 'separator'		=> ' ',
+    set 'separator2'		=> '',
+    set 'abbrev_chars'		=> "~\x{301c}",
+    set 'viewer_item_bg'	=> sb_format_expand('{sb_background}'),
+    set 'title'			=> '\V'.setc().'\:',
+   ]);
+}
+Irssi::settings_add_bool(setc, set 'prefer_name',    0); #
+Irssi::settings_add_int( setc, set 'hide_empty',     0); #
+Irssi::settings_add_int( setc, set 'hide_data',      0); #
+Irssi::settings_add_int( setc, set 'hide_name_data', 0); #
+Irssi::settings_add_int( setc, set 'maxlines',       9); #
+Irssi::settings_add_int( setc, set 'maxcolumns',     4); #
+Irssi::settings_add_int( setc, set 'block',          15); #
+Irssi::settings_add_bool(setc, set 'sbar_maxlength', 1); #
+Irssi::settings_add_int( setc, set 'height_adjust',  2); #
+Irssi::settings_add_str( setc, set 'sort',           'refnum'); #
+Irssi::settings_add_str( setc, set 'placement',      'bottom'); #
+Irssi::settings_add_int( setc, set 'position',       0); #
+Irssi::settings_add_bool(setc, set 'all_disable',    1); #
+Irssi::settings_add_bool(setc, set 'viewer',         1); #
+Irssi::settings_add_str( setc, set 'shared_sbar',    'OFF'); #
+Irssi::settings_add_bool(setc, set 'mouse',          0); #
+Irssi::settings_add_str( setc, set 'path', Irssi::get_irssi_dir . '/_windowlist'); #
+Irssi::settings_add_str( setc, set 'custom_xform',   ''); #
+Irssi::settings_add_time(setc, set 'last_line_shade', '0'); #
+Irssi::settings_add_int( setc, set 'mouse_offset',   1); #
+Irssi::settings_add_int( setc, 'mouse_scroll',       3); #
+Irssi::settings_add_int( setc, 'mouse_escape',       1); #
+Irssi::settings_add_str( setc, 'banned_channels',    '');
+Irssi::settings_add_bool(setc, 'banned_channels_on', 1);
+Irssi::settings_add_str( setc, 'fancy_abbrev',       'fancy'); #
+Irssi::settings_add_bool(setc, set 'no_mode_hint',   0); #
+Irssi::settings_add_bool(setc, set 'viewer_launch',  1); #
+Irssi::settings_add_str( setc, set 'viewer_launch_env',  ''); #
+Irssi::settings_add_str( setc, set 'viewer_tmux_position',  'left'); #
+Irssi::settings_add_str( setc, set 'viewer_xwin_command',  'xterm +sb -e %A'); #
+Irssi::settings_add_str( setc, set 'viewer_custom_command',  ''); #
+
+Irssi::signal_add_last({
+    'setup changed'    => 'setup_changed',
+    'print text'       => 'addPrintTextHook',
+    'terminal resized' => 'termsize_changed',
+    'setup reread'     => 'screenFullRedraw',
+    'window hilight'   => 'wl_changed',
+    'command format'   => 'wl_changed',
+});
+Irssi::signal_add({
+    'window changed'	       => 'window_changed',
+    'window item changed'      => 'wl_changed',
+    'window changed automatic' => 'window_changed',
+    'window created'	       => 'awins_changed',
+    'window destroyed'	       => 'awins_changed',
+    'window name changed'      => 'wl_changed',
+    'window refnum changed'    => 'wl_changed',
+});
+Irssi::signal_add_last('gui mouse' => 'mouse_escape');
+Irssi::signal_add_last('gui mouse' => 'mouse_scroll_event');
+Irssi::signal_add_last('gui mouse' => 'awl_mouse_event');
+Irssi::command_bind( setc() => runsub(setc()) );
+Irssi::command_bind( setc() . ' redraw' => 'screenFullRedraw' );
+Irssi::command_bind( setc() . ' restart' => 'restartViewerServer' );
+
+{
+    my $l = set 'shared';
+    {
+	no strict 'refs';
+	*{$l} = $awl_shared_empty;
+    }
+    Irssi::statusbar_item_register($l, '$0', $l);
+}
+
+awl_init();
+
+# Mouse script based on irssi mouse patch by mirage
+{ my $mouse_status = -1; # -1:off 0,1,2:filling mouse_combo
+  my @mouse_combo; # 0:button 1:x 2:y
+  my @mouse_previous; # previous contents of mouse_combo
+
+  sub mouse_xterm_off {
+      $mouse_status = -1;
+  }
+  sub mouse_xterm {
+      $mouse_status = 0;
+      Irssi::timeout_add_once(10, 'mouse_xterm_off', undef);
+  }
+
+  sub mouse_key_hook {
+      my ($key) = @_;
+      if ($mouse_status != -1) {
+	  if ($mouse_status == 0) {
+	      @mouse_previous = @mouse_combo;
+		  #if @mouse_combo && $mouse_combo[0] < 64;
+	  }
+	  $mouse_combo[$mouse_status] = $key - 32;
+	  $mouse_status++;
+	  if ($mouse_status == 3) {
+	      $mouse_status = -1;
+	      # match screen coordinates
+	      $mouse_combo[1]--;
+	      $mouse_combo[2]--;
+	      Irssi::signal_emit('gui mouse', @mouse_combo[0 .. 2], @mouse_previous[0 .. 2]);
+	  }
+	  Irssi::signal_stop;
+      }
+  }
+}
+
+sub string_LCSS {
+    my $str = join "\0", @_;
+    (sort { length $b <=> length $a } $str =~ /(?=(.+).*\0.*\1)/g)[0]
+}
+
+# workaround for issue #271
+{ package Irssi::Nick }
+
+# workaround for issue #572
+@Irssi::UI::Exec::ISA = 'Irssi::Windowitem'
+    if Irssi::version >= 20140822 && Irssi::version <= 20161101 && !@Irssi::UI::Exec::ISA;
+
+UNITCHECK
+{ package AwlViewer;
+  use strict;
+  use warnings;
+  no warnings 'redefine';
+  use Encode;
+  use IO::Socket::UNIX;
+  use IO::Select;
+  use List::Util qw(max);
+  use constant BLOCK_SIZE => 1024;
+  use constant RECONNECT_TIME => 5;
+
+  my $sockpath;
+
+  our $VERSION = '0.8';
+
+  our ($got_int, $resized, $timeout);
+
+  my %vars;
+  my (%c2w, @seqlist);
+  my %mouse_coords;
+  my (@mouse, @last_mouse);
+  my ($err, $sock, $loop);
+  my ($keybuf, $rcvbuf);
+  my @screen;
+  my ($screenHeight, $screenWidth);
+  my ($disp_update, $fs_open, $one_shot_integration, $one_shot_resize);
+  my $integration_position;
+  my $show_title_bar;
+
+  sub connect_it {
+      $sock = IO::Socket::UNIX->new(
+	  Type => SOCK_STREAM,
+	  Peer => $sockpath,
+	 );
+      unless ($sock) {
+	  $err = $!;
+	  return;
+      }
+      $sock->blocking(0);
+      $loop->add($sock);
+  }
+
+  sub remove_conn {
+      my $fh = shift;
+      $loop->remove($fh);
+      $fh->close;
+      $sock = undef;
+      %vars = ();
+      @screen = ();
+  }
+
+  { package Terminfo; # xterm
+    sub civis      { "\e[?25l" }
+    sub sc	   { "\e7" }
+    sub cup	   { "\e[" . ($_[0] + 1) . ';' . ($_[1] + 1) . 'H' }
+    sub el	   { "\e[K" }
+    sub rc	   { "\e8" }
+    sub cnorm      { "\e[?25h" }
+    sub setab      { "\e[4" . $_[0] . 'm' }
+    sub setaf      { "\e[3" . $_[0] . 'm' }
+    sub setaf16    { "\e[9" . $_[0] . 'm' }
+    sub setab16    { "\e[10" . $_[0] . 'm' }
+    sub setaf256   { "\e[38;5;" . $_[0] . 'm' }
+    sub setab256   { "\e[48;5;" . $_[0] . 'm' }
+    sub sgr0       { "\e[0m" }
+    sub bold       { "\e[1m" }
+    sub it         { "\e[3m" }
+    sub ul         { "\e[4m" }
+    sub blink      { "\e[5m" }
+    sub rev	   { "\e[7m" }
+    sub op	   { "\e[39;49m" }
+    sub exit_bold  { "\e[22m" }
+    sub exit_it    { "\e[23m" }
+    sub exit_ul    { "\e[24m" }
+    sub exit_blink { "\e[25m" }
+    sub exit_rev   { "\e[27m" }
+    sub smcup      { "\e[?1049h" }
+    sub rmcup      { "\e[?1049l" }
+    sub smmouse    { "\e[?1000h\e[?1005h" }
+    sub rmmouse    { "\e[?1005l\e[?1000l" }
+  }
+
+  sub init {
+      $sockpath = shift // "$ENV{HOME}/.irssi/_windowlist";
+      STDOUT->autoflush(1);
+      printf "\r%swaiting for %s...", Terminfo::sc, $::IRSSI{name};
+
+      `stty -icanon -echo`;
+
+      $loop = IO::Select->new;
+      STDIN->blocking(0);
+      $loop->add(\*STDIN);
+
+      $SIG{INT} = sub {
+	  $got_int = 1
+      };
+      $SIG{WINCH} = sub {
+	  $resized = 1
+      };
+
+      $resized = 3;
+
+      $disp_update = 2;
+
+      $show_title_bar = 1;
+  }
+
+  sub enter_fs {
+      return if $fs_open;
+      safe_print(Terminfo::rc, Terminfo::smcup, Terminfo::civis, Terminfo::smmouse);
+      $fs_open = 1;
+  }
+
+  sub leave_fs {
+      return unless $fs_open;
+      safe_print(Terminfo::rmmouse, Terminfo::cnorm, Terminfo::rmcup);
+      safe_print(sprintf "\r%swaiting for %s...", Terminfo::sc, $::IRSSI{name}) if $_[0];
+
+      $fs_open = 0;
+  }
+
+  sub end_prog {
+      leave_fs();
+      STDIN->blocking(1);
+      `stty sane`;
+      printf "\r%s%sthanks for using %s\n", Terminfo::rc, Terminfo::el, $::IRSSI{name};
+  }
+
+  sub safe_print {
+      my $st = STDIN->blocking(1);
+      print @_;
+      STDIN->blocking($st);
+  }
+
+  sub safe_qx {
+      my $st = STDIN->blocking(1);
+      my $ret = `$_[0]`;
+      STDIN->blocking($st);
+      $ret
+  }
+
+  sub safe_print_sock {
+      return unless $sock;
+      my $was = $sock->blocking(1);
+      $sock->print(@_);
+      $sock->blocking($was);
+  }
+
+  sub process_recv {
+      my $need = 0;
+      while ($rcvbuf =~ s/\n(.+)_BEGIN\n((?: .*\n)*)\1_END\n//) {
+	  my $var = lc $1;
+	  my $data = $2;
+	  my @data = split "\n ", "\n$data ", -1;
+	  shift @data; pop @data;
+	  my $itembg = $vars{itembg};
+	  if ($var =~ s/list$//) {
+	      $vars{$var} = \@data;
+	  }
+	  elsif ($var =~ s/map$//) {
+	      $vars{$var} = +{ @data };
+	  }
+	  else {
+	      $vars{$var} = join "\n", @data;
+	  }
+	  $need = 1 if $var eq 'win';
+	  $need = 1 if $var eq 'redraw' && $vars{$var};
+	  if (($itembg//'') ne ($vars{itembg}//'')) {
+	      $need = $vars{redraw} = 1;
+	  }
+	  _build_keymap() if $var eq 'key2';
+      }
+      $need
+  }
+
+  { my %ansi_table;
+    my ($i, $j, $k) = (0, 0, 0);
+    my %term_state;
+    sub reset_term_state { my %old_term = %term_state; %term_state = (); %old_term }
+    sub set_term_state { my %old_term = %term_state; %term_state = @_; %old_term }
+    %ansi_table = (
+	# fe-common::core::formats.c:format_expand_styles
+	(map { my $t = $i++; ($_ => sub { my $n = $term_state{hicolor} ? \&Terminfo::setab16 : \&Terminfo::setab;
+					  $n->($t) }) } (split //, '01234567' )),
+	(map { my $t = $j++; ($_ => sub { my $n = $term_state{hicolor} ? \&Terminfo::setaf16 : \&Terminfo::setaf;
+					  $n->($t) }) } (split //, 'krgybmcw' )),
+	(map { my $t = $k++; ($_ => sub { my $n = $term_state{hicolor} ? \&Terminfo::setaf : \&Terminfo::setaf16;
+					  $n->($t) }) } (split //, 'KRGYBMCW')),
+	# reset
+	n => sub { $term_state{hicolor} = 0; my $r = Terminfo::op;
+		   for (qw(blink rev bold)) {
+		       $r .= Terminfo->can("exit_$_")->() if delete $term_state{$_};
+		   }
+		   {
+		       local $ansi_table{n} = $ansi_table{N};
+		       $r .= formats_to_ansi_basic($vars{itembg});
+		   }
+		   $r
+	       },
+	N => sub { reset_term_state(); Terminfo::sgr0 },
+	# flash/bright
+	F => sub { my $n = 'blink'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# reverse
+	8 => sub { my $n = 'rev'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# bold
+	"_" => sub { my $n = 'bold'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# underline
+	U => sub { my $n = 'ul'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# italic
+	I => sub { my $n = 'it'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# bold, used as colour modifier if AWL_HI9 is set
+	9 => $ENV{AWL_HI9} ? sub { $term_state{hicolor} ^= 1; '' }
+	    : sub { my $n = 'bold'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	#      delete                other stuff
+	(map { $_ => sub { '' } } (split //, ':|>#[')),
+	#      escape
+	(map { my $close = $_; $_ => sub { $close } } (split //, '{}%')),
+       );
+    for my $base (0 .. 15) {
+	my $close = $base;
+	my $idx = ($close&8) | ($close&4)>>2 | ($close&2) | ($close&1)<<2;
+	$ansi_table{ (sprintf "x0%x", $close) } =
+	    $ansi_table{ (sprintf "x0%X", $close) } =
+		sub { Terminfo::setab256($idx) };
+	$ansi_table{ (sprintf "X0%x", $close) } =
+	    $ansi_table{ (sprintf "X0%X", $close) } =
+		sub { Terminfo::setaf256($idx) };
+    }
+    for my $plane (1 .. 6) {
+	for my $coord (0 .. 35) {
+	    my $close = 16 + ($plane-1) * 36 + $coord;
+	    my $ch = $coord < 10 ? $coord : chr( $coord - 10 + ord 'a' );
+	    $ansi_table{ "x$plane$ch" } =
+		$ansi_table{ "x$plane\U$ch" } =
+		    sub { Terminfo::setab256($close) };
+	    $ansi_table{ "X$plane$ch" } =
+		$ansi_table{ "X$plane\U$ch" } =
+		    sub { Terminfo::setaf256($close) };
+	}
+    }
+    for my $gray (0 .. 23) {
+	my $close = 232 + $gray;
+	my $ch = chr( $gray + ord 'a' );
+	$ansi_table{ "x7$ch" } =
+	    $ansi_table{ "x7\U$ch" } =
+		sub { Terminfo::setab256($close) };
+	$ansi_table{ "X7$ch" } =
+	    $ansi_table{ "X7\U$ch" } =
+		sub { Terminfo::setaf256($close) };
+    }
+    sub formats_to_ansi_basic {
+	my $o = shift;
+	$o =~ s/(%(X..|x..|.))/exists $ansi_table{$2} ? $ansi_table{$2}->() : $1/gex;
+	$o
+    }
+  }
+
+  sub _header {
+      my $str = $vars{title} // uc ::setc();
+      my $ccs = qr/%(?:X(?:[1-6][0-9A-Z]|7[A-X])|[0-9BCFGIKMNRUWY_])/i;
+      (my $stripstr = $str) =~ s/($ccs)//g;
+      my $space = int( ((abs $vars{block}) - length $stripstr) / (1 + length $stripstr));
+      if ($space > 0) {
+	  my $ss = ' ' x $space;
+	  my @x = $str =~ /((?:$ccs)*\X(?:(?:$ccs)*$)?)/g;
+	  $str = join $ss, '', @x, '';
+      }
+      ($stripstr = $str) =~ s/($ccs)//g;
+      my $pad = max 0, (abs $vars{block}) - length $stripstr;
+      $str = ' ' x ($pad/2) . $str . ' ' x ($pad/2 + $pad%2);
+      $str
+  }
+
+  sub _add_item {
+      my ($i, $j, $c, $wi, $screen, $mouse) = @_;
+      $screen->[$i][$j] = "%N%n$wi";
+      if (exists $vars{mouse}{$c - 1}) {
+	  $mouse->[$i][$j] = $vars{mouse}{$c - 1};
+      }
+  }
+  sub update_screen {
+      $disp_update = 0;
+      unless ($sock && exists $vars{seplen} && exists $vars{block}) {
+	  leave_fs(1);
+	  return;
+      }
+      enter_fs();
+      @screen = () if delete $vars{redraw};
+      %mouse_coords = ();
+      my $ncols = ($vars{seplen} + abs $vars{block}) ?
+	  int( ($screenWidth + $vars{seplen}) / ($vars{seplen} + abs $vars{block}) ) : 0;
+      my $xenl = ($vars{seplen} + abs $vars{block})
+	  && $ncols > int( ($screenWidth + $vars{seplen} - 1) / ($vars{seplen} + abs $vars{block}) );
+      my $nrows = $screenHeight - $vars{ha};
+      my @wi = @{$vars{win}//[]};
+      my $max_items = $ncols * $nrows;
+      my $c = $show_title_bar ? 1 : 0;
+      my $items = @wi + $c;
+      my $titems = $items > $max_items ? $max_items : $items;
+      my $i = 0;
+      my $j = 0;
+      my @new_screen;
+      my @new_mouse;
+      $new_screen[0][0] = _header() #. ' ' x $vars{seplen}
+	  if $show_title_bar;
+      unless ($nrows > $ncols) { # line layout
+	  ++$j if $show_title_bar;
+	  for my $wi (@wi) {
+	      if ($j >= $ncols) {
+		  $j = 0;
+		  ++$i;
+	      }
+	      last if $i >= $nrows;
+	      _add_item($i, $j, $show_title_bar ? $c : $c + 1,
+			$wi, \@new_screen, \@new_mouse);
+	      if ($c + 1 < $titems && $j + 1 < $ncols) {
+		  $new_screen[$i][$j] .= $vars{separator};
+	      }
+	      ++$j;
+	      ++$c;
+	  }
+      }
+      else { # column layout
+	  ++$i if $show_title_bar;
+	  for my $wi (@wi) {
+	      if ($i >= $nrows) {
+		  $i = 0;
+		  ++$j;
+	      }
+	      last if $j >= $ncols;
+	      _add_item($i, $j, $show_title_bar ? $c : $c + 1,
+			$wi, \@new_screen, \@new_mouse);
+	      if ($c + $nrows < $titems) {
+		  $new_screen[$i][$j] .= $vars{separator};
+	      }
+	      ++$i;
+	      ++$c;
+	  }
+      }
+      my $step = $vars{seplen} + abs $vars{block};
+      $i = 0;
+      my $str = Terminfo::sc . Terminfo::sgr0;
+      for (my $i = 0; $i < @new_screen; ++$i) {
+	  for (my $j = 0; $j < @{$new_screen[$i]}; ++$j) {
+	      if (defined $new_mouse[$i] && defined $new_mouse[$i][$j]) {
+		  my $from = $j * $step;
+		  $mouse_coords{$i}{$_} = $new_mouse[$i][$j]
+		      for $from .. $from + abs $vars{block};
+	      }
+	      next if defined $screen[$i] && defined $screen[$i][$j]
+		  && $screen[$i][$j] eq $new_screen[$i][$j];
+	      $str .= Terminfo::cup($i, $j * $step)
+		   .  formats_to_ansi_basic($new_screen[$i][$j])
+		   .  Terminfo::sgr0;
+	      $str .= Terminfo::el if $j == $#{$new_screen[$i]} && (!$xenl || $j + 1 != $ncols);
+	  }
+      }
+      for (@new_screen .. $screenHeight - 1) {
+	  if (!@screen || defined $screen[$_]) {
+	      $str .= Terminfo::cup($_, 0) . Terminfo::sgr0 . Terminfo::el;
+	  }
+      }
+      $str .= Terminfo::rc;
+      safe_print $str;
+      @screen = @new_screen;
+  }
+
+  sub handle_resize {
+      if (defined (my $r = safe_qx('stty size'))) {
+	  ($screenHeight, $screenWidth) = split ' ', $r;
+	  $resized = 0;
+	  @screen = ();
+	  $disp_update = 1;
+	  if ($one_shot_integration == 2) {
+	      $one_shot_resize--;
+	  }
+      }
+      else {
+      }
+  }
+
+  sub _build_keymap {
+      %c2w = reverse( %{$vars{key}}, %{$vars{key2}} );
+      if (!grep { /^[+-]./ } keys %c2w) {
+	  %c2w = (%c2w, map { ("-$_" => $c2w{$_}) } grep { !/^\^./ } keys %c2w);
+      }
+      %c2w = map {
+	  my $key = $_;
+	  s{^(-)?(\+)?(\^)?(.)}{
+	      join '', (
+		  ($1 ? "\e" : ''),
+		  ($2 ? "\e\e" : ''),
+		  ($3 ? "$4"^"@" : $4)
+		 )
+	  }e;
+	  $_ => $c2w{$key}
+      } keys %c2w;
+      @seqlist = sort { length $b <=> length $a } keys %c2w;
+  }
+
+  sub _match_tmux {
+      length $ENV{TMUX} && exists $vars{irssienv}{tmux_srv} && length $vars{irssienv}{tmux_pane}
+	  && $ENV{TMUX} eq $vars{irssienv}{tmux_srv}
+  }
+
+  sub process_keys {
+      Encode::_utf8_on($keybuf);
+      my $win;
+      my $use_mouse;
+      my $maybe;
+  KEY: while (length $keybuf && !$maybe) {
+	  $maybe = 0;
+	  if ($keybuf =~ s/^\e\[M(.)(.)(.)//) {
+	      @last_mouse = @mouse;# if @mouse && $mouse[0] < 64;
+	      @mouse = map { -32 + ord } ($1, $2, $3);
+	      $use_mouse = 1;
+	      next KEY;
+	  }
+	  for my $s (@seqlist) {
+	      if ($keybuf =~ s/^\Q$s//) {
+		  $win = $c2w{$s};
+		  $use_mouse = 0;
+		  next KEY;
+	      }
+	      elsif (length $keybuf < length $s && $s =~ /^\Q$keybuf/) {
+		  $maybe = 1;
+	      }
+	  }
+	  unless ($maybe) {
+	      substr $keybuf, 0, 1, '';
+	  }
+      }
+      if ($use_mouse && @mouse && @last_mouse &&
+	      $mouse[2] == $last_mouse[2] &&
+		  $mouse[1] == $last_mouse[1] &&
+		      ($mouse[0] == 3 || $mouse[0] == 64 || $mouse[0] == 65)) {
+	  if ($mouse[0] == 64) {
+	      $win = 'up';
+	  }
+	  elsif ($mouse[0] == 65) {
+	      $win = 'down';
+	  }
+	  elsif (exists $mouse_coords{$mouse[2] - 1}{$mouse[1] - 1}) {
+	      $win = $mouse_coords{$mouse[2] - 1}{$mouse[1] - 1};
+	  }
+	  elsif ($mouse[2] == 1 && $mouse[1] <= abs $vars{block}) {
+	      $win = $last_mouse[0] != 0 ? 'last' : 'active';
+	  }
+	  else {
+	  }
+      }
+      if (defined $win) {
+	  $win =~ s/^_//;
+	  safe_print_sock("$win\n");
+	  if (!exists $ENV{AWL_AUTOFOCUS} || $ENV{AWL_AUTOFOCUS}) {
+	      if (_match_tmux()) {
+		  safe_qx("tmux selectp -t $vars{irssienv}{tmux_pane} 2>&1");
+	      }
+	      elsif (exists $vars{irssienv}{xwinid}) {
+		  safe_qx("wmctrl -ia $vars{irssienv}{xwinid} 2>/dev/null");
+	      }
+	  }
+      }
+      Encode::_utf8_off($keybuf);
+  }
+
+  sub check_integration {
+      return unless $vars{irssienv};
+      return unless $sock && exists $vars{seplen} && exists $vars{block};
+      if ($one_shot_integration == 1) {
+	  my $nrows = $screenHeight - $vars{ha};
+	  my $ncols = ($vars{seplen} + abs $vars{block}) ? int( ($screenWidth + $vars{seplen}) / ($vars{seplen} + abs $vars{block}) ) : 0;
+	  my $items = ($show_title_bar ? 1 : 0) + @{$vars{win}//[]};
+	  my $dcols_required = $nrows ? int($items/$nrows) + !!($items%$nrows) : 0;
+	  my $rows_required = $ncols ? int($items/$ncols) + !!($items%$ncols) : 0;
+	  $rows_required = abs $vars{ml}
+	      if ($vars{ml} < 0 || ($vars{ml} > 0 && $rows_required > $vars{ml}));
+	  $dcols_required = abs $vars{mc}
+	      if ($vars{mc} < 0 || ($vars{mc} > 0 && $dcols_required > $vars{mc}));
+	  my $rows = $rows_required + $vars{ha};
+	  my $cols = ($dcols_required * ($vars{seplen} + abs $vars{block})) - $vars{seplen};
+	  if (_match_tmux()) {
+	      # int( ($screenWidth + $vars{seplen}) / ($vars{seplen} + abs $vars{block}) );
+	      my ($pos_flag, $before);
+	      if ($integration_position eq 'left') {
+		  $pos_flag = 'h';
+		  $before = 1;
+	      }
+	      elsif ($integration_position eq 'top') {
+		  $pos_flag = 'v';
+		  $before = 1;
+	      }
+	      elsif ($integration_position eq 'right') {
+		  $pos_flag = 'h';
+	      }
+	      else {
+		  $pos_flag = 'v';
+	      }
+	      my @cmd = "joinp -d$pos_flag -s $ENV{TMUX_PANE} -t $vars{irssienv}{tmux_pane}";
+	      push @cmd, "swapp -d -t $ENV{TMUX_PANE} -s $vars{irssienv}{tmux_pane}"
+		  if $before;
+	      $cols = max($cols, 2);
+	      $rows = max($rows, 2);
+
+	      safe_qx("tmux " . (join " \\\; ", @cmd) . " 2>&1");
+	  }
+	  else {
+	      $resized = 1;
+	      #safe_qx("resize -s $screenHeight $cols 2>&1")
+		#  if $cols > 0;
+	  }
+	  $one_shot_integration++;
+	  if ($resized == 1) {
+	      handle_resize();
+	      resize_integration();
+	  }
+      }
+      elsif ($one_shot_integration == 2) {
+	  resize_integration(1);
+      }
+  }
+
+  sub resize_integration {
+      return unless $one_shot_integration;
+      return unless ($one_shot_resize//0) < 0 || shift;
+      my $nrows = $screenHeight - $vars{ha};
+      my $ncols = ($vars{seplen} + abs $vars{block}) ? int( ($screenWidth + $vars{seplen}) / ($vars{seplen} + abs $vars{block}) ) : 0;
+      my $items = ($show_title_bar ? 1 : 0) + @{$vars{win}//[]};
+      my $dcols_required = $nrows ? (int($items/$nrows) + !!($items%$nrows)) : 0;
+      my $rows_required = $ncols ? int($items/$ncols) + !!($items%$ncols) : 0;
+      $rows_required = abs $vars{ml}
+	  if ($vars{ml} < 0 || ($vars{ml} > 0 && $rows_required > $vars{ml}));
+      $dcols_required = abs $vars{mc}
+	  if ($vars{mc} < 0 || ($vars{mc} > 0 && $dcols_required > $vars{mc}));
+      my $rows = $rows_required + $vars{ha};
+      my $cols = ($dcols_required * ($vars{seplen} + abs $vars{block})) - $vars{seplen};
+      if (_match_tmux()) {
+	  my $pos_flag;
+	  my $before = 0;
+	  if ($integration_position eq 'left') {
+	      $pos_flag = 'h';
+	      $before = 1;
+	  }
+	  elsif ($integration_position eq 'top') {
+	      $pos_flag = 'v';
+	      $before = 1;
+	  }
+	  elsif ($integration_position eq 'right') {
+	      $pos_flag = 'h';
+	  }
+	  else {
+	      $pos_flag = 'v';
+	  }
+	  my @cmd;
+	  # hard tmux limits
+	  $cols = max($cols, 2);
+	  $rows = max($rows, 2);
+	  if ($pos_flag eq 'h' && $cols != $screenWidth) {
+	      my $change = $screenWidth - $cols;
+	      my $dir = ($before ^ ($change<0)) ? 'L' : 'R';
+	      push @cmd, "resizep -$dir -t $ENV{TMUX_PANE} @{[abs $change]}";
+	      #push @cmd, "resizep -x $cols -t $ENV{TMUX_PANE}";
+	      $one_shot_resize = 1;
+	  }
+	  if ($pos_flag eq 'v' && $rows != $screenHeight) {
+	      #push @cmd, "resizep -y $rows -t $ENV{TMUX_PANE}";
+	      my $change = $screenHeight - $rows;
+	      my $dir = ($before ^ ($change<0)) ? 'U' : 'D';
+	      push @cmd, "resizep -$dir -t $ENV{TMUX_PANE} @{[abs $change]}";
+	      $one_shot_resize = 1;
+	  }
+
+	  safe_qx("tmux " . (join " \\\; ", @cmd) . " 2>&1")
+	      if @cmd;
+      }
+      else {
+	  $cols = max($cols, 1);
+	  $rows = max($rows, 1);
+	  unless ($nrows > $ncols) { # line layout
+	      if ($rows != $screenHeight) {
+		  safe_qx("resize -s $rows $screenWidth 2>&1");
+		  $one_shot_resize = 1;
+	      }
+	  }
+	  else {
+	      if ($cols != $screenWidth) {
+		  safe_qx("resize -s $screenHeight $cols 2>&1");
+		  $one_shot_resize = 1;
+	      }
+	  }
+      }
+      if ($resized == 1) {
+	  handle_resize();
+      }
+  }
+
+  sub init_integration {
+      return unless $one_shot_integration;
+      if (_match_tmux()) {
+      }
+      else {
+      }
+      safe_print("\e]2;".(uc ::setc())."\e\\");
+  }
+
+  sub main {
+      require Getopt::Std;
+      my %opts;
+      Getopt::Std::getopts('1p:', \%opts);
+      my $one_shot = $opts{1};
+      $integration_position = $opts{p};
+      $one_shot_integration = 0+!!$one_shot;
+      #shift if @_ && $_[0] eq '--';
+      &init;
+      $show_title_bar = 0 if $ENV{AWL_NOTITLE};
+      init_integration();
+      until ($got_int) {
+	  $timeout = undef;
+	  if ($resized) {
+	      if ($resized == 1) {
+		  $timeout = 1;
+		  $resized++;
+	      }
+	      else {
+		  handle_resize();
+		  resize_integration();
+	      }
+	  }
+	  unless ($sock || $timeout) {
+	      connect_it();
+	  }
+	  $timeout ||= RECONNECT_TIME unless $sock;
+	  update_screen() if $disp_update;
+      SELECT: while (my @read = $loop->can_read($timeout)) {
+	      for my $fh (@read) {
+		  if ($fh == \*STDIN) {
+		      if (read STDIN, my $buf, BLOCK_SIZE) {
+			  do {
+			      $keybuf .= $buf;
+			  } while read STDIN, $buf, BLOCK_SIZE;
+		      }
+		      else {
+			  $got_int = 1;
+			  last SELECT;
+		      }
+		  }
+		  else {
+		      if ($fh->read(my $buf, BLOCK_SIZE)) {
+			  do {
+			      $rcvbuf .= $buf;
+			  } while $fh->read($buf, BLOCK_SIZE);
+		      }
+		      else {
+			  $disp_update = 1;
+			  remove_conn($fh);
+			  if ($one_shot) {
+			      $got_int = 1;
+			      last SELECT;
+			  }
+			  $timeout ||= RECONNECT_TIME;
+		      }
+		  }
+	      }
+	      $disp_update |= process_recv() if length $rcvbuf;
+	      process_keys() if length $keybuf;
+	      check_integration() if $one_shot;
+	      update_screen() if $disp_update;
+	  }
+	  continue {
+	  }
+      }
+      end_prog();
+  }
+}
+
+1;
+
+# Changelog
+# =========
+# 1.4
+# - fix line wrapping in some themes, reported by justanotherbody
+# - fix named window key detection, reported by madduck
+# - make title (in viewer and shared_sbar) configurable
+#
+# 1.3 - workaround for irssi issue #572
+# 1.2 - new format to choose abbreviation character
+# 1.1 - infinite loop on shortening certain window names reported by Kalan
+#
+# 1.0
+# - new awl_viewer_launch setting and an array of related settings
+# - fixed regression bug /exec -interactive
+# - fixed some warnings in perl 5.10 reported by kl3
+# - workaround for crash due to infinite recursion in irssi's Perl
+#   error handling
+#
+# 0.9
+# - fix endless loop in awin detection code!
+# - correct colour swap in awl_viewer
+# - fix passing of alternate socket path to the viewer
+# - potential undefinedness in mouse refnum hinted at by Canopus
+# - fixed regression bug /exec -interactive
+# - add case-insensitive modifier to awl_sort
+# - run custom_xform on awl_prefer_name also
+# - avoid inconsistent active window state after awin detection
+#   reported by ss
+# - revert %9-hack in the viewer prompted by discussion with pierrot
+# - fix new warning in perl 5.22
+#
+# 0.8
+# - replace fifo mode with external viewer script
+# - remove bundled cpan modules
+# - work around bogus irssi warning
+# - improve mouse support
+# - workaround for broken cumode in irssi 0.8.15
+# - fix handling of non-meta windows (uninitialized warning)
+# - add 256 colour support, strip true colour codes
+# - fix totally bogus $N padding reported by Ed S.
+# - make /window goto #name mappings work but ignore non-existant ones
+# - improve incomplete reads reported by bcode
+# - fix single % in awl_viewer reported by bcode
+# - add support for key bindings by nike and ferret
+# - coerce utf8 key binds
+# - add settings: custom_xform, last_line_shade, hide_name_data
+# - abbreviations were broken in some cases
+# - fix some misuse of / as cmdchar in mouse script reported by bcode
+# - add shared status bar mode
+# - ${type} variables for custom_xform setting
+# - crash if custom_xform had runtime error
+# - update sorting documentation
+# - fix odd case in size calculation noted by lasers
+# - add missing font styles to the viewer reported by ishanyx
+# - add italic
+#
+# 0.7g
+# - remove screen support and replace it with fifo support
+# - add double-width support to the shortener
+# - correct documentation regarding $T vs. display_header
+# - add missing refresh for window item changed (thanks vague)
+# - add visible windows
+# - add exemptions for active window
+# - workaround for hiding the window changes from trackbar
+# - hack to force 16colours in screen mode
+# - remember last window (reported by earthnative)
+# - wrong window focus on new queries (reported by emsid)
+# - dataloss bug on trying to remember last window
+#
+# 0.6d+
+# - add support for network headers
+# - fixed regression bug /exec -interactive
+#
+# 0.6ca+
+# - add screen support (from nicklist.pl)
+# - names can now have a max length and window names can be used
+# - fixed a bug with block display in screen mode and status bar mode
+# - added space handling to ir_fe and removed it again
+# - now handling formats on my own
+# - started to work on $tag display
+# - added warning about missing sb_act_none abstract leading to
+# - display*active settings
+# - added warning about the bug in awl_display_(no)key_active settings
+# - mouse hack
+#
+# 0.5d
+# - add setting to also hide the last status bar if empty (awl_all_disable)
+# - reverted to old utf8 code to also calculate broken utf8 length correctly
+# - simplified dealing with status bars in wlreset
+# - added a little tweak for the renamed term_type somewhere after Irssi 0.8.9
+# - fixed bug in handling channel #$$
+# - reset background colour at the beginning of an entry
+#
+# 0.4d
+# - fixed order of disabling status bars
+# - several attempts at special chars, without any real success
+#   and much more weird new bugs caused by this
+# - setting to specify sort order
+# - reduced timeout values
+# - added awl_hide_data
+# - make it so the dynamic sub is actually deleted
+# - fix a bug with removing of the last separator
+# - take into consideration parse_special
+#
+# 0.3b
+# - automatically kill old status bars
+# - reset on /reload
+# - position/placement settings
+#
+# 0.2
+# - automated retrieval of key bindings (thanks grep.pl authors)
+# - improved removing of status bars
+# - got rid of status chop
+#
+# 0.1
+# - Based on chanact.pl which was apparently based on lightbar.c and
+#   nicklist.pl with various other ideas from random scripts.
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/chansort.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/chansort.pl
@@ -0,0 +1,43 @@
+use strict;
+use Irssi;
+use Irssi::Irc;
+
+sub sig_sort_trigger {
+    return unless Irssi::settings_get_bool('chansort_autosort');
+    cmd_chansort();
+}
+
+sub cmd_chansort {
+    my(@windows);
+    my($minwin);
+    for my $win (Irssi::windows()) {
+	my $act = $win->{active};
+	my $key;
+	if ($act->{type} eq 'CHANNEL') {
+	    $key = "C".$act->{server}{tag}.' '.substr($act->{visible_name}, 1);
+	}
+	elsif ($act->{type} eq 'QUERY') {
+	    $key = "Q".$act->{server}{tag}.' '.$act->{visible_name};
+	}
+	else {
+	    next;
+	}
+	if (!defined($minwin) || $minwin > $win->{refnum}) {
+	    $minwin = $win->{refnum};
+	}
+	push @windows, [ lc $key, $win ];
+
+    }
+    for (sort {$a->[0] cmp $b->[0]} @windows) {
+	my($key,$win) = @$_;
+	my($act) = $win->{active};
+	$win->command("window move $minwin");
+	$minwin++;
+    }
+}
+
+Irssi::command_bind('chansort', 'cmd_chansort');
+Irssi::settings_add_bool('chansort', 'chansort_autosort', 0);
+Irssi::signal_add_last('window item name changed', 'sig_sort_trigger');
+Irssi::signal_add_last('channel created', 'sig_sort_trigger');
+Irssi::signal_add_last('query created', 'sig_sort_trigger');
+\ No newline at end of file
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/dispatch.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/dispatch.pl
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+use Irssi;
+use Irssi::Irc;
+
+sub event_default_command {
+    my ($command, $server) = @_;
+    return if (Irssi::settings_get_bool("dispatch_unknown_commands") == 0 || !$server);
+    $server->send_raw($command);
+    Irssi::signal_stop();
+}
+
+Irssi::settings_add_bool("misc", "dispatch_unknown_commands", 1);
+Irssi::signal_add_first("default command", "event_default_command");
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/limit.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/limit.pl
@@ -0,0 +1,32 @@
+use strict;
+use Irssi;
+use Irssi::Irc;
+
+our $VERSION = '1.0';
+our %IRSSI = (
+	authors     => 'acidvegas',
+	contact     => 'acidvegas@supernets.org',
+	name        => 'Limit',
+	description => 'A script to limit channel users in a timed interval with timer.pl usage.',
+	license     => 'ISC',
+	url         => 'https://github.com/acidvegas/irssi',
+);
+
+sub limit {
+	my ($data, $server, $channel) = @_;
+	my @nicklist = $channel->nicks();
+	my $totalnicks = scalar @nicklist;
+	my $limit_num = $totalnicks + 10;
+	$channel->command("mode +l $limit_num");
+}
+
+sub cslimit {
+	my ($data, $server, $channel) = @_;
+	my @nicklist = $channel->nicks();
+	my $totalnicks = scalar @nicklist;
+	my $limit_num = $totalnicks + 10;
+	$channel->command("msg chanserv mode $channel->{name} lock add +l $limit_num");
+}
+
+Irssi::command_bind('limit', 'limit');
+Irssi::command_bind('cslimit', 'cslimit');
+\ No newline at end of file
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/masshlkick.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/masshlkick.pl
@@ -0,0 +1,31 @@
+use strict;
+use Irssi;
+use Irssi::Irc;
+
+our $VERSION = '1.0';
+our %IRSSI = (
+    authors     => 'acidvegas',
+    contact     => 'acidvegas@supernets.org',
+    name        => 'MassHLKick',
+    description => 'A script to kick people who mass hilight on a channel.',
+    license     => 'ISC',
+    url         => 'http://github.com/acidvegas/irssi',
+);
+
+sub sig_public {
+  my ($server, $msg, $nick, $address, $target) = @_;
+  my $count;
+  my $channel = $server->channel_find($target);
+  my $max_num_nicks=Irssi::settings_get_int('mass_hilight_threshold');
+  while ($msg =~ /([\]\[\\`_{|}\w^-][\]\[\\`_{|}\w\d^-]*)/g) {
+      if ($channel->nick_find($1)) {
+          $count++;
+      }
+  }
+  if ($count > $max_num_nicks) {
+      $channel->command("kick $target $nick ENTER THE VOID");
+  }
+}
+
+Irssi::signal_add_first('message public', 'sig_public');
+Irssi::settings_add_int('misc','mass_hilight_threshold', 5);
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/nickcolor.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/nickcolor.pl
@@ -0,0 +1,145 @@
+use strict;
+use Irssi 20020101.0250 ();
+use vars qw($VERSION %IRSSI); 
+$VERSION = "2";
+%IRSSI = (
+    authors     => "Timo Sirainen, Ian Peters, David Leadbeater",
+    contact	=> "tss\@iki.fi", 
+    name        => "Nick Color",
+    description => "assign a different color for each nick",
+    license	=> "Public Domain",
+    url		=> "http://irssi.org/",
+    changed	=> "Sun 15 Jun 19:10:44 BST 2014",
+);
+
+# Settings:
+#   nickcolor_colors: List of color codes to use.
+#   e.g. /set nickcolor_colors 2 3 4 5 6 7 9 10 11 12 13
+#   (avoid 8, as used for hilights in the default theme).
+
+my %saved_colors;
+my %session_colors = {};
+
+sub load_colors {
+  open my $color_fh, "<", "$ENV{HOME}/.irssi/saved_colors";
+  while (<$color_fh>) {
+    chomp;
+    my($nick, $color) = split ":";
+    $saved_colors{$nick} = $color;
+  }
+}
+
+sub save_colors {
+  open COLORS, ">", "$ENV{HOME}/.irssi/saved_colors";
+
+  foreach my $nick (keys %saved_colors) {
+    print COLORS "$nick:$saved_colors{$nick}\n";
+  }
+
+  close COLORS;
+}
+
+# If someone we've colored (either through the saved colors, or the hash
+# function) changes their nick, we'd like to keep the same color associated
+# with them (but only in the session_colors, ie a temporary mapping).
+
+sub sig_nick {
+  my ($server, $newnick, $nick, $address) = @_;
+  my $color;
+
+  $newnick = substr ($newnick, 1) if ($newnick =~ /^:/);
+
+  if ($color = $saved_colors{$nick}) {
+    $session_colors{$newnick} = $color;
+  } elsif ($color = $session_colors{$nick}) {
+    $session_colors{$newnick} = $color;
+  }
+}
+
+# This gave reasonable distribution values when run across
+# /usr/share/dict/words
+
+sub simple_hash {
+  my ($string) = @_;
+  chomp $string;
+  my @chars = split //, $string;
+  my $counter;
+
+  foreach my $char (@chars) {
+    $counter += ord $char;
+  }
+
+  my @colors = split / /, Irssi::settings_get_str('nickcolor_colors');
+  $counter = $colors[$counter % @colors];
+
+  return $counter;
+}
+
+sub sig_public {
+  my ($server, $msg, $nick, $address, $target) = @_;
+
+  # Has the user assigned this nick a color?
+  my $color = $saved_colors{$nick};
+
+  # Have -we- already assigned this nick a color?
+  if (!$color) {
+    $color = $session_colors{$nick};
+  }
+
+  # Let's assign this nick a color
+  if (!$color) {
+    $color = simple_hash $nick;
+    $session_colors{$nick} = $color;
+  }
+
+  $color = sprintf "\003%02d", $color;
+  $server->command('/^format pubmsg {pubmsgnick $2 {pubnick ' . $color . '$0}}$1');
+}
+
+sub cmd_color {
+  my ($data, $server, $witem) = @_;
+  my ($op, $nick, $color) = split " ", $data;
+
+  $op = lc $op;
+
+  if (!$op) {
+    Irssi::print ("No operation given (save/set/clear/list/preview)");
+  } elsif ($op eq "save") {
+    save_colors;
+  } elsif ($op eq "set") {
+    if (!$nick) {
+      Irssi::print ("Nick not given");
+    } elsif (!$color) {
+      Irssi::print ("Color not given");
+    } elsif ($color < 2 || $color > 14) {
+      Irssi::print ("Color must be between 2 and 14 inclusive");
+    } else {
+      $saved_colors{$nick} = $color;
+    }
+  } elsif ($op eq "clear") {
+    if (!$nick) {
+      Irssi::print ("Nick not given");
+    } else {
+      delete ($saved_colors{$nick});
+    }
+  } elsif ($op eq "list") {
+    Irssi::print ("\nSaved Colors:");
+    foreach my $nick (keys %saved_colors) {
+      Irssi::print (chr (3) . "$saved_colors{$nick}$nick" .
+		    chr (3) . "1 ($saved_colors{$nick})");
+    }
+  } elsif ($op eq "preview") {
+    Irssi::print ("\nAvailable colors:");
+    foreach my $i (2..14) {
+      Irssi::print (chr (3) . "$i" . "Color #$i");
+    }
+  }
+}
+
+load_colors;
+
+Irssi::settings_add_str('misc', 'nickcolor_colors', '2 3 4 5 6 7 9 10 11 12 13');
+Irssi::command_bind('color', 'cmd_color');
+
+Irssi::signal_add('message public', 'sig_public');
+Irssi::signal_add('event nick', 'sig_nick');
+\ No newline at end of file
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/rejoin.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/rejoin.pl
@@ -0,0 +1,31 @@
+use Irssi;
+use Irssi::Irc;
+use strict;
+
+my $delay  = 1;
+my $acttag = 0;
+my @tags;
+
+sub rejoin {
+    my ( $data ) = @_;
+    my ( $tag, $servtag, $channel, $pass ) = split( / +/, $data );
+    my $server = Irssi::server_find_tag( $servtag );
+    $server->send_raw( "JOIN $channel $pass" ) if ( $server );
+    Irssi::timeout_remove( $tags[$tag] );
+}
+
+sub event_rejoin_kick {
+    my ( $server, $data ) = @_;
+    my ( $channel, $nick ) = split( / +/, $data );
+    return if ( $server->{ nick } ne $nick );
+    my $chanrec = $server->channel_find( $channel );
+    my $password = $chanrec->{ key } if ( $chanrec );
+    my $rejoinchan = $chanrec->{ name } if ( $chanrec );
+    my $servtag = $server->{ tag };
+    Irssi::print "Rejoining $rejoinchan in $delay seconds.";
+    $tags[$acttag] = Irssi::timeout_add( $delay * 1000, "rejoin", "$acttag $servtag $rejoinchan $password" );
+    $acttag++;
+    $acttag = 0 if ( $acttag > 60 );
+}
+
+Irssi::signal_add('event kick', 'event_rejoin_kick');
+\ No newline at end of file
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/timer.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/timer.pl
@@ -0,0 +1,175 @@
+# Fixes for multiple servers and window items by dg
+#
+# 2003-08-27 coekie:
+# - use item names and server tags, fixes irssi crash if window item or server is destroyed
+#
+# 2003-08-19
+#  - changed timer stop code a bit.
+#    should fix the random timer o.O never happened to me before.
+#
+# 2002-12-21 darix:
+#  - nearly complete rewrite ;) the old version wasnt "use strict;" capable =)
+#  - still some warnings with "use warnings;"
+#  - use of command_runsub now :)
+#
+
+use strict;
+use Data::Dumper;
+use warnings;
+use vars  qw ($VERSION %IRSSI);
+use Irssi 20020325 qw (command_bind command_runsub command timeout_add timeout_remove signal_add_first);
+
+$VERSION = '0.6';
+%IRSSI = (
+    authors     => 'Kimmo Lehto, Marcus Rueckert',
+    contact     => 'kimmo@a-men.org, darix@irssi.org' ,
+    name        => 'Timer',
+    description => 'Provides /timer command for mIRC/BitchX type timer functionality.',
+    license     => 'Public Domain',
+    changed     => '2015-02-07'
+);
+
+our %timers;
+# my %timer = { repeat => \d+, command => '' , windowitem => NULL , server=> NULL, timer = NULL};
+
+sub timer_command {
+    my ( $name ) = @_;
+    if ( exists ( $timers{$name} ) ) {
+        if ( $timers{$name}->{'repeat'} != -1 ) {
+            if ( $timers{$name}->{'repeat'}-- == 0) {
+                cmd_timerstop( $name );
+                return;
+            }
+        }
+
+        my ($server, $item);
+        if ($timers{$name}->{'server'}) {
+            $server = Irssi::server_find_tag( $timers{$name}->{'server'} );
+        }
+        if ( $server ) {
+	    if ( $timers{$name}->{'windowitem'}) {
+                $item = $server->window_find_item( $timers{$name}->{'windowitem'} );
+            }
+            ($item ? $item : $server)->command( $timers{$name}->{'command'} );
+        } else {
+            command( $timers{$name}->{'command'} );
+        }
+    }
+}
+
+sub cmd_timerstop {
+    my ( $name ) = @_;
+
+    if ( exists ( $timers{$name} ) ) {
+        timeout_remove($timers{$name}->{'timer'});
+        $timers{$name} = ();
+        delete ( $timers{$name} );
+        print( CRAP "Timer \"$name\" stopped." );
+    }
+    else {
+        print( CRAP "\cBTimer:\cB No such timer \"$name\"." );
+    }
+}
+
+sub cmd_timer_help {
+    print ( <<EOF
+
+TIMER LIST
+TIMER ADD  <name> <interval in seconds> [<repeat>] <command>
+TIMER STOP <name>
+
+repeat value of 0 means unlimited too
+
+EOF
+    );
+}
+
+command_bind 'timer add' => sub {
+    my ( $data, $server, $item ) = @_;
+    my ( $name, $interval, $times, $command );
+
+    if ( $data =~ /^\s*(\w+)\s+(\d+(?:\.\d+)?)\s+(-?\d+)\s+(.*)$/ ) {
+        ( $name, $interval, $times, $command ) = ( $1, $2, $3, $4 );
+        $times = -1 if ( $times == 0 );
+    }
+    elsif ( $data =~ /^\s*(\w+)\s+(\d+(?:\.\d+)?)\s+(.*)$/ )
+    {
+        ( $name, $interval, $times, $command ) = ( $1, $2, -1, $3 );
+    }
+    else {
+        print( CRAP "\cBTimer:\cB parameters not understood. commandline was: timer add $data");
+        return;
+    };
+
+    if ( $times < -1 ) {
+        print( CRAP "\cBTimer:\cB repeat should be greater or equal to -1" );
+        return;
+    };
+
+    if ( $command eq "" ) {
+        print( CRAP "\cBTimer:\cB command is empty commandline was: timer add $data" );
+        return;
+    };
+
+    if ( exists ( $timers{$name} ) ) {
+        print( CRAP "\cBTimer:\cB Timer \"$name\" already active." );
+    }
+    else {
+        #$timers{$name} = {};
+        $timers{$name}->{'repeat'}     = $times;
+        $timers{$name}->{'interval'}   = $interval;
+        $timers{$name}->{'command'}    = $command;
+	if ($item) {
+            $timers{$name}->{'windowitem'} = $item->{'name'};
+	}
+	if ($server) {
+            $timers{$name}->{'server'}     = $server->{'tag'};
+	}
+
+        if ( $times == -1 ) {
+            $times = 'until stopped.';
+        }
+        else {
+            $times .= " times.";
+        }
+
+        print( CRAP "Starting timer \"$name\" repeating \"$command\" every $interval seconds $times" );
+
+        $timers{$name}->{'timer'} = timeout_add( $interval * 1000, \&timer_command, $name );
+    }
+};
+
+command_bind 'timer list' => sub {
+    print( CRAP "Active timers:" );
+    foreach my $name ( keys %timers ) {
+        if ( $timers{$name}->{repeat} == -1 ) {
+            print( CRAP "$name = $timers{$name}->{'command'} (until stopped)");
+        }
+        else {
+            print( CRAP "$name = $timers{$name}->{'command'} ($timers{$name}->{'repeat'} repeats left)" );
+        }
+    }
+    print( CRAP "End of /timer list" );
+};
+
+command_bind 'timer stop' => sub {
+    my ( $data, $server, $item ) = @_;
+    cmd_timerstop ($data);
+};
+
+command_bind 'timer help' => sub { cmd_timer_help() };
+
+command_bind 'timer' => sub {
+    my ( $data, $server, $item ) = @_;
+    $data =~ s/\s+$//g;
+    command_runsub ( 'timer', $data, $server, $item ) ;
+};
+
+
+signal_add_first 'default command timer' => sub {
+#
+# gets triggered if called with unknown subcommand
+#
+    cmd_timer_help()
+}
+
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/trigger.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/trigger.pl
@@ -0,0 +1,1248 @@
+# trigger.pl - execute a command or replace text, triggered by an event in irssi
+# Do /TRIGGER HELP or look at http://wouter.coekaerts.be/irssi/ for help
+
+# Copyright (C) 2002-2010  Wouter Coekaerts <wouter@coekaerts.be>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+use strict;
+use Irssi 20020324 qw(command_bind command_runsub command signal_add_first signal_continue signal_stop signal_remove);
+use Text::ParseWords;
+use IO::File;
+use vars qw($VERSION %IRSSI);
+
+$VERSION = '1.0+';
+%IRSSI = (
+	authors     => 'Wouter Coekaerts',
+	contact     => 'wouter@coekaerts.be',
+	name        => 'trigger',
+	description => 'execute a command or replace text, triggered by an event in irssi',
+	license     => 'GPLv2 or later',
+	url         => 'http://wouter.coekaerts.be/irssi/',
+	changed     => '$LastChangedDate: 2009-02-07 21:35:47 +0100 (Sat, 07 Feb 2009) $',
+);
+
+sub cmd_help {
+	Irssi::print (<<'SCRIPTHELP_EOF', MSGLEVEL_CLIENTCRAP);
+
+TRIGGER LIST
+TRIGGER SAVE
+TRIGGER RELOAD
+TRIGGER MOVE <number> <number>
+TRIGGER DELETE <number>
+TRIGGER CHANGE <number> ...
+TRIGGER ADD ...
+
+%U%_When to match%_%U 
+%UOn which types of event to trigger%U 
+     These are simply specified by -name_of_the_type
+     The normal IRC event types are:
+          publics, %|privmsgs, (pub|priv)actions, (pub|priv)notices, (pub|priv)ctcps, (pub|priv)ctcpreplies, joins, parts, quits, kicks, topics, invites, nick_changes, dcc_msgs, dcc_actions, dcc_ctcps
+          mode_channel: %|a mode on the (whole) channel (like +t, +i, +b)
+          mode_nick: %|a mode on someone in the channel (like +o, +v)
+     -all is an alias for all of those.
+     Additionally, there is:
+          rawin: %|raw text incoming from the server
+          send_command: %|commands you give to irssi
+          send_text: %|lines you type that aren't commands
+          beep: %|when irssi beeps
+          notify_join: %|someone in you notify list comes online
+          notify_part: %|someone in your notify list goes offline
+          notify_away: %|someone in your notify list goes away
+          notify_unaway: %|someone in your notify list goes unaway
+          notify_unidle: %|someone in your notify list stops idling
+          (pub|priv)flood: %|flood in a channel or in private detected. See /set flood. Be careful, these flood signals can trigger many times for one flood (unless you have autoignore enabled)
+
+%UFilters (conditions) the event has to satisfy%U 
+They all take one parameter. If you can give a list, seperate elements by space and use quotes around the list.
+All filters except for -pattern and -regexp can also be inversed by prefixing with -not_.
+     -pattern: %|The message must match the given pattern. ? and * can be used as wildcards
+     -regexp: %|The message must match the given regexp. (see man perlre)
+       %|if -nocase is given as an option, the regexp or pattern is matched case insensitive
+     -tags: %|The servertag must be in the given list of tags
+     -channels: %|The event must be in one of the given list of channels.
+                Examples: %|-channels '#chan1 #chan2' or -channels 'IRCNet/#channel'
+                          %|-channels 'EFNet/' means every channel on EFNet and is the same as -tags 'EFNet'
+     -masks: %|The person who triggers it must match one of the given list of masks
+     -hasmode: %|The person who triggers it must have the give mode
+               Examples: %|'-o' means not opped, '+ov' means opped OR voiced, '-o&-v' means not opped AND not voiced
+     -hasflag: %|Only trigger if friends.pl (friends_shasta.pl) or people.pl is loaded and the person who triggers it has the given flag in the script (same syntax as -hasmode)
+     -other_masks
+     -other_hasmode
+     -other_hasflag: %|Same as above but for the victim for kicks or mode_nick.
+
+%U%_What to do when it matches%_%U 
+     -command: Execute the given Irssi-command
+                %|You are able to use $1, $2 and so on generated by your regexp pattern.
+                %|For multiple commands ; can be used as seperator
+                %|The following variables are also expanded:
+                   $T: %|Server tag
+                   $C: %|Channel name
+                   $N: %|Nickname of the person who triggered this command
+                   $A: %|His address (foo@bar.com),
+                   $I: %|His ident (foo)
+                   $H: %|His hostname (bar.com)
+                   $M: %|The complete message
+                   ${other}: %|The victim for kicks or mode_nick
+                   ${mode_type}: %|The type ('+' or '-') for a mode_channel or mode_nick
+                   ${mode_char}: %|The mode char ('o' for ops, 'b' for ban,...)
+                   ${mode_arg} : %|The argument to the mode (if there is one)
+                %|$\X, with X being one of the above expands (e.g. $\M), escapes all non-alphanumeric characters, so it can be used with /eval or /exec. Don't use /eval or /exec without this, it's not safe.
+     -replace: %|replaces the matching part with the given replacement in the event (requires a -regexp or -pattern)
+     -once: %|remove the trigger if it is triggered, so it only executes once and then is forgotten.
+     -stop: %|stops the signal. It won't get displayed by Irssi. Like /IGNORE
+     -debug: %|print some debugging info
+
+%U%_Other options%_%U 
+     -disabled: %|Same as removing it, but keeps it in case you might need it later
+     -name: %|Give the trigger a name. You can refer to the trigger with this name in add/del/change commands
+
+%U%_Examples%_%U 
+ Knockout people who do a !list:
+   %#/TRIGGER ADD %|-publics -channels "#channel1 #channel2" -nocase -regexp ^!list -command "KN $N This is not a warez channel!"
+ React to !echo commands from people who are +o in your friends-script:
+   %#/TRIGGER ADD %|-publics -regexp '^!echo (.*)' -hasflag '+o' -command 'say echo: $1'
+ Ignore all non-ops on #channel:
+   %#/TRIGGER ADD %|-publics -actions -channels "#channel" -hasmode '-o' -stop
+ Send a mail to yourself every time a topic is changed:
+   %#/TRIGGER ADD %|-topics -command 'exec echo $\N changed topic of $\C to: $\M | mail you@somewhere.com -s topic'
+
+
+%U%_Examples with -replace%_%U 
+ %|Replace every occurence of shit with sh*t, case insensitive:
+   %#/TRIGGER ADD %|-all -nocase -regexp shit -replace sh*t
+ %|Strip all colorcodes from *!lamer@*:
+   %#/TRIGGER ADD %|-all -masks *!lamer@* -regexp '\x03\d?\d?(,\d\d?)?|\x02|\x1f|\x16|\x06' -replace ''
+ %|Never let *!bot1@foo.bar or *!bot2@foo.bar hilight you
+ %|(this works by cutting your nick in 2 different parts, 'myn' and 'ick' here)
+ %|you don't need to understand the -replace argument, just trust that it works if the 2 parts separately don't hilight:
+   %#/TRIGGER ADD %|-all masks '*!bot1@foo.bar *!bot2@foo.bar' -regexp '(myn)(ick)' -nocase -replace '$1\x02\x02$2'
+ %|Avoid being hilighted by !top10 in eggdrops with stats.mod (but show your nick in bold):
+   %#/TRIGGER ADD %|-publics -regexp '(Top.0\(.*\): 1.*)(my)(nick)' -replace '$1\x02$2\x02\x02$3\x02'
+ %|Convert a Windows-1252 Euro to an ISO-8859-15 Euro (same effect as euro.pl):
+   %#/TRIGGER ADD %|-regexp '\x80' -replace '\xA4'
+ %|Show tabs as spaces, not the inverted I (same effect as tab_stop.pl):
+   %#/TRIGGER ADD %|-all -regexp '\t' -replace '    '
+SCRIPTHELP_EOF
+} # /
+
+my @triggers; # array of all triggers
+my %triggers_by_type; # hash mapping types on triggers of that type
+my $recursion_depth = 0;
+my $changed_since_last_save = 0;
+
+###############
+### formats ###
+###############
+
+Irssi::theme_register([
+	'trigger_header' => 'Triggers:',
+	'trigger_line' => '%#$[-4]0 $1',
+	'trigger_added' => 'Trigger $0 added: $1',
+	'trigger_not_found' => 'Trigger {hilight $0} not found',
+	'trigger_saved' => 'Triggers saved to $0',
+	'trigger_loaded' => 'Triggers loaded from $0'
+]);
+
+#########################################
+### catch the signals & do your thing ###
+#########################################
+
+# trigger types with a message and a channel
+my @allchanmsg_types = qw(publics pubactions pubnotices pubctcps pubctcpreplies parts quits kicks topics);
+# trigger types with a message
+my @allmsg_types = (@allchanmsg_types, qw(privmsgs privactions privnotices privctcps privctcpreplies dcc_msgs dcc_actions dcc_ctcps));
+# trigger types with a channel
+my @allchan_types = (@allchanmsg_types, qw(mode_channel mode_nick joins invites pubflood));
+# trigger types in -all
+my @all_types = (@allmsg_types, qw(mode_channel mode_nick joins invites nick_changes));
+# trigger types with a server
+my @all_server_types = (@all_types, qw(rawin notify_join notify_part notify_away notify_unaway notify_unidle pubflood privflood));
+# all trigger types
+my @trigger_types = (@all_server_types, qw(send_command send_text beep));
+#trigger types that are not in -all
+#my @notall_types = grep {my $a=$_; return (!grep {$_ eq $a} @all_types);} @trigger_types;
+my @notall_types = qw(rawin notify_join notify_part notify_away notify_unaway notify_unidle send_command send_text beep pubflood privflood);
+
+my @signals = (
+# "message public", SERVER_REC, char *msg, char *nick, char *address, char *target
+{
+	'types' => ['publics'],
+	'signal' => 'message public',
+	'sub' => sub {check_signal_message(\@_,1,$_[0],$_[4],$_[2],$_[3],'publics');},
+},
+# "message private", SERVER_REC, char *msg, char *nick, char *address
+{
+	'types' => ['privmsgs'],
+	'signal' => 'message private',
+	'sub' => sub {check_signal_message(\@_,1,$_[0],undef,$_[2],$_[3],'privmsgs');},
+},
+# "message irc action", SERVER_REC, char *msg, char *nick, char *address, char *target
+{
+	'types' => ['privactions','pubactions'],
+	'signal' => 'message irc action',
+	'sub' => sub {
+		if ($_[4] eq $_[0]->{nick}) {
+			check_signal_message(\@_,1,$_[0],undef,$_[2],$_[3],'privactions');
+		} else {
+			check_signal_message(\@_,1,$_[0],$_[4],$_[2],$_[3],'pubactions');
+		}
+	},
+},
+# "message irc notice", SERVER_REC, char *msg, char *nick, char *address, char *target
+{
+	'types' => ['privnotices','pubnotices'],
+	'signal' => 'message irc notice',
+	'sub' => sub {
+		if ($_[4] eq $_[0]->{nick}) {
+			check_signal_message(\@_,1,$_[0],undef,$_[2],$_[3],'privnotices');
+		} else {
+			check_signal_message(\@_,1,$_[0],$_[4],$_[2],$_[3],'pubnotices');
+		}
+	}
+},
+# "message join", SERVER_REC, char *channel, char *nick, char *address
+{
+	'types' => ['joins'],
+	'signal' => 'message join',
+	'sub' => sub {check_signal_message(\@_,-1,$_[0],$_[1],$_[2],$_[3],'joins');}
+},
+# "message part", SERVER_REC, char *channel, char *nick, char *address, char *reason
+{
+	'types' => ['parts'],
+	'signal' => 'message part',
+	'sub' => sub {check_signal_message(\@_,4,$_[0],$_[1],$_[2],$_[3],'parts');}
+},
+# "message quit", SERVER_REC, char *nick, char *address, char *reason
+{
+	'types' => ['quits'],
+	'signal' => 'message quit',
+	'sub' => sub {check_signal_message(\@_,3,$_[0],undef,$_[1],$_[2],'quits');}
+},
+# "message kick", SERVER_REC, char *channel, char *nick, char *kicker, char *address, char *reason
+{
+	'types' => ['kicks'],
+	'signal' => 'message kick',
+	'sub' => sub {check_signal_message(\@_,5,$_[0],$_[1],$_[3],$_[4],'kicks',{'other'=>$_[2]});}
+},
+# "message topic", SERVER_REC, char *channel, char *topic, char *nick, char *address
+{
+	'types' => ['topics'],
+	'signal' => 'message topic',
+	'sub' => sub {check_signal_message(\@_,2,$_[0],$_[1],$_[3],$_[4],'topics');}
+},
+# "message invite", SERVER_REC, char *channel, char *nick, char *address
+{
+	'types' => ['invites'],
+	'signal' => 'message invite',
+	'sub' => sub {check_signal_message(\@_,-1,$_[0],$_[1],$_[2],$_[3],'invites');}
+},
+# "message nick", SERVER_REC, char *newnick, char *oldnick, char *address
+{
+	'types' => ['nick_changes'],
+	'signal' => 'message nick',
+	'sub' => sub {check_signal_message(\@_,-1,$_[0],undef,$_[1],$_[3],'nick_changes');}
+},
+# "message dcc", DCC_REC *dcc, char *msg
+{
+	'types' => ['dcc_msgs'],
+	'signal' => 'message dcc',
+	'sub' => sub {check_signal_message(\@_,1,$_[0]->{'server'},undef,$_[0]->{'nick'},undef,'dcc_msgs');
+	}
+},
+# "message dcc action", DCC_REC *dcc, char *msg
+{
+	'types' => ['dcc_actions'],
+	'signal' => 'message dcc action',
+	'sub' => sub {check_signal_message(\@_,1,$_[0]->{'server'},undef,$_[0]->{'nick'},undef,'dcc_actions');}
+},
+# "message dcc ctcp", DCC_REC *dcc, char *cmd, char *data
+{
+	'types' => ['dcc_ctcps'],
+	'signal' => 'message dcc ctcp',
+	'sub' => sub {check_signal_message(\@_,1,$_[0]->{'server'},undef,$_[0]->{'nick'},undef,'dcc_ctcps');}
+},
+# "server incoming", SERVER_REC, char *data
+{
+	'types' => ['rawin'],
+	'signal' => 'server incoming',
+	'sub' => sub {check_signal_message(\@_,1,$_[0],undef,undef,undef,'rawin');}
+},
+# "send command", char *args, SERVER_REC, WI_ITEM_REC
+{
+	'types' => ['send_command'],
+	'signal' => 'send command',
+	'sub' => sub {
+		sig_send_text_or_command(\@_,1);
+	}
+},
+# "send text", char *line, SERVER_REC, WI_ITEM_REC
+{
+	'types' => ['send_text'],
+	'signal' => 'send text',
+	'sub' => sub {
+		sig_send_text_or_command(\@_,0);
+	}
+},
+# "beep"
+{
+	'types' => ['beep'],
+	'signal' => 'beep',
+	'sub' => sub {check_signal_message(\@_,-1,undef,undef,undef,undef,'beep');}
+},
+# "event "<cmd>, SERVER_REC, char *args, char *sender_nick, char *sender_address
+{
+	'types' => ['mode_channel', 'mode_nick'],
+	'signal' => 'event mode',
+	'sub' => sub {
+		my ($server, $event_args, $nickname, $address) = @_;
+		my ($target, $modes, $modeargs) = split(/ /, $event_args, 3);
+		return if (!$server->ischannel($target));
+		my (@modeargs) = split(/ /,$modeargs);
+		my ($pos, $type, $event_type, $arg) = (0, '+');
+		foreach my $char (split(//,$modes)) {
+			if ($char eq "+" || $char eq "-") {
+				$type = $char;
+			} else {
+				if ($char =~ /[Oovh]/) { # mode_nick
+					$event_type = 'mode_nick';
+					$arg = $modeargs[$pos++];
+				} elsif ($char =~ /[beIqdk]/ || ( $char =~ /[lfJ]/ && $type eq '+')) { # chan_mode with arg
+					$event_type = 'mode_channel';
+					$arg = $modeargs[$pos++];
+				} else { # chan_mode without arg
+					$event_type = 'mode_channel';
+					$arg = undef;
+				}
+				check_signal_message(\@_,-1,$server,$target,$nickname,$address,$event_type,{
+					'mode_type' => $type,
+					'mode_char' => $char,
+					'mode_arg' => $arg,
+					'other' => ($event_type eq 'mode_nick') ? $arg : undef
+				});
+			}
+		}
+	}
+},
+# "notifylist joined", SERVER_REC, char *nick, char *user, char *host, char *realname, char *awaymsg
+{
+	'types' => ['notify_join'],
+	'signal' => 'notifylist joined',
+	'sub' => sub {check_signal_message(\@_, 5, $_[0], undef, $_[1], $_[2].'@'.$_[3], 'notify_join', {'realname' => $_[4]});}
+},
+{
+	'types' => ['notify_part'],
+	'signal' => 'notifylist left',
+	'sub' => sub {check_signal_message(\@_, 5, $_[0], undef, $_[1], $_[2].'@'.$_[3], 'notify_left', {'realname' => $_[4]});}
+},
+{
+	'types' => ['notify_unidle'],
+	'signal' => 'notifylist unidle',
+	'sub' => sub {check_signal_message(\@_, 5, $_[0], undef, $_[1], $_[2].'@'.$_[3], 'notify_unidle', {'realname' => $_[4]});}
+},
+{
+	'types' => ['notify_away', 'notify_unaway'],
+	'signal' => 'notifylist away changed',
+	'sub' => sub {check_signal_message(\@_, 5, $_[0], undef, $_[1], $_[2].'@'.$_[3], ($_[5] ? 'notify_away' : 'notify_unaway'), {'realname' => $_[4]});}
+},
+# "ctcp msg", SERVER_REC, char *args, char *nick, char *addr, char *target
+{
+	'types' => ['pubctcps', 'privctcps'],
+	'signal' => 'ctcp msg',
+	'sub' => sub {
+		my ($server, $args, $nick, $addr, $target) = @_;
+		if ($target eq $server->{'nick'}) {
+			check_signal_message(\@_, 1, $server, undef, $nick, $addr, 'privctcps');
+		} else {
+			check_signal_message(\@_, 1, $server, $target, $nick, $addr, 'pubctcps');
+		}
+	}
+},
+# "ctcp reply", SERVER_REC, char *args, char *nick, char *addr, char *target
+{
+	'types' => ['pubctcpreplies', 'privctcpreplies'],
+	'signal' => 'ctcp reply',
+	'sub' => sub {
+		my ($server, $args, $nick, $addr, $target) = @_;
+		if ($target eq $server->{'nick'}) {
+			check_signal_message(\@_, 1, $server, undef, $nick, $addr, 'privctcpreplies');
+		} else {
+			check_signal_message(\@_, 1, $server, $target, $nick, $addr, 'pubctcpreplies');
+		}
+	}
+},
+# "flood", SERVER_REC, char *nick, char *host, int level, char *target
+{
+	'types' => ['pubflood', 'privflood'],
+	'signal' => 'flood',
+	'sub' => sub {
+		my ($server, $nick, $host, $level, $target) = @_;
+		if ($target eq $server->{'nick'}) {
+			check_signal_message(\@_, -1, $server, undef, $nick, $host, 'privflood');
+		} else {
+			check_signal_message(\@_, -1, $server, $target, $nick, $host, 'pubflood');
+		}
+	}
+}
+);
+
+sub sig_send_text_or_command {
+	my ($signal, $iscommand) = @_;
+	my ($line, $server, $item) = @$signal;
+	my ($channelname,$nickname,$address) = (undef,undef,undef);
+	if ($item && (ref($item) eq 'Irssi::Irc::Channel' || ref($item) eq 'Irssi::Silc::Channel')) {
+		$channelname = $item->{'name'};
+	} elsif ($item && ref($item) eq 'Irssi::Irc::Query') { # TODO Silc query ?
+		$nickname = $item->{'name'};
+		$address = $item->{'address'}
+	}
+	# TODO pass context also for non-channels (queries and other stuff)
+	check_signal_message($signal,0,$server,$channelname,$nickname,$address,$iscommand ? 'send_command' : 'send_text');
+
+}
+
+my %filters = (
+'tags' => {
+	'types' => \@all_server_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		
+		if (!defined($server)) {
+			return 0;
+		}
+		my $matches = 0;
+		foreach my $tag (split(/ /,$param)) {
+			if (lc($server->{'tag'}) eq lc($tag)) {
+				$matches = 1;
+				last;
+			}
+		}
+		return $matches;
+	}
+},
+'channels' => {
+	'types' => \@allchan_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		
+		if (!defined($channelname) || !defined($server)) {
+			return 0;
+		}
+		my $matches = 0;
+		foreach my $trigger_channel (split(/ /,$param)) {
+			if (lc($channelname) eq lc($trigger_channel)
+				|| lc($server->{'tag'}.'/'.$channelname) eq lc($trigger_channel)
+				|| lc($server->{'tag'}.'/') eq lc($trigger_channel)) {
+				$matches = 1;
+				last; # this channel matches, stop checking channels
+			}
+		}
+		return $matches;
+	}
+},
+'masks' => {
+	'types' => \@all_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return  (defined($nickname) && defined($address) && defined($server) && $server->masks_match($param, $nickname, $address));
+	}
+},
+'other_masks' => {
+	'types' => ['kicks', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return 0 unless defined($extra->{'other'});
+		my $other_address = get_address($extra->{'other'}, $server, $channelname);
+		return defined($other_address) && $server->masks_match($param, $extra->{'other'}, $other_address);
+	}
+},
+'hasmode' => {
+	'types' => \@all_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return hasmode($param, $nickname, $server, $channelname);
+	}
+},
+'other_hasmode' => {
+	'types' => ['kicks', 'mode_nick'],
+	'sub' => sub {
+		my ($param,$signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return defined($extra->{'other'}) && hasmode($param, $extra->{'other'}, $server, $channelname);
+	}
+},
+'hasflag' => {
+	'types' => \@all_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return 0 unless defined($nickname) && defined($address) && defined($server);
+		my $flags = get_flags ($server->{'chatnet'},$channelname,$nickname,$address);
+		return defined($flags) && check_modes($flags,$param);
+	}
+},
+'other_hasflag' => {
+	'types' => ['kicks', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return 0 unless defined($extra->{'other'});
+		my $other_address = get_address($extra->{'other'}, $server, $channelname);
+		return 0 unless defined($other_address);
+		my $flags = get_flags ($server->{'chatnet'},$channelname,$extra->{'other'},$other_address);
+		return defined($flags) && check_modes($flags,$param);
+	}
+},
+'mode_type' => {
+	'types' => ['mode_channel', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return (($param) eq $extra->{'mode_type'});
+	}
+},
+'mode_char' => {
+	'types' => ['mode_channel', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return (($param) eq $extra->{'mode_char'});
+	}
+},
+'mode_arg' => {
+	'types' => ['mode_channel', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return (($param) eq $extra->{'mode_arg'});
+	}
+}
+);
+
+sub get_address {
+	my ($nick, $server, $channel) = @_;
+	my $nickrec = get_nickrec($nick, $server, $channel);
+	return $nickrec ? $nickrec->{'host'} : undef;
+}
+sub get_nickrec {
+	my ($nick, $server, $channel) = @_;
+	return unless defined($server) && defined($channel) && defined($nick);
+	my $chanrec = $server->channel_find($channel);
+	return $chanrec ? $chanrec->nick_find($nick) : undef;
+}
+
+sub hasmode {
+	my ($param, $nickname, $server, $channelname) = @_;
+	my $nickrec = get_nickrec($nickname, $server, $channelname);
+	return 0 unless defined $nickrec;
+	my $modes =
+		($nickrec->{'op'} ? 'o' : '')
+		. ($nickrec->{'voice'} ? 'v' : '')
+		. ($nickrec->{'halfop'} ? 'h' : '')
+	;
+	return check_modes($modes, $param);
+}
+
+# list of all switches
+my @trigger_switches = (@trigger_types, qw(all nocase stop once debug disabled));
+# parameters (with an argument)
+my @trigger_params = qw(pattern regexp command replace name);
+# all options that can be used to set filters, including negative matches (not_<filter>)
+my @trigger_filter_options = map(($_,'not_'.$_), keys(%filters));
+# list of all options (including switches) for /TRIGGER ADD
+my @trigger_add_options = (@trigger_switches, @trigger_params, @trigger_filter_options);
+# same for /TRIGGER CHANGE, this includes the -no<option>'s
+my @trigger_options = map(($_,'no'.$_) ,@trigger_add_options);
+
+# check the triggers on $signal's $parammessage parameter, for triggers with $condition set
+#  on $server in $channelname, for $nickname!$address
+# set $parammessage to -1 if the signal doesn't have a message
+# for signal without channel, nick or address, set to undef
+sub check_signal_message {
+	my ($signal, $parammessage, $server, $channelname, $nickname, $address, $condition, $extra) = @_;
+	my ($changed, $stopped, $context, $need_rebuild);
+	my $message = ($parammessage == -1) ? '' : $signal->[$parammessage];
+
+	return if (!$triggers_by_type{$condition});
+	
+	if ($recursion_depth > 10) {
+		Irssi::print("Trigger error: Maximum recursion depth reached, aborting trigger.", MSGLEVEL_CLIENTERROR);
+		return;
+	}
+	$recursion_depth++;
+
+TRIGGER:	
+	foreach my $trigger (@{$triggers_by_type{$condition}}) {
+		# check filters
+		foreach my $trigfilter (filters_for_trigger($trigger)) {
+			my $filter_sub = $trigfilter->{'filter'}->{'sub'};
+			my $filter_matches = !!(&$filter_sub($trigfilter->{'param'}, $signal, $parammessage, $server, $channelname, $nickname, $address, $condition, $extra));
+			if ($filter_matches != $trigfilter->{'must_match'}) { # if it didn't match, or if it's a -not_* filter and it did match
+				next TRIGGER;
+			}
+		}
+		
+		# check regexp (and keep matches in @- and @+, so don't make a this a {block})
+		next if ($trigger->{'compregexp'} && ($parammessage == -1 || $message !~ m/$trigger->{'compregexp'}/));
+		
+		# if we got this far, it fully matched, and we need to do the replace/command/stop/once
+		my $expands = $extra;
+		$expands->{'M'} = $message,;
+		$expands->{'T'} = (defined($server)) ? $server->{'tag'} : '';
+		$expands->{'C'} = $channelname;
+		$expands->{'N'} = $nickname;
+		$expands->{'A'} = $address;
+		$expands->{'I'} = ((!defined($address)) ? '' : substr($address,0,index($address,'@')));
+		$expands->{'H'} = ((!defined($address)) ? '' : substr($address,index($address,'@')+1));
+		$expands->{'$'} = '$';
+		$expands->{';'} = ';';
+
+		if (defined($trigger->{'replace'})) { # it's a -replace
+			$message =~ s/$trigger->{'compregexp'}/do_expands($trigger->{'compreplace'},$expands,$message)/ge;
+			$changed = 1;
+		}
+		
+		if ($trigger->{'command'}) { # it's a (nonempty) -command
+			my $command = $trigger->{'command'};
+			# $1 = the stuff behind the $ we want to expand: a number, or a character from %expands
+			$command = do_expands($command, $expands, $message);
+			
+			if (defined($server)) {
+				if (defined($channelname) && $server->channel_find($channelname)) {
+					$context = $server->channel_find($channelname);
+				} else {
+					$context = $server;
+				}
+			} else {
+				$context = undef;
+			}
+			
+			if (defined($context)) {
+				$context->command("eval $command");
+			} else {
+				Irssi::command("eval $command");
+			}
+		}
+
+		if ($trigger->{'debug'}) {
+			print("DEBUG: trigger $condition pmesg=$parammessage message=$message server=$server->{tag} channel=$channelname nick=$nickname address=$address " . join(' ',map {$_ . '=' . $extra->{$_}} keys(%$extra)));
+		}
+		
+		if ($trigger->{'stop'}) {
+			$stopped = 1;
+		}
+		
+		if ($trigger->{'once'}) {
+			# find this trigger in the real trigger list, and remove it
+			for (my $realindex=0; $realindex < scalar(@triggers); $realindex++) {
+				if ($triggers[$realindex] == $trigger) {
+					splice (@triggers,$realindex,1);
+					last;
+				}
+			}
+			$need_rebuild = 1;
+		}
+	}
+
+	if ($need_rebuild) {
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+	if ($stopped) { # stopped with -stop
+		signal_stop();
+	} elsif ($changed) { # changed with -replace
+		$signal->[$parammessage] = $message;
+		signal_continue(@$signal);
+	}
+	$recursion_depth--;
+}
+
+# return array of filters for the given trigger
+sub filters_for_trigger($) {
+	my ($trigger) = @_;
+	return values(%{$trigger->{'filters'}});
+}
+
+# used in check_signal_message to expand $'s
+# $inthis is a string that can contain $ stuff (like 'foo$1bar$N')
+sub do_expands {
+	my ($inthis, $expands, $from) = @_;
+	# @+ and @- are copied because there are two s/// nested, and the inner needs the $1 and $2,... of the outer one
+	my @plus = @+;
+	my @min = @-;
+	my $p = \@plus; my $m = \@min;
+	$inthis =~ s/\$(\\*(\d+|[^0-9x{]|x[0-9a-fA-F][0-9a-fA-F]|{.*?}))/expand_and_escape($1,$expands,$m,$p,$from)/ge;	
+	return $inthis;
+}
+
+# \ $ and ; need extra escaping because we use eval
+sub expand_and_escape {
+	my $retval = expand(@_);
+	$retval =~ s/([\\\$;])/\\\1/g;
+	return $retval;
+}
+
+# used in do_expands (via expand_and_escape), to_expand is the part after the $
+sub expand {
+	my ($to_expand, $expands, $min, $plus, $from) = @_;
+	if ($to_expand =~ /^\d+$/) { # a number => look up in $vars
+		# from man perlvar:
+		# $3 is the same as "substr $var, $-[3], $+[3] - $-[3])"
+		return ($to_expand > @{$min} ? '' : substr($from,$min->[$to_expand],$plus->[$to_expand]-$min->[$to_expand]));
+	} elsif ($to_expand =~ s/^\\//) { # begins with \, so strip that from to_expand
+		my $exp = expand($to_expand,$expands,$min,$plus,$from); # first expand without \
+		$exp =~ s/([^a-zA-Z0-9])/\\\1/g; # escape non-word chars
+		return $exp;
+	} elsif ($to_expand =~ /^x([0-9a-fA-F]{2})/) { # $xAA
+		return chr(hex($1));
+	} elsif ($to_expand =~ /^{(.*?)}$/) { # ${foo}
+		return expand($1, $expands, $min, $plus, $from);
+	} else { # look up in $expands
+		return $expands->{$to_expand};
+	}
+}
+
+sub check_modes {
+	my ($has_modes, $need_modes) = @_;
+	my $matches;
+	my $switch = 1; # if a '-' if found, will be 0 (meaning the modes should not be set)
+	foreach my $need_mode (split /&/, $need_modes) {
+		$matches = 0;
+		foreach my $char (split //, $need_mode) {
+			if ($char eq '-') {
+				$switch = 0;
+			} elsif ($char eq '+') {
+				$switch = 1;
+			} elsif ((index($has_modes, $char) != -1) == $switch) {
+				$matches = 1;
+				last;
+			}
+		}
+		if (!$matches) {
+			return 0;
+		}
+	}
+	return 1;
+}
+
+# get someones flags from people.pl or friends(_shasta).pl
+sub get_flags {
+	my ($chatnet, $channel, $nick, $address) = @_;
+	my $flags;
+	no strict 'refs';
+	if (%{ 'Irssi::Script::people::' }) {
+		if (defined ($channel)) {
+			$flags = (&{ 'Irssi::Script::people::find_local_flags' }($chatnet,$channel,$nick,$address));
+		} else {
+			$flags = (&{ 'Irssi::Script::people::find_global_flags' }($chatnet,$nick,$address));
+		}
+		$flags = join('',keys(%{$flags}));
+	} else {
+		my $shasta;
+		if (%{ 'Irssi::Script::friends_shasta::' }) {
+			$shasta = 'friends_shasta';
+		} elsif (defined &{ 'Irssi::Script::friends::get_idx' }) {
+			$shasta = 'friends';
+		} else {
+			return undef;
+		}
+		my $idx = (&{ 'Irssi::Script::'.$shasta.'::get_idx' }($nick, $address));
+		if ($idx == -1) {
+			return '';
+		}
+		$flags = (&{ 'Irssi::Script::'.$shasta.'::get_friends_flags' }($idx,undef));
+		if ($channel) {
+			$flags .= (&{ 'Irssi::Script::'.$shasta.'::get_friends_flags' }($idx,$channel));
+		}
+	}
+	return $flags;
+}
+
+########################################################
+### internal stuff called by manage, needed by above ###
+########################################################
+
+my %mask_to_regexp = ();
+foreach my $i (0..255) {
+    my $ch = chr $i;
+    $mask_to_regexp{$ch} = "\Q$ch\E";
+}
+$mask_to_regexp{'?'} = '(.)';
+$mask_to_regexp{'*'} = '(.*)';
+
+sub compile_trigger {
+	my ($trigger) = @_;
+	my $regexp;
+	
+	if ($trigger->{'regexp'}) {
+		$regexp = $trigger->{'regexp'};
+	} elsif ($trigger->{'pattern'}) {
+		$regexp = $trigger->{'pattern'};
+		$regexp =~ s/(.)/$mask_to_regexp{$1}/g;
+	} else {
+		delete $trigger->{'compregexp'};
+		return;
+	}
+	
+	if ($trigger->{'nocase'}) {
+		$regexp = '(?i)' . $regexp;
+	}
+	
+	$trigger->{'compregexp'} = qr/$regexp/;
+	
+	if(defined($trigger->{'replace'})) {
+		(my $replace = $trigger->{'replace'}) =~ s/\$/\$\$/g;
+		$trigger->{'compreplace'} = Irssi::parse_special($replace);
+	}
+}
+
+# rebuilds triggers_by_type and updates signal binds
+sub rebuild {
+	%triggers_by_type = ();
+	foreach my $trigger (@triggers) {
+		if (!$trigger->{'disabled'}) {
+			if ($trigger->{'all'}) {
+				# -all is an alias for all types in @all_types for which the filters can apply
+ALLTYPES:
+				foreach my $type (@all_types) {
+					# check if all filters can apply to $type
+					foreach my $trigfilter (filters_for_trigger($trigger)) {
+						if (! grep {$_ eq $type} @{$trigfilter->{'filter'}->{'types'}}) {
+							next ALLTYPES;
+						}
+					}
+					push @{$triggers_by_type{$type}}, ($trigger);
+				}
+			}
+			
+			foreach my $type ($trigger->{'all'} ? @notall_types : @trigger_types) {
+				if ($trigger->{$type}) {
+					push @{$triggers_by_type{$type}}, ($trigger);
+				}
+			}
+		}
+	}
+	
+	foreach my $signal (@signals) {
+		my $should_bind = 0;
+		foreach my $type (@{$signal->{'types'}}) {
+			if (defined($triggers_by_type{$type})) {
+				$should_bind = 1;
+			}
+		}
+		if ($should_bind && !$signal->{'bind'}) {
+			signal_add_first($signal->{'signal'}, $signal->{'sub'});
+			$signal->{'bind'} = 1;
+		} elsif (!$should_bind && $signal->{'bind'}) {
+			signal_remove($signal->{'signal'}, $signal->{'sub'});
+			$signal->{'bind'} = 0;
+		}
+	}
+}
+
+################################
+### manage the triggers-list ###
+################################
+
+my $trigger_file; # cached setting
+
+sub sig_setup_changed {
+	$trigger_file = Irssi::settings_get_str('trigger_file');
+}
+
+sub autosave {
+	cmd_save() if ($changed_since_last_save);
+}
+
+# TRIGGER SAVE
+sub cmd_save {
+	my $io = new IO::File $trigger_file, "w";
+	if (defined $io) {
+		$io->print("#Triggers file version $VERSION\n");
+		foreach my $trigger (@triggers) {
+			$io->print(to_string($trigger) . "\n");
+		}
+		$io->close;
+	}
+	Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'trigger_saved', $trigger_file);
+	$changed_since_last_save = 0;
+}
+
+# save on unload
+sub UNLOAD {
+	cmd_save();
+}
+
+# TRIGGER LOAD
+sub cmd_load {
+	sig_setup_changed(); # make sure we've read the trigger_file setting
+	my $converted = 0;
+	my $io = new IO::File $trigger_file, "r";
+	if (not defined $io) {
+		if (-e $trigger_file) {
+			Irssi::print("Error opening triggers file", MSGLEVEL_CLIENTERROR);
+		}
+		return;
+	}
+	if (defined $io) {
+		@triggers = ();
+		my $text;
+		$text = $io->getline;
+		my $file_version = '';
+		if ($text =~ /^#Triggers file version (.*)\n/) {
+			$file_version = $1;
+		}
+		if ($file_version lt '0.6.1+2') {
+			no strict 'vars';
+			$text .= $_ foreach ($io->getlines);
+			my $rep = eval "$text";
+			if (! ref $rep) {
+				Irssi::print("Error in triggers file");
+				return;
+			}
+			my @old_triggers = @$rep;
+		
+			for (my $index=0;$index < scalar(@old_triggers);$index++) { 
+				my $trigger = $old_triggers[$index];
+	
+				if ($file_version lt '0.6.1') {
+					# convert old names: notices => pubnotices, actions => pubactions
+					foreach $oldname ('notices','actions') {
+						if ($trigger->{$oldname}) {
+							delete $trigger->{$oldname};
+							$trigger->{'pub'.$oldname} = 1;
+							$converted = 1;
+						}
+					}
+				}
+				if ($file_version lt '0.6.1+1' && $trigger->{'modifiers'}) {
+					if ($trigger->{'modifiers'} =~ /i/) {
+						$trigger->{'nocase'} = 1;
+						Irssi::print("Trigger: trigger ".($index+1)." had 'i' in it's modifiers, it has been converted to -nocase");
+					}
+					if ($trigger->{'modifiers'} !~ /^[ig]*$/) {
+						Irssi::print("Trigger: trigger ".($index+1)." had unrecognised modifier '". $trigger->{'modifiers'} ."', which couldn't be converted.");
+					}
+					delete $trigger->{'modifiers'};
+					$converted = 1;
+				}
+				
+				# convert to text with compat, and then to new trigger hash
+				$text = to_string($trigger,1);
+				my @args = &shellwords($text . ' a');
+				my $trigger = parse_options({},@args);
+				if ($trigger) {
+					push @triggers, $trigger;
+				}
+			}
+		} else { # new format
+			while ( $text = $io->getline ) {
+				chop($text);
+				next if ($text =~ /^[ ]*$|^#/);
+				my @args = &shellwords($text . ' a');
+				my $trigger = parse_options({},@args);
+				if ($trigger) {
+					push @triggers, $trigger;
+				}
+			}
+		}
+	}
+	Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'trigger_loaded', $trigger_file);
+	if ($converted) {
+		Irssi::print("Trigger: Triggers file will be in new format next time it's saved.");
+	}
+	rebuild();
+}
+
+# escape for printing with to_string
+# <<abcdef>>      => << 'abcdef' >>
+# <<abc'def>>     => << "abc'def" >>
+# <<abc'def\x02>> => << 'abc'\''def\x02' >>
+sub param_to_string {
+	my ($text) = @_;
+	# avoid ugly escaping if we can use "-quotes without other escaping (no " or \)
+	if ($text =~ /^[^"\\]*'[^"\\]$/) {
+		return ' "' . $text . '" ';
+	}
+	# "'" signs without a (odd number of) \ in front of them, need be to escaped as '\''
+	# this is ugly :(
+	$text =~ s/(^|[^\\](\\\\)*)'/$1'\\''/g;
+	return " '$text' ";
+}
+
+# converts a trigger back to "-switch -options 'foo'" form
+# if $compat, $trigger is in the old format (used to convert)
+sub to_string {
+	my ($trigger, $compat) = @_;
+	my $string;
+	
+	foreach my $switch (@trigger_switches) {
+		if ($trigger->{$switch}) {
+			$string .= '-'.$switch.' ';
+		}
+	}
+	
+	if ($compat) {
+		foreach my $filter (keys(%filters)) {
+			if ($trigger->{$filter}) {
+				$string .= '-' . $filter . param_to_string($trigger->{$filter});
+			}
+		}
+	} else {
+		foreach my $trigfilter (filters_for_trigger($trigger)) {
+			$string .= '-' . $trigfilter->{'option'} . param_to_string($trigfilter->{'param'});
+		}
+	}
+
+	foreach my $param (@trigger_params) {
+		if ($trigger->{$param} || ($param eq 'replace' && defined($trigger->{'replace'}))) {
+			$string .= '-' . $param . param_to_string($trigger->{$param});
+		}
+	}
+	return $string;
+}
+
+# find a trigger (for REPLACE and DELETE), returns index of trigger, or -1 if not found
+sub find_trigger {
+	my ($data) = @_;
+	if ($data =~ /^[0-9]*$/ and defined($triggers[$data-1])) {
+		return $data-1;
+	} else {
+		for (my $i=0; $i < scalar(@triggers); $i++) {
+			if ($triggers[$i]->{'name'} eq $data) {
+				return $i;
+			}
+		}
+	}
+	Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'trigger_not_found', $data);
+	return -1; # not found
+}
+
+
+# TRIGGER ADD <options>
+sub cmd_add {
+	my ($data, $server, $item) = @_;
+	my @args = shellwords($data . ' a');
+	
+	my $trigger = parse_options({}, @args);
+	if ($trigger) {
+		push @triggers, $trigger;
+		Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'trigger_added', scalar(@triggers), to_string($trigger));
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+}
+
+# TRIGGER CHANGE <nr> <options>
+sub cmd_change {
+	my ($data, $server, $item) = @_;
+	my @args = shellwords($data . ' a');
+	my $index = find_trigger(shift @args);
+	if ($index != -1) {
+		if(parse_options($triggers[$index], @args)) {
+			Irssi::print("Trigger " . ($index+1) ." changed to: ". to_string($triggers[$index]));
+		}
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+}
+
+# parses options for TRIGGER ADD and TRIGGER CHANGE
+# if invalid args returns undef, else changes $thetrigger and returns it
+sub parse_options {
+	my ($thetrigger,@args) = @_;
+	my ($trigger, $option);
+	
+	if (pop(@args) ne 'a') {
+		Irssi::print("Syntax error, probably missing a closing quote", MSGLEVEL_CLIENTERROR);
+		return undef;
+	}
+	
+	%$trigger = %$thetrigger; # make a copy to prevent changing the given trigger if args doesn't parse
+ARGS:	for (my $arg = shift @args; $arg; $arg = shift @args) {
+		# expand abbreviated options, put in $option
+		$arg =~ s/^-//;
+		$option = undef;
+		foreach my $ioption (@trigger_options) {
+			if (index($ioption, $arg) == 0) { # -$opt starts with $arg
+				if ($option) { # another already matched
+					Irssi::print("Ambiguous option: $arg", MSGLEVEL_CLIENTERROR);
+					return undef;
+				}
+				$option = $ioption;
+				last if ($arg eq $ioption); # exact match is unambiguous
+			}
+		}
+		if (!$option) {
+			Irssi::print("Unknown option: $arg", MSGLEVEL_CLIENTERROR);
+			return undef;
+		}
+
+		# -<param> <value> or -no<param>
+		foreach my $param (@trigger_params) {
+			if ($option eq $param) {
+				$trigger->{$param} = shift @args;
+				next ARGS;
+			}
+			if ($option eq 'no'.$param) {
+				$trigger->{$param} = undef;
+				next ARGS;
+			}
+		}
+
+		# -[no]<switch>
+		foreach my $switch (@trigger_switches) {
+			# -<switch>
+			if ($option eq $switch) {
+				$trigger->{$switch} = 1;
+				next ARGS;
+			}
+			# -no<switch>
+			elsif ($option eq 'no'.$switch) {
+				$trigger->{$switch} = undef;
+				next ARGS;
+			}
+		}
+		
+		# -[not_]<filter> <value>
+		if ($option =~ /^(not_)?(.*)$/ && $filters{$2}) {
+			$trigger->{'filters'}->{$option} = {
+				option => $option,
+				must_match => ($1 ne 'not_'), # if false, trigger must only be done if filter sub returns false
+				filter_name => $2,
+				filter => $filters{$2},
+				param => shift @args
+			};
+			
+			next ARGS;
+		}
+		
+		# -no<filter>
+		if ($option =~ /^no(.*)$/ && $filters{$1}) {
+			delete $trigger->{'filters'}->{$option};
+		}
+	}
+	
+	if (defined($trigger->{'replace'}) && ! $trigger->{'regexp'} && !$trigger->{'pattern'}) {
+		Irssi::print("Trigger error: Can't have -replace without -regexp", MSGLEVEL_CLIENTERROR);
+		return undef;
+	}
+
+	if ($trigger->{'pattern'} && $trigger->{'regexp'}) {
+		Irssi::print("Trigger error: Can't have -pattern and -regexp in same trigger", MSGLEVEL_CLIENTERROR);
+		return undef;
+	}
+	
+	# remove types that are implied by -all
+	if ($trigger->{'all'}) {
+		foreach my $type (@all_types) {
+			delete $trigger->{$type};
+		}
+	}
+	
+	# remove types for which the filters don't apply
+	foreach my $type (@trigger_types) {
+		if ($trigger->{$type}) {
+			foreach my $trigfilter (filters_for_trigger($trigger)) {
+				if (!grep {$_ eq $type} @{$trigfilter->{'filter'}->{'types'}}) {
+					Irssi::print("Warning: the filter -" . $trigfilter->{'option'} . " can't apply to an event of type -$type, so I'm removing that type from this trigger.");
+					delete $trigger->{$type};
+				}
+			}
+		}
+	}
+
+	# check if it has at least one type
+	my $has_a_type;
+	foreach my $type (@trigger_types) {
+		if ($trigger->{$type}) {
+			$has_a_type = 1;
+			last;
+		}
+	}
+	if (!$has_a_type && !$trigger->{'all'}) {
+		Irssi::print("Warning: this trigger doesn't trigger on any type of message. you probably want to add -publics or -all");
+	}
+	
+	compile_trigger($trigger);
+	%$thetrigger = %$trigger; # copy changes to real trigger
+	return $thetrigger;
+}
+
+# TRIGGER DELETE <num>
+sub cmd_del {
+	my ($data, $server, $item) = @_;
+	my @args = shellwords($data);
+	my $index = find_trigger(shift @args);
+	if ($index != -1) {
+		Irssi::print("Deleted ". ($index+1) .": ". to_string($triggers[$index]));
+		splice (@triggers,$index,1);
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+}
+
+# TRIGGER MOVE <num> <num>
+sub cmd_move {
+	my ($data, $server, $item) = @_;
+	my @args = &shellwords($data);
+	my $index = find_trigger(shift @args);
+	if ($index != -1) {
+		my $newindex = shift @args;
+		if ($newindex < 1 || $newindex > scalar(@triggers)) {
+			Irssi::print("$newindex is not a valid trigger number");
+			return;
+		}
+		Irssi::print("Moved from ". ($index+1) ." to $newindex: ". to_string($triggers[$index]));
+		$newindex -= 1; # array starts counting from 0
+		my $trigger = splice (@triggers,$index,1); # remove from old place
+		splice (@triggers,$newindex,0,($trigger)); # insert at new place
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+}
+
+# TRIGGER LIST
+sub cmd_list {
+	Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'trigger_header');
+	my $i=1;
+	foreach my $trigger (@triggers) {
+		Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'trigger_line', $i++, to_string($trigger));
+	}
+}
+
+######################
+### initialisation ###
+######################
+
+command_bind('trigger help',\&cmd_help);
+command_bind('help trigger',\&cmd_help);
+command_bind('trigger add',\&cmd_add);
+command_bind('trigger change',\&cmd_change);
+command_bind('trigger move',\&cmd_move);
+command_bind('trigger list',\&cmd_list);
+command_bind('trigger delete',\&cmd_del);
+command_bind('trigger save',\&cmd_save);
+command_bind('trigger reload',\&cmd_load);
+command_bind 'trigger' => sub {
+    my ( $data, $server, $item ) = @_;
+    $data =~ s/\s+$//g;
+    command_runsub('trigger', $data, $server, $item);
+};
+
+Irssi::signal_add('setup saved', \&autosave);
+Irssi::signal_add('setup changed', \&sig_setup_changed);
+
+# This makes tab completion work
+Irssi::command_set_options('trigger add',join(' ',@trigger_add_options));
+Irssi::command_set_options('trigger change',join(' ',@trigger_options));
+
+Irssi::settings_add_str($IRSSI{'name'}, 'trigger_file', Irssi::get_irssi_dir()."/triggers");
+
+cmd_load();
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/unfuck.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/unfuck.pl
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+use Irssi;
+use Irssi::Irc;
+
+sub cmd_unfuck {
+    my @windows = Irssi::windows();
+    foreach my $window (@windows) {
+        next if $window->{immortal};
+        $window->{active}->{topic_by} ? next : $window->destroy;
+    }
+}
+
+Irssi::command_bind('unfuck', 'cmd_unfuck');
+\ No newline at end of file
diff --git a/bots/blackhole/blackhole/.irssi/scripts/autorun/voicer.pl b/bots/blackhole/blackhole/.irssi/scripts/autorun/voicer.pl
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+use Irssi;
+use Irssi::Irc;
+
+our $VERSION = '1.0';
+our %IRSSI = (
+    authors     => 'acidvegas (help from www)',
+    contact     => 'acidvegas@supernets.org',
+    name        => 'Voicer',
+    description => 'A script to auto voice anyone who joins the channel after voicer_delay seconds..',
+    license     => 'ISC',
+    url         => 'http://github.coM/acidvegas/irssi',
+);
+
+sub send_voice {
+    my ($server, $channel, $nick) = @{$_[0]};
+    $server->command("/mode $channel +v $nick");
+}
+
+sub event_join {
+    my ($server, $channel, $nick) = @_;
+    my $delay = Irssi::settings_get_int('voicer_delay');
+    Irssi::timeout_add_once( $delay * 1000, \&send_voice, [$server, $channel, $nick]);
+}
+
+Irssi::settings_add_int('misc', 'voicer_delay', 10);
+Irssi::signal_add_last('message join', 'event_join');
diff --git a/bots/blackhole/blackhole/.irssi/startup b/bots/blackhole/blackhole/.irssi/startup
@@ -0,0 +1 @@
+/timer add limit 300 /alimit
diff --git a/bots/blackhole/blackhole/.irssi/triggers b/bots/blackhole/blackhole/.irssi/triggers
@@ -0,0 +1,8 @@
+#Triggers file version 1.0+
+-privmsgs -masks 'CHANGEME1!CHAGEME1@CHANGEME1' -tags 'supernets' -command 'blackhole_kill $M'
+-privmsgs -masks 'CHANGEME2!CHAGEME2@CHANGEME2' -tags 'supernets' -command 'blackhole_kill $M'
+-privmsgs -masks 'CHANGEME3!CHAGEME3@CHANGEME3' -tags 'supernets' -command 'blackhole_kill $M'
+-kicks -tags 'supernets' -other_masks 'CHANGEME1!CHAGEME1@CHANGEME1' -command 'blackhole_kick $C $N'
+-kicks -tags 'supernets' -other_masks 'CHANGEME2!CHAGEME2@CHANGEME2' -command 'blackhole_kick $C $N'
+-kicks -tags 'supernets' -other_masks 'CHANGEME3!CHAGEME3@CHANGEME3' -command 'blackhole_kick $C $N'
+-publics -pubactions -pubnotices -pubctcps -nocase -tags 'supernets' -regexp '^.*(nick1|nick2|nick3).*$' -command 'blackhole_kick $C $N'
+\ No newline at end of file
diff --git a/bots/blackhole/honeypot/.irssi/config b/bots/blackhole/honeypot/.irssi/config
@@ -0,0 +1,177 @@
+servers = (
+  { address = "irc.supernets.org"; chatnet = "supernets"; port = "6697"; autoconnect = "no"; use_ssl = "yes"; }
+);
+
+chatnets = {
+  supernets = { type = "IRC"; };
+};
+
+channels = (
+  { name = "#christ";    chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#dev";       chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#help";      chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#pumpcoin";  chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#scroll";    chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#superbowl"; chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#tor";       chatnet = "supernets"; autojoin = "yes"; },
+  { name = "#tunes";     chatnet = "supernets"; autojoin = "yes"; }
+);
+
+aliases = {
+  wc = "window close";
+};
+
+statusbar = {
+  items = {
+    barstart = "{sbstart}";
+    barend = "{sbend}";
+    topicbarstart = "{topicsbstart}";
+    topicbarend = "{topicsbend}";
+    time = "";
+    user = "";
+    window = "";
+    window_empty = "";
+    prompt = "{prompt $[.15]itemname@$tag}";
+    prompt_empty = "{prompt $winname}";
+    topic = " $topic";
+    topic_empty = "";
+    act = "";
+    lag = "";
+    more = "-- more --";
+  };
+  default = {
+    window = {
+      disabled = "yes";
+      type = "window";
+      placement = "bottom";
+      position = "1";
+      visible = "active";
+      items = {
+        barstart = { priority = "100"; };
+        time = { };
+        user = { };
+        window = { };
+        window_empty = { };
+        lag = { priority = "-1"; };
+        more = { priority = "-1"; alignment = "right"; };
+        barend = { priority = "100"; alignment = "right"; };
+      };
+    };
+    window_inact = {
+      type = "window";
+      placement = "bottom";
+      position = "1";
+      visible = "inactive";
+      items = {
+        barstart = { priority = "100"; };
+        window = { };
+        window_empty = { };
+        more = { priority = "-1"; alignment = "right"; };
+        barend = { priority = "100"; alignment = "right"; };
+      };
+      disabled = "yes";
+    };
+    prompt = {
+      type = "root";
+      placement = "bottom";
+      position = "100";
+      visible = "always";
+      items = {
+        prompt = { priority = "-1"; };
+        prompt_empty = { priority = "-1"; };
+        colours = { alignment = "right"; };
+        input = { priority = "10"; };
+      };
+    };
+    topic = {
+      type = "root";
+      placement = "top";
+      position = "1";
+      visible = "always";
+      items = {
+        topicbarstart = { priority = "100"; };
+        topic = { };
+        topic_empty = { };
+        topicbarend = { priority = "100"; alignment = "right"; };
+      };
+    };
+    inact = { items = { }; disabled = "yes"; };
+    awl_0 = {
+      items = {
+        barstart = { priority = "100"; };
+        awl_0 = { };
+        barend = { priority = "100"; alignment = "right"; };
+      };
+    };
+  };
+};
+
+settings = {
+  core = {
+    nick = "CHANGEME";
+    quit_message = "G-line: User has been permanently banned from this network.";
+    real_name = "CHANGEME";
+    settings_autosave = "yes";
+    timestamp_format = "%I:%M";
+    user_name = "CHANGEME";
+    server_reconnect_time = "5min";
+    recode_fallback = "UTF-8";
+    recode_out_default_charset = "UTF-8";
+    recode_transliterate = "yes";
+    recode = "yes";
+    recode_autodetect_utf8 = "yes";
+    awaylog_level = "hilight";
+    awaylog_file = "~/.irssi/logs/away.log";
+  };
+  "fe-text" = { actlist_sort = "refnum"; };
+  "irc/core" = {
+    alternate_nick = "CHANGEME";
+    channel_sync = "yes";
+    cmds_max_at_once = "0";
+    cmd_queue_speed = "0";
+    ctcp_version_reply = "?";
+    ctcp_userinfo_reply = "?";
+    max_ctcp_queue = "0";
+    part_message = "G-line: User has been permanently banned from this network.";
+    usermode = "+ix";
+    skip_motd = "yes";
+    ban_type = "host";
+    kick_first_on_kickban = "yes";
+  };
+  "irc/flood" = { flood_timecheck = "0"; flood_max_msgs = "0"; };
+  "fe-common/core" = {
+    show_names_on_join = "no";
+    beep_msg_level = "MSGS HILIGHT";
+    term_charset = "UTF-8";
+    max_command_history = "25";
+    autolog_path = "~/.irssi/logs/$tag/$0.log";
+    autocreate_query_level = "MSGS";
+    activity_hilight_level = "MSGS";
+    beep_when_away = "no";
+    beep_when_window_active = "no";
+    hilight_level = "PUBLIC";
+  };
+  "perl/core/scripts" = {
+    nickcolor_colors = "3 5 6 7 10 11 12 13 14";
+    awl_shared_sbar = "OFF";
+    awl_block = "-14";
+    awl_viewer = "no";
+    awl_prefer_name = "yes";
+    awl_sbar_maxlength = "yes";
+    chansort_autosort = "yes";
+    awl_mouse = "yes";
+  };
+};
+
+windows = { 1 = { immortal = "yes"; name = "status"; level = "ALL"; }; };
+mainwindows = { 1 = { first_line = "7"; lines = "13"; }; };
+logs = { };
+keyboard = ( 
+  { key = "meta-[M"; id = "command"; data = "mouse_xterm"; }
+);
+ignores = (
+  { mask = "*!*@services.supernets.org"; level = "CRAP MSGS PUBLICS NOTICES SNOTES CTCPS ACTIONS MODES TOPICS WALLOPS INVITES NICKS DCC DCCMSGS CLIENTNOTICES CLIENTCRAP CLIENTERRORS HILIGHTS"; servertag = "supernets"; },
+  { mask = "*!*@super.nets";             level = "CRAP MSGS PUBLICS NOTICES SNOTES CTCPS ACTIONS MODES TOPICS WALLOPS INVITES NICKS DCC DCCMSGS CLIENTNOTICES CLIENTCRAP CLIENTERRORS HILIGHTS"; servertag = "supernets"; },
+  { mask = "*!*@super.nets.bot";         level = "CRAP MSGS PUBLICS NOTICES SNOTES CTCPS ACTIONS MODES TOPICS WALLOPS INVITES NICKS DCC DCCMSGS CLIENTNOTICES CLIENTCRAP CLIENTERRORS HILIGHTS"; servertag = "supernets"; },
+  { mask = "*!*@super.nets.link";        level = "CRAP MSGS PUBLICS NOTICES SNOTES CTCPS ACTIONS MODES TOPICS WALLOPS INVITES NICKS DCC DCCMSGS CLIENTNOTICES CLIENTCRAP CLIENTERRORS HILIGHTS"; servertag = "supernets"; }
+);
+\ No newline at end of file
diff --git a/bots/blackhole/honeypot/.irssi/default.theme b/bots/blackhole/honeypot/.irssi/default.theme
@@ -0,0 +1,533 @@
+default_color = "-1";
+info_eol = "false";
+replaces = { "[]=" = "%K$*%n"; "<>=" = "%K$*%n"; };
+abstracts = {
+  line_start = "";
+  timestamp = "[$*]";
+  hilight = "%_$*%_";
+  error = "%R$*%n";
+  channel = "%_%b$*%_%w";
+  nick = "%_$*%_";
+  nickhost = "[$*]";
+  server = "%_$*%_";
+  comment = "[$*]";
+  reason = "{comment $*}";
+  mode = "{comment $*}";
+  channick_hilight = "%b$*%n";
+  chanhost_hilight = "{nickhost %b$*%n}";
+  channick = "%_$*%_";
+  chanhost = "{nickhost $*}";
+  channelhilight = "%b$*%n";
+  ban = "%c$*%n";
+  msgnick = "%K<%n$0$1-%K>%n %|";
+  ownmsgnick = "{msgnick $0 $1-}";
+  ownnick = "%_$*%n";
+  pubmsgnick = "{msgnick $0 $1-}";
+  pubnick = "%N$*%n";
+  pubmsgmenick = "{msgnick $0 $1-}";
+  menick = "%Y$*%n";
+  pubmsghinick = "{msgnick $0$1$2-%n}";
+  msgchannel = "%K:%c$*%n";
+  privmsg = "[%R$0%K(%r$1-%K)%n] ";
+  ownprivmsg = "[%r$0%K(%R$1-%K)%n] ";
+  ownprivmsgnick = "{msgnick  $*}";
+  ownprivnick = "%_$*%n";
+  privmsgnick = "{msgnick  %R$*%n}";
+  action_core = "%_ * $*%n";
+  action = "{action_core $*} ";
+  ownaction = "{action $*}";
+  ownaction_target = "{action_core $0}%K:%c$1%n ";
+  pvtaction = "%_ (*) $*%n ";
+  pvtaction_query = "{action $*}";
+  pubaction = "{action $*}";
+  whois = "%# $[8]0 : $1-";
+  ownnotice = "[%m$0%K]%n ";
+  notice = "[%m$*%K]%n ";
+  pubnotice_channel = "%K:%m$*";
+  pvtnotice_host = "%K(%m$*%K)";
+  servernotice = "%g!$*%n ";
+  ownctcp = "[%r$0%K(%R$1-%K)] ";
+  ctcp = "%g$*%n";
+  wallop = "%_$*%n: ";
+  wallop_nick = "%n$*";
+  wallop_action = "%_ * $*%n ";
+  netsplit = "%b$*%n";
+  netjoin = "%g$*%n";
+  names_prefix = "";
+  names_nick = "[%_$0%_$1-] ";
+  names_nick_op = "{names_nick $*}";
+  names_nick_halfop = "{names_nick $*}";
+  names_nick_voice = "{names_nick $*}";
+  names_users = "[%g$*%n]";
+  names_channel = "%G$*%n";
+  dcc = "%g$*%n";
+  dccfile = "%_$*%_";
+  dccownmsg = "[%r$0%K($1-%K)%n] ";
+  dccownnick = "%R$*%n";
+  dccownquerynick = "%_$*%n";
+  dccownaction = "{action $*}";
+  dccownaction_target = "{action_core $0}%K:%c$1%n ";
+  dccmsg = "[%G$1-%K(%g$0%K)%n] ";
+  dccquerynick = "%G$*%n";
+  dccaction = "%_ (*dcc*) $*%n %|";
+  sb_background = "%n%w";
+  sb_default_bg = "%n";
+  sb_prompt_bg = "%n";
+  sb_info_bg = "%n";
+  sb_topic_bg = "%n";
+  sbstart = "";
+  sbend = " ";
+  topicsbstart = "%_[IRSSI]%_{sbstart $*}";
+  topicsbend = "{sbend $*}";
+  prompt = "[%b$*%w] ";
+  sb = "%K[%n$*%K]%n";
+  sbmode = " %c+%n$*";
+  sbaway = " %GzZzZ%n";
+  sbservertag = ":$0";
+  sbnickmode = "$0";
+  sb_act_sep = "%c$*";
+  sb_act_text = "%W$*";
+  sb_act_msg = "%c$*";
+  sb_act_hilight = "%Y$*";
+  sb_act_hilight_color = "$0$1-%n";
+};
+formats = {
+  "fe-common/irc/dcc" = {
+    own_dcc = "{dccownmsg dcc {dccownnick $1}}$2";
+    own_dcc_action = "{dccownaction_target $0 $1}$2";
+    own_dcc_action_query = "{dccownaction $0}$2";
+    own_dcc_ctcp = "{ownctcp ctcp $0}$1 $2";
+    dcc_msg = "{dccmsg dcc $0}$1";
+    action_dcc = "{dccaction $0}$1";
+    action_dcc_query = "{dccaction $0}$1";
+    own_dcc_query = "{ownmsgnick {dccownquerynick $0}}$2";
+    dcc_msg_query = "{privmsgnick $0}$1";
+    dcc_ctcp = "{dcc >>> DCC CTCP {hilight $1} received from {hilight $0}: $2}";
+    dcc_chat = "{dcc DCC CHAT from {nick $0} [$1 port $2]}";
+    dcc_chat_channel = "{dcc DCC CHAT from {nick $0} [$1 port $2] requested in channel {channel $3}}";
+    dcc_chat_not_found = "{dcc No DCC CHAT connection open to {nick $0}}";
+    dcc_chat_connected = "{dcc DCC CHAT connection with {nick $0} [$1 port $2] established}";
+    dcc_chat_disconnected = "{dcc DCC lost chat to {nick $0}}";
+    dcc_send = "{dcc DCC SEND from {nick $0} [$1 port $2]: $3 [$4]}";
+    dcc_send_channel = "{dcc DCC SEND from {nick $0} [$1 port $2]: $3 [$4 bytes] requested in channel {channel $5}}";
+    dcc_send_exists = "{dcc DCC already sending file {dccfile $0} for {nick $1}}";
+    dcc_send_no_route = "{dcc DCC route lost to nick {nick $0} when trying to send file {dccfile $1}}";
+    dcc_send_not_found = "{dcc DCC not sending file {dccfile $1} to {nick $0}}";
+    dcc_send_file_open_error = "{dcc DCC can't open file {dccfile $0}: $1}";
+    dcc_send_connected = "{dcc DCC sending file {dccfile $0} for {nick $1} [$2 port $3]}";
+    dcc_send_complete = "{dcc DCC sent file {dccfile $0} [{hilight $1}] for {nick $2} in {hilight $3} [{hilight $4kB/s}]}";
+    dcc_send_aborted = "{dcc DCC aborted sending file {dccfile $0} for {nick $1}}";
+    dcc_get_not_found = "{dcc DCC no file offered by {nick $0}}";
+    dcc_get_connected = "{dcc DCC receiving file {dccfile $0} from {nick $1} [$2 port $3]}";
+    dcc_get_complete = "{dcc DCC received file {dccfile $0} [$1] from {nick $2} in {hilight $3} [$4kB/s]}";
+    dcc_get_aborted = "{dcc DCC aborted receiving file {dccfile $0} from {nick $1}}";
+    dcc_get_write_error = "{dcc DCC error writing to file {dccfile $0}: {comment $1}";
+    dcc_unknown_ctcp = "{dcc DCC unknown ctcp {hilight $0} from {nick $1} [$2]}";
+    dcc_unknown_reply = "{dcc DCC unknown reply {hilight $0} from {nick $1} [$2]}";
+    dcc_unknown_type = "{dcc DCC unknown type {hilight $0}}";
+    dcc_invalid_ctcp = "{dcc DCC received CTCP {hilight $0} with invalid parameters from {nick $1}}";
+    dcc_connect_error = "{dcc DCC can't connect to {hilight $0} port {hilight $1}}";
+    dcc_cant_create = "{dcc DCC can't create file {dccfile $0}: $1}";
+    dcc_rejected = "{dcc DCC $0 was rejected by {nick $1} [{hilight $2}]}";
+    dcc_request_send = "{dcc DCC $0 request sent to {nick $1}: $2";
+    dcc_close = "{dcc DCC $0 close for {nick $1} [{hilight $2}]}";
+    dcc_lowport = "{dcc Warning: Port sent with DCC request is a lowport ({hilight $0, $1}) - this isn't normal. It is possible the address/port is faked (or maybe someone is just trying to bypass firewall)}";
+    dcc_list_header = "{dcc DCC connections}";
+    dcc_list_line_chat = "{dcc  $0 $1}";
+    dcc_list_line_file = "{dcc  $0 $1: %|$2 of $3 ($4%%) - $5kB/s - ETA $7 - $6}";
+    dcc_list_line_queued_send = "{dcc   - $0 $2 (queued)}";
+    dcc_list_footer = "";
+    dcc_list_line_server = "{dcc  $0: Port($1) - Send($2) - Chat($3) - Fserve($4)}";
+    dcc_server_started = "{dcc  DCC SERVER started on port {hilight $0}}";
+    dcc_server_closed = "{dcc  DCC SERVER on port {hilight $0} closed}";
+  };
+  "fe-common/irc/notifylist" = {
+    notify_join = "{nick $0} [$1@$2] [{hilight $3}] has joined to $4";
+    notify_part = "{nick $0} has left $4";
+    notify_away = "{nick $0} [$5] [$1@$2] [{hilight $3}] is now away: $4";
+    notify_unaway = "{nick $0} [$4] [$1@$2] [{hilight $3}] is now unaway";
+    notify_online = "On $0: {hilight $1}";
+    notify_offline = "Offline: $0";
+    notify_list = "$0: $1 $2";
+    notify_list_empty = "The notify list is empty";
+  };
+  "fe-common/core" = {
+    line_start = "{line_start}";
+    #line_start_irssi = "{line_start}{hilight Irssi:} ";
+    line_start_irssi = "";
+    timestamp = "{timestamp $Z} ";
+    servertag = "[$0] ";
+    daychange = "Day changed to %%d %%b %%Y";
+    talking_with = "You are now talking with {nick $0}";
+    refnum_too_low = "Window number must be greater than 1";
+    error_server_sticky = "Window's server is sticky and it cannot be changed without -unsticky option";
+    set_server_sticky = "Window's server set sticky";
+    unset_server_sticky = "Window's server isn't sticky anymore";
+    window_name_not_unique = "Window names must be unique";
+    window_level = "Window level is now $0";
+    window_set_immortal = "Window is now immortal";
+    window_unset_immortal = "Window isn't immortal anymore";
+    window_immortal_error = "Window is immortal, if you really want to close it, say /WINDOW IMMORTAL OFF";
+    windowlist_header = "%#Ref Name                 Active item     Server          Level";
+    windowlist_line = "%#$[3]0 %|$[20]1 $[15]2 $[15]3 $4";
+    windowlist_footer = "";
+    windows_layout_saved = "Layout of windows is now remembered";
+    windows_layout_reset = "Layout of windows reset to defaults";
+    window_info_header = "";
+    window_info_footer = "";
+    window_info_refnum = "%#Window  : {hilight #$0}";
+    window_info_refnum_sticky = "%#Window  : {hilight #$0 (sticky)}";
+    window_info_name = "%#Name    : $0";
+    window_info_history = "%#History : $0";
+    window_info_immortal = "%#Immortal: yes";
+    window_info_size = "%#Size    : $0x$1";
+    window_info_level = "%#Level   : $0";
+    window_info_server = "%#Server  : $0";
+    window_info_server_sticky = "%#Server  : $0 (sticky)";
+    window_info_theme = "%#Theme   : $0$1";
+    window_info_bound_items_header = "%#Bounds  : {hilight Name                           Server tag}";
+    window_info_bound_item = "%#        : $[!30]0 $[!15]1 $2";
+    window_info_bound_items_footer = "";
+    window_info_items_header = "%#Items   : {hilight Name                           Server tag}";
+    window_info_item = "%# $[7]0: $[!30]1 $2";
+    window_info_items_footer = "";
+    looking_up = "Looking up {server $0}";
+    connecting = "Connecting to {server $0} [$1] port {hilight $2}";
+    reconnecting = "Reconnecting to {server $0} [$1] port {hilight $2} - use /RMRECONNS to abort";
+    connection_established = "Connection to {server $0} established";
+    cant_connect = "Unable to connect server {server $0} port {hilight $1} {reason $2}";
+    connection_lost = "Connection lost to {server $0}";
+    lag_disconnected = "No PONG reply from server {server $0} in $1 seconds, disconnecting";
+    disconnected = "Disconnected from {server $0} {reason $1}";
+    server_quit = "Disconnecting from server {server $0}: {reason $1}";
+    server_changed = "Changed to {hilight $2} server {server $1}";
+    unknown_server_tag = "Unknown server tag {server $0}";
+    no_connected_servers = "Not connected to any servers";
+    server_list = "{server $0}: $1:$2 ($3)";
+    server_lookup_list = "{server $0}: $1:$2 ($3) (connecting...)";
+    server_reconnect_list = "{server $0}: $1:$2 ($3) ($5 left before reconnecting)";
+    server_reconnect_removed = "Removed reconnection to server {server $0} port {hilight $1}";
+    server_reconnect_not_found = "Reconnection tag {server $0} not found";
+    setupserver_added = "Server {server $0} saved";
+    setupserver_removed = "Server {server $0} removed";
+    setupserver_not_found = "Server {server $0} not found";
+    your_nick = "Your nickname is {nick $0}";
+    join = "<%gJoin> {channick $0} {chanhost $1}";
+    part = "<%rPart> {channick $0} {chanhost $1} {reason $3}";
+    kick = "<%rKick> {channick $0} was kicked by {nick $2} {reason $3}";
+    quit = "<%rQuit> {channick $0} {chanhost $1} {reason $2}";
+    quit_once = "<%rQuit> {channel $3} {channick $0} {chanhost $1} {reason $2}";
+    invite = "{nick $0} invites you to {channel $1}";
+    not_invited = "You have not been invited to a channel!";
+    new_topic = "<%btopic> %b\"$2\"%w set by {nick $0}";
+    topic_unset = "Topic unset by {nick $0} on {channel $1}";
+    your_nick_changed = "<%bNick> You are now {nick $1}";
+    nick_changed = "<%bNick> {channick $0} is now {channick $1}";
+    talking_in = "You are now talking in {channel $0}";
+    not_in_channels = "You are not on any channels";
+    current_channel = "Current channel {channel $0}";
+    #names = "{names_users Users {names_channel $0}}";
+    names = "";
+    names_prefix = "%#{names_prefix $0}";
+    names_nick_op = "{names_nick_op $0 $1}";
+    names_nick_halfop = "{names_nick_halfop $0 $1}";
+    names_nick_voice = "{names_nick_voice $0 $1}";
+    names_nick = "{names_nick $0 $1}";
+    endofnames = "{channel $0} - Total of {hilight $1} nicks {comment {hilight $2} ops, {hilight $3} halfops, {hilight $4} voices, {hilight $5} normal}";
+    chanlist_header = "%#You are on the following channels:";
+    chanlist_line = "%#{channel $[-10]0} %|+$1 ($2): $3";
+    chansetup_not_found = "Channel {channel $0} not found";
+    chansetup_added = "Channel {channel $0} saved";
+    chansetup_removed = "Channel {channel $0} removed";
+    chansetup_header = "%#Channel         Network    Password   Settings";
+    chansetup_line = "%#{channel $[15]0} %|$[10]1 $[10]2 $3";
+    chansetup_footer = "";
+    own_msg = "{ownmsgnick $2 {ownnick $0}}$1";
+    own_msg_channel = "{ownmsgnick $3 {ownnick $0}{msgchannel $1}}$2";
+    own_msg_private = "{ownprivmsg msg $0}$1";
+    own_msg_private_query = "{ownprivmsgnick {ownprivnick $2}}$1";
+    pubmsg_me = "{pubmsgmenick $2 {menick $0}}$1";
+    pubmsg_me_channel = "{pubmsgmenick $3 {menick $0}{msgchannel $1}}$2";
+    pubmsg_hilight = "{pubmsghinick $0 $3 $1}$2";
+    pubmsg_hilight_channel = "{pubmsghinick $0 $4 $1{msgchannel $2}}$3";
+    pubmsg = "{pubmsgnick $2 {pubnick \00306$0}}$1";
+    pubmsg_channel = "{pubmsgnick $3 {pubnick $0}{msgchannel $1}}$2";
+    msg_private = "{privmsg $0 $1}$2";
+    msg_private_query = "{privmsgnick $0}$2";
+    no_msgs_got = "You have not received a message from anyone yet";
+    no_msgs_sent = "You have not sent a message to anyone yet";
+    query_start = "Starting query in {server $1} with {nick $0}";
+    query_stop = "Closing query with {nick $0}";
+    no_query = "No query with {nick $0}";
+    query_server_changed = "Query with {nick $0} changed to server {server $1}";
+    hilight_header = "%#Highlights:";
+    hilight_line = "%#$[-4]0 $1 $2 $3$4";
+    hilight_footer = "";
+    hilight_not_found = "Highlight not found: $0";
+    hilight_removed = "Highlight removed: $0";
+    alias_added = "Alias $0 added";
+    alias_removed = "Alias $0 removed";
+    alias_not_found = "No such alias: $0";
+    aliaslist_header = "%#Aliases:";
+    aliaslist_line = "%#$[10]0 $1";
+    aliaslist_footer = "";
+    log_opened = "Log file {hilight $0} opened";
+    log_closed = "Log file {hilight $0} closed";
+    log_create_failed = "Couldn't create log file {hilight $0}: $1";
+    log_locked = "Log file {hilight $0} is locked, probably by another running Irssi";
+    log_not_open = "Log file {hilight $0} not open";
+    log_started = "Started logging to file {hilight $0}";
+    log_stopped = "Stopped logging to file {hilight $0}";
+    log_list_header = "%#Logs:";
+    log_list = "%#$0 $1: $2 $3$4$5";
+    log_list_footer = "";
+    windowlog_file = "Window LOGFILE set to $0";
+    windowlog_file_logging = "Can't change window's logfile while log is on";
+    no_away_msgs = "No new messages in awaylog";
+    away_msgs = "{hilight $1} new messages in awaylog:";
+    module_header = "%#Module               Type    Submodules";
+    module_line = "%#$[!20]0 $[7]1 $2";
+    module_footer = "";
+    module_already_loaded = "Module {hilight $0/$1} already loaded";
+    module_not_loaded = "Module {hilight $0/$1} is not loaded";
+    module_load_error = "Error loading module {hilight $0/$1}: $2";
+    module_invalid = "{hilight $0/$1} isn't Irssi module";
+    module_loaded = "Loaded module {hilight $0/$1}";
+    module_unloaded = "Unloaded module {hilight $0/$1}";
+    command_unknown = "Unknown command: $0";
+    command_ambiguous = "Ambiguous command: $0";
+    option_unknown = "Unknown option: $0";
+    option_ambiguous = "Ambiguous option: $0";
+    option_missing_arg = "Missing required argument for: $0";
+    not_enough_params = "Not enough parameters given";
+    not_connected = "Not connected to server";
+    not_joined = "Not joined to any channel";
+    chan_not_found = "Not joined to such channel";
+    chan_not_synced = "Channel not fully synchronized yet, try again after a while";
+    illegal_proto = "Command isn't designed for the chat protocol of the active server";
+    not_good_idea = "Doing this is not a good idea. Add -YES option to command if you really mean it";
+    invalid_number = "Invalid number";
+    invalid_time = "Invalid timestamp";
+    invalid_level = "Invalid message level";
+    invalid_size = "Invalid size";
+    invalid_charset = "Invalid charset: $0";
+    eval_max_recurse = "/eval hit maximum recursion limit";
+    program_not_found = "Could not find file or file is not executable";
+    theme_saved = "Theme saved to $0";
+    theme_save_failed = "Error saving theme to $0: $1";
+    theme_not_found = "Theme {hilight $0} not found";
+    theme_changed = "Now using theme {hilight $0} ($1)";
+    window_theme = "Using theme {hilight $0} in this window";
+    window_theme_default = "No theme is set for this window";
+    window_theme_changed = "Now using theme {hilight $0} ($1) in this window";
+    window_theme_removed = "Removed theme from this window";
+    format_title = "%:[{hilight $0}] - [{hilight $1}]%:";
+    format_subtitle = "[{hilight $0}]";
+    format_item = "$0 = $1";
+    ignored = "Ignoring {hilight $1} from {nick $0}";
+    ignored_options = "Ignoring {hilight $1} from {nick $0} {comment $2}";
+    unignored = "Unignored {nick $0}";
+    ignore_not_found = "{nick $0} is not being ignored";
+    ignore_no_ignores = "There are no ignores";
+    ignore_header = "%#Ignore List:";
+    ignore_line = "%#$[-4]0 $1: $2 $3 $4";
+    ignore_footer = "";
+    not_channel_or_query = "The current window is not a channel or query window";
+    conversion_added = "Added {hilight $0}/{hilight $1} to conversion database";
+    conversion_removed = "Removed {hilight $0} from conversion database";
+    conversion_not_found = "{hilight $0} not found in conversion database";
+    conversion_no_translits = "Transliterations not supported in this system";
+    recode_header = "%#Target                         Character set";
+    recode_line = "%#%|$[!30]0 $1";
+    unknown_chat_protocol = "Unknown chat protocol: $0";
+    unknown_chatnet = "Unknown chat network: $0 (create it with /NETWORK ADD)";
+    not_toggle = "Value must be either ON, OFF or TOGGLE";
+    perl_error = "Perl error: $0";
+    bind_header = "%#Key                  Action";
+    bind_list = "%#$[!20]0 $1 $2";
+    bind_command_list = "$[!30]0 $1";
+    bind_footer = "";
+    bind_unknown_id = "Unknown bind action: $0";
+    config_saved = "Saved configuration to file $0";
+    config_reloaded = "Reloaded configuration";
+    config_modified = "Configuration file was modified since irssi was last started - do you want to overwrite the possible changes?";
+    glib_error = "{error $0} $1";
+    overwrite_config = "Overwrite config (y/N)?";
+    set_title = "[{hilight $0}]";
+    set_item = "$0 = $1";
+    set_unknown = "Unknown setting $0";
+    set_not_boolean = "Setting {hilight $0} isn't boolean, use /SET";
+    no_completions = "There's no completions";
+    completion_removed = "Removed completion $0";
+    completion_header = "%#Key        Value                                    Auto";
+    completion_line = "%#$[10]0 $[!40]1 $2";
+    completion_footer = "";
+  };
+  "fe-text" = {
+    lastlog_too_long = "/LASTLOG would print $0 lines. If you really want to print all these lines use -force option.";
+    lastlog_count = "{hilight Lastlog}: $0 lines";
+    lastlog_start = "{hilight Lastlog}:";
+    lastlog_end = "{hilight End of Lastlog}";
+    lastlog_separator = "--";
+    refnum_not_found = "Window number $0 not found";
+    window_too_small = "Not enough room to resize this window";
+    cant_hide_last = "You can't hide the last window";
+    cant_hide_sticky_windows = "You can't hide sticky windows (use /WINDOW STICK OFF)";
+    cant_show_sticky_windows = "You can't show sticky windows (use /WINDOW STICK OFF)";
+    window_not_sticky = "Window is not sticky";
+    window_set_sticky = "Window set sticky";
+    window_unset_sticky = "Window is not sticky anymore";
+    window_info_sticky = "%#Sticky  : $0";
+    window_info_scroll = "%#Scroll  : $0";
+    window_scroll = "Window scroll mode is now $0";
+    window_scroll_unknown = "Unknown scroll mode $0, must be ON, OFF or DEFAULT";
+    statusbar_list_header = "%#Name                           Type   Placement Position Visible";
+    statusbar_list_footer = "";
+    statusbar_list = "%#$[30]0 $[6]1 $[9]2 $[8]3 $4";
+    statusbar_info_name = "%#Statusbar: {hilight $0}";
+    statusbar_info_type = "%#Type     : $0";
+    statusbar_info_placement = "%#Placement: $0";
+    statusbar_info_position = "%#Position : $0";
+    statusbar_info_visible = "%#Visible  : $0";
+    statusbar_info_item_header = "%#Items    : Name                                Priority  Alignment";
+    statusbar_info_item_footer = "";
+    statusbar_info_item_name = "%#         : $[35]0 $[9]1 $2";
+    statusbar_not_found = "Statusbar doesn't exist: $0";
+    statusbar_item_not_found = "Statusbar item doesn't exist: $0";
+    statusbar_unknown_command = "Unknown statusbar command: $0";
+    statusbar_unknown_type = "Statusbar type must be 'window' or 'root'";
+    statusbar_unknown_placement = "Statusbar placement must be 'top' or 'bottom'";
+    statusbar_unknown_visibility = "Statusbar visibility must be 'always', 'active' or 'inactive'";
+    paste_warning = "Pasting $0 lines to $1. Press Ctrl-K if you wish to do this or Ctrl-C to cancel.";
+    paste_prompt = "Hit Ctrl-K to paste, Ctrl-C to abort?";
+  };
+  "fe-common/perl" = {
+    script_not_found = "Script {hilight $0} not found";
+    script_not_loaded = "Script {hilight $0} is not loaded";
+    script_loaded = "Loaded script {hilight $0}";
+    script_unloaded = "Unloaded script {hilight $0}";
+    no_scripts_loaded = "No scripts are loaded";
+    script_list_header = "%#Loaded scripts:";
+    script_list_line = "%#$[!15]0 $1";
+    script_list_footer = "";
+    script_error = "{error Error in script {hilight $0}:}";
+  };
+  "fe-common/irc" = {
+    netsplit = "{netsplit Netsplit} {server $0} <-> {server $1} quits: $2";
+    netsplit_more = "{netsplit Netsplit} {server $0} <-> {server $1} quits: $2 (+$3 more, use /NETSPLIT to show all of them)";
+    netsplit_join = "{netjoin Netsplit} over, joins: $0";
+    netsplit_join_more = "{netjoin Netsplit} over, joins: $0 (+$1 more)";
+    no_netsplits = "There are no net splits";
+    netsplits_header = "%#Nick      Channel    Server               Split server";
+    netsplits_line = "%#$[9]0 $[10]1 $[20]2 $3";
+    netsplits_footer = "";
+    network_added = "Network $0 saved";
+    network_removed = "Network $0 removed";
+    network_not_found = "Network $0 not found";
+    network_header = "%#Networks:";
+    network_line = "%#$0: $1";
+    network_footer = "";
+    setupserver_header = "%#Server               Port  Network    Settings";
+    setupserver_line = "%#%|$[!20]0 $[5]1 $[10]2 $3";
+    setupserver_footer = "";
+    joinerror_toomany = "Cannot join to channel {channel $0} (You have joined to too many channels)";
+    joinerror_full = "Cannot join to channel {channel $0} (Channel is full)";
+    joinerror_invite = "Cannot join to channel {channel $0} (You must be invited)";
+    joinerror_banned = "Cannot join to channel {channel $0} (You are banned)";
+    joinerror_bad_key = "Cannot join to channel {channel $0} (Bad channel key)";
+    joinerror_bad_mask = "Cannot join to channel {channel $0} (Bad channel mask)";
+    joinerror_unavail = "Cannot join to channel {channel $0} (Channel is temporarily unavailable)";
+    joinerror_duplicate = "Channel {channel $0} already exists - cannot create it";
+    channel_rejoin = "Channel {channel $0} is temporarily unavailable, this is normally because of netsplits. Irssi will now automatically try to rejoin back to this channel until the join is successful. Use /RMREJOINS command if you wish to abort this.";
+    inviting = "Inviting {nick $0} to {channel $1}";
+    channel_created = "Channel {channelhilight $0} created $1";
+    url = "Home page for {channelhilight $0}: $1";
+    topic = "";
+    no_topic = "";
+    topic_info = "";
+    chanmode_change = "<%bMode> {mode $1} by {nick $2}";
+    server_chanmode_change = "<{netsplit Mode}> {mode $1} by {nick $2}";
+    channel_mode = "mode/{channelhilight $0} {mode $1}";
+    bantype = "Ban type changed to {channel $0}";
+    no_bans = "No bans in channel {channel $0}";
+    banlist = "$0 - {channel $1}: ban {ban $2}";
+    banlist_long = "$0 - {channel $1}: ban {ban $2} {comment by {nick $3}, $4 secs ago}";
+    ebanlist = "{channel $0}: ban exception {ban $1}";
+    ebanlist_long = "{channel $0}: ban exception {ban $1} {comment by {nick $2}, $3 secs ago}";
+    no_invitelist = "Invite list is empty in channel {channel $0}";
+    invitelist = "{channel $0}: invite {ban $1}";
+    invitelist_long = "{channel $0}: invite {ban $1} {comment by {nick $2}, $3 secs ago}";
+    no_such_channel = "{channel $0}: No such channel";
+    channel_synced = "Join to {channel $0} was synced in {hilight $1} secs";
+    usermode_change = "Mode change {mode $0} for user {nick $1}";
+    user_mode = "Your user mode is {mode $0}";
+    away = "You have been marked as being away";
+    unaway = "You are no longer marked as being away";
+    nick_away = "{nick $0} is away: $1";
+    no_such_nick = "{nick $0}: No such nick/channel";
+    nick_in_use = "Nick {nick $0} is already in use";
+    nick_unavailable = "Nick {nick $0} is temporarily unavailable";
+    your_nick_owned = "Your nick is owned by {nick $3} {comment $1@$2}";
+    whois = "{nick $0} {nickhost $1@$2}%:{whois ircname $3}";
+    whowas = "{nick $0} {nickhost $1@$2}%:{whois was $3}";
+    whois_idle = "{whois idle %|$1 days $2 hours $3 mins $4 secs}";
+    whois_idle_signon = "{whois idle %|$1 days $2 hours $3 mins $4 secs {comment signon: $5}}";
+    whois_server = "{whois server %|$1 {comment $2}}";
+    whois_oper = "{whois  {hilight $1}}";
+    whois_modes = "{whois modes $1}";
+    whois_realhost = "{whois hostname $1-}";
+    whois_usermode = "{whois usermode $1}";
+    whois_channels = "{whois channels %|$1}";
+    whois_away = "{whois away %|$1}";
+    whois_special = "{whois  %|$1}";
+    whois_extra = "{whois account %|$1}";
+    end_of_whois = "End of WHOIS";
+    end_of_whowas = "End of WHOWAS";
+    whois_not_found = "There is no such nick $0";
+    who = "%#{channelhilight $[-10]0} %|{nick $[!9]1} $[!3]2 $[!2]3 $4@$5 {comment {hilight $6}}";
+    end_of_who = "End of /WHO list";
+    own_notice = "{ownnotice notice $0}$1";
+    own_action = "{ownaction $0}$1";
+    own_action_target = "{ownaction_target $0 $2}$1";
+    own_ctcp = "{ownctcp ctcp $0}$1 $2";
+    notice_server = "{servernotice $0}$1";
+    notice_public = "{notice $0{pubnotice_channel $1}}$2";
+    notice_private = "{notice $0{pvtnotice_host $1}}$2";
+    action_private = "{pvtaction $0}$2";
+    action_private_query = "{pvtaction_query $0}$2";
+    action_public = "{pubaction $0}$1";
+    action_public_channel = "{pubaction $0{msgchannel $1}}$2";
+    ctcp_reply = "CTCP {hilight $0} reply from {nick $1}: $2";
+    ctcp_reply_channel = "CTCP {hilight $0} reply from {nick $1} in channel {channel $3}: $2";
+    ctcp_ping_reply = "CTCP {hilight PING} reply from {nick $0}: $1.$[-3.0]2 seconds";
+    ctcp_requested = "{ctcp {hilight $0} {comment $1} requested CTCP {hilight $2} from {nick $4}}: $3";
+    ctcp_requested_unknown = "{ctcp {hilight $0} {comment $1} requested unknown CTCP {hilight $2} from {nick $4}}: $3";
+    online = "Users online: {hilight $0}";
+    pong = "PONG received from $0: $1";
+    wallops = "{wallop WALLOP {wallop_nick $0}} $1";
+    action_wallops = "{wallop WALLOP {wallop_action $0}} $1";
+    kill = "You were {error killed} by {nick $0} {nickhost $1} {reason $2} {comment Path: $3}";
+    kill_server = "You were {error killed} by {server $0} {reason $1} {comment Path: $2}";
+    error = "{error ERROR} $0";
+    unknown_mode = "Unknown mode character $0";
+    default_event = "$1";
+    default_event_server = "[$0] $1";
+    silenced = "Silenced {nick $0}";
+    unsilenced = "Unsilenced {nick $0}";
+    silence_line = "{nick $0}: silence {ban $1}";
+    ask_oper_pass = "Operator password:";
+    accept_list = "Accepted users: {hilight $0}";
+  };
+  "Irssi::Script::awl" = {
+    awl_display_nokey = "$N $H$C$S";
+    awl_display_key = "$Q $H$C$S";
+    awl_display_nokey_visible = "%2$N $H$C$";
+    awl_display_key_visible = "%2$Q $H$C$S";
+    awl_display_nokey_active = "%1$N $H$C$S";
+    awl_display_key_active = "%1$Q $H$C$S";
+    awl_display_header = "%8$C";
+    awl_separator = "|";
+    awl_separator2 = "|";
+    awl_viewer_item_bg = "%0%w";
+  };
+};
diff --git a/bots/blackhole/honeypot/.irssi/scripts/autorun/awl.pl b/bots/blackhole/honeypot/.irssi/scripts/autorun/awl.pl
@@ -0,0 +1,2552 @@
+use strict;
+use warnings;
+
+our $VERSION = '1.4'; # b46fded611292cb
+our %IRSSI = (
+    authors     => 'Nei',
+    contact     => 'Nei @ anti@conference.jabber.teamidiot.de',
+    url         => "http://anti.teamidiot.de/",
+    name        => 'adv_windowlist',
+    description => 'Adds a permanent advanced window list on the right or in a status bar.',
+    license     => 'GNU GPLv2 or later',
+   );
+
+# UPGRADE NOTE
+# ============
+# for users of 0.7 or earlier series, please note that appearance
+# settings have moved to /format, i.e. inside your theme!
+# the fifo (screen) has been replaced by an external viewer script
+
+# Usage
+# =====
+# copy the script to ~/.irssi/scripts/
+#
+# In irssi:
+#
+#		/run adv_windowlist
+#
+# In your shell (for example a tmux split):
+#
+#		perl ~/.irssi/scripts/adv_windowlist.pl
+#
+# To use sbar mode instead:
+#
+#		/toggle awl_viewer
+#
+# Hint: to get rid of the old [Act:] display
+#     /statusbar window remove act
+#
+# to get it back:
+#     /statusbar window add -after lag -priority 10 act
+
+# Options
+# =======
+# formats can be cleared with /format -delete
+#
+# /format awl_display_(no)key(_active|_visible) <string>
+# * string : Format String for one window. The following $'s are expanded:
+#     $C : Name
+#     $N : Number of the Window
+#     $Q : meta-Keymap
+#     $H : Start hilighting
+#     $S : Stop hilighting
+#         /+++++++++++++++++++++++++++++++++,
+#        | ****  I M P O R T A N T :  ****  |
+#        |                                  |
+#        | don't forget  to use  $S  if you |
+#        | used $H before!                  |
+#        |                                  |
+#        '+++++++++++++++++++++++++++++++++/
+#   key     : a key binding that goes to this window could be detected in /bind
+#   nokey   : no such key binding was detected
+#   active  : window would receive the input you are currently typing
+#   visible : window is also visible on screen but not active (a split window)
+#
+# /format awl_name_display <string>
+# * string : Format String for window names
+#     $0 : name as formatted by the settings
+#
+# /format awl_display_header <string>
+# * string : Format String for this header line. The following $'s are expanded:
+#     $C : network tag
+#
+# /format awl_separator(2) <string>
+# * string : Character to use between the channel entries
+# variant 2 can be used for alternating separators (only in status bar
+# without block display)
+#
+# /format awl_abbrev_chars <string>
+# * string : Character to use when shortening long names. The second character
+#   will be used if two blocks need to be filled.
+#
+# /format awl_title <string>
+# * string : Text to display in the title string or title bar
+#
+# /format awl_viewer_item_bg <string>
+# * string : Format String specifying the viewer's item background colour
+#
+# /set awl_prefer_name <ON|OFF>
+# * this setting decides whether awl will use the active_name (OFF) or the
+#   window name as the name/caption in awl_display_*.
+#   That way you can rename windows using /window name myownname.
+#
+# /set awl_hide_empty <num>
+# * if visible windows without items should be hidden from the window list
+# set it to 0 to show all windows
+#           1 to hide visible windows without items (negative exempt
+#           active window)
+#
+# /set awl_hide_data <num>
+# * num : hide the window if its data_level is below num
+# set it to 0 to basically disable this feature,
+#           1 if you don't want windows without activity to be shown
+#           2 to show only those windows with channel text or hilight
+#           3 to show only windows with hilight (negative exempt active window)
+#
+# /set awl_hide_name_data <num>
+# * num : hide the name of the window if its data_level is below num
+#   (only works in status bar without block display)
+# you will want to change your formats to add $H...$S around $Q or $N
+# if you plan to use this
+#
+# /set awl_maxlines <num>
+# * num : number of lines to use for the window list (0 to disable, negative
+#   lock)
+#
+# /set awl_maxcolumns <num>
+# * num : number of columns to use for the window list when using the
+#   tmux integration (0 to disable)
+#
+# /set awl_block <num>
+# * num : width of a column in viewer mode (negative values = block
+#   display in status bar mode)
+#         /+++++++++++++++++++++++++++++++++,
+#        | ******  W A R N I N G !  ******  |
+#        |                                  |
+#        | If  your  block  display  looks  |
+#        | DISTORTED,  you need to add the  |
+#        | following  line to your  .theme  |
+#        | file under                       |
+#        |     abstracts = {             :  |
+#        |                                  |
+#        |       sb_act_none = "%K$*";      |
+#        |                                  |
+#        '+++++++++++++++++++++++++++++++++/
+#
+# /set awl_sbar_maxlength <ON|OFF>
+# * if you enable the maxlength setting, the block width will be used as a
+#   maximum length for the non-block status bar mode too.
+#
+# /set awl_height_adjust <num>
+# * num : how many lines to leave empty in viewer mode
+#
+# /set awl_sort <-data_level|-last_line|refnum>
+# * you can change the window sort order with this variable
+#     -data_level : sort windows with hilight first
+#     -last_line  : sort windows in order of activity
+#     refnum      : sort windows by window number
+#     active/server/tag : sort by server name
+#   "-" reverses the sort order
+#   typechecks are supported via ::, e.g. active::Query or active::Irc::Query
+#   undefinedness can be checked with ~, e.g. ~active
+#   string comparison can be done with =, e.g. name=(status)
+#   to make sort case insensitive, use #i, e.g. name#i
+#   any key in the window hash can be tested, e.g. active/chat_type=XMPP
+#   multiple criteria can be separated with , or +, e.g. -data_level+-last_line
+#
+# /set awl_placement <top|bottom>
+# /set awl_position <num>
+# * these settings correspond to /statusbar because awl will create
+#   status bars for you
+# (see /help statusbar to learn more)
+#
+# /set awl_all_disable <ON|OFF>
+# * if you set awl_all_disable to ON, awl will also remove the
+#   last status bar it created if it is empty.
+#   As you might guess, this only makes sense with awl_hide_data > 0 ;)
+#
+# /set awl_viewer <ON|OFF>
+# * enable the external viewer script
+#
+# /set awl_viewer_launch <ON|OFF>
+# * try to auto-launch the viewer under tmux or with a shell command
+#   /awl restart is required all auto-launch related settings to take
+#   effect
+#
+# /set awl_viewer_tmux_position <left|top|right|bottom|custom>
+# * try to split in this direction when using tmux for the viewer
+#   custom : use custom_command setting
+#
+# /set awl_viewer_xwin_command <shell command>
+# * custom command to run in order to start the viewer when irssi is
+#   running under X
+#   %A  - gets replaced by the command to run the viewer
+#   %qA - additionally quote the command
+#
+# /set awl_viewer_custom_command <shell command>
+# * custom command to run in order to start the viewer
+#
+# /set awl_viewer_launch_env <string>
+# * specific environment settings for use on viewer auto-launch,
+#   without the AWL_ prefix
+#
+# /set awl_shared_sbar <left<right|OFF>
+# * share a status bar for the first awl item, you will need to manually
+#   /statusbar window add -after lag -priority 10 awl_shared
+#     left   : space in cells occupied on the left of status bar
+#     right  : space occupied on the right
+# Note: you need to replace "left" AND "right" with the appropriate numbers!
+#
+# /set awl_path <path>
+# * path to the file which the viewer script reads
+#
+# /set fancy_abbrev <no|head|strict|fancy>
+# * how to shorten too long names
+#     no     : shorten in the middle
+#     head   : always cut off the ends
+#     strict : shorten repeating substrings
+#     fancy  : combination of no+strict
+#
+# /set awl_custom_xform <perl code>
+# * specify a custom routine to transform window names
+#   example: s/^#// remove the #-mark of IRC channels
+#   the special flags $CHANNEL / $TAG / $QUERY / $NAME can be
+#   tested in conditionals
+#
+# /set awl_last_line_shade <timeout>
+# * set timeout to shade activity base colours, to enable
+#   you also need to add +-last_line to awl_sort
+#   (requires 256 colour support)
+#
+# /set awl_no_mode_hint <ON|OFF>
+# * whether to show the hint of running the viewer script in the
+#   status bar
+#
+# /set awl_mouse <ON|OFF>
+# * enable the terminal mouse in irssi
+# (use the awl-patched mouse.pl for gestures and commands if you need
+# them and disable mouse_escape)
+#
+# /set awl_mouse_offset <num>
+# * specifies where on the screen is the awl status bar
+#   (0 = on top/bottom, 1 = one additional line in between,
+#   e.g. prompt)
+#   you MUST set this correctly otherwise the mouse coordinates will
+#   be off
+#
+# /set mouse_scroll <num>
+# * how many lines the mouse wheel scrolls
+#
+# /set mouse_escape <num>
+# * seconds to disable the mouse, when not clicked on the windowlist
+#
+
+# Commands
+# ========
+# /awl redraw
+# * redraws the windowlist. There may be occasions where the
+#   windowlist can get destroyed so you can use this command to
+#   force a redraw.
+#
+# /awl restart
+# * restart the connection to the viewer script.
+
+# Viewer script
+# =============
+# When run from the command line, adv_windowlist acts as the viewer
+# script to be used together with the irssi script to display the
+# window list in a sidebar/terminal of its own.
+#
+# One optional parameter is accepted, the awl_path
+#
+# The viewer can be configured by three environment variables:
+#
+# AWL_HI9=1
+# * interpret %9 as high-intensity toggle instead of bold. This had
+#   been the default prior to version 0.9b8
+#
+# AWL_AUTOFOCUS=0
+# * disable auto-focus behaviour when activating a window
+#
+# AWL_NOTITLE=1
+# * disable the title bar
+
+# Nei =^.^= ( anti@conference.jabber.teamidiot.de )
+
+no warnings 'redefine';
+use constant IN_IRSSI => __PACKAGE__ ne 'main' || $ENV{IRSSI_MOCK};
+use constant SCRIPT_FILE => __FILE__;
+no if !IN_IRSSI, strict => (qw(subs refs));
+use if IN_IRSSI, Irssi => ();
+use if IN_IRSSI, 'Irssi::TextUI' => ();
+use v5.10;
+use Encode;
+use Storable ();
+use IO::Socket::UNIX;
+use List::Util qw(min max reduce);
+use Hash::Util qw(lock_keys);
+use Text::ParseWords qw(shellwords);
+
+BEGIN {
+    if ($] < 5.012) {
+	*CORE::GLOBAL::length = *CORE::GLOBAL::length = sub (_) {
+	    defined $_[0] ? CORE::length($_[0]) : undef
+	};
+	*Irssi::active_win = {}; # hide incorrect warning
+    }
+}
+
+unless (IN_IRSSI) {
+    local *_ = \@ARGV;
+    &AwlViewer::main;
+    exit;
+}
+
+
+use constant GLOB_QUEUE_TIMER => 100;
+
+our $BLOCK_ALL;  # localized blocker
+my @actString;   # status bar texts
+my @win_items;
+my $currentLines = 0;
+my %awins;
+my $globTime;    # timer to limit remake calls
+
+my %CHANGED;
+my $VIEWER_MODE;
+my $MOUSE_ON;
+my %mouse_coords;
+my %statusbars;
+my %S; # settings
+my $settings_str = '';
+my $window_sort_func;
+my $custom_xform;
+my ($sb_base_width, $sb_base_width_pre, $sb_base_width_post);
+my $print_text_activity;
+my $shade_line_timer;
+my ($screenHeight, $screenWidth);
+my %viewer;
+
+my (%keymap, %nummap, %wnmap, %specialmap, %wnmap_exp, %custom_key_map);
+my %banned_channels;
+my %abbrev_cache;
+
+use constant setc => 'awl';
+
+sub set ($) {
+    setc . '_' . $_[0]
+}
+
+sub add_statusbar {
+    for (@_) {
+	# add subs
+	my $l = set $_;
+	{
+	    my $close = $_;
+	    no strict 'refs';
+	    *{$l} = sub { awl($close, @_) };
+	}
+	Irssi::command("statusbar $l reset");
+	Irssi::command("statusbar $l enable");
+	if (lc $S{placement} eq 'top') {
+	    Irssi::command("statusbar $l placement top");
+	}
+	if (my $x = $S{position}) {
+	    Irssi::command("statusbar $l position $x");
+	}
+	Irssi::command("statusbar $l add -priority 100 -alignment left barstart");
+	Irssi::command("statusbar $l add $l");
+	Irssi::command("statusbar $l add -priority 100 -alignment right barend");
+	Irssi::command("statusbar $l disable");
+	Irssi::statusbar_item_register($l, '$0', $l);
+	$statusbars{$_} = 1;
+	Irssi::command("statusbar $l enable");
+    }
+}
+
+sub remove_statusbar {
+    for (@_) {
+	my $l = set $_;
+	Irssi::command("statusbar $l disable");
+	Irssi::command("statusbar $l reset");
+	Irssi::statusbar_item_unregister($l);
+	{
+	    no strict 'refs';
+	    undef &{$l};
+	}
+	delete $statusbars{$_};
+    }
+}
+
+my $awl_shared_empty = sub {
+    return if $BLOCK_ALL;
+    my ($item, $get_size_only) = @_;
+    $item->default_handler($get_size_only, '', '', 0);
+};
+
+sub syncLines {
+    my $maxLines = $S{maxlines};
+    my $newLines = ($maxLines > 0 and @actString > $maxLines) ?
+	$maxLines :
+    ($maxLines < 0) ?
+	-$maxLines :
+	    @actString;
+    $currentLines = 1 if !$currentLines && $S{shared_sbar};
+    if ($S{shared_sbar} && !$statusbars{shared}) {
+	my $l = set 'shared';
+	{
+	    no strict 'refs';
+	    *{$l} = sub {
+		return if $BLOCK_ALL;
+		my ($item, $get_size_only) = @_;
+
+		my $text = $actString[0];
+		my $title = _get_format(set 'title');
+		if (length $title) {
+		    $title =~ s{\\(.)|(.)}{
+			defined $2 ? quotemeta $2
+			    : $1 eq 'V' ? '\u'
+			    : $1 eq ':' ? quotemeta ':%n'
+			    : $1 =~ /^[uUFQE]$/ ? "\\$1"
+			    : quotemeta "\\$1"
+			}sge;
+		    $title = eval qq{"$title"};
+		    $title .= ' ';
+		}
+		my $pat = defined $text ? "{sb $title\$*}" : '{sb }';
+		$text //= '';
+		$item->default_handler($get_size_only, $pat, $text, 0);
+	    };
+	}
+	$statusbars{shared} = 1;
+	remove_statusbar (0) if $statusbars{0};
+    }
+    elsif ($statusbars{shared} && !$S{shared_sbar}) {
+	add_statusbar (0) if $currentLines && $newLines;
+	delete $statusbars{shared};
+	my $l = set 'shared';
+	{
+	    no strict 'refs';
+	    *{$l} = $awl_shared_empty;
+	}
+    }
+    if ($currentLines == $newLines) { return; }
+    elsif ($newLines > $currentLines) {
+	add_statusbar ($currentLines .. ($newLines - 1));
+    }
+    else {
+	remove_statusbar (reverse ($newLines .. ($currentLines - 1)));
+    }
+    $currentLines = $newLines;
+}
+
+sub awl {
+    return if $BLOCK_ALL;
+    my ($line, $item, $get_size_only) = @_;
+
+    my $text = $actString[$line];
+    my $pat = defined $text ? '{sb $*}' : '{sb }';
+    $text //= '';
+    $item->default_handler($get_size_only, $pat, $text, 0);
+}
+
+# remove old statusbars
+{ my %killBar;
+  sub get_old_status {
+      my ($textDest, $cont, $cont_stripped) = @_;
+      if ($textDest->{level} == 524288 and $textDest->{target} eq '' and !defined $textDest->{server}) {
+	  my $name = quotemeta(set '');
+	  if ($cont_stripped =~ m/^$name(\d+)\s/) { $killBar{$1} = 1; }
+	  Irssi::signal_stop;
+      }
+  }
+  sub killOldStatus {
+      %killBar = ();
+      Irssi::signal_add_first('print text' => 'get_old_status');
+      Irssi::command('statusbar');
+      Irssi::signal_remove('print text' => 'get_old_status');
+      remove_statusbar(keys %killBar);
+  }
+}
+
+sub _add_map {
+    my ($type, $target, $map) = @_;
+    ($type->{$target}) = sort { length $a <=> length $b || $a cmp $b }
+	$map, exists $type->{$target} ? $type->{$target} : ();
+}
+
+sub get_keymap {
+    my ($textDest, undef, $cont_stripped) = @_;
+    if ($textDest->{level} == 524288 and $textDest->{target} eq '' and !defined $textDest->{server}) {
+	my $one_meta_or_ctrl_key = qr/((?:meta-)*?)(?:(meta-|\^)(\S)|(\w+))/;
+	$cont_stripped = as_uni($cont_stripped);
+	if ($cont_stripped =~ m/((?:$one_meta_or_ctrl_key-)*$one_meta_or_ctrl_key)\s+(.*)$/) {
+	    my ($combo, $command) = ($1, $10);
+	    my $map = '';
+	    while ($combo =~ s/(?:-|^)$one_meta_or_ctrl_key$//) {
+		my ($level, $ctl, $key, $nkey) = ($1, $2, $3, $4);
+		my $numlevel = ($level =~ y/-//);
+		$ctl = '' if !$ctl || $ctl ne '^';
+		$map = ('-' x ($numlevel%2)) . ('+' x ($numlevel/2)) .
+		    $ctl . (defined $key ? $key : "\01$nkey\01") . $map;
+	    }
+	    for ($command) {
+		last unless length $map;
+		if (/^change_window (\d+)/i) {
+		    _add_map(\%nummap, $1, $map);
+		}
+		elsif (/^(?:command window goto|change_window) (\S+)/i) {
+		    my $window = $1;
+		    if ($window !~ /\D/) {
+			_add_map(\%nummap, $window, $map);
+		    }
+		    elsif (lc $window eq 'active') {
+			_add_map(\%specialmap, '_active', $map);
+		    }
+		    else {
+			_add_map(\%wnmap, $window, $map);
+		    }
+		}
+		elsif (/^(?:active_window|command (ack))/i) {
+		    _add_map(\%specialmap, '_active', $map);
+		    $viewer{use_ack} = !!$1;
+		}
+		elsif (/^command window last/i) {
+		    _add_map(\%specialmap, '_last', $map);
+		}
+		elsif (/^(?:upper_window|command window up)/i) {
+		    _add_map(\%specialmap, '_up', $map);
+		}
+		elsif (/^(?:lower_window|command window down)/i) {
+		    _add_map(\%specialmap, '_down', $map);
+		}
+		elsif (/^key\s+(\w+)/i) {
+		    $custom_key_map{$1} = $map;
+		}
+	    }
+	}
+	Irssi::signal_stop;
+    }
+}
+
+sub update_keymap {
+    %nummap = %wnmap = %specialmap = %custom_key_map = ();
+    Irssi::signal_remove('command bind' => 'watch_keymap');
+    Irssi::signal_add_first('print text' => 'get_keymap');
+    Irssi::command('bind');
+    Irssi::signal_remove('print text' => 'get_keymap');
+    for (keys %custom_key_map) {
+	if (exists $custom_key_map{$_} &&
+		$custom_key_map{$_} =~ s/\01(\w+)\01/exists $custom_key_map{$1} ? $custom_key_map{$1} : "\02"/ge) {
+	    if ($custom_key_map{$_} =~ /\02/) {
+		delete $custom_key_map{$_};
+	    }
+	    else {
+		redo;
+	    }
+	}
+    }
+    for my $keymap (\(%specialmap, %wnmap, %nummap)) {
+	for (keys %$keymap) {
+	    if ($keymap->{$_} =~ s/\01(\w+)\01/exists $custom_key_map{$1} ? $custom_key_map{$1} : "\02"/ge) {
+		if ($keymap->{$_} =~ /\02/) {
+		    delete $keymap->{$_};
+		}
+	    }
+	}
+    }
+    Irssi::signal_add('command bind' => 'watch_keymap');
+    delete $viewer{client_keymap};
+    &wl_changed;
+}
+
+# watch keymap changes
+sub watch_keymap {
+    Irssi::timeout_add_once(1000, 'update_keymap', undef);
+}
+
+{ my %strip_table = (
+    # fe-common::core::formats.c:format_expand_styles
+    #      delete                format_backs  format_fores bold_fores   other stuff
+    (map { $_ => '' } (split //, '04261537' .  'kbgcrmyw' . 'KBGCRMYW' . 'U9_8I:|FnN>#[' . 'pP')),
+    #      escape
+    (map { $_ => $_ } (split //, '{}%')),
+   );
+  sub ir_strip_codes { # strip %codes
+      my $o = shift;
+      $o =~ s/(%(%|Z.{6}|z.{6}|X..|x..|.))/exists $strip_table{$2} ? $strip_table{$2} :
+	  $2 =~ m{x(?:0[a-f]|[1-6][0-9a-z]|7[a-x])|z[0-9a-f]{6}}i ? '' : $1/gex;
+      $o
+  }
+}
+## ir_parse_special -- wrapper around parse_special
+## $i - input format
+## $args - array ref of arguments to format
+## $win - different target window (default current window)
+## $flags - different kind of escape flags (default 4|8)
+## returns formatted str
+sub ir_parse_special {
+    my $o;
+    my $i = shift;
+    my $args = shift // [];
+    y/ /\177/ for @$args; # hack to escape spaces
+    my $win = shift || Irssi::active_win;
+    my $flags = shift // 0x4|0x8;
+    my @cmd_args = ($i, (join ' ', @$args), $flags);
+    my $server = Irssi::active_server();
+    if (ref $win and ref $win->{active}) {
+	$o = $win->{active}->parse_special(@cmd_args);
+    }
+    elsif (ref $win and ref $win->{active_server}) {
+	$o = $win->{active_server}->parse_special(@cmd_args);
+    }
+    elsif (ref $server) {
+	$o =  $server->parse_special(@cmd_args);
+    }
+    else {
+	$o = &Irssi::parse_special(@cmd_args);
+    }
+    $o =~ y/\177/ /;
+    $o
+}
+
+sub sb_format_expand { # Irssi::current_theme->format_expand wrapper
+    Irssi::current_theme->format_expand(
+	$_[0],
+	(
+	    Irssi::EXPAND_FLAG_IGNORE_REPLACES
+		    |
+	    ($_[1] ? 0 : Irssi::EXPAND_FLAG_IGNORE_EMPTY)
+	)
+    )
+}
+
+{ my $term_type = Irssi::version > 20040819 ? 'term_charset' : 'term_type';
+  local $@;
+  eval { require Text::CharWidth; };
+  unless ($@) {
+      *screen_length = sub { Text::CharWidth::mbswidth($_[0]) };
+  }
+  else {
+      my $err = $@; chomp $err; $err =~ s/\sat .* line \d+\.$//;
+      #Irssi::print("%_$IRSSI{name}: warning:%_ Text::CharWidth module failed to load. Length calculation may be off! Error was:");
+      print "%_$IRSSI{name}:%_ $err";
+      *screen_length = sub {
+	  my $temp = shift;
+	  if (lc Irssi::settings_get_str($term_type) eq 'utf-8') {
+	      Encode::_utf8_on($temp);
+	  }
+	  length($temp)
+      };
+  }
+  sub as_uni {
+      no warnings 'utf8';
+      Encode::decode(Irssi::settings_get_str($term_type), $_[0], 0)
+  }
+  sub as_tc {
+      Encode::encode(Irssi::settings_get_str($term_type), $_[0], 0)
+  }
+}
+
+sub sb_length {
+    screen_length(ir_strip_codes($_[0]))
+}
+
+sub run_custom_xform {
+    local $@;
+    eval {
+	$custom_xform->()
+    };
+    if ($@) {
+	$@ =~ /^(.*)/;
+	print '%_'.(set 'custom_xform').'%_ died (disabling): '.$1;
+	$custom_xform = undef;
+    }
+}
+
+sub remove_uniform {
+    my $o = shift;
+    $o =~ s/^xmpp:(.*?[%@]).+\.[^.]+$/$1/ or
+	$o =~ s#^psyc://.+\.[^.]+/([@~].*)$#$1#;
+    if ($custom_xform) {
+	run_custom_xform() for $o;
+    }
+    $o
+}
+
+sub remove_uniform_vars {
+    my $win = shift;
+    my $name = __PACKAGE__ . '::custom_xform::' . $win->{active}{type}
+	if ref $win->{active} && $win->{active}{type};
+    no strict 'refs';
+    local ${$name} = 1 if $name;
+    remove_uniform(+shift);
+}
+
+sub lc1459 {
+    my $x = shift;
+    $x =~ y/][\\^/}{|~/;
+    lc $x
+}
+
+sub window_list {
+    sort $window_sort_func Irssi::windows;
+}
+
+sub _calculate_abbrev {
+    my ($wins, $abbrevList) = @_;
+    if ($S{fancy_abbrev} !~ /^(no|off|head)/i) {
+	my @nameList = map { ref $_ ? remove_uniform_vars($_, as_uni($_->get_active_name) // '') : '' } @$wins;
+	for (my $i = 0; $i < @nameList - 1; ++$i) {
+	    my ($x, $y) = ($nameList[$i], $nameList[$i + 1]);
+	    s/^[+#!=]// for $x, $y;
+	    my $res = exists $abbrev_cache{$x}{$y} ? $abbrev_cache{$x}{$y}
+		: $abbrev_cache{$x}{$y} = string_LCSS($x, $y);
+	    if (defined $res) {
+		for ($nameList[$i], $nameList[$i + 1]) {
+		    $abbrevList->{$_} //= int((index $_, $res) + (length $res) / 2);
+		}
+	    }
+	}
+    }
+}
+
+my %act_last_line_shades = (
+    r => [qw[ 50 40 30 20 ]],
+    g => [qw[ 1O 1I 1C 16 ]],
+    y => [qw[ 5O 4I 3C 26 ]],
+    b => [qw[ 15 14 13 12 ]],
+    m => [qw[ 54 43 32 21 ]],
+    c => [qw[ 1S 1L 1E 17 ]],
+    w => [qw[ 7W 7T 7Q 3E ]],
+    K => [qw[ 7M 7K 27 7H ]],
+    R => [qw[ 60 50 40 30 ]],
+    G => [qw[ 1U 1O 1I 1C ]],
+    Y => [qw[ 6U 5O 4I 3C ]],
+    B => [qw[ 2B 2A 29 28 ]],
+    M => [qw[ 65 54 43 32 ]],
+    C => [qw[ 1Z 1S 1L 1E ]],
+    W => [qw[ 6Z 5S 7R 7O ]],
+   );
+
+sub _format_display {
+    my (undef, $format, $cformat, $hilight, $name, $number, $key, $win) = @_;
+    if ($print_text_activity && $S{line_shade}) {
+	my @hilight_code = split /\177/, sb_format_expand("{$hilight \177}"), 2;
+	my $max_time = max(1, log($S{line_shade}) - log(1000));
+	my $time_delta = min(3, min($max_time, log(max(1, time - $win->{last_line}))) / $max_time * 3);
+	if ($hilight_code[0] =~ /%(.)/ && exists $act_last_line_shades{$1}) {
+	    $hilight = 'sb_act_hilight_color %X'.$act_last_line_shades{$1}[$time_delta];
+	}
+    }
+    $cformat = '$0' unless length $cformat;
+    my %map = ('$C' => $cformat, '$N' => '$1', '$Q' => '$2');
+    $format =~ s<(\$.)><$map{$1}//$1>ge;
+    $format =~ s<\$H((?:\$.|[^\$])*?)\$S><{$hilight $1%n}>g;
+    my @ret = ir_parse_special(sb_format_expand($format), [$name, $number, $key], $win);
+    @ret
+}
+
+sub _get_format {
+    Irssi::current_theme->get_format(__PACKAGE__, @_)
+}
+
+sub _calculate_items {
+    my ($wins, $abbrevList) = @_;
+
+    my $display_header = _get_format(set 'display_header');
+    my $name_format = _get_format(set 'name_display');
+    my $abbrev_chars = as_uni(_get_format(set 'abbrev_chars'));
+
+    my %displays;
+
+    my $active = Irssi::active_win;
+    @win_items = ();
+    %keymap = (%nummap, %wnmap_exp);
+
+    my ($numPad, $keyPad) = (0, 0);
+    if ($VIEWER_MODE or $S{block} < 0) {
+	$numPad = length((sort { length $b <=> length $a } keys %keymap)[0]) // 0;
+	$keyPad = length((sort { length $b <=> length $a } values %keymap)[0]) // 0;
+    }
+    my $last_net;
+    my ($abbrev1, $abbrev2) = $abbrev_chars =~ /(\X)(.*)/;
+    my @abbrev_chars = ('~', "\x{301c}");
+    unless (defined $abbrev1 && screen_length(as_tc($abbrev1)) == 1) { $abbrev1 = $abbrev_chars[0] }
+    unless (length $abbrev2) {
+	$abbrev2 = $abbrev1;
+	if ($abbrev1 eq $abbrev_chars[0]) {
+	    $abbrev2 = $abbrev_chars[1];
+	}
+	else {
+	    $abbrev2 = $abbrev1;
+	}
+    }
+    if (screen_length(as_tc($abbrev2)) == 1) {
+	$abbrev2 x= 2;
+    }
+    while (screen_length(as_tc($abbrev2)) > 2) {
+	chop $abbrev2;
+    }
+    unless (screen_length(as_tc($abbrev2)) == 2) {
+	$abbrev2 = $abbrev_chars[1];
+    }
+    for my $win (@$wins) {
+	my $global_tag_header_mode;
+
+	next unless ref $win;
+
+	my $backup_win = Storable::dclone($win);
+	delete $backup_win->{active} unless ref $backup_win->{active};
+
+	$global_tag_header_mode =
+	    $display_header && ($last_net // '') ne ($backup_win->{active}{server}{tag} // '');
+
+	if ($win->{data_level} < abs $S{hide_data}
+		&& ($win->{refnum} != $active->{refnum} || 0 <= $S{hide_data})) {
+	    next; }
+	elsif (exists $awins{$win->{refnum}} && $S{hide_empty} && !$win->items
+		&& ($win->{refnum} != $active->{refnum} || 0 <= $S{hide_empty})) {
+	    next; }
+
+	my $colour = $win->{hilight_color} // '';
+	my $hilight = do {
+	    if    ($win->{data_level} == 0) { 'sb_act_none'; }
+	    elsif ($win->{data_level} == 1) { 'sb_act_text'; }
+	    elsif ($win->{data_level} == 2) { 'sb_act_msg'; }
+	    elsif ($colour           ne '') { "sb_act_hilight_color $colour"; }
+	    elsif ($win->{data_level} == 3) { 'sb_act_hilight'; }
+	    else                            { 'sb_act_special'; }
+	};
+	my $number = $win->{refnum};
+
+	my ($name, $display, $cdisplay);
+	if ($global_tag_header_mode) {
+	    $display = $display_header;
+	    $name = as_uni($backup_win->{active}{server}{tag}) // '';
+	    if ($custom_xform) {
+		no strict 'refs';
+		local ${ __PACKAGE__ . '::custom_xform::TAG' } = 1;
+		run_custom_xform() for $name;
+	    }
+	}
+	else {
+	    my @display = ('display_nokey');
+	    if (defined $keymap{$number} and $keymap{$number} ne '') {
+		unshift @display, map { (my $cpy = $_) =~ s/_no/_/; $cpy } @display;
+	    }
+	    if (exists $awins{$number}) {
+		unshift @display, map { my $cpy = $_; $cpy .= '_visible'; $cpy } @display;
+	    }
+	    if ($active->{refnum} == $number) {
+		unshift @display, map { my $cpy = $_; $cpy .= '_active'; $cpy }
+		    grep { !/_visible$/ } @display;
+	    }
+	    $display = (grep { length $_ }
+			       map { $displays{$_} //= _get_format(set $_) }
+				   @display)[0];
+	    $cdisplay = $name_format;
+	    $name = as_uni($win->get_active_name) // '';
+	    $name = '*' if $S{banned_on} and exists $banned_channels{lc1459($name)};
+	    $name = remove_uniform_vars($win, $name) if $name ne '*';
+	    if ($name ne '*' and $win->{name} ne '' and $S{prefer_name}) {
+		$name = as_uni($win->{name});
+		if ($custom_xform) {
+		    no strict 'refs';
+		    local ${ __PACKAGE__ . '::custom_xform::NAME' } = 1;
+		    run_custom_xform() for $name;
+		}
+	    }
+
+	    if (!$VIEWER_MODE && $S{block} >= 0 && $S{hide_name}
+		&& $win->{data_level} < abs $S{hide_name}
+		&& ($win->{refnum} != $active->{refnum} || 0 <= $S{hide_name})) {
+		$name = '';
+		$cdisplay = '';
+	    }
+	}
+
+	$display = "$display%n";
+	my $num_ent = (' 'x max(0,$numPad - length $number)) . $number;
+	my $key_ent = exists $keymap{$number} ? ((' 'x max(0,$keyPad - length $keymap{$number})) . $keymap{$number}) : ' 'x$keyPad;
+	if ($VIEWER_MODE or $S{sbar_maxlen} or $S{block} < 0) {
+	    my $baseLength = sb_length(_format_display(
+		'', $display, $cdisplay, $hilight,
+		'x', # placeholder
+		$num_ent,
+		$key_ent,
+		$win)) - 1;
+	    my $diff = (abs $S{block}) - (screen_length(as_tc($name)) + $baseLength);
+	    if ($diff < 0) { # too long
+		my $screen_length = screen_length(as_tc($name));
+		if ((abs $diff) >= $screen_length) { $name = '' } # forget it
+		elsif ((abs $diff) + screen_length(as_tc(substr($name, 0, 1))) >= $screen_length) { $name = substr($name, 0, 1); }
+		else {
+		    my $ulen = length $name;
+		    my $middle2 = exists $abbrevList->{$name} ?
+			($S{fancy_strict}) ?
+			    2* $abbrevList->{$name} :
+			   (2*($abbrevList->{$name} + $ulen) / 3) :
+			       ($S{fancy_head}) ?
+				2*$ulen :
+				    $ulen;
+		    my $first = 1;
+		    while (length $name > 1) {
+			my $cp = $middle2 >= 0 ? $middle2/2 : -1; # clearing position
+			my $rm = 2;
+			# if character at end is wider than 1 cell -> replace it with ~
+			if (screen_length(as_tc(substr $name, $cp, 1)) > 1) {
+			    if ($first || $cp < 0) {
+				$rm = 1;
+				$first = undef;
+			    }
+			}
+			elsif ($cp < 0) { # elsif at end -> replace last 2 characters
+			    --$cp;
+			}
+			(substr $name, $cp, $rm) = $abbrev1;
+			if ($cp > -1 && $rm > 1) {
+			    --$middle2;
+			}
+			my $sl = screen_length(as_tc($name));
+			if ($sl + $baseLength < abs $S{block}) {
+			    (substr $name, ($middle2+1)/2, 1) = $abbrev2;
+			    last;
+			}
+			elsif ($sl + $baseLength == abs $S{block}) {
+			    last;
+			}
+		    }
+		}
+	    }
+	    elsif ($VIEWER_MODE or $S{block} < 0) {
+		$name .= (' ' x $diff);
+	    }
+	}
+
+	push @win_items, _format_display(
+	    '', $display, $cdisplay, $hilight,
+	    as_tc($name),
+	    $num_ent,
+	    as_tc($key_ent),
+	    $win);
+
+	if ($global_tag_header_mode) {
+	    $last_net = $backup_win->{active}{server}{tag};
+	    redo;
+	}
+
+	$mouse_coords{refnum}{$#win_items} = $number;
+    }
+}
+
+sub _spread_items {
+    my $width = [Irssi::windows]->[0]{width} - $sb_base_width - 1;
+    my @separator = _get_format(set 'separator');
+    if ($S{block} >= 0) {
+	my $sep2 = _get_format(set 'separator2');
+	push @separator, $sep2 if length $sep2 && $sep2 ne $separator[0];
+    }
+    $separator[0] .= '%n';
+    my @sepLen = map { sb_length($_) } @separator;
+
+    @actString = ();
+    my $curLine;
+    my $curLen = 0;
+    if ($S{shared_sbar}) {
+	$curLen += $S{shared_sbar}[0] + 2;
+	$width -= $S{shared_sbar}[2];
+    }
+    my $mouse_header_check = 0;
+    for my $it (@win_items) {
+	my $itemLen = sb_length($it);
+	if ($curLen) {
+	    if ($curLen + $itemLen + $sepLen[$mouse_header_check % @sepLen] > $width) {
+		$width += $S{shared_sbar}[2]
+		    if !@actString && $S{shared_sbar};
+		push @actString, $curLine;
+		$curLine = undef;
+		$curLen = 0;
+	    }
+	    elsif (defined $curLine) {
+		$curLine .= $separator[$mouse_header_check % @separator];
+		$curLen += $sepLen[$mouse_header_check % @sepLen];
+	    }
+	}
+	$curLine .= $it;
+	if (exists $mouse_coords{refnum}{$mouse_header_check}) {
+	    $mouse_coords{scalar @actString}{ $_ } = $mouse_coords{refnum}{$mouse_header_check}
+		for $curLen .. $curLen + $itemLen - 1;
+	}
+	$curLen += $itemLen;
+    }
+    continue {
+	++$mouse_header_check;
+    }
+    $curLen -= $S{shared_sbar}[0]
+	if !@actString && $S{shared_sbar};
+    push @actString, $curLine if $curLen;
+}
+
+sub remake {
+    my %abbrevList;
+    my @wins = window_list();
+    if ($VIEWER_MODE or $S{sbar_maxlen} or $S{block} < 0) {
+	_calculate_abbrev(\@wins, \%abbrevList);
+    }
+
+    %mouse_coords = ( refnum => +{} );
+    _calculate_items(\@wins, \%abbrevList);
+
+    unless ($VIEWER_MODE) {
+	_spread_items();
+
+	push @actString, undef unless @actString || $S{all_disable};
+    }
+}
+
+sub update_wl {
+    return if $BLOCK_ALL;
+    remake();
+
+    Irssi::statusbar_items_redraw(set $_) for keys %statusbars;
+
+    unless ($VIEWER_MODE) {
+	Irssi::timeout_add_once(100, 'syncLines', undef);
+    }
+    else {
+	syncViewer();
+    }
+}
+
+sub screenFullRedraw {
+    my ($window) = @_;
+    if (!ref $window or $window->{refnum} == Irssi::active_win->{refnum}) {
+	$viewer{fullRedraw} = 1 if $viewer{client};
+	$settings_str = '';
+	&setup_changed;
+    }
+}
+
+sub restartViewerServer {
+    if ($VIEWER_MODE) {
+	stop_viewer();
+	start_viewer();
+    }
+}
+
+sub _simple_quote {
+    my @r = map {
+	my $x = $_;
+	$x =~ s/'/'"'"'/g;
+	$x = "'$x'";
+    } @_;
+    wantarray ? @r : shift @r
+}
+
+sub _viewer_command_replace_format {
+    my ($ecmd, @args) = @_;
+    my $file = _simple_quote(SCRIPT_FILE());
+    my $path = _simple_quote($viewer{path});
+    my @env;
+    for my $env (shellwords($S{viewer_launch_env})) {
+	if ($env =~ /^(\w+)(?:=(.*))$/) {
+	    push @env, "AWL_$1=$2"
+	}
+    }
+    my $cmd = join ' ',
+	(@env ? ('env', _simple_quote(@env)) : ()),
+	'perl', $file, '-1', _simple_quote(@args), $path;
+    $ecmd =~ s{%(%|\w+)}{
+	my $sub = $1;
+	if ($sub eq '%') {
+	    '%'
+	}
+	elsif ($sub =~ /^(q*)A(.*)/) {
+	    my $ret = $cmd;
+	    for (1..length $1) {
+		$ret = _simple_quote($ret);
+	    }
+	    "$ret$2"
+	}
+	else {
+	    "%$sub"
+	}
+    }gex;
+    $ecmd
+}
+
+sub start_viewer {
+    unlink $viewer{path} if -S $viewer{path} || -p _;
+
+    $viewer{server} = IO::Socket::UNIX->new(
+	Type => SOCK_STREAM,
+	Local => $viewer{path},
+	Listen => 1
+       );
+    unless ($viewer{server}) {
+	$viewer{msg} = "Viewer: $!";
+	$viewer{retry} = Irssi::timeout_add_once(5000, 'retry_viewer', 1);
+	return;
+    }
+    $viewer{server}->blocking(0);
+    set_viewer_mode_hint();
+    $viewer{server_tag} = Irssi::input_add($viewer{server}->fileno, INPUT_READ, 'vi_connected', undef);
+
+    if ($S{viewer_launch}) {
+	if (length $ENV{TMUX_PANE} && length $ENV{TMUX} && lc $S{viewer_tmux_position} ne 'custom') {
+	    my $cmd = _viewer_command_replace_format('%qA', '-p', lc $S{viewer_tmux_position});
+	    Irssi::command("exec - tmux neww -d $cmd 2>&1 &");
+	}
+	elsif (length $ENV{WINDOWID} && length $ENV{DISPLAY} && length $S{viewer_xwin_command} && $S{viewer_xwin_command} =~ /\S/) {
+	    my $cmd = _viewer_command_replace_format($S{viewer_xwin_command});
+	    Irssi::command("exec - $cmd 2>&1 &");
+	}
+	elsif (length $S{viewer_custom_command} && $S{viewer_custom_command} =~ /\S/) {
+	    my $cmd = _viewer_command_replace_format($S{viewer_custom_command});
+	    Irssi::command("exec - $cmd 2>&1 &");
+	}
+    }
+}
+
+sub set_viewer_mode_hint {
+    return unless $viewer{server};
+    if ($S{no_mode_hint}) {
+	$viewer{msg} = undef;
+    }
+    else {
+	my ($name) = __PACKAGE__ =~ /::([^:]+)$/;
+	$viewer{msg} = "Run $name from the shell or switch to sbar mode";
+    }
+}
+
+sub retry_viewer {
+    start_viewer();
+}
+
+sub vi_close_client {
+    Irssi::input_remove(delete $viewer{client_tag}) if exists $viewer{client_tag};
+    $viewer{client}->close if $viewer{client};
+    delete $viewer{client};
+    delete $viewer{client_keymap};
+    delete $viewer{client_settings};
+    delete $viewer{client_env};
+    delete $viewer{fullRedraw};
+}
+
+sub vi_connected {
+    vi_close_client();
+    $viewer{client} = $viewer{server}->accept or return;
+    $viewer{client}->blocking(0);
+    $viewer{client_tag} = Irssi::input_add($viewer{client}->fileno, INPUT_READ, 'vi_clientinput', undef);
+    syncViewer();
+}
+
+use constant VIEWER_BLOCK_SIZE => 1024;
+sub vi_clientinput {
+    if ($viewer{client}->read(my $buf, VIEWER_BLOCK_SIZE)) {
+	$viewer{rcvbuf} .= $buf;
+	if ($viewer{rcvbuf} =~ s/^(?:(active|\d+)|(last|up|down))\n//igm) {
+	    if (defined $2) {
+		Irssi::command("window $2");
+	    }
+	    elsif (lc $1 eq 'active' && $viewer{use_ack}) {
+		Irssi::command("ack");
+	    }
+	    else {
+		Irssi::command("window goto $1");
+	    }
+	}
+    }
+    else {
+	vi_close_client();
+	Irssi::timeout_add_once(100, 'syncViewer', undef);
+    }
+}
+
+sub stop_viewer {
+    Irssi::timeout_remove(delete $viewer{retry}) if exists $viewer{retry};
+    vi_close_client();
+    Irssi::input_remove(delete $viewer{server_tag}) if exists $viewer{server_tag};
+    return unless $viewer{server};
+    $viewer{server}->close;
+    delete $viewer{server};
+}
+sub _encode_var {
+    my $str;
+    while (@_) {
+	my ($name, $var) = splice @_, 0, 2;
+	my $type = ref $var ? $var =~ /HASH/ ? 'map' : $var =~ /ARRAY/ ? 'list' : '' : '';
+	$str .= "\n\U$name$type\_begin\n";
+	if ($type eq 'map') {
+	    no warnings 'numeric';
+	    $str .= " $_\n ${$var}{$_}\n" for sort { $a <=> $b || $a cmp $b } keys %$var;
+	}
+	elsif ($type eq 'list') {
+	    $str .= " $_\n" for @$var;
+	}
+	else {
+	    $str .= " $var\n";
+	}
+	$str .= "\U$name$type\_end\n";
+    }
+    $str
+}
+sub syncViewer {
+    if ($viewer{client}) {
+	@actString = ();
+	if ($currentLines) {
+	    killOldStatus();
+	    $currentLines = 0;
+	}
+	my $str;
+	unless ($viewer{client_keymap}) {
+	    $str .= _encode_var('key', +{ %nummap, %specialmap });
+	    $viewer{client_keymap} = 1;
+	}
+	unless ($viewer{client_settings}) {
+	    $str .= _encode_var(
+		block => $S{block},
+		ha => $S{height_adjust},
+		mc => $S{maxcolumns},
+		ml => $S{maxlines},
+	       );
+	    $viewer{client_settings} = 1;
+	}
+	unless ($viewer{client_env}) {
+	    $str .= _encode_var(irssienv => +{
+		length $ENV{TMUX_PANE} && length $ENV{TMUX} ?
+		     (tmux_pane => $ENV{TMUX_PANE},
+		      tmux_srv => $ENV{TMUX}) : (),
+		length $ENV{WINDOWID} ?
+		     (xwinid => $ENV{WINDOWID}) : (),
+	       });
+	    $viewer{client_env} = 1;
+	}
+	my $separator = _get_format(set 'separator');
+	my $sepLen = sb_length($separator);
+	my $item_bg = _get_format(set 'viewer_item_bg');
+	my $title = _get_format(set 'title');
+	if (length $title) {
+	    $title =~ s{\\(.)|(.)}{
+		defined $2 ? quotemeta $2
+		    : $1 eq 'V' ? '\U'
+		    : $1 eq ':' ? quotemeta '%N'
+		    : $1 =~ /^[uUFQE]$/ ? "\\$1"
+		    : quotemeta "\\$1"
+		}sge;
+	    $title = eval qq{"$title"};
+	}
+	$str .= _encode_var(redraw => 1) if delete $viewer{fullRedraw};
+	$str .= _encode_var(separator => $separator,
+			    seplen => $sepLen,
+			    itembg => $item_bg,
+			    title => $title,
+			    mouse => $mouse_coords{refnum},
+			    key2 => \%wnmap_exp,
+			    win => \@win_items);
+
+	my $was = $viewer{client}->blocking(1);
+	$viewer{client}->print($str);
+	$viewer{client}->blocking($was);
+    }
+    elsif ($viewer{server}) {
+	if (defined $viewer{msg}) {
+	    @actString = ((uc setc()).": $viewer{msg}");
+	}
+	else {
+	    @actString = ();
+	}
+    }
+    elsif (defined $viewer{msg}) {
+	@actString = ((uc setc()).": $viewer{msg}");
+    }
+    if (@actString) {
+	Irssi::timeout_add_once(100, 'syncLines', undef);
+    }
+    elsif ($currentLines) {
+	killOldStatus();
+	$currentLines = 0;
+    }
+}
+
+sub reset_awl {
+    Irssi::timeout_remove($shade_line_timer) if $shade_line_timer; $shade_line_timer = undef;
+    my $was_sort = $S{sort} // '';
+    my $was_xform = $S{xform} // '';
+    my $was_shared = $S{shared_sbar};
+    my $was_no_hint = $S{no_mode_hint};
+    %S = (
+	sort	      => Irssi::settings_get_str( set 'sort'),
+	fancy_abbrev  => Irssi::settings_get_str('fancy_abbrev'),
+	xform	      => Irssi::settings_get_str( set 'custom_xform'),
+	block	      => Irssi::settings_get_int( set 'block'),
+	banned_on     => Irssi::settings_get_bool('banned_channels_on'),
+	prefer_name   => Irssi::settings_get_bool(set 'prefer_name'),
+	hide_data     => Irssi::settings_get_int( set 'hide_data'),
+	hide_name     => Irssi::settings_get_int( set 'hide_name_data'),
+	hide_empty    => Irssi::settings_get_int( set 'hide_empty'),
+	sbar_maxlen   => Irssi::settings_get_bool(set 'sbar_maxlength'),
+	placement     => Irssi::settings_get_str( set 'placement'),
+	position      => Irssi::settings_get_int( set 'position'),
+	maxlines      => Irssi::settings_get_int( set 'maxlines'),
+	maxcolumns    => Irssi::settings_get_int( set 'maxcolumns'),
+	all_disable   => Irssi::settings_get_bool(set 'all_disable'),
+	height_adjust => Irssi::settings_get_int( set 'height_adjust'),
+	mouse_offset  => Irssi::settings_get_int( set 'mouse_offset'),
+	mouse_scroll  => Irssi::settings_get_int( 'mouse_scroll'),
+	mouse_escape  => Irssi::settings_get_int( 'mouse_escape'),
+	line_shade    => Irssi::settings_get_time(set 'last_line_shade'),
+	no_mode_hint  => Irssi::settings_get_bool(set 'no_mode_hint'),
+	viewer_launch	      => Irssi::settings_get_bool(set 'viewer_launch'),
+	viewer_launch_env     => Irssi::settings_get_str(set 'viewer_launch_env'),
+	viewer_xwin_command   => Irssi::settings_get_str(set 'viewer_xwin_command'),
+	viewer_custom_command => Irssi::settings_get_str(set 'viewer_custom_command'),
+	viewer_tmux_position  => Irssi::settings_get_str(set 'viewer_tmux_position'),
+	);
+    $S{fancy_strict} = $S{fancy_abbrev} =~ /^strict/i;
+    $S{fancy_head} = $S{fancy_abbrev} =~ /^head/i;
+    my $shared = Irssi::settings_get_str(set 'shared_sbar');
+    if ($shared =~ /^(\d+)([<])(\d+)$/) {
+	$S{shared_sbar} = [$1, $2, $3];
+    }
+    else {
+	Irssi::settings_set_str(set 'shared_sbar', 'OFF');
+	$S{shared_sbar} = undef;
+    }
+    lock_keys(%S);
+    if ($was_sort ne $S{sort}) {
+	$print_text_activity = undef;
+	my @sort_order = grep { @$_ > 4 } map {
+	    s/^\s*//;
+	    my $reverse = s/^\W*\K[-!]//;
+	    my $undef_check = s/^\W*\K~// ? 1 : undef;
+	    my $equal_check = s/=(.*)\s?$// ? $1 : undef;
+	    s/\s*$//;
+	    my $ignore_case = s/#i$// ? 1 : undef;
+
+	    $print_text_activity = 1 if $_ eq 'last_line';
+
+	    my @path = split '/';
+	    my $class_check = @path && $path[-1] =~ s/(::.*)$// ? $1 : undef;
+
+	    [ $reverse ? -1 : 1, $undef_check, $equal_check, $class_check, $ignore_case, @path ]
+	} "$S{sort}," =~ /([^+,]*|[^+,]*=[^,]*?\s(?=\+)|[^+,]*=[^,]*)[+,]/g;
+	$window_sort_func = sub {
+	    no warnings qw(numeric uninitialized);
+	    for my $so (@sort_order) {
+		my @x = map {
+		    my $ret = 0;
+		    $_ = lc1459($_) if defined $_ && !ref $_ && $so->[4];
+		    $ret = $_ eq ($so->[4] ? lc1459($so->[2]) : $so->[2]) ? 1 : -1 if defined $so->[2];
+		    $ret = defined $_ ? ($ret || -3) : 3 if $so->[1];
+		    $ret = ref $_ && $_->isa('Irssi'.$so->[3]) ? 2 : ($ret || -2) if $so->[3];
+		    -$ret || $_
+		}
+		map {
+		    reduce { return unless ref $a; $a->{$b} } $_, @{$so}[5..$#$so]
+		} $a, $b;
+		return ((($x[0] <=> $x[1] || $x[0] cmp $x[1]) * $so->[0]) || next);
+	    }
+	    return ($a->{refnum} <=> $b->{refnum});
+	};
+    }
+    if ($was_xform ne $S{xform}) {
+	if ($S{xform} !~ /\S/) {
+	    $custom_xform = undef;
+	}
+	else {
+	    my $script_pkg = __PACKAGE__ . '::custom_xform';
+	    local $@;
+	    $custom_xform = eval qq{
+package $script_pkg;
+use strict;
+no warnings;
+our (\$QUERY, \$CHANNEL, \$TAG, \$NAME);
+return sub {
+# line 1 @{[ set 'custom_xform' ]}\n$S{xform}\n}};
+	    if ($@) {
+		$@ =~ /^(.*)/;
+		print '%_'.(set 'custom_xform').'%_ did not compile: '.$1;
+	    }
+	}
+    }
+
+    my $new_settings = join "\n", $VIEWER_MODE
+	 ? ("\\", $S{block}, $S{height_adjust}, $S{maxlines}, $S{maxcolumns})
+	 : ("!", $S{placement}, $S{position});
+
+    if ($settings_str ne $new_settings) {
+	@actString = ();
+	%abbrev_cache = ();
+	$currentLines = 0;
+	killOldStatus();
+	delete $viewer{client_settings};
+	$settings_str = $new_settings;
+    }
+
+    my $was_mouse_mode = $MOUSE_ON;
+    if ($MOUSE_ON = Irssi::settings_get_bool(set 'mouse') and !$was_mouse_mode) {
+	install_mouse();
+    }
+    elsif ($was_mouse_mode and !$MOUSE_ON) {
+	uninstall_mouse();
+    }
+
+    my $path = Irssi::settings_get_str(set 'path');
+    my $was_viewer_mode = $VIEWER_MODE;
+    if ($was_viewer_mode &&
+	defined $viewer{path} && $viewer{path} ne $path) {
+	stop_viewer();
+	$was_viewer_mode = 0;
+    }
+    elsif ($was_viewer_mode && $S{no_mode_hint} != $was_no_hint + 0) {
+	set_viewer_mode_hint();
+    }
+    $viewer{path} = $path;
+    if ($VIEWER_MODE = Irssi::settings_get_bool(set 'viewer') and !$was_viewer_mode) {
+	start_viewer();
+    }
+    elsif ($was_viewer_mode and !$VIEWER_MODE) {
+	stop_viewer();
+    }
+
+    %banned_channels = map { lc1459(to_uni($_)) => undef }
+	split ' ', Irssi::settings_get_str('banned_channels');
+
+    my @sb_base = split /\177/, sb_format_expand("{sbstart}{sb \177}{sbend}"), 2;
+    $sb_base_width_pre = sb_length($sb_base[0]);
+    $sb_base_width_post = max 0, sb_length($sb_base[1])-1;
+    $sb_base_width = $sb_base_width_pre + $sb_base_width_post;
+
+    if ($print_text_activity && $S{line_shade}) {
+	$shade_line_timer = Irssi::timeout_add(max(10 * GLOB_QUEUE_TIMER, 100*$S{line_shade}**(1/3)), 'wl_changed', undef);
+    }
+
+    $CHANGED{AWINS} = 1;
+}
+
+sub stop_mouse_tracking {
+    print STDERR "\e[?1005l\e[?1000l";
+}
+sub start_mouse_tracking {
+    print STDERR "\e[?1000h\e[?1005h";
+}
+sub install_mouse {
+    Irssi::command_bind('mouse_xterm' => 'mouse_xterm');
+    Irssi::command('^bind meta-[M command mouse_xterm');
+    Irssi::signal_add_first('gui key pressed' => 'mouse_key_hook');
+    start_mouse_tracking();
+}
+sub uninstall_mouse {
+    stop_mouse_tracking();
+    Irssi::signal_remove('gui key pressed' => 'mouse_key_hook');
+    Irssi::command('^bind -delete meta-[M');
+    Irssi::command_unbind('mouse_xterm' => 'mouse_xterm');
+}
+
+sub awl_mouse_event {
+    return if $VIEWER_MODE;
+    if ((($_[0] == 3 and $_[3] == 0)
+	     || $_[0] == 64 || $_[0] == 65) and
+	    $_[1] == $_[4] and $_[2] == $_[5]) {
+	my $top = lc $S{placement} eq 'top';
+	my ($pos, $line) = @_[1 .. 2];
+	unless ($top) {
+	    $line -= $screenHeight;
+	    $line += $currentLines;
+	    $line += $S{mouse_offset};
+	}
+	else {
+	    $line -= $S{mouse_offset};
+	}
+	$pos -= $sb_base_width_pre;
+	return if $line < 0 || $line >= $currentLines;
+	if ($_[0] == 64) {
+	    Irssi::command('window up');
+	}
+	elsif ($_[0] == 65) {
+	    Irssi::command('window down');
+	}
+	elsif (exists $mouse_coords{$line}{$pos}) {
+	    my $win = $mouse_coords{$line}{$pos};
+	    Irssi::command('window ' . $win);
+	}
+	Irssi::signal_stop;
+    }
+}
+
+sub mouse_scroll_event {
+    return unless $S{mouse_scroll};
+    if (($_[3] == 64 or $_[3] == 65) and
+	    $_[0] == $_[3] and $_[1] == $_[4] and $_[2] == $_[5]) {
+	my $cmd = 'scrollback goto ' . ($_[3] == 64 ? '-' : '+') . $S{mouse_scroll};
+	Irssi::active_win->command($cmd);
+	Irssi::signal_stop;
+    }
+    elsif ($_[0] == 64 or $_[0] == 65) {
+	Irssi::signal_stop;
+    }
+}
+
+sub mouse_escape {
+    return unless $S{mouse_escape} > 0;
+    if ($_[0] == 3) {
+	my $tm = $S{mouse_escape};
+	$tm *= 1000 if $tm < 1000;
+	stop_mouse_tracking();
+	Irssi::timeout_add_once($tm, 'start_mouse_tracking', undef);
+	Irssi::signal_stop;
+    }
+}
+
+sub UNLOAD {
+    @actString = ();
+    killOldStatus();
+    stop_viewer() if $VIEWER_MODE;
+    uninstall_mouse() if $MOUSE_ON;
+}
+
+sub addPrintTextHook { # update on print text
+    return unless defined $^S;
+    return if $BLOCK_ALL;
+    return unless $print_text_activity;
+    return if $_[0]->{level} == 262144 and $_[0]->{target} eq ''
+	and !defined($_[0]->{server});
+    &wl_changed;
+}
+
+sub block_event_window_change {
+    Irssi::signal_stop;
+}
+
+sub update_awins {
+    my @wins = Irssi::windows;
+    local $BLOCK_ALL = 1;
+    Irssi::signal_add_first('window changed' => 'block_event_window_change');
+    my $bwin =
+	my $awin = Irssi::active_win;
+    my $lwin;
+    my $defer_irssi_broken_last;
+    unless ($wins[0]{refnum} == $awin->{refnum}) {
+	# special case: more than 1 last win, so /win last;
+	# /win last doesn't come back to the current window. eg. after
+	# connect & autojoin; we can't handle this situation, bail out
+	$defer_irssi_broken_last = 1;
+    }
+    else {
+	$awin->command('window last');
+	$lwin = Irssi::active_win;
+	$lwin->command('window last');
+	$defer_irssi_broken_last = $lwin->{refnum} == $bwin->{refnum};
+    }
+    my $awin_counter = 0;
+    Irssi::signal_remove('window changed' => 'block_event_window_change');
+    unless ($defer_irssi_broken_last) {
+	# we need to keep the fe-windows code running here
+	Irssi::signal_add_priority('window changed' => 'block_event_window_change', -99);
+	%awins = %wnmap_exp = ();
+	do {
+	    Irssi::active_win->command('window up');
+	    $awin = Irssi::active_win;
+	    $awins{$awin->{refnum}} = undef;
+	    ++$awin_counter;
+	} until ($awin->{refnum} == $bwin->{refnum} || $awin_counter >= @wins);
+	Irssi::signal_remove('window changed' => 'block_event_window_change');
+
+	Irssi::signal_add_first('window changed' => 'block_event_window_change');
+	for my $key (keys %wnmap) {
+	    next unless Irssi::window_find_name($key) || Irssi::window_find_item($key);
+	    $awin->command("window goto $key");
+	    my $cwin = Irssi::active_win;
+	    $wnmap_exp{ $cwin->{refnum} } = $wnmap{$key};
+	    $cwin->command('window last')
+		if $cwin->{refnum} != $awin->{refnum};
+	}
+	for my $win (reverse @wins) { # restore original window order
+	    Irssi::active_win->command('window '.$win->{refnum});
+	}
+	$awin->command('window '.$lwin->{refnum}); # restore last win
+	Irssi::active_win->command('window last');
+	Irssi::signal_remove('window changed' => 'block_event_window_change');
+    }
+    $CHANGED{WL} = 1;
+}
+
+sub resizeTerm {
+    if (defined (my $r = `stty size 2>/dev/null`)) {
+	($screenHeight, $screenWidth) = split ' ', $r;
+	$CHANGED{SETUP} = 1;
+    }
+    else {
+	$CHANGED{SIZE} = 1;
+    }
+}
+
+sub awl_refresh {
+    $globTime = undef;
+    resizeTerm()   if delete $CHANGED{SIZE};
+    reset_awl()    if delete $CHANGED{SETUP};
+    update_awins() if delete $CHANGED{AWINS};
+    update_wl()    if delete $CHANGED{WL};
+}
+
+sub termsize_changed { $CHANGED{SIZE}  = 1; &queue_refresh; }
+sub setup_changed    { $CHANGED{SETUP} = 1; &queue_refresh; }
+sub awins_changed    { $CHANGED{AWINS} = 1; &queue_refresh; }
+sub wl_changed       { $CHANGED{WL}    = 1; &queue_refresh; }
+
+sub window_changed {
+    &awins_changed if $_[1];
+}
+
+sub queue_refresh {
+    return if $BLOCK_ALL;
+    Irssi::timeout_remove($globTime)
+	    if defined $globTime; # delay the update further
+    $globTime = Irssi::timeout_add_once(GLOB_QUEUE_TIMER, 'awl_refresh', undef);
+}
+
+sub awl_init {
+    termsize_changed();
+    update_keymap();
+}
+
+sub runsub {
+    my $cmd = shift;
+    sub {
+	my ($data, $server, $item) = @_;
+	Irssi::command_runsub($cmd, $data, $server, $item);
+    };
+}
+
+Irssi::signal_register({
+    'gui mouse' => [qw/int int int int int int/],
+   });
+{ my $broken_expandos = (Irssi::version >= 20081128 && Irssi::version < 20110210)
+      ? sub { my $x = shift; $x =~ s/\$\{cumode_space\}/ /; $x } : undef;
+  Irssi::theme_register([
+    map { $broken_expandos ? $broken_expandos->($_) : $_ }
+    set 'display_nokey'		=>   '$N${cumode_space}$H$C$S',
+    set 'display_key'		=>   '$Q${cumode_space}$H$C$S',
+    set 'display_nokey_visible' => '%2$N${cumode_space}$H$C$S',
+    set 'display_key_visible'	=> '%2$Q${cumode_space}$H$C$S',
+    set 'display_nokey_active'	=> '%1$N${cumode_space}$H$C$S',
+    set 'display_key_active'	=> '%1$Q${cumode_space}$H$C$S',
+    set 'display_header'	=> '%8$C|${N}',
+    set 'name_display'		=> '$0',
+    set 'separator'		=> ' ',
+    set 'separator2'		=> '',
+    set 'abbrev_chars'		=> "~\x{301c}",
+    set 'viewer_item_bg'	=> sb_format_expand('{sb_background}'),
+    set 'title'			=> '\V'.setc().'\:',
+   ]);
+}
+Irssi::settings_add_bool(setc, set 'prefer_name',    0); #
+Irssi::settings_add_int( setc, set 'hide_empty',     0); #
+Irssi::settings_add_int( setc, set 'hide_data',      0); #
+Irssi::settings_add_int( setc, set 'hide_name_data', 0); #
+Irssi::settings_add_int( setc, set 'maxlines',       9); #
+Irssi::settings_add_int( setc, set 'maxcolumns',     4); #
+Irssi::settings_add_int( setc, set 'block',          15); #
+Irssi::settings_add_bool(setc, set 'sbar_maxlength', 1); #
+Irssi::settings_add_int( setc, set 'height_adjust',  2); #
+Irssi::settings_add_str( setc, set 'sort',           'refnum'); #
+Irssi::settings_add_str( setc, set 'placement',      'bottom'); #
+Irssi::settings_add_int( setc, set 'position',       0); #
+Irssi::settings_add_bool(setc, set 'all_disable',    1); #
+Irssi::settings_add_bool(setc, set 'viewer',         1); #
+Irssi::settings_add_str( setc, set 'shared_sbar',    'OFF'); #
+Irssi::settings_add_bool(setc, set 'mouse',          0); #
+Irssi::settings_add_str( setc, set 'path', Irssi::get_irssi_dir . '/_windowlist'); #
+Irssi::settings_add_str( setc, set 'custom_xform',   ''); #
+Irssi::settings_add_time(setc, set 'last_line_shade', '0'); #
+Irssi::settings_add_int( setc, set 'mouse_offset',   1); #
+Irssi::settings_add_int( setc, 'mouse_scroll',       3); #
+Irssi::settings_add_int( setc, 'mouse_escape',       1); #
+Irssi::settings_add_str( setc, 'banned_channels',    '');
+Irssi::settings_add_bool(setc, 'banned_channels_on', 1);
+Irssi::settings_add_str( setc, 'fancy_abbrev',       'fancy'); #
+Irssi::settings_add_bool(setc, set 'no_mode_hint',   0); #
+Irssi::settings_add_bool(setc, set 'viewer_launch',  1); #
+Irssi::settings_add_str( setc, set 'viewer_launch_env',  ''); #
+Irssi::settings_add_str( setc, set 'viewer_tmux_position',  'left'); #
+Irssi::settings_add_str( setc, set 'viewer_xwin_command',  'xterm +sb -e %A'); #
+Irssi::settings_add_str( setc, set 'viewer_custom_command',  ''); #
+
+Irssi::signal_add_last({
+    'setup changed'    => 'setup_changed',
+    'print text'       => 'addPrintTextHook',
+    'terminal resized' => 'termsize_changed',
+    'setup reread'     => 'screenFullRedraw',
+    'window hilight'   => 'wl_changed',
+    'command format'   => 'wl_changed',
+});
+Irssi::signal_add({
+    'window changed'	       => 'window_changed',
+    'window item changed'      => 'wl_changed',
+    'window changed automatic' => 'window_changed',
+    'window created'	       => 'awins_changed',
+    'window destroyed'	       => 'awins_changed',
+    'window name changed'      => 'wl_changed',
+    'window refnum changed'    => 'wl_changed',
+});
+Irssi::signal_add_last('gui mouse' => 'mouse_escape');
+Irssi::signal_add_last('gui mouse' => 'mouse_scroll_event');
+Irssi::signal_add_last('gui mouse' => 'awl_mouse_event');
+Irssi::command_bind( setc() => runsub(setc()) );
+Irssi::command_bind( setc() . ' redraw' => 'screenFullRedraw' );
+Irssi::command_bind( setc() . ' restart' => 'restartViewerServer' );
+
+{
+    my $l = set 'shared';
+    {
+	no strict 'refs';
+	*{$l} = $awl_shared_empty;
+    }
+    Irssi::statusbar_item_register($l, '$0', $l);
+}
+
+awl_init();
+
+# Mouse script based on irssi mouse patch by mirage
+{ my $mouse_status = -1; # -1:off 0,1,2:filling mouse_combo
+  my @mouse_combo; # 0:button 1:x 2:y
+  my @mouse_previous; # previous contents of mouse_combo
+
+  sub mouse_xterm_off {
+      $mouse_status = -1;
+  }
+  sub mouse_xterm {
+      $mouse_status = 0;
+      Irssi::timeout_add_once(10, 'mouse_xterm_off', undef);
+  }
+
+  sub mouse_key_hook {
+      my ($key) = @_;
+      if ($mouse_status != -1) {
+	  if ($mouse_status == 0) {
+	      @mouse_previous = @mouse_combo;
+		  #if @mouse_combo && $mouse_combo[0] < 64;
+	  }
+	  $mouse_combo[$mouse_status] = $key - 32;
+	  $mouse_status++;
+	  if ($mouse_status == 3) {
+	      $mouse_status = -1;
+	      # match screen coordinates
+	      $mouse_combo[1]--;
+	      $mouse_combo[2]--;
+	      Irssi::signal_emit('gui mouse', @mouse_combo[0 .. 2], @mouse_previous[0 .. 2]);
+	  }
+	  Irssi::signal_stop;
+      }
+  }
+}
+
+sub string_LCSS {
+    my $str = join "\0", @_;
+    (sort { length $b <=> length $a } $str =~ /(?=(.+).*\0.*\1)/g)[0]
+}
+
+# workaround for issue #271
+{ package Irssi::Nick }
+
+# workaround for issue #572
+@Irssi::UI::Exec::ISA = 'Irssi::Windowitem'
+    if Irssi::version >= 20140822 && Irssi::version <= 20161101 && !@Irssi::UI::Exec::ISA;
+
+UNITCHECK
+{ package AwlViewer;
+  use strict;
+  use warnings;
+  no warnings 'redefine';
+  use Encode;
+  use IO::Socket::UNIX;
+  use IO::Select;
+  use List::Util qw(max);
+  use constant BLOCK_SIZE => 1024;
+  use constant RECONNECT_TIME => 5;
+
+  my $sockpath;
+
+  our $VERSION = '0.8';
+
+  our ($got_int, $resized, $timeout);
+
+  my %vars;
+  my (%c2w, @seqlist);
+  my %mouse_coords;
+  my (@mouse, @last_mouse);
+  my ($err, $sock, $loop);
+  my ($keybuf, $rcvbuf);
+  my @screen;
+  my ($screenHeight, $screenWidth);
+  my ($disp_update, $fs_open, $one_shot_integration, $one_shot_resize);
+  my $integration_position;
+  my $show_title_bar;
+
+  sub connect_it {
+      $sock = IO::Socket::UNIX->new(
+	  Type => SOCK_STREAM,
+	  Peer => $sockpath,
+	 );
+      unless ($sock) {
+	  $err = $!;
+	  return;
+      }
+      $sock->blocking(0);
+      $loop->add($sock);
+  }
+
+  sub remove_conn {
+      my $fh = shift;
+      $loop->remove($fh);
+      $fh->close;
+      $sock = undef;
+      %vars = ();
+      @screen = ();
+  }
+
+  { package Terminfo; # xterm
+    sub civis      { "\e[?25l" }
+    sub sc	   { "\e7" }
+    sub cup	   { "\e[" . ($_[0] + 1) . ';' . ($_[1] + 1) . 'H' }
+    sub el	   { "\e[K" }
+    sub rc	   { "\e8" }
+    sub cnorm      { "\e[?25h" }
+    sub setab      { "\e[4" . $_[0] . 'm' }
+    sub setaf      { "\e[3" . $_[0] . 'm' }
+    sub setaf16    { "\e[9" . $_[0] . 'm' }
+    sub setab16    { "\e[10" . $_[0] . 'm' }
+    sub setaf256   { "\e[38;5;" . $_[0] . 'm' }
+    sub setab256   { "\e[48;5;" . $_[0] . 'm' }
+    sub sgr0       { "\e[0m" }
+    sub bold       { "\e[1m" }
+    sub it         { "\e[3m" }
+    sub ul         { "\e[4m" }
+    sub blink      { "\e[5m" }
+    sub rev	   { "\e[7m" }
+    sub op	   { "\e[39;49m" }
+    sub exit_bold  { "\e[22m" }
+    sub exit_it    { "\e[23m" }
+    sub exit_ul    { "\e[24m" }
+    sub exit_blink { "\e[25m" }
+    sub exit_rev   { "\e[27m" }
+    sub smcup      { "\e[?1049h" }
+    sub rmcup      { "\e[?1049l" }
+    sub smmouse    { "\e[?1000h\e[?1005h" }
+    sub rmmouse    { "\e[?1005l\e[?1000l" }
+  }
+
+  sub init {
+      $sockpath = shift // "$ENV{HOME}/.irssi/_windowlist";
+      STDOUT->autoflush(1);
+      printf "\r%swaiting for %s...", Terminfo::sc, $::IRSSI{name};
+
+      `stty -icanon -echo`;
+
+      $loop = IO::Select->new;
+      STDIN->blocking(0);
+      $loop->add(\*STDIN);
+
+      $SIG{INT} = sub {
+	  $got_int = 1
+      };
+      $SIG{WINCH} = sub {
+	  $resized = 1
+      };
+
+      $resized = 3;
+
+      $disp_update = 2;
+
+      $show_title_bar = 1;
+  }
+
+  sub enter_fs {
+      return if $fs_open;
+      safe_print(Terminfo::rc, Terminfo::smcup, Terminfo::civis, Terminfo::smmouse);
+      $fs_open = 1;
+  }
+
+  sub leave_fs {
+      return unless $fs_open;
+      safe_print(Terminfo::rmmouse, Terminfo::cnorm, Terminfo::rmcup);
+      safe_print(sprintf "\r%swaiting for %s...", Terminfo::sc, $::IRSSI{name}) if $_[0];
+
+      $fs_open = 0;
+  }
+
+  sub end_prog {
+      leave_fs();
+      STDIN->blocking(1);
+      `stty sane`;
+      printf "\r%s%sthanks for using %s\n", Terminfo::rc, Terminfo::el, $::IRSSI{name};
+  }
+
+  sub safe_print {
+      my $st = STDIN->blocking(1);
+      print @_;
+      STDIN->blocking($st);
+  }
+
+  sub safe_qx {
+      my $st = STDIN->blocking(1);
+      my $ret = `$_[0]`;
+      STDIN->blocking($st);
+      $ret
+  }
+
+  sub safe_print_sock {
+      return unless $sock;
+      my $was = $sock->blocking(1);
+      $sock->print(@_);
+      $sock->blocking($was);
+  }
+
+  sub process_recv {
+      my $need = 0;
+      while ($rcvbuf =~ s/\n(.+)_BEGIN\n((?: .*\n)*)\1_END\n//) {
+	  my $var = lc $1;
+	  my $data = $2;
+	  my @data = split "\n ", "\n$data ", -1;
+	  shift @data; pop @data;
+	  my $itembg = $vars{itembg};
+	  if ($var =~ s/list$//) {
+	      $vars{$var} = \@data;
+	  }
+	  elsif ($var =~ s/map$//) {
+	      $vars{$var} = +{ @data };
+	  }
+	  else {
+	      $vars{$var} = join "\n", @data;
+	  }
+	  $need = 1 if $var eq 'win';
+	  $need = 1 if $var eq 'redraw' && $vars{$var};
+	  if (($itembg//'') ne ($vars{itembg}//'')) {
+	      $need = $vars{redraw} = 1;
+	  }
+	  _build_keymap() if $var eq 'key2';
+      }
+      $need
+  }
+
+  { my %ansi_table;
+    my ($i, $j, $k) = (0, 0, 0);
+    my %term_state;
+    sub reset_term_state { my %old_term = %term_state; %term_state = (); %old_term }
+    sub set_term_state { my %old_term = %term_state; %term_state = @_; %old_term }
+    %ansi_table = (
+	# fe-common::core::formats.c:format_expand_styles
+	(map { my $t = $i++; ($_ => sub { my $n = $term_state{hicolor} ? \&Terminfo::setab16 : \&Terminfo::setab;
+					  $n->($t) }) } (split //, '01234567' )),
+	(map { my $t = $j++; ($_ => sub { my $n = $term_state{hicolor} ? \&Terminfo::setaf16 : \&Terminfo::setaf;
+					  $n->($t) }) } (split //, 'krgybmcw' )),
+	(map { my $t = $k++; ($_ => sub { my $n = $term_state{hicolor} ? \&Terminfo::setaf : \&Terminfo::setaf16;
+					  $n->($t) }) } (split //, 'KRGYBMCW')),
+	# reset
+	n => sub { $term_state{hicolor} = 0; my $r = Terminfo::op;
+		   for (qw(blink rev bold)) {
+		       $r .= Terminfo->can("exit_$_")->() if delete $term_state{$_};
+		   }
+		   {
+		       local $ansi_table{n} = $ansi_table{N};
+		       $r .= formats_to_ansi_basic($vars{itembg});
+		   }
+		   $r
+	       },
+	N => sub { reset_term_state(); Terminfo::sgr0 },
+	# flash/bright
+	F => sub { my $n = 'blink'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# reverse
+	8 => sub { my $n = 'rev'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# bold
+	"_" => sub { my $n = 'bold'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# underline
+	U => sub { my $n = 'ul'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# italic
+	I => sub { my $n = 'it'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	# bold, used as colour modifier if AWL_HI9 is set
+	9 => $ENV{AWL_HI9} ? sub { $term_state{hicolor} ^= 1; '' }
+	    : sub { my $n = 'bold'; my $e = ($term_state{$n} ^= 1) ? $n : "exit_$n"; Terminfo->can($e)->() },
+	#      delete                other stuff
+	(map { $_ => sub { '' } } (split //, ':|>#[')),
+	#      escape
+	(map { my $close = $_; $_ => sub { $close } } (split //, '{}%')),
+       );
+    for my $base (0 .. 15) {
+	my $close = $base;
+	my $idx = ($close&8) | ($close&4)>>2 | ($close&2) | ($close&1)<<2;
+	$ansi_table{ (sprintf "x0%x", $close) } =
+	    $ansi_table{ (sprintf "x0%X", $close) } =
+		sub { Terminfo::setab256($idx) };
+	$ansi_table{ (sprintf "X0%x", $close) } =
+	    $ansi_table{ (sprintf "X0%X", $close) } =
+		sub { Terminfo::setaf256($idx) };
+    }
+    for my $plane (1 .. 6) {
+	for my $coord (0 .. 35) {
+	    my $close = 16 + ($plane-1) * 36 + $coord;
+	    my $ch = $coord < 10 ? $coord : chr( $coord - 10 + ord 'a' );
+	    $ansi_table{ "x$plane$ch" } =
+		$ansi_table{ "x$plane\U$ch" } =
+		    sub { Terminfo::setab256($close) };
+	    $ansi_table{ "X$plane$ch" } =
+		$ansi_table{ "X$plane\U$ch" } =
+		    sub { Terminfo::setaf256($close) };
+	}
+    }
+    for my $gray (0 .. 23) {
+	my $close = 232 + $gray;
+	my $ch = chr( $gray + ord 'a' );
+	$ansi_table{ "x7$ch" } =
+	    $ansi_table{ "x7\U$ch" } =
+		sub { Terminfo::setab256($close) };
+	$ansi_table{ "X7$ch" } =
+	    $ansi_table{ "X7\U$ch" } =
+		sub { Terminfo::setaf256($close) };
+    }
+    sub formats_to_ansi_basic {
+	my $o = shift;
+	$o =~ s/(%(X..|x..|.))/exists $ansi_table{$2} ? $ansi_table{$2}->() : $1/gex;
+	$o
+    }
+  }
+
+  sub _header {
+      my $str = $vars{title} // uc ::setc();
+      my $ccs = qr/%(?:X(?:[1-6][0-9A-Z]|7[A-X])|[0-9BCFGIKMNRUWY_])/i;
+      (my $stripstr = $str) =~ s/($ccs)//g;
+      my $space = int( ((abs $vars{block}) - length $stripstr) / (1 + length $stripstr));
+      if ($space > 0) {
+	  my $ss = ' ' x $space;
+	  my @x = $str =~ /((?:$ccs)*\X(?:(?:$ccs)*$)?)/g;
+	  $str = join $ss, '', @x, '';
+      }
+      ($stripstr = $str) =~ s/($ccs)//g;
+      my $pad = max 0, (abs $vars{block}) - length $stripstr;
+      $str = ' ' x ($pad/2) . $str . ' ' x ($pad/2 + $pad%2);
+      $str
+  }
+
+  sub _add_item {
+      my ($i, $j, $c, $wi, $screen, $mouse) = @_;
+      $screen->[$i][$j] = "%N%n$wi";
+      if (exists $vars{mouse}{$c - 1}) {
+	  $mouse->[$i][$j] = $vars{mouse}{$c - 1};
+      }
+  }
+  sub update_screen {
+      $disp_update = 0;
+      unless ($sock && exists $vars{seplen} && exists $vars{block}) {
+	  leave_fs(1);
+	  return;
+      }
+      enter_fs();
+      @screen = () if delete $vars{redraw};
+      %mouse_coords = ();
+      my $ncols = ($vars{seplen} + abs $vars{block}) ?
+	  int( ($screenWidth + $vars{seplen}) / ($vars{seplen} + abs $vars{block}) ) : 0;
+      my $xenl = ($vars{seplen} + abs $vars{block})
+	  && $ncols > int( ($screenWidth + $vars{seplen} - 1) / ($vars{seplen} + abs $vars{block}) );
+      my $nrows = $screenHeight - $vars{ha};
+      my @wi = @{$vars{win}//[]};
+      my $max_items = $ncols * $nrows;
+      my $c = $show_title_bar ? 1 : 0;
+      my $items = @wi + $c;
+      my $titems = $items > $max_items ? $max_items : $items;
+      my $i = 0;
+      my $j = 0;
+      my @new_screen;
+      my @new_mouse;
+      $new_screen[0][0] = _header() #. ' ' x $vars{seplen}
+	  if $show_title_bar;
+      unless ($nrows > $ncols) { # line layout
+	  ++$j if $show_title_bar;
+	  for my $wi (@wi) {
+	      if ($j >= $ncols) {
+		  $j = 0;
+		  ++$i;
+	      }
+	      last if $i >= $nrows;
+	      _add_item($i, $j, $show_title_bar ? $c : $c + 1,
+			$wi, \@new_screen, \@new_mouse);
+	      if ($c + 1 < $titems && $j + 1 < $ncols) {
+		  $new_screen[$i][$j] .= $vars{separator};
+	      }
+	      ++$j;
+	      ++$c;
+	  }
+      }
+      else { # column layout
+	  ++$i if $show_title_bar;
+	  for my $wi (@wi) {
+	      if ($i >= $nrows) {
+		  $i = 0;
+		  ++$j;
+	      }
+	      last if $j >= $ncols;
+	      _add_item($i, $j, $show_title_bar ? $c : $c + 1,
+			$wi, \@new_screen, \@new_mouse);
+	      if ($c + $nrows < $titems) {
+		  $new_screen[$i][$j] .= $vars{separator};
+	      }
+	      ++$i;
+	      ++$c;
+	  }
+      }
+      my $step = $vars{seplen} + abs $vars{block};
+      $i = 0;
+      my $str = Terminfo::sc . Terminfo::sgr0;
+      for (my $i = 0; $i < @new_screen; ++$i) {
+	  for (my $j = 0; $j < @{$new_screen[$i]}; ++$j) {
+	      if (defined $new_mouse[$i] && defined $new_mouse[$i][$j]) {
+		  my $from = $j * $step;
+		  $mouse_coords{$i}{$_} = $new_mouse[$i][$j]
+		      for $from .. $from + abs $vars{block};
+	      }
+	      next if defined $screen[$i] && defined $screen[$i][$j]
+		  && $screen[$i][$j] eq $new_screen[$i][$j];
+	      $str .= Terminfo::cup($i, $j * $step)
+		   .  formats_to_ansi_basic($new_screen[$i][$j])
+		   .  Terminfo::sgr0;
+	      $str .= Terminfo::el if $j == $#{$new_screen[$i]} && (!$xenl || $j + 1 != $ncols);
+	  }
+      }
+      for (@new_screen .. $screenHeight - 1) {
+	  if (!@screen || defined $screen[$_]) {
+	      $str .= Terminfo::cup($_, 0) . Terminfo::sgr0 . Terminfo::el;
+	  }
+      }
+      $str .= Terminfo::rc;
+      safe_print $str;
+      @screen = @new_screen;
+  }
+
+  sub handle_resize {
+      if (defined (my $r = safe_qx('stty size'))) {
+	  ($screenHeight, $screenWidth) = split ' ', $r;
+	  $resized = 0;
+	  @screen = ();
+	  $disp_update = 1;
+	  if ($one_shot_integration == 2) {
+	      $one_shot_resize--;
+	  }
+      }
+      else {
+      }
+  }
+
+  sub _build_keymap {
+      %c2w = reverse( %{$vars{key}}, %{$vars{key2}} );
+      if (!grep { /^[+-]./ } keys %c2w) {
+	  %c2w = (%c2w, map { ("-$_" => $c2w{$_}) } grep { !/^\^./ } keys %c2w);
+      }
+      %c2w = map {
+	  my $key = $_;
+	  s{^(-)?(\+)?(\^)?(.)}{
+	      join '', (
+		  ($1 ? "\e" : ''),
+		  ($2 ? "\e\e" : ''),
+		  ($3 ? "$4"^"@" : $4)
+		 )
+	  }e;
+	  $_ => $c2w{$key}
+      } keys %c2w;
+      @seqlist = sort { length $b <=> length $a } keys %c2w;
+  }
+
+  sub _match_tmux {
+      length $ENV{TMUX} && exists $vars{irssienv}{tmux_srv} && length $vars{irssienv}{tmux_pane}
+	  && $ENV{TMUX} eq $vars{irssienv}{tmux_srv}
+  }
+
+  sub process_keys {
+      Encode::_utf8_on($keybuf);
+      my $win;
+      my $use_mouse;
+      my $maybe;
+  KEY: while (length $keybuf && !$maybe) {
+	  $maybe = 0;
+	  if ($keybuf =~ s/^\e\[M(.)(.)(.)//) {
+	      @last_mouse = @mouse;# if @mouse && $mouse[0] < 64;
+	      @mouse = map { -32 + ord } ($1, $2, $3);
+	      $use_mouse = 1;
+	      next KEY;
+	  }
+	  for my $s (@seqlist) {
+	      if ($keybuf =~ s/^\Q$s//) {
+		  $win = $c2w{$s};
+		  $use_mouse = 0;
+		  next KEY;
+	      }
+	      elsif (length $keybuf < length $s && $s =~ /^\Q$keybuf/) {
+		  $maybe = 1;
+	      }
+	  }
+	  unless ($maybe) {
+	      substr $keybuf, 0, 1, '';
+	  }
+      }
+      if ($use_mouse && @mouse && @last_mouse &&
+	      $mouse[2] == $last_mouse[2] &&
+		  $mouse[1] == $last_mouse[1] &&
+		      ($mouse[0] == 3 || $mouse[0] == 64 || $mouse[0] == 65)) {
+	  if ($mouse[0] == 64) {
+	      $win = 'up';
+	  }
+	  elsif ($mouse[0] == 65) {
+	      $win = 'down';
+	  }
+	  elsif (exists $mouse_coords{$mouse[2] - 1}{$mouse[1] - 1}) {
+	      $win = $mouse_coords{$mouse[2] - 1}{$mouse[1] - 1};
+	  }
+	  elsif ($mouse[2] == 1 && $mouse[1] <= abs $vars{block}) {
+	      $win = $last_mouse[0] != 0 ? 'last' : 'active';
+	  }
+	  else {
+	  }
+      }
+      if (defined $win) {
+	  $win =~ s/^_//;
+	  safe_print_sock("$win\n");
+	  if (!exists $ENV{AWL_AUTOFOCUS} || $ENV{AWL_AUTOFOCUS}) {
+	      if (_match_tmux()) {
+		  safe_qx("tmux selectp -t $vars{irssienv}{tmux_pane} 2>&1");
+	      }
+	      elsif (exists $vars{irssienv}{xwinid}) {
+		  safe_qx("wmctrl -ia $vars{irssienv}{xwinid} 2>/dev/null");
+	      }
+	  }
+      }
+      Encode::_utf8_off($keybuf);
+  }
+
+  sub check_integration {
+      return unless $vars{irssienv};
+      return unless $sock && exists $vars{seplen} && exists $vars{block};
+      if ($one_shot_integration == 1) {
+	  my $nrows = $screenHeight - $vars{ha};
+	  my $ncols = ($vars{seplen} + abs $vars{block}) ? int( ($screenWidth + $vars{seplen}) / ($vars{seplen} + abs $vars{block}) ) : 0;
+	  my $items = ($show_title_bar ? 1 : 0) + @{$vars{win}//[]};
+	  my $dcols_required = $nrows ? int($items/$nrows) + !!($items%$nrows) : 0;
+	  my $rows_required = $ncols ? int($items/$ncols) + !!($items%$ncols) : 0;
+	  $rows_required = abs $vars{ml}
+	      if ($vars{ml} < 0 || ($vars{ml} > 0 && $rows_required > $vars{ml}));
+	  $dcols_required = abs $vars{mc}
+	      if ($vars{mc} < 0 || ($vars{mc} > 0 && $dcols_required > $vars{mc}));
+	  my $rows = $rows_required + $vars{ha};
+	  my $cols = ($dcols_required * ($vars{seplen} + abs $vars{block})) - $vars{seplen};
+	  if (_match_tmux()) {
+	      # int( ($screenWidth + $vars{seplen}) / ($vars{seplen} + abs $vars{block}) );
+	      my ($pos_flag, $before);
+	      if ($integration_position eq 'left') {
+		  $pos_flag = 'h';
+		  $before = 1;
+	      }
+	      elsif ($integration_position eq 'top') {
+		  $pos_flag = 'v';
+		  $before = 1;
+	      }
+	      elsif ($integration_position eq 'right') {
+		  $pos_flag = 'h';
+	      }
+	      else {
+		  $pos_flag = 'v';
+	      }
+	      my @cmd = "joinp -d$pos_flag -s $ENV{TMUX_PANE} -t $vars{irssienv}{tmux_pane}";
+	      push @cmd, "swapp -d -t $ENV{TMUX_PANE} -s $vars{irssienv}{tmux_pane}"
+		  if $before;
+	      $cols = max($cols, 2);
+	      $rows = max($rows, 2);
+
+	      safe_qx("tmux " . (join " \\\; ", @cmd) . " 2>&1");
+	  }
+	  else {
+	      $resized = 1;
+	      #safe_qx("resize -s $screenHeight $cols 2>&1")
+		#  if $cols > 0;
+	  }
+	  $one_shot_integration++;
+	  if ($resized == 1) {
+	      handle_resize();
+	      resize_integration();
+	  }
+      }
+      elsif ($one_shot_integration == 2) {
+	  resize_integration(1);
+      }
+  }
+
+  sub resize_integration {
+      return unless $one_shot_integration;
+      return unless ($one_shot_resize//0) < 0 || shift;
+      my $nrows = $screenHeight - $vars{ha};
+      my $ncols = ($vars{seplen} + abs $vars{block}) ? int( ($screenWidth + $vars{seplen}) / ($vars{seplen} + abs $vars{block}) ) : 0;
+      my $items = ($show_title_bar ? 1 : 0) + @{$vars{win}//[]};
+      my $dcols_required = $nrows ? (int($items/$nrows) + !!($items%$nrows)) : 0;
+      my $rows_required = $ncols ? int($items/$ncols) + !!($items%$ncols) : 0;
+      $rows_required = abs $vars{ml}
+	  if ($vars{ml} < 0 || ($vars{ml} > 0 && $rows_required > $vars{ml}));
+      $dcols_required = abs $vars{mc}
+	  if ($vars{mc} < 0 || ($vars{mc} > 0 && $dcols_required > $vars{mc}));
+      my $rows = $rows_required + $vars{ha};
+      my $cols = ($dcols_required * ($vars{seplen} + abs $vars{block})) - $vars{seplen};
+      if (_match_tmux()) {
+	  my $pos_flag;
+	  my $before = 0;
+	  if ($integration_position eq 'left') {
+	      $pos_flag = 'h';
+	      $before = 1;
+	  }
+	  elsif ($integration_position eq 'top') {
+	      $pos_flag = 'v';
+	      $before = 1;
+	  }
+	  elsif ($integration_position eq 'right') {
+	      $pos_flag = 'h';
+	  }
+	  else {
+	      $pos_flag = 'v';
+	  }
+	  my @cmd;
+	  # hard tmux limits
+	  $cols = max($cols, 2);
+	  $rows = max($rows, 2);
+	  if ($pos_flag eq 'h' && $cols != $screenWidth) {
+	      my $change = $screenWidth - $cols;
+	      my $dir = ($before ^ ($change<0)) ? 'L' : 'R';
+	      push @cmd, "resizep -$dir -t $ENV{TMUX_PANE} @{[abs $change]}";
+	      #push @cmd, "resizep -x $cols -t $ENV{TMUX_PANE}";
+	      $one_shot_resize = 1;
+	  }
+	  if ($pos_flag eq 'v' && $rows != $screenHeight) {
+	      #push @cmd, "resizep -y $rows -t $ENV{TMUX_PANE}";
+	      my $change = $screenHeight - $rows;
+	      my $dir = ($before ^ ($change<0)) ? 'U' : 'D';
+	      push @cmd, "resizep -$dir -t $ENV{TMUX_PANE} @{[abs $change]}";
+	      $one_shot_resize = 1;
+	  }
+
+	  safe_qx("tmux " . (join " \\\; ", @cmd) . " 2>&1")
+	      if @cmd;
+      }
+      else {
+	  $cols = max($cols, 1);
+	  $rows = max($rows, 1);
+	  unless ($nrows > $ncols) { # line layout
+	      if ($rows != $screenHeight) {
+		  safe_qx("resize -s $rows $screenWidth 2>&1");
+		  $one_shot_resize = 1;
+	      }
+	  }
+	  else {
+	      if ($cols != $screenWidth) {
+		  safe_qx("resize -s $screenHeight $cols 2>&1");
+		  $one_shot_resize = 1;
+	      }
+	  }
+      }
+      if ($resized == 1) {
+	  handle_resize();
+      }
+  }
+
+  sub init_integration {
+      return unless $one_shot_integration;
+      if (_match_tmux()) {
+      }
+      else {
+      }
+      safe_print("\e]2;".(uc ::setc())."\e\\");
+  }
+
+  sub main {
+      require Getopt::Std;
+      my %opts;
+      Getopt::Std::getopts('1p:', \%opts);
+      my $one_shot = $opts{1};
+      $integration_position = $opts{p};
+      $one_shot_integration = 0+!!$one_shot;
+      #shift if @_ && $_[0] eq '--';
+      &init;
+      $show_title_bar = 0 if $ENV{AWL_NOTITLE};
+      init_integration();
+      until ($got_int) {
+	  $timeout = undef;
+	  if ($resized) {
+	      if ($resized == 1) {
+		  $timeout = 1;
+		  $resized++;
+	      }
+	      else {
+		  handle_resize();
+		  resize_integration();
+	      }
+	  }
+	  unless ($sock || $timeout) {
+	      connect_it();
+	  }
+	  $timeout ||= RECONNECT_TIME unless $sock;
+	  update_screen() if $disp_update;
+      SELECT: while (my @read = $loop->can_read($timeout)) {
+	      for my $fh (@read) {
+		  if ($fh == \*STDIN) {
+		      if (read STDIN, my $buf, BLOCK_SIZE) {
+			  do {
+			      $keybuf .= $buf;
+			  } while read STDIN, $buf, BLOCK_SIZE;
+		      }
+		      else {
+			  $got_int = 1;
+			  last SELECT;
+		      }
+		  }
+		  else {
+		      if ($fh->read(my $buf, BLOCK_SIZE)) {
+			  do {
+			      $rcvbuf .= $buf;
+			  } while $fh->read($buf, BLOCK_SIZE);
+		      }
+		      else {
+			  $disp_update = 1;
+			  remove_conn($fh);
+			  if ($one_shot) {
+			      $got_int = 1;
+			      last SELECT;
+			  }
+			  $timeout ||= RECONNECT_TIME;
+		      }
+		  }
+	      }
+	      $disp_update |= process_recv() if length $rcvbuf;
+	      process_keys() if length $keybuf;
+	      check_integration() if $one_shot;
+	      update_screen() if $disp_update;
+	  }
+	  continue {
+	  }
+      }
+      end_prog();
+  }
+}
+
+1;
+
+# Changelog
+# =========
+# 1.4
+# - fix line wrapping in some themes, reported by justanotherbody
+# - fix named window key detection, reported by madduck
+# - make title (in viewer and shared_sbar) configurable
+#
+# 1.3 - workaround for irssi issue #572
+# 1.2 - new format to choose abbreviation character
+# 1.1 - infinite loop on shortening certain window names reported by Kalan
+#
+# 1.0
+# - new awl_viewer_launch setting and an array of related settings
+# - fixed regression bug /exec -interactive
+# - fixed some warnings in perl 5.10 reported by kl3
+# - workaround for crash due to infinite recursion in irssi's Perl
+#   error handling
+#
+# 0.9
+# - fix endless loop in awin detection code!
+# - correct colour swap in awl_viewer
+# - fix passing of alternate socket path to the viewer
+# - potential undefinedness in mouse refnum hinted at by Canopus
+# - fixed regression bug /exec -interactive
+# - add case-insensitive modifier to awl_sort
+# - run custom_xform on awl_prefer_name also
+# - avoid inconsistent active window state after awin detection
+#   reported by ss
+# - revert %9-hack in the viewer prompted by discussion with pierrot
+# - fix new warning in perl 5.22
+#
+# 0.8
+# - replace fifo mode with external viewer script
+# - remove bundled cpan modules
+# - work around bogus irssi warning
+# - improve mouse support
+# - workaround for broken cumode in irssi 0.8.15
+# - fix handling of non-meta windows (uninitialized warning)
+# - add 256 colour support, strip true colour codes
+# - fix totally bogus $N padding reported by Ed S.
+# - make /window goto #name mappings work but ignore non-existant ones
+# - improve incomplete reads reported by bcode
+# - fix single % in awl_viewer reported by bcode
+# - add support for key bindings by nike and ferret
+# - coerce utf8 key binds
+# - add settings: custom_xform, last_line_shade, hide_name_data
+# - abbreviations were broken in some cases
+# - fix some misuse of / as cmdchar in mouse script reported by bcode
+# - add shared status bar mode
+# - ${type} variables for custom_xform setting
+# - crash if custom_xform had runtime error
+# - update sorting documentation
+# - fix odd case in size calculation noted by lasers
+# - add missing font styles to the viewer reported by ishanyx
+# - add italic
+#
+# 0.7g
+# - remove screen support and replace it with fifo support
+# - add double-width support to the shortener
+# - correct documentation regarding $T vs. display_header
+# - add missing refresh for window item changed (thanks vague)
+# - add visible windows
+# - add exemptions for active window
+# - workaround for hiding the window changes from trackbar
+# - hack to force 16colours in screen mode
+# - remember last window (reported by earthnative)
+# - wrong window focus on new queries (reported by emsid)
+# - dataloss bug on trying to remember last window
+#
+# 0.6d+
+# - add support for network headers
+# - fixed regression bug /exec -interactive
+#
+# 0.6ca+
+# - add screen support (from nicklist.pl)
+# - names can now have a max length and window names can be used
+# - fixed a bug with block display in screen mode and status bar mode
+# - added space handling to ir_fe and removed it again
+# - now handling formats on my own
+# - started to work on $tag display
+# - added warning about missing sb_act_none abstract leading to
+# - display*active settings
+# - added warning about the bug in awl_display_(no)key_active settings
+# - mouse hack
+#
+# 0.5d
+# - add setting to also hide the last status bar if empty (awl_all_disable)
+# - reverted to old utf8 code to also calculate broken utf8 length correctly
+# - simplified dealing with status bars in wlreset
+# - added a little tweak for the renamed term_type somewhere after Irssi 0.8.9
+# - fixed bug in handling channel #$$
+# - reset background colour at the beginning of an entry
+#
+# 0.4d
+# - fixed order of disabling status bars
+# - several attempts at special chars, without any real success
+#   and much more weird new bugs caused by this
+# - setting to specify sort order
+# - reduced timeout values
+# - added awl_hide_data
+# - make it so the dynamic sub is actually deleted
+# - fix a bug with removing of the last separator
+# - take into consideration parse_special
+#
+# 0.3b
+# - automatically kill old status bars
+# - reset on /reload
+# - position/placement settings
+#
+# 0.2
+# - automated retrieval of key bindings (thanks grep.pl authors)
+# - improved removing of status bars
+# - got rid of status chop
+#
+# 0.1
+# - Based on chanact.pl which was apparently based on lightbar.c and
+#   nicklist.pl with various other ideas from random scripts.
diff --git a/bots/blackhole/honeypot/.irssi/scripts/autorun/chansort.pl b/bots/blackhole/honeypot/.irssi/scripts/autorun/chansort.pl
@@ -0,0 +1,43 @@
+use strict;
+use Irssi;
+use Irssi::Irc;
+
+sub sig_sort_trigger {
+    return unless Irssi::settings_get_bool('chansort_autosort');
+    cmd_chansort();
+}
+
+sub cmd_chansort {
+    my(@windows);
+    my($minwin);
+    for my $win (Irssi::windows()) {
+	my $act = $win->{active};
+	my $key;
+	if ($act->{type} eq 'CHANNEL') {
+	    $key = "C".$act->{server}{tag}.' '.substr($act->{visible_name}, 1);
+	}
+	elsif ($act->{type} eq 'QUERY') {
+	    $key = "Q".$act->{server}{tag}.' '.$act->{visible_name};
+	}
+	else {
+	    next;
+	}
+	if (!defined($minwin) || $minwin > $win->{refnum}) {
+	    $minwin = $win->{refnum};
+	}
+	push @windows, [ lc $key, $win ];
+
+    }
+    for (sort {$a->[0] cmp $b->[0]} @windows) {
+	my($key,$win) = @$_;
+	my($act) = $win->{active};
+	$win->command("window move $minwin");
+	$minwin++;
+    }
+}
+
+Irssi::command_bind('chansort', 'cmd_chansort');
+Irssi::settings_add_bool('chansort', 'chansort_autosort', 0);
+Irssi::signal_add_last('window item name changed', 'sig_sort_trigger');
+Irssi::signal_add_last('channel created', 'sig_sort_trigger');
+Irssi::signal_add_last('query created', 'sig_sort_trigger');
+\ No newline at end of file
diff --git a/bots/blackhole/honeypot/.irssi/scripts/autorun/dispatch.pl b/bots/blackhole/honeypot/.irssi/scripts/autorun/dispatch.pl
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+use Irssi;
+use Irssi::Irc;
+
+sub event_default_command {
+    my ($command, $server) = @_;
+    return if (Irssi::settings_get_bool("dispatch_unknown_commands") == 0 || !$server);
+    $server->send_raw($command);
+    Irssi::signal_stop();
+}
+
+Irssi::settings_add_bool("misc", "dispatch_unknown_commands", 1);
+Irssi::signal_add_first("default command", "event_default_command");
diff --git a/bots/blackhole/honeypot/.irssi/scripts/autorun/killreconnect.pl b/bots/blackhole/honeypot/.irssi/scripts/autorun/killreconnect.pl
@@ -0,0 +1,12 @@
+use strict;
+use Irssi;
+
+Irssi::signal_add('event error', sub { Irssi::signal_stop(); });
+
+Irssi::signal_add('event kill', sub {
+    my ($server, $args, $nick, $address) = @_;
+    my $reason = $args;
+    $reason =~ s/^.*://g;
+    Irssi::print("You were killed by $nick ($reason)."); 
+    Irssi::signal_stop(); 
+});
+\ No newline at end of file
diff --git a/bots/blackhole/honeypot/.irssi/scripts/autorun/nickcolor.pl b/bots/blackhole/honeypot/.irssi/scripts/autorun/nickcolor.pl
@@ -0,0 +1,145 @@
+use strict;
+use Irssi 20020101.0250 ();
+use vars qw($VERSION %IRSSI); 
+$VERSION = "2";
+%IRSSI = (
+    authors     => "Timo Sirainen, Ian Peters, David Leadbeater",
+    contact	=> "tss\@iki.fi", 
+    name        => "Nick Color",
+    description => "assign a different color for each nick",
+    license	=> "Public Domain",
+    url		=> "http://irssi.org/",
+    changed	=> "Sun 15 Jun 19:10:44 BST 2014",
+);
+
+# Settings:
+#   nickcolor_colors: List of color codes to use.
+#   e.g. /set nickcolor_colors 2 3 4 5 6 7 9 10 11 12 13
+#   (avoid 8, as used for hilights in the default theme).
+
+my %saved_colors;
+my %session_colors = {};
+
+sub load_colors {
+  open my $color_fh, "<", "$ENV{HOME}/.irssi/saved_colors";
+  while (<$color_fh>) {
+    chomp;
+    my($nick, $color) = split ":";
+    $saved_colors{$nick} = $color;
+  }
+}
+
+sub save_colors {
+  open COLORS, ">", "$ENV{HOME}/.irssi/saved_colors";
+
+  foreach my $nick (keys %saved_colors) {
+    print COLORS "$nick:$saved_colors{$nick}\n";
+  }
+
+  close COLORS;
+}
+
+# If someone we've colored (either through the saved colors, or the hash
+# function) changes their nick, we'd like to keep the same color associated
+# with them (but only in the session_colors, ie a temporary mapping).
+
+sub sig_nick {
+  my ($server, $newnick, $nick, $address) = @_;
+  my $color;
+
+  $newnick = substr ($newnick, 1) if ($newnick =~ /^:/);
+
+  if ($color = $saved_colors{$nick}) {
+    $session_colors{$newnick} = $color;
+  } elsif ($color = $session_colors{$nick}) {
+    $session_colors{$newnick} = $color;
+  }
+}
+
+# This gave reasonable distribution values when run across
+# /usr/share/dict/words
+
+sub simple_hash {
+  my ($string) = @_;
+  chomp $string;
+  my @chars = split //, $string;
+  my $counter;
+
+  foreach my $char (@chars) {
+    $counter += ord $char;
+  }
+
+  my @colors = split / /, Irssi::settings_get_str('nickcolor_colors');
+  $counter = $colors[$counter % @colors];
+
+  return $counter;
+}
+
+sub sig_public {
+  my ($server, $msg, $nick, $address, $target) = @_;
+
+  # Has the user assigned this nick a color?
+  my $color = $saved_colors{$nick};
+
+  # Have -we- already assigned this nick a color?
+  if (!$color) {
+    $color = $session_colors{$nick};
+  }
+
+  # Let's assign this nick a color
+  if (!$color) {
+    $color = simple_hash $nick;
+    $session_colors{$nick} = $color;
+  }
+
+  $color = sprintf "\003%02d", $color;
+  $server->command('/^format pubmsg {pubmsgnick $2 {pubnick ' . $color . '$0}}$1');
+}
+
+sub cmd_color {
+  my ($data, $server, $witem) = @_;
+  my ($op, $nick, $color) = split " ", $data;
+
+  $op = lc $op;
+
+  if (!$op) {
+    Irssi::print ("No operation given (save/set/clear/list/preview)");
+  } elsif ($op eq "save") {
+    save_colors;
+  } elsif ($op eq "set") {
+    if (!$nick) {
+      Irssi::print ("Nick not given");
+    } elsif (!$color) {
+      Irssi::print ("Color not given");
+    } elsif ($color < 2 || $color > 14) {
+      Irssi::print ("Color must be between 2 and 14 inclusive");
+    } else {
+      $saved_colors{$nick} = $color;
+    }
+  } elsif ($op eq "clear") {
+    if (!$nick) {
+      Irssi::print ("Nick not given");
+    } else {
+      delete ($saved_colors{$nick});
+    }
+  } elsif ($op eq "list") {
+    Irssi::print ("\nSaved Colors:");
+    foreach my $nick (keys %saved_colors) {
+      Irssi::print (chr (3) . "$saved_colors{$nick}$nick" .
+		    chr (3) . "1 ($saved_colors{$nick})");
+    }
+  } elsif ($op eq "preview") {
+    Irssi::print ("\nAvailable colors:");
+    foreach my $i (2..14) {
+      Irssi::print (chr (3) . "$i" . "Color #$i");
+    }
+  }
+}
+
+load_colors;
+
+Irssi::settings_add_str('misc', 'nickcolor_colors', '2 3 4 5 6 7 9 10 11 12 13');
+Irssi::command_bind('color', 'cmd_color');
+
+Irssi::signal_add('message public', 'sig_public');
+Irssi::signal_add('event nick', 'sig_nick');
+\ No newline at end of file
diff --git a/bots/blackhole/honeypot/.irssi/scripts/autorun/rejoin.pl b/bots/blackhole/honeypot/.irssi/scripts/autorun/rejoin.pl
@@ -0,0 +1,31 @@
+use Irssi;
+use Irssi::Irc;
+use strict;
+
+my $delay  = 1;
+my $acttag = 0;
+my @tags;
+
+sub rejoin {
+    my ( $data ) = @_;
+    my ( $tag, $servtag, $channel, $pass ) = split( / +/, $data );
+    my $server = Irssi::server_find_tag( $servtag );
+    $server->send_raw( "JOIN $channel $pass" ) if ( $server );
+    Irssi::timeout_remove( $tags[$tag] );
+}
+
+sub event_rejoin_kick {
+    my ( $server, $data ) = @_;
+    my ( $channel, $nick ) = split( / +/, $data );
+    return if ( $server->{ nick } ne $nick );
+    my $chanrec = $server->channel_find( $channel );
+    my $password = $chanrec->{ key } if ( $chanrec );
+    my $rejoinchan = $chanrec->{ name } if ( $chanrec );
+    my $servtag = $server->{ tag };
+    Irssi::print "Rejoining $rejoinchan in $delay seconds.";
+    $tags[$acttag] = Irssi::timeout_add( $delay * 1000, "rejoin", "$acttag $servtag $rejoinchan $password" );
+    $acttag++;
+    $acttag = 0 if ( $acttag > 60 );
+}
+
+Irssi::signal_add('event kick', 'event_rejoin_kick');
+\ No newline at end of file
diff --git a/bots/blackhole/honeypot/.irssi/scripts/autorun/trigger.pl b/bots/blackhole/honeypot/.irssi/scripts/autorun/trigger.pl
@@ -0,0 +1,1248 @@
+# trigger.pl - execute a command or replace text, triggered by an event in irssi
+# Do /TRIGGER HELP or look at http://wouter.coekaerts.be/irssi/ for help
+
+# Copyright (C) 2002-2010  Wouter Coekaerts <wouter@coekaerts.be>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+use strict;
+use Irssi 20020324 qw(command_bind command_runsub command signal_add_first signal_continue signal_stop signal_remove);
+use Text::ParseWords;
+use IO::File;
+use vars qw($VERSION %IRSSI);
+
+$VERSION = '1.0+';
+%IRSSI = (
+	authors     => 'Wouter Coekaerts',
+	contact     => 'wouter@coekaerts.be',
+	name        => 'trigger',
+	description => 'execute a command or replace text, triggered by an event in irssi',
+	license     => 'GPLv2 or later',
+	url         => 'http://wouter.coekaerts.be/irssi/',
+	changed     => '$LastChangedDate: 2009-02-07 21:35:47 +0100 (Sat, 07 Feb 2009) $',
+);
+
+sub cmd_help {
+	Irssi::print (<<'SCRIPTHELP_EOF', MSGLEVEL_CLIENTCRAP);
+
+TRIGGER LIST
+TRIGGER SAVE
+TRIGGER RELOAD
+TRIGGER MOVE <number> <number>
+TRIGGER DELETE <number>
+TRIGGER CHANGE <number> ...
+TRIGGER ADD ...
+
+%U%_When to match%_%U 
+%UOn which types of event to trigger%U 
+     These are simply specified by -name_of_the_type
+     The normal IRC event types are:
+          publics, %|privmsgs, (pub|priv)actions, (pub|priv)notices, (pub|priv)ctcps, (pub|priv)ctcpreplies, joins, parts, quits, kicks, topics, invites, nick_changes, dcc_msgs, dcc_actions, dcc_ctcps
+          mode_channel: %|a mode on the (whole) channel (like +t, +i, +b)
+          mode_nick: %|a mode on someone in the channel (like +o, +v)
+     -all is an alias for all of those.
+     Additionally, there is:
+          rawin: %|raw text incoming from the server
+          send_command: %|commands you give to irssi
+          send_text: %|lines you type that aren't commands
+          beep: %|when irssi beeps
+          notify_join: %|someone in you notify list comes online
+          notify_part: %|someone in your notify list goes offline
+          notify_away: %|someone in your notify list goes away
+          notify_unaway: %|someone in your notify list goes unaway
+          notify_unidle: %|someone in your notify list stops idling
+          (pub|priv)flood: %|flood in a channel or in private detected. See /set flood. Be careful, these flood signals can trigger many times for one flood (unless you have autoignore enabled)
+
+%UFilters (conditions) the event has to satisfy%U 
+They all take one parameter. If you can give a list, seperate elements by space and use quotes around the list.
+All filters except for -pattern and -regexp can also be inversed by prefixing with -not_.
+     -pattern: %|The message must match the given pattern. ? and * can be used as wildcards
+     -regexp: %|The message must match the given regexp. (see man perlre)
+       %|if -nocase is given as an option, the regexp or pattern is matched case insensitive
+     -tags: %|The servertag must be in the given list of tags
+     -channels: %|The event must be in one of the given list of channels.
+                Examples: %|-channels '#chan1 #chan2' or -channels 'IRCNet/#channel'
+                          %|-channels 'EFNet/' means every channel on EFNet and is the same as -tags 'EFNet'
+     -masks: %|The person who triggers it must match one of the given list of masks
+     -hasmode: %|The person who triggers it must have the give mode
+               Examples: %|'-o' means not opped, '+ov' means opped OR voiced, '-o&-v' means not opped AND not voiced
+     -hasflag: %|Only trigger if friends.pl (friends_shasta.pl) or people.pl is loaded and the person who triggers it has the given flag in the script (same syntax as -hasmode)
+     -other_masks
+     -other_hasmode
+     -other_hasflag: %|Same as above but for the victim for kicks or mode_nick.
+
+%U%_What to do when it matches%_%U 
+     -command: Execute the given Irssi-command
+                %|You are able to use $1, $2 and so on generated by your regexp pattern.
+                %|For multiple commands ; can be used as seperator
+                %|The following variables are also expanded:
+                   $T: %|Server tag
+                   $C: %|Channel name
+                   $N: %|Nickname of the person who triggered this command
+                   $A: %|His address (foo@bar.com),
+                   $I: %|His ident (foo)
+                   $H: %|His hostname (bar.com)
+                   $M: %|The complete message
+                   ${other}: %|The victim for kicks or mode_nick
+                   ${mode_type}: %|The type ('+' or '-') for a mode_channel or mode_nick
+                   ${mode_char}: %|The mode char ('o' for ops, 'b' for ban,...)
+                   ${mode_arg} : %|The argument to the mode (if there is one)
+                %|$\X, with X being one of the above expands (e.g. $\M), escapes all non-alphanumeric characters, so it can be used with /eval or /exec. Don't use /eval or /exec without this, it's not safe.
+     -replace: %|replaces the matching part with the given replacement in the event (requires a -regexp or -pattern)
+     -once: %|remove the trigger if it is triggered, so it only executes once and then is forgotten.
+     -stop: %|stops the signal. It won't get displayed by Irssi. Like /IGNORE
+     -debug: %|print some debugging info
+
+%U%_Other options%_%U 
+     -disabled: %|Same as removing it, but keeps it in case you might need it later
+     -name: %|Give the trigger a name. You can refer to the trigger with this name in add/del/change commands
+
+%U%_Examples%_%U 
+ Knockout people who do a !list:
+   %#/TRIGGER ADD %|-publics -channels "#channel1 #channel2" -nocase -regexp ^!list -command "KN $N This is not a warez channel!"
+ React to !echo commands from people who are +o in your friends-script:
+   %#/TRIGGER ADD %|-publics -regexp '^!echo (.*)' -hasflag '+o' -command 'say echo: $1'
+ Ignore all non-ops on #channel:
+   %#/TRIGGER ADD %|-publics -actions -channels "#channel" -hasmode '-o' -stop
+ Send a mail to yourself every time a topic is changed:
+   %#/TRIGGER ADD %|-topics -command 'exec echo $\N changed topic of $\C to: $\M | mail you@somewhere.com -s topic'
+
+
+%U%_Examples with -replace%_%U 
+ %|Replace every occurence of shit with sh*t, case insensitive:
+   %#/TRIGGER ADD %|-all -nocase -regexp shit -replace sh*t
+ %|Strip all colorcodes from *!lamer@*:
+   %#/TRIGGER ADD %|-all -masks *!lamer@* -regexp '\x03\d?\d?(,\d\d?)?|\x02|\x1f|\x16|\x06' -replace ''
+ %|Never let *!bot1@foo.bar or *!bot2@foo.bar hilight you
+ %|(this works by cutting your nick in 2 different parts, 'myn' and 'ick' here)
+ %|you don't need to understand the -replace argument, just trust that it works if the 2 parts separately don't hilight:
+   %#/TRIGGER ADD %|-all masks '*!bot1@foo.bar *!bot2@foo.bar' -regexp '(myn)(ick)' -nocase -replace '$1\x02\x02$2'
+ %|Avoid being hilighted by !top10 in eggdrops with stats.mod (but show your nick in bold):
+   %#/TRIGGER ADD %|-publics -regexp '(Top.0\(.*\): 1.*)(my)(nick)' -replace '$1\x02$2\x02\x02$3\x02'
+ %|Convert a Windows-1252 Euro to an ISO-8859-15 Euro (same effect as euro.pl):
+   %#/TRIGGER ADD %|-regexp '\x80' -replace '\xA4'
+ %|Show tabs as spaces, not the inverted I (same effect as tab_stop.pl):
+   %#/TRIGGER ADD %|-all -regexp '\t' -replace '    '
+SCRIPTHELP_EOF
+} # /
+
+my @triggers; # array of all triggers
+my %triggers_by_type; # hash mapping types on triggers of that type
+my $recursion_depth = 0;
+my $changed_since_last_save = 0;
+
+###############
+### formats ###
+###############
+
+Irssi::theme_register([
+	'trigger_header' => 'Triggers:',
+	'trigger_line' => '%#$[-4]0 $1',
+	'trigger_added' => 'Trigger $0 added: $1',
+	'trigger_not_found' => 'Trigger {hilight $0} not found',
+	'trigger_saved' => 'Triggers saved to $0',
+	'trigger_loaded' => 'Triggers loaded from $0'
+]);
+
+#########################################
+### catch the signals & do your thing ###
+#########################################
+
+# trigger types with a message and a channel
+my @allchanmsg_types = qw(publics pubactions pubnotices pubctcps pubctcpreplies parts quits kicks topics);
+# trigger types with a message
+my @allmsg_types = (@allchanmsg_types, qw(privmsgs privactions privnotices privctcps privctcpreplies dcc_msgs dcc_actions dcc_ctcps));
+# trigger types with a channel
+my @allchan_types = (@allchanmsg_types, qw(mode_channel mode_nick joins invites pubflood));
+# trigger types in -all
+my @all_types = (@allmsg_types, qw(mode_channel mode_nick joins invites nick_changes));
+# trigger types with a server
+my @all_server_types = (@all_types, qw(rawin notify_join notify_part notify_away notify_unaway notify_unidle pubflood privflood));
+# all trigger types
+my @trigger_types = (@all_server_types, qw(send_command send_text beep));
+#trigger types that are not in -all
+#my @notall_types = grep {my $a=$_; return (!grep {$_ eq $a} @all_types);} @trigger_types;
+my @notall_types = qw(rawin notify_join notify_part notify_away notify_unaway notify_unidle send_command send_text beep pubflood privflood);
+
+my @signals = (
+# "message public", SERVER_REC, char *msg, char *nick, char *address, char *target
+{
+	'types' => ['publics'],
+	'signal' => 'message public',
+	'sub' => sub {check_signal_message(\@_,1,$_[0],$_[4],$_[2],$_[3],'publics');},
+},
+# "message private", SERVER_REC, char *msg, char *nick, char *address
+{
+	'types' => ['privmsgs'],
+	'signal' => 'message private',
+	'sub' => sub {check_signal_message(\@_,1,$_[0],undef,$_[2],$_[3],'privmsgs');},
+},
+# "message irc action", SERVER_REC, char *msg, char *nick, char *address, char *target
+{
+	'types' => ['privactions','pubactions'],
+	'signal' => 'message irc action',
+	'sub' => sub {
+		if ($_[4] eq $_[0]->{nick}) {
+			check_signal_message(\@_,1,$_[0],undef,$_[2],$_[3],'privactions');
+		} else {
+			check_signal_message(\@_,1,$_[0],$_[4],$_[2],$_[3],'pubactions');
+		}
+	},
+},
+# "message irc notice", SERVER_REC, char *msg, char *nick, char *address, char *target
+{
+	'types' => ['privnotices','pubnotices'],
+	'signal' => 'message irc notice',
+	'sub' => sub {
+		if ($_[4] eq $_[0]->{nick}) {
+			check_signal_message(\@_,1,$_[0],undef,$_[2],$_[3],'privnotices');
+		} else {
+			check_signal_message(\@_,1,$_[0],$_[4],$_[2],$_[3],'pubnotices');
+		}
+	}
+},
+# "message join", SERVER_REC, char *channel, char *nick, char *address
+{
+	'types' => ['joins'],
+	'signal' => 'message join',
+	'sub' => sub {check_signal_message(\@_,-1,$_[0],$_[1],$_[2],$_[3],'joins');}
+},
+# "message part", SERVER_REC, char *channel, char *nick, char *address, char *reason
+{
+	'types' => ['parts'],
+	'signal' => 'message part',
+	'sub' => sub {check_signal_message(\@_,4,$_[0],$_[1],$_[2],$_[3],'parts');}
+},
+# "message quit", SERVER_REC, char *nick, char *address, char *reason
+{
+	'types' => ['quits'],
+	'signal' => 'message quit',
+	'sub' => sub {check_signal_message(\@_,3,$_[0],undef,$_[1],$_[2],'quits');}
+},
+# "message kick", SERVER_REC, char *channel, char *nick, char *kicker, char *address, char *reason
+{
+	'types' => ['kicks'],
+	'signal' => 'message kick',
+	'sub' => sub {check_signal_message(\@_,5,$_[0],$_[1],$_[3],$_[4],'kicks',{'other'=>$_[2]});}
+},
+# "message topic", SERVER_REC, char *channel, char *topic, char *nick, char *address
+{
+	'types' => ['topics'],
+	'signal' => 'message topic',
+	'sub' => sub {check_signal_message(\@_,2,$_[0],$_[1],$_[3],$_[4],'topics');}
+},
+# "message invite", SERVER_REC, char *channel, char *nick, char *address
+{
+	'types' => ['invites'],
+	'signal' => 'message invite',
+	'sub' => sub {check_signal_message(\@_,-1,$_[0],$_[1],$_[2],$_[3],'invites');}
+},
+# "message nick", SERVER_REC, char *newnick, char *oldnick, char *address
+{
+	'types' => ['nick_changes'],
+	'signal' => 'message nick',
+	'sub' => sub {check_signal_message(\@_,-1,$_[0],undef,$_[1],$_[3],'nick_changes');}
+},
+# "message dcc", DCC_REC *dcc, char *msg
+{
+	'types' => ['dcc_msgs'],
+	'signal' => 'message dcc',
+	'sub' => sub {check_signal_message(\@_,1,$_[0]->{'server'},undef,$_[0]->{'nick'},undef,'dcc_msgs');
+	}
+},
+# "message dcc action", DCC_REC *dcc, char *msg
+{
+	'types' => ['dcc_actions'],
+	'signal' => 'message dcc action',
+	'sub' => sub {check_signal_message(\@_,1,$_[0]->{'server'},undef,$_[0]->{'nick'},undef,'dcc_actions');}
+},
+# "message dcc ctcp", DCC_REC *dcc, char *cmd, char *data
+{
+	'types' => ['dcc_ctcps'],
+	'signal' => 'message dcc ctcp',
+	'sub' => sub {check_signal_message(\@_,1,$_[0]->{'server'},undef,$_[0]->{'nick'},undef,'dcc_ctcps');}
+},
+# "server incoming", SERVER_REC, char *data
+{
+	'types' => ['rawin'],
+	'signal' => 'server incoming',
+	'sub' => sub {check_signal_message(\@_,1,$_[0],undef,undef,undef,'rawin');}
+},
+# "send command", char *args, SERVER_REC, WI_ITEM_REC
+{
+	'types' => ['send_command'],
+	'signal' => 'send command',
+	'sub' => sub {
+		sig_send_text_or_command(\@_,1);
+	}
+},
+# "send text", char *line, SERVER_REC, WI_ITEM_REC
+{
+	'types' => ['send_text'],
+	'signal' => 'send text',
+	'sub' => sub {
+		sig_send_text_or_command(\@_,0);
+	}
+},
+# "beep"
+{
+	'types' => ['beep'],
+	'signal' => 'beep',
+	'sub' => sub {check_signal_message(\@_,-1,undef,undef,undef,undef,'beep');}
+},
+# "event "<cmd>, SERVER_REC, char *args, char *sender_nick, char *sender_address
+{
+	'types' => ['mode_channel', 'mode_nick'],
+	'signal' => 'event mode',
+	'sub' => sub {
+		my ($server, $event_args, $nickname, $address) = @_;
+		my ($target, $modes, $modeargs) = split(/ /, $event_args, 3);
+		return if (!$server->ischannel($target));
+		my (@modeargs) = split(/ /,$modeargs);
+		my ($pos, $type, $event_type, $arg) = (0, '+');
+		foreach my $char (split(//,$modes)) {
+			if ($char eq "+" || $char eq "-") {
+				$type = $char;
+			} else {
+				if ($char =~ /[Oovh]/) { # mode_nick
+					$event_type = 'mode_nick';
+					$arg = $modeargs[$pos++];
+				} elsif ($char =~ /[beIqdk]/ || ( $char =~ /[lfJ]/ && $type eq '+')) { # chan_mode with arg
+					$event_type = 'mode_channel';
+					$arg = $modeargs[$pos++];
+				} else { # chan_mode without arg
+					$event_type = 'mode_channel';
+					$arg = undef;
+				}
+				check_signal_message(\@_,-1,$server,$target,$nickname,$address,$event_type,{
+					'mode_type' => $type,
+					'mode_char' => $char,
+					'mode_arg' => $arg,
+					'other' => ($event_type eq 'mode_nick') ? $arg : undef
+				});
+			}
+		}
+	}
+},
+# "notifylist joined", SERVER_REC, char *nick, char *user, char *host, char *realname, char *awaymsg
+{
+	'types' => ['notify_join'],
+	'signal' => 'notifylist joined',
+	'sub' => sub {check_signal_message(\@_, 5, $_[0], undef, $_[1], $_[2].'@'.$_[3], 'notify_join', {'realname' => $_[4]});}
+},
+{
+	'types' => ['notify_part'],
+	'signal' => 'notifylist left',
+	'sub' => sub {check_signal_message(\@_, 5, $_[0], undef, $_[1], $_[2].'@'.$_[3], 'notify_left', {'realname' => $_[4]});}
+},
+{
+	'types' => ['notify_unidle'],
+	'signal' => 'notifylist unidle',
+	'sub' => sub {check_signal_message(\@_, 5, $_[0], undef, $_[1], $_[2].'@'.$_[3], 'notify_unidle', {'realname' => $_[4]});}
+},
+{
+	'types' => ['notify_away', 'notify_unaway'],
+	'signal' => 'notifylist away changed',
+	'sub' => sub {check_signal_message(\@_, 5, $_[0], undef, $_[1], $_[2].'@'.$_[3], ($_[5] ? 'notify_away' : 'notify_unaway'), {'realname' => $_[4]});}
+},
+# "ctcp msg", SERVER_REC, char *args, char *nick, char *addr, char *target
+{
+	'types' => ['pubctcps', 'privctcps'],
+	'signal' => 'ctcp msg',
+	'sub' => sub {
+		my ($server, $args, $nick, $addr, $target) = @_;
+		if ($target eq $server->{'nick'}) {
+			check_signal_message(\@_, 1, $server, undef, $nick, $addr, 'privctcps');
+		} else {
+			check_signal_message(\@_, 1, $server, $target, $nick, $addr, 'pubctcps');
+		}
+	}
+},
+# "ctcp reply", SERVER_REC, char *args, char *nick, char *addr, char *target
+{
+	'types' => ['pubctcpreplies', 'privctcpreplies'],
+	'signal' => 'ctcp reply',
+	'sub' => sub {
+		my ($server, $args, $nick, $addr, $target) = @_;
+		if ($target eq $server->{'nick'}) {
+			check_signal_message(\@_, 1, $server, undef, $nick, $addr, 'privctcpreplies');
+		} else {
+			check_signal_message(\@_, 1, $server, $target, $nick, $addr, 'pubctcpreplies');
+		}
+	}
+},
+# "flood", SERVER_REC, char *nick, char *host, int level, char *target
+{
+	'types' => ['pubflood', 'privflood'],
+	'signal' => 'flood',
+	'sub' => sub {
+		my ($server, $nick, $host, $level, $target) = @_;
+		if ($target eq $server->{'nick'}) {
+			check_signal_message(\@_, -1, $server, undef, $nick, $host, 'privflood');
+		} else {
+			check_signal_message(\@_, -1, $server, $target, $nick, $host, 'pubflood');
+		}
+	}
+}
+);
+
+sub sig_send_text_or_command {
+	my ($signal, $iscommand) = @_;
+	my ($line, $server, $item) = @$signal;
+	my ($channelname,$nickname,$address) = (undef,undef,undef);
+	if ($item && (ref($item) eq 'Irssi::Irc::Channel' || ref($item) eq 'Irssi::Silc::Channel')) {
+		$channelname = $item->{'name'};
+	} elsif ($item && ref($item) eq 'Irssi::Irc::Query') { # TODO Silc query ?
+		$nickname = $item->{'name'};
+		$address = $item->{'address'}
+	}
+	# TODO pass context also for non-channels (queries and other stuff)
+	check_signal_message($signal,0,$server,$channelname,$nickname,$address,$iscommand ? 'send_command' : 'send_text');
+
+}
+
+my %filters = (
+'tags' => {
+	'types' => \@all_server_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		
+		if (!defined($server)) {
+			return 0;
+		}
+		my $matches = 0;
+		foreach my $tag (split(/ /,$param)) {
+			if (lc($server->{'tag'}) eq lc($tag)) {
+				$matches = 1;
+				last;
+			}
+		}
+		return $matches;
+	}
+},
+'channels' => {
+	'types' => \@allchan_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		
+		if (!defined($channelname) || !defined($server)) {
+			return 0;
+		}
+		my $matches = 0;
+		foreach my $trigger_channel (split(/ /,$param)) {
+			if (lc($channelname) eq lc($trigger_channel)
+				|| lc($server->{'tag'}.'/'.$channelname) eq lc($trigger_channel)
+				|| lc($server->{'tag'}.'/') eq lc($trigger_channel)) {
+				$matches = 1;
+				last; # this channel matches, stop checking channels
+			}
+		}
+		return $matches;
+	}
+},
+'masks' => {
+	'types' => \@all_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return  (defined($nickname) && defined($address) && defined($server) && $server->masks_match($param, $nickname, $address));
+	}
+},
+'other_masks' => {
+	'types' => ['kicks', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return 0 unless defined($extra->{'other'});
+		my $other_address = get_address($extra->{'other'}, $server, $channelname);
+		return defined($other_address) && $server->masks_match($param, $extra->{'other'}, $other_address);
+	}
+},
+'hasmode' => {
+	'types' => \@all_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return hasmode($param, $nickname, $server, $channelname);
+	}
+},
+'other_hasmode' => {
+	'types' => ['kicks', 'mode_nick'],
+	'sub' => sub {
+		my ($param,$signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return defined($extra->{'other'}) && hasmode($param, $extra->{'other'}, $server, $channelname);
+	}
+},
+'hasflag' => {
+	'types' => \@all_types,
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return 0 unless defined($nickname) && defined($address) && defined($server);
+		my $flags = get_flags ($server->{'chatnet'},$channelname,$nickname,$address);
+		return defined($flags) && check_modes($flags,$param);
+	}
+},
+'other_hasflag' => {
+	'types' => ['kicks', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return 0 unless defined($extra->{'other'});
+		my $other_address = get_address($extra->{'other'}, $server, $channelname);
+		return 0 unless defined($other_address);
+		my $flags = get_flags ($server->{'chatnet'},$channelname,$extra->{'other'},$other_address);
+		return defined($flags) && check_modes($flags,$param);
+	}
+},
+'mode_type' => {
+	'types' => ['mode_channel', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return (($param) eq $extra->{'mode_type'});
+	}
+},
+'mode_char' => {
+	'types' => ['mode_channel', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return (($param) eq $extra->{'mode_char'});
+	}
+},
+'mode_arg' => {
+	'types' => ['mode_channel', 'mode_nick'],
+	'sub' => sub {
+		my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
+		return (($param) eq $extra->{'mode_arg'});
+	}
+}
+);
+
+sub get_address {
+	my ($nick, $server, $channel) = @_;
+	my $nickrec = get_nickrec($nick, $server, $channel);
+	return $nickrec ? $nickrec->{'host'} : undef;
+}
+sub get_nickrec {
+	my ($nick, $server, $channel) = @_;
+	return unless defined($server) && defined($channel) && defined($nick);
+	my $chanrec = $server->channel_find($channel);
+	return $chanrec ? $chanrec->nick_find($nick) : undef;
+}
+
+sub hasmode {
+	my ($param, $nickname, $server, $channelname) = @_;
+	my $nickrec = get_nickrec($nickname, $server, $channelname);
+	return 0 unless defined $nickrec;
+	my $modes =
+		($nickrec->{'op'} ? 'o' : '')
+		. ($nickrec->{'voice'} ? 'v' : '')
+		. ($nickrec->{'halfop'} ? 'h' : '')
+	;
+	return check_modes($modes, $param);
+}
+
+# list of all switches
+my @trigger_switches = (@trigger_types, qw(all nocase stop once debug disabled));
+# parameters (with an argument)
+my @trigger_params = qw(pattern regexp command replace name);
+# all options that can be used to set filters, including negative matches (not_<filter>)
+my @trigger_filter_options = map(($_,'not_'.$_), keys(%filters));
+# list of all options (including switches) for /TRIGGER ADD
+my @trigger_add_options = (@trigger_switches, @trigger_params, @trigger_filter_options);
+# same for /TRIGGER CHANGE, this includes the -no<option>'s
+my @trigger_options = map(($_,'no'.$_) ,@trigger_add_options);
+
+# check the triggers on $signal's $parammessage parameter, for triggers with $condition set
+#  on $server in $channelname, for $nickname!$address
+# set $parammessage to -1 if the signal doesn't have a message
+# for signal without channel, nick or address, set to undef
+sub check_signal_message {
+	my ($signal, $parammessage, $server, $channelname, $nickname, $address, $condition, $extra) = @_;
+	my ($changed, $stopped, $context, $need_rebuild);
+	my $message = ($parammessage == -1) ? '' : $signal->[$parammessage];
+
+	return if (!$triggers_by_type{$condition});
+	
+	if ($recursion_depth > 10) {
+		Irssi::print("Trigger error: Maximum recursion depth reached, aborting trigger.", MSGLEVEL_CLIENTERROR);
+		return;
+	}
+	$recursion_depth++;
+
+TRIGGER:	
+	foreach my $trigger (@{$triggers_by_type{$condition}}) {
+		# check filters
+		foreach my $trigfilter (filters_for_trigger($trigger)) {
+			my $filter_sub = $trigfilter->{'filter'}->{'sub'};
+			my $filter_matches = !!(&$filter_sub($trigfilter->{'param'}, $signal, $parammessage, $server, $channelname, $nickname, $address, $condition, $extra));
+			if ($filter_matches != $trigfilter->{'must_match'}) { # if it didn't match, or if it's a -not_* filter and it did match
+				next TRIGGER;
+			}
+		}
+		
+		# check regexp (and keep matches in @- and @+, so don't make a this a {block})
+		next if ($trigger->{'compregexp'} && ($parammessage == -1 || $message !~ m/$trigger->{'compregexp'}/));
+		
+		# if we got this far, it fully matched, and we need to do the replace/command/stop/once
+		my $expands = $extra;
+		$expands->{'M'} = $message,;
+		$expands->{'T'} = (defined($server)) ? $server->{'tag'} : '';
+		$expands->{'C'} = $channelname;
+		$expands->{'N'} = $nickname;
+		$expands->{'A'} = $address;
+		$expands->{'I'} = ((!defined($address)) ? '' : substr($address,0,index($address,'@')));
+		$expands->{'H'} = ((!defined($address)) ? '' : substr($address,index($address,'@')+1));
+		$expands->{'$'} = '$';
+		$expands->{';'} = ';';
+
+		if (defined($trigger->{'replace'})) { # it's a -replace
+			$message =~ s/$trigger->{'compregexp'}/do_expands($trigger->{'compreplace'},$expands,$message)/ge;
+			$changed = 1;
+		}
+		
+		if ($trigger->{'command'}) { # it's a (nonempty) -command
+			my $command = $trigger->{'command'};
+			# $1 = the stuff behind the $ we want to expand: a number, or a character from %expands
+			$command = do_expands($command, $expands, $message);
+			
+			if (defined($server)) {
+				if (defined($channelname) && $server->channel_find($channelname)) {
+					$context = $server->channel_find($channelname);
+				} else {
+					$context = $server;
+				}
+			} else {
+				$context = undef;
+			}
+			
+			if (defined($context)) {
+				$context->command("eval $command");
+			} else {
+				Irssi::command("eval $command");
+			}
+		}
+
+		if ($trigger->{'debug'}) {
+			print("DEBUG: trigger $condition pmesg=$parammessage message=$message server=$server->{tag} channel=$channelname nick=$nickname address=$address " . join(' ',map {$_ . '=' . $extra->{$_}} keys(%$extra)));
+		}
+		
+		if ($trigger->{'stop'}) {
+			$stopped = 1;
+		}
+		
+		if ($trigger->{'once'}) {
+			# find this trigger in the real trigger list, and remove it
+			for (my $realindex=0; $realindex < scalar(@triggers); $realindex++) {
+				if ($triggers[$realindex] == $trigger) {
+					splice (@triggers,$realindex,1);
+					last;
+				}
+			}
+			$need_rebuild = 1;
+		}
+	}
+
+	if ($need_rebuild) {
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+	if ($stopped) { # stopped with -stop
+		signal_stop();
+	} elsif ($changed) { # changed with -replace
+		$signal->[$parammessage] = $message;
+		signal_continue(@$signal);
+	}
+	$recursion_depth--;
+}
+
+# return array of filters for the given trigger
+sub filters_for_trigger($) {
+	my ($trigger) = @_;
+	return values(%{$trigger->{'filters'}});
+}
+
+# used in check_signal_message to expand $'s
+# $inthis is a string that can contain $ stuff (like 'foo$1bar$N')
+sub do_expands {
+	my ($inthis, $expands, $from) = @_;
+	# @+ and @- are copied because there are two s/// nested, and the inner needs the $1 and $2,... of the outer one
+	my @plus = @+;
+	my @min = @-;
+	my $p = \@plus; my $m = \@min;
+	$inthis =~ s/\$(\\*(\d+|[^0-9x{]|x[0-9a-fA-F][0-9a-fA-F]|{.*?}))/expand_and_escape($1,$expands,$m,$p,$from)/ge;	
+	return $inthis;
+}
+
+# \ $ and ; need extra escaping because we use eval
+sub expand_and_escape {
+	my $retval = expand(@_);
+	$retval =~ s/([\\\$;])/\\\1/g;
+	return $retval;
+}
+
+# used in do_expands (via expand_and_escape), to_expand is the part after the $
+sub expand {
+	my ($to_expand, $expands, $min, $plus, $from) = @_;
+	if ($to_expand =~ /^\d+$/) { # a number => look up in $vars
+		# from man perlvar:
+		# $3 is the same as "substr $var, $-[3], $+[3] - $-[3])"
+		return ($to_expand > @{$min} ? '' : substr($from,$min->[$to_expand],$plus->[$to_expand]-$min->[$to_expand]));
+	} elsif ($to_expand =~ s/^\\//) { # begins with \, so strip that from to_expand
+		my $exp = expand($to_expand,$expands,$min,$plus,$from); # first expand without \
+		$exp =~ s/([^a-zA-Z0-9])/\\\1/g; # escape non-word chars
+		return $exp;
+	} elsif ($to_expand =~ /^x([0-9a-fA-F]{2})/) { # $xAA
+		return chr(hex($1));
+	} elsif ($to_expand =~ /^{(.*?)}$/) { # ${foo}
+		return expand($1, $expands, $min, $plus, $from);
+	} else { # look up in $expands
+		return $expands->{$to_expand};
+	}
+}
+
+sub check_modes {
+	my ($has_modes, $need_modes) = @_;
+	my $matches;
+	my $switch = 1; # if a '-' if found, will be 0 (meaning the modes should not be set)
+	foreach my $need_mode (split /&/, $need_modes) {
+		$matches = 0;
+		foreach my $char (split //, $need_mode) {
+			if ($char eq '-') {
+				$switch = 0;
+			} elsif ($char eq '+') {
+				$switch = 1;
+			} elsif ((index($has_modes, $char) != -1) == $switch) {
+				$matches = 1;
+				last;
+			}
+		}
+		if (!$matches) {
+			return 0;
+		}
+	}
+	return 1;
+}
+
+# get someones flags from people.pl or friends(_shasta).pl
+sub get_flags {
+	my ($chatnet, $channel, $nick, $address) = @_;
+	my $flags;
+	no strict 'refs';
+	if (%{ 'Irssi::Script::people::' }) {
+		if (defined ($channel)) {
+			$flags = (&{ 'Irssi::Script::people::find_local_flags' }($chatnet,$channel,$nick,$address));
+		} else {
+			$flags = (&{ 'Irssi::Script::people::find_global_flags' }($chatnet,$nick,$address));
+		}
+		$flags = join('',keys(%{$flags}));
+	} else {
+		my $shasta;
+		if (%{ 'Irssi::Script::friends_shasta::' }) {
+			$shasta = 'friends_shasta';
+		} elsif (defined &{ 'Irssi::Script::friends::get_idx' }) {
+			$shasta = 'friends';
+		} else {
+			return undef;
+		}
+		my $idx = (&{ 'Irssi::Script::'.$shasta.'::get_idx' }($nick, $address));
+		if ($idx == -1) {
+			return '';
+		}
+		$flags = (&{ 'Irssi::Script::'.$shasta.'::get_friends_flags' }($idx,undef));
+		if ($channel) {
+			$flags .= (&{ 'Irssi::Script::'.$shasta.'::get_friends_flags' }($idx,$channel));
+		}
+	}
+	return $flags;
+}
+
+########################################################
+### internal stuff called by manage, needed by above ###
+########################################################
+
+my %mask_to_regexp = ();
+foreach my $i (0..255) {
+    my $ch = chr $i;
+    $mask_to_regexp{$ch} = "\Q$ch\E";
+}
+$mask_to_regexp{'?'} = '(.)';
+$mask_to_regexp{'*'} = '(.*)';
+
+sub compile_trigger {
+	my ($trigger) = @_;
+	my $regexp;
+	
+	if ($trigger->{'regexp'}) {
+		$regexp = $trigger->{'regexp'};
+	} elsif ($trigger->{'pattern'}) {
+		$regexp = $trigger->{'pattern'};
+		$regexp =~ s/(.)/$mask_to_regexp{$1}/g;
+	} else {
+		delete $trigger->{'compregexp'};
+		return;
+	}
+	
+	if ($trigger->{'nocase'}) {
+		$regexp = '(?i)' . $regexp;
+	}
+	
+	$trigger->{'compregexp'} = qr/$regexp/;
+	
+	if(defined($trigger->{'replace'})) {
+		(my $replace = $trigger->{'replace'}) =~ s/\$/\$\$/g;
+		$trigger->{'compreplace'} = Irssi::parse_special($replace);
+	}
+}
+
+# rebuilds triggers_by_type and updates signal binds
+sub rebuild {
+	%triggers_by_type = ();
+	foreach my $trigger (@triggers) {
+		if (!$trigger->{'disabled'}) {
+			if ($trigger->{'all'}) {
+				# -all is an alias for all types in @all_types for which the filters can apply
+ALLTYPES:
+				foreach my $type (@all_types) {
+					# check if all filters can apply to $type
+					foreach my $trigfilter (filters_for_trigger($trigger)) {
+						if (! grep {$_ eq $type} @{$trigfilter->{'filter'}->{'types'}}) {
+							next ALLTYPES;
+						}
+					}
+					push @{$triggers_by_type{$type}}, ($trigger);
+				}
+			}
+			
+			foreach my $type ($trigger->{'all'} ? @notall_types : @trigger_types) {
+				if ($trigger->{$type}) {
+					push @{$triggers_by_type{$type}}, ($trigger);
+				}
+			}
+		}
+	}
+	
+	foreach my $signal (@signals) {
+		my $should_bind = 0;
+		foreach my $type (@{$signal->{'types'}}) {
+			if (defined($triggers_by_type{$type})) {
+				$should_bind = 1;
+			}
+		}
+		if ($should_bind && !$signal->{'bind'}) {
+			signal_add_first($signal->{'signal'}, $signal->{'sub'});
+			$signal->{'bind'} = 1;
+		} elsif (!$should_bind && $signal->{'bind'}) {
+			signal_remove($signal->{'signal'}, $signal->{'sub'});
+			$signal->{'bind'} = 0;
+		}
+	}
+}
+
+################################
+### manage the triggers-list ###
+################################
+
+my $trigger_file; # cached setting
+
+sub sig_setup_changed {
+	$trigger_file = Irssi::settings_get_str('trigger_file');
+}
+
+sub autosave {
+	cmd_save() if ($changed_since_last_save);
+}
+
+# TRIGGER SAVE
+sub cmd_save {
+	my $io = new IO::File $trigger_file, "w";
+	if (defined $io) {
+		$io->print("#Triggers file version $VERSION\n");
+		foreach my $trigger (@triggers) {
+			$io->print(to_string($trigger) . "\n");
+		}
+		$io->close;
+	}
+	Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'trigger_saved', $trigger_file);
+	$changed_since_last_save = 0;
+}
+
+# save on unload
+sub UNLOAD {
+	cmd_save();
+}
+
+# TRIGGER LOAD
+sub cmd_load {
+	sig_setup_changed(); # make sure we've read the trigger_file setting
+	my $converted = 0;
+	my $io = new IO::File $trigger_file, "r";
+	if (not defined $io) {
+		if (-e $trigger_file) {
+			Irssi::print("Error opening triggers file", MSGLEVEL_CLIENTERROR);
+		}
+		return;
+	}
+	if (defined $io) {
+		@triggers = ();
+		my $text;
+		$text = $io->getline;
+		my $file_version = '';
+		if ($text =~ /^#Triggers file version (.*)\n/) {
+			$file_version = $1;
+		}
+		if ($file_version lt '0.6.1+2') {
+			no strict 'vars';
+			$text .= $_ foreach ($io->getlines);
+			my $rep = eval "$text";
+			if (! ref $rep) {
+				Irssi::print("Error in triggers file");
+				return;
+			}
+			my @old_triggers = @$rep;
+		
+			for (my $index=0;$index < scalar(@old_triggers);$index++) { 
+				my $trigger = $old_triggers[$index];
+	
+				if ($file_version lt '0.6.1') {
+					# convert old names: notices => pubnotices, actions => pubactions
+					foreach $oldname ('notices','actions') {
+						if ($trigger->{$oldname}) {
+							delete $trigger->{$oldname};
+							$trigger->{'pub'.$oldname} = 1;
+							$converted = 1;
+						}
+					}
+				}
+				if ($file_version lt '0.6.1+1' && $trigger->{'modifiers'}) {
+					if ($trigger->{'modifiers'} =~ /i/) {
+						$trigger->{'nocase'} = 1;
+						Irssi::print("Trigger: trigger ".($index+1)." had 'i' in it's modifiers, it has been converted to -nocase");
+					}
+					if ($trigger->{'modifiers'} !~ /^[ig]*$/) {
+						Irssi::print("Trigger: trigger ".($index+1)." had unrecognised modifier '". $trigger->{'modifiers'} ."', which couldn't be converted.");
+					}
+					delete $trigger->{'modifiers'};
+					$converted = 1;
+				}
+				
+				# convert to text with compat, and then to new trigger hash
+				$text = to_string($trigger,1);
+				my @args = &shellwords($text . ' a');
+				my $trigger = parse_options({},@args);
+				if ($trigger) {
+					push @triggers, $trigger;
+				}
+			}
+		} else { # new format
+			while ( $text = $io->getline ) {
+				chop($text);
+				next if ($text =~ /^[ ]*$|^#/);
+				my @args = &shellwords($text . ' a');
+				my $trigger = parse_options({},@args);
+				if ($trigger) {
+					push @triggers, $trigger;
+				}
+			}
+		}
+	}
+	Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'trigger_loaded', $trigger_file);
+	if ($converted) {
+		Irssi::print("Trigger: Triggers file will be in new format next time it's saved.");
+	}
+	rebuild();
+}
+
+# escape for printing with to_string
+# <<abcdef>>      => << 'abcdef' >>
+# <<abc'def>>     => << "abc'def" >>
+# <<abc'def\x02>> => << 'abc'\''def\x02' >>
+sub param_to_string {
+	my ($text) = @_;
+	# avoid ugly escaping if we can use "-quotes without other escaping (no " or \)
+	if ($text =~ /^[^"\\]*'[^"\\]$/) {
+		return ' "' . $text . '" ';
+	}
+	# "'" signs without a (odd number of) \ in front of them, need be to escaped as '\''
+	# this is ugly :(
+	$text =~ s/(^|[^\\](\\\\)*)'/$1'\\''/g;
+	return " '$text' ";
+}
+
+# converts a trigger back to "-switch -options 'foo'" form
+# if $compat, $trigger is in the old format (used to convert)
+sub to_string {
+	my ($trigger, $compat) = @_;
+	my $string;
+	
+	foreach my $switch (@trigger_switches) {
+		if ($trigger->{$switch}) {
+			$string .= '-'.$switch.' ';
+		}
+	}
+	
+	if ($compat) {
+		foreach my $filter (keys(%filters)) {
+			if ($trigger->{$filter}) {
+				$string .= '-' . $filter . param_to_string($trigger->{$filter});
+			}
+		}
+	} else {
+		foreach my $trigfilter (filters_for_trigger($trigger)) {
+			$string .= '-' . $trigfilter->{'option'} . param_to_string($trigfilter->{'param'});
+		}
+	}
+
+	foreach my $param (@trigger_params) {
+		if ($trigger->{$param} || ($param eq 'replace' && defined($trigger->{'replace'}))) {
+			$string .= '-' . $param . param_to_string($trigger->{$param});
+		}
+	}
+	return $string;
+}
+
+# find a trigger (for REPLACE and DELETE), returns index of trigger, or -1 if not found
+sub find_trigger {
+	my ($data) = @_;
+	if ($data =~ /^[0-9]*$/ and defined($triggers[$data-1])) {
+		return $data-1;
+	} else {
+		for (my $i=0; $i < scalar(@triggers); $i++) {
+			if ($triggers[$i]->{'name'} eq $data) {
+				return $i;
+			}
+		}
+	}
+	Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'trigger_not_found', $data);
+	return -1; # not found
+}
+
+
+# TRIGGER ADD <options>
+sub cmd_add {
+	my ($data, $server, $item) = @_;
+	my @args = shellwords($data . ' a');
+	
+	my $trigger = parse_options({}, @args);
+	if ($trigger) {
+		push @triggers, $trigger;
+		Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'trigger_added', scalar(@triggers), to_string($trigger));
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+}
+
+# TRIGGER CHANGE <nr> <options>
+sub cmd_change {
+	my ($data, $server, $item) = @_;
+	my @args = shellwords($data . ' a');
+	my $index = find_trigger(shift @args);
+	if ($index != -1) {
+		if(parse_options($triggers[$index], @args)) {
+			Irssi::print("Trigger " . ($index+1) ." changed to: ". to_string($triggers[$index]));
+		}
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+}
+
+# parses options for TRIGGER ADD and TRIGGER CHANGE
+# if invalid args returns undef, else changes $thetrigger and returns it
+sub parse_options {
+	my ($thetrigger,@args) = @_;
+	my ($trigger, $option);
+	
+	if (pop(@args) ne 'a') {
+		Irssi::print("Syntax error, probably missing a closing quote", MSGLEVEL_CLIENTERROR);
+		return undef;
+	}
+	
+	%$trigger = %$thetrigger; # make a copy to prevent changing the given trigger if args doesn't parse
+ARGS:	for (my $arg = shift @args; $arg; $arg = shift @args) {
+		# expand abbreviated options, put in $option
+		$arg =~ s/^-//;
+		$option = undef;
+		foreach my $ioption (@trigger_options) {
+			if (index($ioption, $arg) == 0) { # -$opt starts with $arg
+				if ($option) { # another already matched
+					Irssi::print("Ambiguous option: $arg", MSGLEVEL_CLIENTERROR);
+					return undef;
+				}
+				$option = $ioption;
+				last if ($arg eq $ioption); # exact match is unambiguous
+			}
+		}
+		if (!$option) {
+			Irssi::print("Unknown option: $arg", MSGLEVEL_CLIENTERROR);
+			return undef;
+		}
+
+		# -<param> <value> or -no<param>
+		foreach my $param (@trigger_params) {
+			if ($option eq $param) {
+				$trigger->{$param} = shift @args;
+				next ARGS;
+			}
+			if ($option eq 'no'.$param) {
+				$trigger->{$param} = undef;
+				next ARGS;
+			}
+		}
+
+		# -[no]<switch>
+		foreach my $switch (@trigger_switches) {
+			# -<switch>
+			if ($option eq $switch) {
+				$trigger->{$switch} = 1;
+				next ARGS;
+			}
+			# -no<switch>
+			elsif ($option eq 'no'.$switch) {
+				$trigger->{$switch} = undef;
+				next ARGS;
+			}
+		}
+		
+		# -[not_]<filter> <value>
+		if ($option =~ /^(not_)?(.*)$/ && $filters{$2}) {
+			$trigger->{'filters'}->{$option} = {
+				option => $option,
+				must_match => ($1 ne 'not_'), # if false, trigger must only be done if filter sub returns false
+				filter_name => $2,
+				filter => $filters{$2},
+				param => shift @args
+			};
+			
+			next ARGS;
+		}
+		
+		# -no<filter>
+		if ($option =~ /^no(.*)$/ && $filters{$1}) {
+			delete $trigger->{'filters'}->{$option};
+		}
+	}
+	
+	if (defined($trigger->{'replace'}) && ! $trigger->{'regexp'} && !$trigger->{'pattern'}) {
+		Irssi::print("Trigger error: Can't have -replace without -regexp", MSGLEVEL_CLIENTERROR);
+		return undef;
+	}
+
+	if ($trigger->{'pattern'} && $trigger->{'regexp'}) {
+		Irssi::print("Trigger error: Can't have -pattern and -regexp in same trigger", MSGLEVEL_CLIENTERROR);
+		return undef;
+	}
+	
+	# remove types that are implied by -all
+	if ($trigger->{'all'}) {
+		foreach my $type (@all_types) {
+			delete $trigger->{$type};
+		}
+	}
+	
+	# remove types for which the filters don't apply
+	foreach my $type (@trigger_types) {
+		if ($trigger->{$type}) {
+			foreach my $trigfilter (filters_for_trigger($trigger)) {
+				if (!grep {$_ eq $type} @{$trigfilter->{'filter'}->{'types'}}) {
+					Irssi::print("Warning: the filter -" . $trigfilter->{'option'} . " can't apply to an event of type -$type, so I'm removing that type from this trigger.");
+					delete $trigger->{$type};
+				}
+			}
+		}
+	}
+
+	# check if it has at least one type
+	my $has_a_type;
+	foreach my $type (@trigger_types) {
+		if ($trigger->{$type}) {
+			$has_a_type = 1;
+			last;
+		}
+	}
+	if (!$has_a_type && !$trigger->{'all'}) {
+		Irssi::print("Warning: this trigger doesn't trigger on any type of message. you probably want to add -publics or -all");
+	}
+	
+	compile_trigger($trigger);
+	%$thetrigger = %$trigger; # copy changes to real trigger
+	return $thetrigger;
+}
+
+# TRIGGER DELETE <num>
+sub cmd_del {
+	my ($data, $server, $item) = @_;
+	my @args = shellwords($data);
+	my $index = find_trigger(shift @args);
+	if ($index != -1) {
+		Irssi::print("Deleted ". ($index+1) .": ". to_string($triggers[$index]));
+		splice (@triggers,$index,1);
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+}
+
+# TRIGGER MOVE <num> <num>
+sub cmd_move {
+	my ($data, $server, $item) = @_;
+	my @args = &shellwords($data);
+	my $index = find_trigger(shift @args);
+	if ($index != -1) {
+		my $newindex = shift @args;
+		if ($newindex < 1 || $newindex > scalar(@triggers)) {
+			Irssi::print("$newindex is not a valid trigger number");
+			return;
+		}
+		Irssi::print("Moved from ". ($index+1) ." to $newindex: ". to_string($triggers[$index]));
+		$newindex -= 1; # array starts counting from 0
+		my $trigger = splice (@triggers,$index,1); # remove from old place
+		splice (@triggers,$newindex,0,($trigger)); # insert at new place
+		rebuild();
+		$changed_since_last_save = 1;
+	}
+}
+
+# TRIGGER LIST
+sub cmd_list {
+	Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'trigger_header');
+	my $i=1;
+	foreach my $trigger (@triggers) {
+		Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'trigger_line', $i++, to_string($trigger));
+	}
+}
+
+######################
+### initialisation ###
+######################
+
+command_bind('trigger help',\&cmd_help);
+command_bind('help trigger',\&cmd_help);
+command_bind('trigger add',\&cmd_add);
+command_bind('trigger change',\&cmd_change);
+command_bind('trigger move',\&cmd_move);
+command_bind('trigger list',\&cmd_list);
+command_bind('trigger delete',\&cmd_del);
+command_bind('trigger save',\&cmd_save);
+command_bind('trigger reload',\&cmd_load);
+command_bind 'trigger' => sub {
+    my ( $data, $server, $item ) = @_;
+    $data =~ s/\s+$//g;
+    command_runsub('trigger', $data, $server, $item);
+};
+
+Irssi::signal_add('setup saved', \&autosave);
+Irssi::signal_add('setup changed', \&sig_setup_changed);
+
+# This makes tab completion work
+Irssi::command_set_options('trigger add',join(' ',@trigger_add_options));
+Irssi::command_set_options('trigger change',join(' ',@trigger_options));
+
+Irssi::settings_add_str($IRSSI{'name'}, 'trigger_file', Irssi::get_irssi_dir()."/triggers");
+
+cmd_load();
diff --git a/bots/blackhole/honeypot/.irssi/scripts/autorun/unfuck.pl b/bots/blackhole/honeypot/.irssi/scripts/autorun/unfuck.pl
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+use Irssi;
+use Irssi::Irc;
+
+sub cmd_unfuck {
+    my @windows = Irssi::windows();
+    foreach my $window (@windows) {
+        next if $window->{immortal};
+        $window->{active}->{topic_by} ? next : $window->destroy;
+    }
+}
+
+Irssi::command_bind('unfuck',  'cmd_unfuck');
+\ No newline at end of file
diff --git a/bots/blackhole/honeypot/.irssi/triggers b/bots/blackhole/honeypot/.irssi/triggers
@@ -0,0 +1,2 @@
+#Triggers file version 1.0+
+-privmsgs -privactions -privnotices -privctcps -dcc_msgs -dcc_actions -dcc_ctcps -invites -tags 'supernets' -command 'MSG blackhole $N'
+\ No newline at end of file
diff --git a/bots/hugecock.py b/bots/hugecock.py
@@ -0,0 +1,277 @@
+#!/usr/bin/env python
+# HUGECOCK (as seen in #efnetnews)
+# Developed by acidvegas/vap0r in Python 3
+# https://github.com/acidvegas/random
+# hugecock.py
+
+'''
+Patreon : https://www.patreon.com/efnetnews
+Twitter : https://twitter.com/pp4l
+YouTube : https://www.youtube.com/channel/UCrB3e00DBKTyVhGLrrGuhOw
+'''
+
+import os
+import random
+import socket
+import ssl
+import time
+import threading
+
+# Connection
+server   = 'irc.efnet.org'
+port     = 6667
+use_ipv6 = False
+use_ssl  = False
+vhost    = None
+password = None
+channel  = '#efnetnews'
+key      = None
+
+# Identity
+nickname = 'HUGECOCK'
+username = 'HUGECOCK'
+realname = 'HUGECOCK'
+
+# Globals (DO NOT EDIT)
+random_file  = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'random.txt')
+
+# Formatting Control Characters / Color Codes
+bold        = '\x02'
+italic      = '\x1D'
+underline   = '\x1F'
+reverse     = '\x16'
+reset       = '\x0f'
+white       = '00'
+black       = '01'
+blue        = '02'
+green       = '03'
+red         = '04'
+brown       = '05'
+purple      = '06'
+orange      = '07'
+yellow      = '08'
+light_green = '09'
+cyan        = '10'
+light_cyan  = '11'
+light_blue  = '12'
+pink        = '13'
+grey        = '14'
+light_grey  = '15'
+
+def debug(msg):
+    print(f'{get_time()} | [~] - {msg}')
+
+def error(msg, reason=None):
+    if reason:
+        print(f'{get_time()} | [!] - {msg} ({reason})')
+    else:
+        print(f'{get_time()} | [!] - {msg}')
+
+def get_time():
+    return time.strftime('%I:%M:%S')
+
+class IRC(object):
+    server    = server
+    port      = port
+    use_ipv6  = use_ipv6
+    use_ssl   = use_ssl
+    vhost     = vhost
+    password  = password
+    channel   = channel
+    key       = key
+    username  = username
+    realname  = realname
+
+    def __init__(self):
+        self.nickname  = nickname
+        self.connected = False
+        self.last_time = 0
+        self.sock      = None
+
+    def action(self, chan, msg):
+        self.sendmsg(chan, f'\x01ACTION {msg}\x01')
+
+    def color(self, msg, foreground, background=None):
+        if background:
+            return f'\x03{foreground},{background}{msg}{reset}'
+        else:
+            return f'\x03{foreground}{msg}{reset}'
+
+    def connect(self):
+        try:
+            self.create_socket()
+            self.sock.connect((self.server, self.port))
+            if self.password:
+                self.raw('PASS ' + self.password)
+            self.raw(f'USER {self.username} 0 * :{self.realname}')
+            self.nick(self.nickname)
+        except socket.error as ex:
+            error('Failed to connect to IRC server.', ex)
+            self.event_disconnect()
+        else:
+            self.listen()
+
+    def create_socket(self):
+        if self.use_ipv6:
+            self.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+        else:
+            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        if self.vhost:
+            self.sock.bind((self.vhost, 0))
+        if self.use_ssl:
+            self.sock = ssl.wrap_socket(self.sock)
+
+    def event_connect(self):
+        self.connected = True
+        self.join(self.channel, self.key)
+        threading.Thread(target=self.loop).start()
+
+    def event_disconnect(self):
+        self.connected = False
+        self.sock.close()
+        time.sleep(10)
+        self.connect()
+
+    def event_join(self, nick, chan):
+        if nick.lower() == 'zardoz':
+            self.sendmsg(chan, nick)
+        self.notice(nick, f'Thank you for joining #EFNetNews, you have {0} memos waiting. Please type /server MemoServ read to check your messages.'.format(color('3', red)))
+
+    def event_kick(self, nick, chan, kicked):
+        if kicked == self.nickname and chan == self.channel:
+            time.sleep(3)
+            self.join(self.channel, self.key)
+
+    def event_message(self, nick, chan, msg):
+        if random.choice((True,False,False,False)):
+            if 'http://' in msg or 'https://' in msg or 'www.' in msg:
+                self.sendmsg(chan, underline + 'not clicking')
+            elif msg == 'h':
+                self.sendmsg(chan, 'h')
+            elif msg == 'pump':
+                self.sendmsg(chan, 'penis')
+            elif msg == 'penis':
+                self.sendmsg(chan, 'pump')
+            elif 'ddos' in msg:
+                self.sendmsg(chan, 'Dudes Drink Owl Sperm')
+            elif 'fag' in msg:
+                self.sendmsg(chan, 'i hate faggots more than i hate war in this world')
+            elif self.nickname in msg:
+                self.action(chan, '8=================================================================D')
+            elif msg.lower() == 'lol':
+                self.sendmsg(chan, 'lol')
+            elif msg == '%%':
+                self.sendmsg(chan, '%%')
+            elif 'supernets' in msg.lower():
+                self.sendmsg(chan, self.color('HAVE YOU HEARD ABOUT IRC.SUPERNETS.ORG ???', light_blue))
+            elif 'readerr' in msg.lower():
+                if random.choice((True,False)):
+                    self.sendmsg(chan, 'can we kill ReadErr')
+                else:
+                    self.sendmsg(chan, 'can we ban ReadErr')
+
+    def event_nick_in_use(self):
+        self.nickname = self.nickname + '_'
+        self.nick(self.nickname)
+
+    def event_part(self, nick, chan):
+        self.sendmsg(nick, 'bet u wont come back pussy')
+        self.sendmsg(chan, self.color('EMOPART DETECTED', red, yellow))
+
+    def event_quit(self, nick):
+        if time.time() - self.last_time > 15:
+            self.nick(nick)
+            self.nickname = nick
+            self.sendmsg(self.channel, 'GOT EEEEEm')
+            self.last_time = time.time()
+
+    def handle_events(self, data):
+        args = data.split()
+        if args[0] == 'PING':
+            self.raw('PONG ' + args[1][1:])
+        elif args[1] == '001':
+            self.event_connect()
+        elif args[1] == '433':
+            self.event_nick_in_use()
+        elif args[1] in ('JOIN','KICK','PART','PRIVMSG','QUIT'):
+            nick  = args[0].split('!')[0][1:]
+            if nick != self.nickname:
+                if args[1] == 'JOIN':
+                    chan = args[2][1:]
+                    self.event_join(nick, chan)
+                elif args[1] == 'KICK':
+                    chan   = args[2]
+                    kicked = args[3]
+                    self.event_kick(nick, chan, kicked)
+                elif args[1] == 'PART':
+                    chan = args[2]
+                    self.event_part(nick, chan)
+                elif args[1] == 'PRIVMSG':
+                    chan = args[2]
+                    msg  = data.split(f'{args[0]} PRIVMSG {chan} :')[1]
+                    if chan != self.nickname:
+                        self.event_message(nick, chan, msg)
+                elif args[1] == 'QUIT':
+                    self.event_quit(nick)
+
+    def join(self, chan, key=None):
+        if key:
+            self.raw(f'JOIN {chan} {key}')
+        else:
+            self.raw('JOIN ' + chan)
+
+    def listen(self):
+        while True:
+            try:
+                data = self.sock.recv(1024).decode('utf-8')
+                if data:
+                    for line in (line for line in data.split('\r\n') if line):
+                        debug(line)
+                        if len(line.split()) >= 2:
+                            if line.startswith('ERROR :Closing Link:'):
+                                raise Exception('Connection has closed.')
+                            else:
+                                self.handle_events(line)
+                else:
+                    error('No data recieved from server.')
+                    break
+            except (UnicodeDecodeError,UnicodeEncodeError):
+                pass
+            except Exception as ex:
+                error('Unexpected error occured.', ex)
+                break
+        self.event_disconnect()
+
+    def loop(self):
+        while self.connected:
+            try:
+                time.sleep(60 * random_int(20,60))
+                self.sendmsg(self.channel, random.choice(random_lines))
+            except Exception as ex:
+                error('Error occured in the loop!', ex)
+                break
+
+    def nick(self, nick):
+        self.raw('NICK ' + nick)
+
+    def notice(self, target, msg):
+        self.raw(f'NOTICE {target} :{msg}')
+
+    def part(self, chan, msg=None):
+        if msg:
+            self.raw(f'PART {chan} {msg}')
+        else:
+            self.raw('PART ' + chan)
+
+    def raw(self, msg):
+        self.sock.send(bytes(msg + '\r\n', 'utf-8'))
+
+    def sendmsg(self, target, msg):
+        self.raw(f'PRIVMSG {target} :{msg}')
+
+# Main
+if os.path.isfile(random_file):
+    random_lines = [line.rstrip() for line in open(random_file, mode='r', encoding='utf8', errors='replace').readlines() if line]
+else:
+    error_exit('Missing random file!')
+IRC().connect()
+\ No newline at end of file
diff --git a/efkh.py b/efkh.py
@@ -1,68 +0,0 @@
-#!/usr/bin/env python
-# EFKnockr Helper - Developed by acidvegas in Python (https://acid.vegas/random)
-
-import json
-
-_bnc     = list()
-_irc     = list()
-_unknown = list()
-
-def _parse_data():
-	with open('netking.json','r') as _data_file:
-		for _line in _data_file:
-			_data = json.loads(_line)
-			if 'product' in _data:
-				if _data['product'] in ('BitlBee IRCd','psyBNC','Minbif','ShroudBNC irc-proxy'):
-					_bnc.append(_line)
-				else:
-					_irc.append(_line)
-			else:
-				if 'data' in _data:
-					if 'bitlbee' in _data['data'].lower() or 'psybnc' in _data['data'].lower() or 'shroudbnc' in _data['data'].lower():
-						_bnc.append(_line)
-					else:
-						if ':***' in _data['data'] or 'Looking up your hostname' in _data['data']:
-							_irc.append(_line)
-						else:
-							if 'PHP Notice' not in _data['data']:
-								if 'NOTICE' in _data['data']:
-									_irc.append(_line)
-								else:
-									_unknown.append(_line)
-				else:
-					_unknown.append(_line)
-
-def _write_data():
-	with open('bnc.json','w') as _bnc_file:
-		for _line in _bnc:
-			_bnc_file.write(_line)
-	with open('irc.json','w') as _irc_file:
-		for _line in _irc:
-			_irc_file.write(_line)
-	with open('unknown.json','w') as _unknown_file:
-		for _line in _unknown:
-			_unknown_file.write(_line)
-
-_parse_data()
-_write_data()
-
-print('BNC: ' + str(len(_bnc    )))
-print('IRC: ' + str(len(_irc    )))
-print('???: ' + str(len(_unknown)))
-
-_ips = list()
-
-def _parse_ips():
-    with open('irc.json','r') as _data_file:
-        for _line in _data_file:
-            _data = json.loads(_line)
-            _ips.append(_data['ip_str'])
-
-def _write_ips():
-    with open('clean.txt','w') as _clean_file:
-        for _line in _ips:
-            _clean_file.write(_line + '\n')
-
-_parse_ips()
-_ips = sorted(set(_ips))
-_write_ips()
diff --git a/hueg-hexchat.pl b/scripts/hexchat/hueg.pl
diff --git a/scripts/irssi/antifuckyou.pl b/scripts/irssi/antifuckyou.pl
@@ -0,0 +1,21 @@
+# AntiFuckYou (SAJOIN Auto-Part Script)
+# Developed by acidvegas in Perl
+# http://github.com/acidvegas/irssi
+# antifuckyou.pl
+
+use strict;
+use Irssi;
+
+sub anti_fuckyou {
+  my ($server, $msg, $nick, $address, $target) = @_;
+  if ($msg =~ /You were forced to join.*/) {
+    my $rand = &getRandom();
+    my $server_addr = $server->{real_address};
+    if ($nick eq $server_addr) {
+      $msg =~ s/.*\W(\w)/$1/;
+      $server->command("PART #$msg");
+    }
+  }
+}
+
+Irssi::signal_add('message irc notice', 'anti_fuckyou');
diff --git a/scripts/irssi/fuckyou.pl b/scripts/irssi/fuckyou.pl
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+use Irssi;
+use Irssi::Irc;
+
+sub getRandom {
+    my $length=5 + int(rand(21 - 5));
+    my @chars=('a'..'z','A'..'Z','0'..'9');
+    my $random_string;
+    foreach (1..$length) {
+        $random_string.=$chars[rand @chars];
+    }
+    return $random_string;
+}
+
+sub cmd_fuckyou {
+    my ($data, $server, $dest)  = @_;
+    my ($nick, $amount) = split(/ +/, $data);
+    unless($nick && $amount) {
+        Irssi::print("/fuckyou <nick> <number>");
+        return;
+    }
+    for(1 .. $amount) {
+        my $rand = &getRandom();
+        $server->command("sajoin $nick #$rand");
+    }
+}
+
+sub cmd_unfuck {
+    my @windows = Irssi::windows();
+    foreach my $window (@windows) {
+        next if $window->{immortal};
+        $window->{active}->{topic_by} ? next : $window->destroy;
+    }
+}
+
+Irssi::command_bind('fuckyou', 'cmd_fuckyou');
+Irssi::command_bind('unfuck',  'cmd_unfuck');
diff --git a/scripts/irssi/takeover.pl b/scripts/irssi/takeover.pl
@@ -0,0 +1,63 @@
+# Takeover (IRSSI Channel Takeover Script)
+# Developed by acidvegas in Perl
+# http://github.com/acidvegas/irssi
+# takeover.pl
+
+# Todo:
+# Detect max network modes.
+# Kickban comma separated nicks.
+
+use strict;
+use Irssi;
+use Irssi::Irc;
+
+sub takeover {
+    my ($data, $server, $channel) = @_;
+    Irssi::printformat(MSGLEVEL_CLIENTCRAP, "takeover_crap", "Not connected to server."),        return if (!$server or !$server->{connected});
+    Irssi::printformat(MSGLEVEL_CLIENTCRAP, "takeover_crap", "No active channel in window."),    return if (!$channel or ($channel->{type} ne "CHANNEL"));
+    my $own_prefixes = $channel->{ownnick}{prefixes};
+    Irssi::printformat(MSGLEVEL_CLIENTCRAP, "takeover_crap", "You are not a channel operator."), return if ($own_prefixes =~ /~|&|@|%/);
+    my ($qops, $aops, $hops, $qcount, $acount, $hcount, $modes);
+    my $hostname      = $channel->{ownnick}{host};
+    my $nicklist      = $channel->nicks();
+    foreach my $nick ($channel->nicks()) {
+        next if ($nick eq $server->{nick});
+        if ($nick->{prefixes} =~ /~/) {
+            $qops .= "$nick->{nick} ";
+            $qcount++;
+        }
+        if ($nick->{prefixes} =~ /&/) {
+            $aops .= "$nick->{nick} ";
+            $acount++;
+        }
+        if ($nick->{halfop}) {
+            $hops .= "$nick->{nick} ";
+            $hcount++;
+        }
+    }
+    if ($qops) {
+        $modes = "q" x $qcount;
+        $channel->command("mode -$modes $qops");
+    }
+    if ($aops) {
+        $modes = "a" x $qcount;
+        $channel->command("mode -$modes $aops");
+    }
+    if ($hops) {
+        $modes = "h" x $qcount;
+        $channel->command("mode -$modes $hops");
+    }
+    $channel->command("deop -YES *");
+    $channel->command("devoice -YES *");
+    foreach ($channel->nicks()) {
+        next if ($_->{'nick'} eq $server->{nick});
+        $channel->command("kickban $_->{'nick'}");
+    }
+    $channel->command("ban *!*@*");
+    $channel->command("mode +im");
+    $channel->command("mode +e *!$hostname");
+    $channel->command("mode +I *!$hostname");
+}
+
+Irssi::theme_register(['takeover_crap', '{line_start}{hilight takeover:} $0',]);
+Irssi::command_bind('takeover', 'takeover');
diff --git a/scripts/irssi/v.pl b/scripts/irssi/v.pl
@@ -0,0 +1,17 @@
+use strict;
+use Irssi;
+
+# The /v command will voice everyone in the channel that doesnt have voice or higher (halfop, op, etc).
+
+sub cmd_massvoice {
+    my ($data, $server, $channel) = @_;
+    Irssi::printformat(MSGLEVEL_CRAP, "v: Not connected to server."),        return if (!$server or !$server->{connected});
+    Irssi::printformat(MSGLEVEL_CRAP, "v: No active channel in window."),    return if (!$channel or ($channel->{type} ne "CHANNEL"));
+    my @nicks             = $channel->nicks();
+    my @normal_nicks      = grep { $_->{prefixes} !~ /[\~\&\@\%\+]/ } @nicks;
+    my @normal_nick_names = map { $_->{nick} } @normal_nicks;
+    my $spaced_nicks      = join(" ", @normal_nick_names);
+    $channel->command("VOICE $spaced_nicks");
+}
+
+Irssi::command_bind('v', 'cmd_massvoice');
diff --git a/weechat-scripts/antifuck.pl b/scripts/weechat/antifuck.pl
diff --git a/weechat-scripts/banner.pl b/scripts/weechat/banner.pl
diff --git a/weechat-scripts/colo.py b/scripts/weechat/colo.py
diff --git a/weechat-scripts/coloconv.pl b/scripts/weechat/coloconv.pl
diff --git a/weechat-scripts/hueg.pl b/scripts/weechat/hueg.pl
diff --git a/weechat-scripts/masshl.py b/scripts/weechat/masshl.py
diff --git a/weechat-scripts/parrot.pl b/scripts/weechat/parrot.pl
diff --git a/weechat-scripts/play.pl b/scripts/weechat/play.pl
diff --git a/weechat-scripts/prismx.py b/scripts/weechat/prismx.py
diff --git a/weechat-scripts/sighup.pl b/scripts/weechat/sighup.pl
diff --git a/weechat-scripts/snomasks.pl b/scripts/weechat/snomasks.pl
diff --git a/weechat-scripts/whoishex.pl b/scripts/weechat/whoishex.pl