a8431e53b8bd

Lots of crap
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 29 Sep 2017 10:28:47 -0400
parents 2b37786c6a97
children 816a02d790f8
branches/tags (none)
files .hgsub .hgsubstate fish/config.fish gitignore hgrc mutt/muttrc tmux/tmux.conf vim/vimrc weechat/alias.conf weechat/aspell.conf weechat/autosort.conf weechat/buffers.conf weechat/buflist.conf weechat/charset.conf weechat/exec.conf weechat/fifo.conf weechat/logger.conf weechat/perl/autoload/buffers.pl weechat/plugins.conf weechat/python/autoload/wee_slack.py weechat/relay.conf weechat/script.conf weechat/sec.conf weechat/trigger.conf weechat/urlgrab.conf weechat/weechat.conf weechat/xfer.conf

Changes

--- a/.hgsub	Fri Sep 08 19:37:36 2017 -0400
+++ b/.hgsub	Fri Sep 29 10:28:47 2017 -0400
@@ -5,7 +5,7 @@
 vim/bundle/clam                  = [hg]https://bitbucket.org/sjl/clam.vim/
 vim/bundle/clojure-static        = [git]git://github.com/guns/vim-clojure-static.git
 vim/bundle/commentary            = [git]git://github.com/tpope/vim-commentary.git
-vim/bundle/ctrlp                 = [git]git://github.com/kien/ctrlp.vim.git
+vim/bundle/ctrlp                 = [git]git://github.com/ctrlpvim/ctrlp.vim.git
 vim/bundle/delimitmate           = [git]git://github.com/Raimondi/delimitMate.git
 vim/bundle/dispatch              = [git]git://github.com/tpope/vim-dispatch.git
 vim/bundle/fireplace             = [git]git://github.com/tpope/vim-fireplace.git
@@ -26,6 +26,8 @@
 vim/bundle/python-mode           = [git]git://github.com/klen/python-mode.git
 vim/bundle/rainbow-parentheses   = [git]git://github.com/kien/rainbow_parentheses.vim.git
 vim/bundle/repeat                = [git]git://github.com/tpope/vim-repeat.git
+vim/bundle/rhubarb               = [git]git://github.com/tpope/vim-rhubarb.git
+vim/bundle/scala                 = [git]git://github.com/derekwyatt/vim-scala
 vim/bundle/securemodelines       = [git]git://github.com/ciaranm/securemodelines.git
 vim/bundle/sexp                  = [git]git://github.com/guns/vim-sexp.git
 vim/bundle/shaderhighlight       = [git]git://github.com/vim-scripts/ShaderHighLight.git
@@ -34,7 +36,7 @@
 vim/bundle/surround              = [git]git://github.com/tpope/vim-surround.git
 vim/bundle/swig                  = [git]git://github.com/vim-scripts/SWIG-syntax.git
 vim/bundle/syntastic             = [git]git://github.com/scrooloose/syntastic.git
-vim/bundle/targets               = [git]git://github.com/wellle/targets.git
+vim/bundle/targets               = [git]git://github.com/wellle/targets.vim.git
 vim/bundle/vimtex                = [git]git://github.com/lervag/vimtex.git
 vim/bundle/vitality              = [hg]https://bitbucket.org/sjl/vitality.vim
 vim/bundle/vlime                 = [git]git://github.com/l04m33/vlime.git
--- a/.hgsubstate	Fri Sep 08 19:37:36 2017 -0400
+++ b/.hgsubstate	Fri Sep 29 10:28:47 2017 -0400
@@ -1,7 +1,7 @@
 5334581e231a5167d03689ff47b3a6fdf082011c mercurial/hg-prompt
 1fc4a9fbead7e0acc4c828b346f3be2658ec3df9 mercurial/templates
 a16a9b63eb85cc0960a7f25c54647ac1f99f3360 vim/bundle/ack
-451b8111344a3a8117996f4e32b6a255b629f87b vim/bundle/badwolf
+5e4a535e2d239cba3db19b6b79abedbc7c541727 vim/bundle/badwolf
 a4d79fc208764917cb58e2aed6fbaeb5e3356d33 vim/bundle/clam
 f1c53e290b16885c2eb3fc96e57d9984b627f735 vim/bundle/clojure-static
 be79030b3e8c0ee3c5f45b4333919e4830531e80 vim/bundle/commentary
@@ -9,7 +9,7 @@
 38487bbec8ba50834e257940b357de03991fa8f9 vim/bundle/delimitmate
 6dd4480388e4727dfe5c723484c500e03b429c28 vim/bundle/dispatch
 1c75b56ceb96a6e7fb6708ae96ab63b3023bab2f vim/bundle/fireplace
-935a2cccd3065b1322fb2235285d42728600afdf vim/bundle/fugitive
+8f60d1d459362771cb68c0097565efdf52e62ec3 vim/bundle/fugitive
 127d706f2def96876605e6bd5d366c973cb8e406 vim/bundle/gdl
 6ea4e1983b18cf440c8f800a3e94b57338a3e99f vim/bundle/glsl
 0d57b080f9fae8573c688b6679b31eb1666edc4c vim/bundle/gnuplot
@@ -26,6 +26,8 @@
 fd70ac2ab74a91fb049cb8e82237c34d88354673 vim/bundle/python-mode
 eb8baa5428bde10ecc1cb14eed1d6e16f5f24695 vim/bundle/rainbow-parentheses
 7a6675f092842c8f81e71d5345bd7cdbf3759415 vim/bundle/repeat
+6caad2b61afcc1b7c476b0ae3dea9ee5f2b1d14a vim/bundle/rhubarb
+e7640f26e56f0be344d60a6098e05d6928fd396d vim/bundle/scala
 10d6c6b52fcdd12f3ba457126f66fee4ccceec04 vim/bundle/securemodelines
 b4398689f7483b01684044ab6b55bf369744c9b3 vim/bundle/sexp
 e02c3e218c51c1e2ea1821a3fe412d4e09ca1502 vim/bundle/shaderhighlight
@@ -37,5 +39,5 @@
 f6f2d6618a321f5b0065586a7bc934325fec81ab vim/bundle/targets
 5d5c71044880443035e07009497962feacb56b20 vim/bundle/vimtex
 bf3fd7f67e730f93765bd3c1cfcdb18fd4043521 vim/bundle/vitality
-d091242de628c09b3ff47e1c67e7cecff39adc44 vim/bundle/vlime
+2686da25b205ae20380a80271efdd74cfbc3969e vim/bundle/vlime
 6876fe38b33732cb124d415ffc4156f16da5e118 vim/bundle/windowswap
--- a/fish/config.fish	Fri Sep 08 19:37:36 2017 -0400
+++ b/fish/config.fish	Fri Sep 29 10:28:47 2017 -0400
@@ -65,6 +65,7 @@
     end
 end
 set -gx PATH "/sbin"
+prepend_to_path "/usr/local/opt/postgresql@9.6/bin"
 prepend_to_path "/usr/sbin"
 prepend_to_path "/bin"
 prepend_to_path "/usr/bin"
@@ -133,7 +134,7 @@
 set PYTHONPATH "$HOME/lib/hg/hg:$PYTHONPATH"
 
 set -gx WORKON_HOME "$HOME/lib/virtualenvs"
-eval (python -m virtualfish)
+eval (python2 -m virtualfish)
 
 set -g -x NLTK_DATA "/Users/sjl/src/ru/malv/nltk_data"
 
--- a/gitignore	Fri Sep 08 19:37:36 2017 -0400
+++ b/gitignore	Fri Sep 29 10:28:47 2017 -0400
@@ -7,3 +7,5 @@
 .idea
 *.iml
 .DS_Store
+.cache-main
+.cache-tests
--- a/hgrc	Fri Sep 08 19:37:36 2017 -0400
+++ b/hgrc	Fri Sep 29 10:28:47 2017 -0400
@@ -34,18 +34,8 @@
 [schemes]
 webf = ssh://sjl@sjl.webfactional.com/repos/
 bbs = ssh://hg@bitbucket.org/
-bbss = ssh://hg@bitbucket.org/sjl/
-bbsd = ssh://hg@bitbucket.org/dwaiter/
 gh = git://github.com/
 ghs = git+ssh://git@github.com/
-cb = ssh://hg@codebasehq.com/
-cbdw = ssh://hg@codebasehq.com/dwaiter/
-cbsl = ssh://hg@codebasehq.com/stevelosh/
-dwd = ssh://hg@bitbucket.org/dwaiter/
-nyh = ssh://sjl@gotham.nyhacker.org/
-dl = ssh://hg@hg.dwaiter.com:38038/
-mirr = ssh://hg@dwaiter.com:38038/mirror/
-gc = https://code.google.com/p/
 
 [diff]
 git = True
--- a/mutt/muttrc	Fri Sep 08 19:37:36 2017 -0400
+++ b/mutt/muttrc	Fri Sep 29 10:28:47 2017 -0400
@@ -43,6 +43,8 @@
 set send_charset="us-ascii:utf-8:iso-8859-1"
 set use_from             # respect the From: address the editor sends back
 
+set sleep_time=0 # don't take for fucking ever to switch folders
+
 # }}}
 # PGP {{{
 
@@ -80,7 +82,8 @@
 bind index,pager <up>     sidebar-prev
 bind index,pager <right>  sidebar-open
 
-set sidebar_format = "%B %> %N "
+set mail_check_stats
+set sidebar_format = "%B %> %S "
 
 # }}}
 # Status Bar {{{
@@ -151,13 +154,14 @@
 set sendmail_wait = 0 # no please don't silently fail, email is important
 unset record
 
-source ~/Dropbox/Settings/mail-accounts/accounts
+# source ~/Dropbox/Settings/mail-accounts/accounts
 
 # }}}
 # Key Bindings {{{
 
 # Index {{{
 
+bind index g noop
 bind index \#       noop
 bind index R        group-reply
 bind index <tab>    sync-mailbox
@@ -196,6 +200,7 @@
 # Pager {{{
 
 bind pager \# noop
+bind pager g noop
 bind pager k  previous-line
 bind pager j  next-line
 bind pager gg top
@@ -232,5 +237,6 @@
 
 # }}}
 # Local Settings {{{
-    source `FILE=$HOME/.mutt-local; if [ ! -s "$FILE" ]; then FILE=/dev/null;fi;echo "$FILE"`
+    # source `FILE=$HOME/.mutt-local; if [ ! -s "$FILE" ]; then FILE=/dev/null;fi;echo "$FILE"`
+    source ~/.mutt-local
 # }}}
--- a/tmux/tmux.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/tmux/tmux.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -8,7 +8,7 @@
 set -sg repeat-time 600
 
 # Shut up.
-set -g quiet on
+#set -g quiet on
 
 # Focus
 set -g focus-events
@@ -114,11 +114,13 @@
 unbind [
 unbind p
 bind p paste-buffer
-bind -t vi-copy H start-of-line
-bind -t vi-copy L end-of-line
-bind -t vi-copy v begin-selection
-bind -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
-bind -t vi-copy Escape cancel
+
+bind -T copy-mode-vi 'v' send -X begin-selection
+bind -T copy-mode-vi 'y' send -X copy-pipe-and-cancel pbcopy
+bind -T copy-mode-vi Escape send -X cancel
+bind -T copy-mode-vi V send -X rectangle-toggle
+bind -T copy-mode-vi H send-keys -X start-of-line
+bind -T copy-mode-vi L send-keys -X end-of-line
 bind y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
 
 # Toggle synchronized panes for the current window
--- a/vim/vimrc	Fri Sep 08 19:37:36 2017 -0400
+++ b/vim/vimrc	Fri Sep 29 10:28:47 2017 -0400
@@ -541,7 +541,7 @@
 nnoremap <leader>ep :!vim ~/.plan/README.markdown && hg -R ~/.plan ci -m 'Update'<cr>
 nnoremap <leader>eq :vsplit ~/Dropbox/quotes.txt<cr>Gzz
 nnoremap <leader>et :vsplit ~/.tmux.conf<cr>
-nnoremap <leader>ev :vsplit $MYVIMRC<cr>
+nnoremap <leader>ev :vsplit ~/.vimrc<cr>
 
 " }}}
 " Status Line ------------------------------------------------------------- {{{
@@ -1788,6 +1788,18 @@
 augroup END
 
 " }}}
+" Scala {{{
+
+augroup ft_scala
+    au!
+
+    au FileType scala setlocal foldmethod=marker
+    au FileType scala setlocal foldmarker={,}
+    au FileType scala setlocal cc=100 tw=100
+    au FileType scala setlocal expandtab
+augroup END
+
+" }}}
 " Scheme {{{
 
 function! OpenSchemeRepl() "{{{
@@ -3128,5 +3140,7 @@
     set encoding=utf-8
 endif
 
+source ~/.vimrc_local
+
 " }}}
 
--- a/weechat/alias.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/alias.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- alias.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [cmd]
 AAWAY = "allserv /away"
--- a/weechat/aspell.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/aspell.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,10 +1,19 @@
 #
 # weechat -- aspell.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [color]
 misspelled = lightred
-suggestions = default
+suggestion = default
+suggestion_delimiter_dict = cyan
+suggestion_delimiter_word = cyan
 
 [check]
 commands = "ame,amsg,away,command,cycle,kick,kickban,me,msg,notice,part,query,quit,topic"
@@ -17,4 +26,8 @@
 
 [dict]
 
+[look]
+suggestion_delimiter_dict = " / "
+suggestion_delimiter_word = ","
+
 [option]
--- a/weechat/autosort.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/autosort.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- autosort.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [sorting]
 case_sensitive = off
--- a/weechat/buffers.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/buffers.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- buffers.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [color]
 current_bg = green
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/weechat/buflist.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -0,0 +1,38 @@
+#
+# weechat -- buflist.conf
+#
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
+
+[look]
+auto_scroll = 50
+display_conditions = "${buffer.hidden}==0"
+enabled = on
+mouse_jump_visited_buffer = off
+mouse_move_buffer = on
+mouse_wheel = on
+nick_prefix = off
+nick_prefix_empty = on
+signals_refresh = ""
+sort = "number,-active"
+
+[format]
+buffer = "${format_number}${indent}${format_nick_prefix}${color_hotlist}${format_name}"
+buffer_current = "${color:,blue}${format_buffer}"
+hotlist = " ${color:green}(${hotlist}${color:green})"
+hotlist_highlight = "${color:magenta}"
+hotlist_low = "${color:white}"
+hotlist_message = "${color:green}"
+hotlist_none = "${color:default}"
+hotlist_private = "${color:white}"
+hotlist_separator = "${color:default},"
+indent = "  "
+lag = " ${color:green}[${color:brown}${lag}${color:green}]"
+name = "${name}"
+nick_prefix = "${color_nick_prefix}${nick_prefix}"
+number = "${color:green}${number}${if:${number_displayed}?.: }"
--- a/weechat/charset.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/charset.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- charset.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [default]
 decode = "iso-8859-1"
--- a/weechat/exec.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/exec.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- exec.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [command]
 default_options = ""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/weechat/fifo.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -0,0 +1,14 @@
+#
+# weechat -- fifo.conf
+#
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
+
+[file]
+enabled = on
+path = "%h/weechat_fifo"
--- a/weechat/logger.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/logger.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- logger.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [look]
 backlog = 20
--- a/weechat/perl/autoload/buffers.pl	Fri Sep 08 19:37:36 2017 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1369 +0,0 @@
-#
-# Copyright (C) 2008-2014 Sebastien Helleu <flashcode@flashtux.org>
-# Copyright (C) 2011-2013 Nils G <weechatter@arcor.de>
-#
-# 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 3 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, see <http://www.gnu.org/licenses/>.
-#
-#
-# Display sidebar with list of buffers.
-#
-# History:
-#
-# 2014-01-01, Sebastien Helleu <flashcode@flashtux.org>:
-#     v4.5: add option "mouse_move_buffer"
-# 2013-12-11, Sebastien Helleu <flashcode@flashtux.org>:
-#     v4.4: fix buffer number on drag to the end of list when option
-#           weechat.look.buffer_auto_renumber is off
-# 2013-12-10, nils_2@freenode.#weechat:
-#     v4.3: add options "prefix_bufname" and "suffix_bufname (idea by silverd)
-#         : fix hook_timer() for show_lag wasn't disabled
-#         : improved signal handling (less updating of buffers list)
-# 2013-11-07, Sebastien Helleu <flashcode@flashtux.org>:
-#     v4.2: use default filling "columns_vertical" when bar position is top/bottom
-# 2013-10-31, nils_2@freenode.#weechat:
-#     v4.1: add option "detach_buffer_immediately" (idea by farn)
-# 2013-10-20, nils_2@freenode.#weechat:
-#     v4.0: add options "detach_displayed_buffers", "detach_display_window_number"
-# 2013-09-27, nils_2@freenode.#weechat:
-#     v3.9: add option "toggle_bar" and option "show_prefix_query" (idea by IvarB)
-#         : fix problem with linefeed at end of list of buffers (reported by grawity)
-# 2012-10-18, nils_2@freenode.#weechat:
-#     v3.8: add option "mark_inactive", to mark buffers you are not in (idea by xrdodrx)
-#         : add wildcard "*" for immune_detach_buffers (idea by StarWeaver)
-#         : add new options "detach_query" and "detach_free_content" (idea by StarWeaver)
-# 2012-10-06, Nei <anti.teamidiot.de>:
-#     v3.7: call menu on right mouse if menu script is loaded.
-# 2012-10-06, nils_2 <weechatter@arcor.de>:
-#     v3.6: add new option "hotlist_counter" (idea by torque).
-# 2012-06-02, nils_2 <weechatter@arcor.de>:
-#     v3.5: add values "server|channel|private|all|keepserver|none" to option "hide_merged_buffers" (suggested by dominikh).
-# 2012-05-25, nils_2 <weechatter@arcor.de>:
-#     v3.4: add new option "show_lag".
-# 2012-04-07, Sebastien Helleu <flashcode@flashtux.org>:
-#     v3.3: fix truncation of wide chars in buffer name (option name_size_max) (bug #36034)
-# 2012-03-15, nils_2 <weechatter@arcor.de>:
-#     v3.2: add new option "detach"(weechat >= 0.3.8)
-#           add new option "immune_detach_buffers" (requested by Mkaysi)
-#           add new function buffers_whitelist add|del|reset (suggested by FiXato)
-#           add new function buffers_detach add|del|reset
-# 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
-#     v3.1: fix reload of config file
-# 2012-01-29, nils_2 <weechatter@arcor.de>:
-#     v3.0: fix: buffers did not update directly during window_switch (reported by FiXato)
-# 2012-01-29, nils_2 <weechatter@arcor.de>:
-#     v2.9: add options "name_size_max" and "name_crop_suffix"
-# 2012-01-08, nils_2 <weechatter@arcor.de>:
-#     v2.8: fix indenting for option "show_number off"
-#           fix unset of buffer activity in hotlist when buffer was moved with mouse
-#           add buffer with free content and core buffer sorted first (suggested  by nyuszika7h)
-#           add options queries_default_fg/bg and queries_message_fg/bg (suggested by FiXato)
-#           add clicking with left button on current buffer will do a jump_previously_visited_buffer (suggested by FiXato)
-#           add clicking with right button on current buffer will do a jump_next_visited_buffer
-#           add additional informations in help texts
-#           add default_fg and default_bg for whitelist channels
-#           internal changes  (script is now 3Kb smaller)
-# 2012-01-04, Sebastien Helleu <flashcode@flashtux.org>:
-#     v2.7: fix regex lookup in whitelist buffers list
-# 2011-12-04, nils_2 <weechatter@arcor.de>:
-#     v2.6: add own config file (buffers.conf)
-#           add new behavior for indenting (under_name)
-#           add new option to set different color for server buffers and buffers with free content
-# 2011-10-30, nils_2 <weechatter@arcor.de>:
-#     v2.5: add new options "show_number_char" and "color_number_char",
-#           add help-description for options
-# 2011-08-24, Sebastien Helleu <flashcode@flashtux.org>:
-#     v2.4: add mouse support
-# 2011-06-06, nils_2 <weechatter@arcor.de>:
-#     v2.3: added: missed option "color_whitelist_default"
-# 2011-03-23, Sebastien Helleu <flashcode@flashtux.org>:
-#     v2.2: fix color of nick prefix with WeeChat >= 0.3.5
-# 2011-02-13, nils_2 <weechatter@arcor.de>:
-#     v2.1: add options "color_whitelist_*"
-# 2010-10-05, Sebastien Helleu <flashcode@flashtux.org>:
-#     v2.0: add options "sort" and "show_number"
-# 2010-04-12, Sebastien Helleu <flashcode@flashtux.org>:
-#     v1.9: replace call to log() by length() to align buffer numbers
-# 2010-04-02, Sebastien Helleu <flashcode@flashtux.org>:
-#     v1.8: fix bug with background color and option indenting_number
-# 2010-04-02, Helios <helios@efemes.de>:
-#     v1.7: add indenting_number option
-# 2010-02-25, m4v <lambdae2@gmail.com>:
-#     v1.6: add option to hide empty prefixes
-# 2010-02-12, Sebastien Helleu <flashcode@flashtux.org>:
-#     v1.5: add optional nick prefix for buffers like IRC channels
-# 2009-09-30, Sebastien Helleu <flashcode@flashtux.org>:
-#     v1.4: remove spaces for indenting when bar position is top/bottom
-# 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
-#     v1.3: add option "hide_merged_buffers"
-# 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
-#     v1.2: improve display with merged buffers
-# 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
-#     v1.1: sync with last API changes
-# 2009-02-21, Sebastien Helleu <flashcode@flashtux.org>:
-#     v1.0: remove timer used to update bar item first time (not needed any more)
-# 2009-02-17, Sebastien Helleu <flashcode@flashtux.org>:
-#     v0.9: fix bug with indenting of private buffers
-# 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
-#     v0.8: update syntax for command /set (comments)
-# 2008-10-20, Jiri Golembiovsky <golemj@gmail.com>:
-#     v0.7: add indenting option
-# 2008-10-01, Sebastien Helleu <flashcode@flashtux.org>:
-#     v0.6: add default color for buffers, and color for current active buffer
-# 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
-#     v0.5: fix color for "low" level entry in hotlist
-# 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
-#     v0.4: rename option "show_category" to "short_names",
-#           remove option "color_slash"
-# 2008-09-15, Sebastien Helleu <flashcode@flashtux.org>:
-#     v0.3: fix bug with priority in hotlist (var not defined)
-# 2008-09-02, Sebastien Helleu <flashcode@flashtux.org>:
-#     v0.2: add color for buffers with activity and config options for
-#           colors, add config option to display/hide categories
-# 2008-03-15, Sebastien Helleu <flashcode@flashtux.org>:
-#     v0.1: script creation
-#
-# Help about settings:
-#   display all settings for script (or use iset.pl script to change settings):
-#      /set buffers*
-#   show help text for option buffers.look.whitelist_buffers:
-#      /help buffers.look.whitelist_buffers
-#
-# Mouse-support (standard key bindings):
-#   left mouse-button:
-#       - click on a buffer to switch to selected buffer
-#       - click on current buffer will do action jump_previously_visited_buffer
-#       - drag a buffer and drop it on another position will move the buffer to position
-#   right mouse-button:
-#       - click on current buffer will do action jump_next_visited_buffer
-#       - moving buffer to the left/right will close buffer.
-#
-
-use strict;
-use Encode qw( decode encode );
-# -------------------------------[ internal ]-------------------------------------
-my $SCRIPT_NAME = "buffers";
-my $SCRIPT_VERSION = "4.5";
-
-my $BUFFERS_CONFIG_FILE_NAME = "buffers";
-my $buffers_config_file;
-my $cmd_buffers_whitelist= "buffers_whitelist";
-my $cmd_buffers_detach   = "buffers_detach";
-
-my %mouse_keys          = ("\@item(buffers):button1*"    => "hsignal:buffers_mouse",     # catch all left mouse button gestures
-                           "\@item(buffers):button2*"     => "hsignal:buffers_mouse");    # catch all right mouse button gestures
-my %options;
-my %hotlist_level       = (0 => "low", 1 => "message", 2 => "private", 3 => "highlight");
-my @whitelist_buffers   = ();
-my @immune_detach_buffers= ();
-my @detach_buffer_immediately= ();
-my @buffers_focus       = ();
-my %buffers_timer       = ();
-my %Hooks               = ();
-
-# --------------------------------[ init ]--------------------------------------
-weechat::register($SCRIPT_NAME, "Sebastien Helleu <flashcode\@flashtux.org>", $SCRIPT_VERSION,
-                  "GPL3", "Sidebar with list of buffers", "shutdown_cb", "");
-my $weechat_version = weechat::info_get("version_number", "") || 0;
-
-buffers_config_init();
-buffers_config_read();
-
-weechat::bar_item_new($SCRIPT_NAME, "build_buffers", "");
-weechat::bar_new($SCRIPT_NAME, "0", "0", "root", "", "left", "columns_vertical",
-                 "vertical", "0", "0", "default", "default", "default", "1",
-                 $SCRIPT_NAME);
-
-if ( check_bar_item() == 0 )
-{
-    weechat::command("","/bar show " . $SCRIPT_NAME) if ( weechat::config_boolean($options{"toggle_bar"}) eq 1 );
-}
-
-weechat::hook_signal("buffer_opened", "buffers_signal_buffer", "");
-weechat::hook_signal("buffer_closed", "buffers_signal_buffer", "");
-weechat::hook_signal("buffer_merged", "buffers_signal_buffer", "");
-weechat::hook_signal("buffer_unmerged", "buffers_signal_buffer", "");
-weechat::hook_signal("buffer_moved", "buffers_signal_buffer", "");
-weechat::hook_signal("buffer_renamed", "buffers_signal_buffer", "");
-weechat::hook_signal("buffer_switch", "buffers_signal_buffer", "");
-
-weechat::hook_signal("window_switch", "buffers_signal_buffer", "");
-weechat::hook_signal("hotlist_changed", "buffers_signal_hotlist", "");
-#weechat::hook_command_run("/input switch_active_*", "buffers_signal_buffer", "");
-weechat::bar_item_update($SCRIPT_NAME);
-
-
-if ($weechat_version >= 0x00030600)
-{
-    weechat::hook_focus($SCRIPT_NAME, "buffers_focus_buffers", "");
-    weechat::hook_hsignal("buffers_mouse", "buffers_hsignal_mouse", "");
-    weechat::key_bind("mouse", \%mouse_keys);
-}
-
-weechat::hook_command(  $cmd_buffers_whitelist,
-                        "add/del current buffer to/from buffers whitelist",
-                        "[add] || [del] || [reset]",
-
-                        "  add: add current buffer in configuration file\n".
-                        "  del: delete current buffer from configuration file\n".
-                        "reset: reset all buffers from configuration file (no confirmation!)\n\n".
-                        "Examples:\n".
-                        "/$cmd_buffers_whitelist add\n",
-                        "add %-||".
-                        "del %-||".
-                        "reset %-",
-                        "buffers_cmd_whitelist", "");
-weechat::hook_command(  $cmd_buffers_detach,
-                        "add/del current buffer to/from buffers detach",
-                        "[add] || [del] || [reset]",
-
-                        "  add: add current buffer in configuration file\n".
-                        "  del: delete current buffer from configuration file\n".
-                        "reset: reset all buffers from configuration file (no confirmation!)\n\n".
-                        "Examples:\n".
-                        "/$cmd_buffers_detach add\n",
-                        "add %-||".
-                        "del %-||".
-                        "reset %-",
-                        "buffers_cmd_detach", "");
-
-if ($weechat_version >= 0x00030800)
-{
-    weechat::hook_config("buffers.look.detach", "hook_timer_detach", "");
-    $Hooks{timer_detach} = weechat::hook_timer( weechat::config_integer( $options{"detach"}) * 1000, 60, 0, "buffers_signal_hotlist", "") if ( weechat::config_integer( $options{"detach"}) > 0 );
-}
-
-    weechat::hook_config("buffers.look.show_lag", "hook_timer_lag", "");
-
-    $Hooks{timer_lag} = weechat::hook_timer( weechat::config_integer(weechat::config_get("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "") if ( weechat::config_boolean($options{"show_lag"}) );
-
-# -------------------------------- [ command ] --------------------------------
-sub buffers_cmd_whitelist
-{
-my ( $data, $buffer, $args ) = @_;
-    $args = lc($args);
-    my $buffers_whitelist = weechat::config_string( weechat::config_get("buffers.look.whitelist_buffers") );
-    return weechat::WEECHAT_RC_OK if ( $buffers_whitelist eq "" and $args eq "del" or $buffers_whitelist eq "" and $args eq "reset" );
-    my @buffers_list = split( /,/, $buffers_whitelist );
-    # get buffers name
-    my $infolist = weechat::infolist_get("buffer", weechat::current_buffer(), "");
-    weechat::infolist_next($infolist);
-    my $buffers_name = weechat::infolist_string($infolist, "name");
-    weechat::infolist_free($infolist);
-    return weechat::WEECHAT_RC_OK if ( $buffers_name eq "" );                   # should never happen
-
-    if ( $args eq "add" )
-    {
-        return weechat::WEECHAT_RC_OK if ( grep /^$buffers_name$/, @buffers_list );     # check if buffer already in list
-        push @buffers_list,( $buffers_name );
-        my $buffers_list = &create_whitelist(\@buffers_list);
-        weechat::config_option_set( weechat::config_get("buffers.look.whitelist_buffers"), $buffers_list,1 );
-        weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" added to buffers whitelist");
-    }
-    elsif ( $args eq "del" )
-    {
-        return weechat::WEECHAT_RC_OK unless ( grep /^$buffers_name$/, @buffers_list );     # check if buffer is in list
-        @buffers_list = grep {$_ ne $buffers_name} @buffers_list;                           # delete entry
-        my $buffers_list = &create_whitelist(\@buffers_list);
-        weechat::config_option_set( weechat::config_get("buffers.look.whitelist_buffers"), $buffers_list,1 );
-        weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" deleted from buffers whitelist");
-    }
-    elsif ( $args eq "reset" )
-    {
-        return weechat::WEECHAT_RC_OK if ( $buffers_whitelist eq "" );
-        weechat::config_option_set( weechat::config_get("buffers.look.whitelist_buffers"), "",1 );
-        weechat::print(weechat::current_buffer(), "buffers whitelist is empty, now...");
-    }
-    return weechat::WEECHAT_RC_OK;
-}
-sub buffers_cmd_detach
-{
-    my ( $data, $buffer, $args ) = @_;
-    $args = lc($args);
-    my $immune_detach_buffers = weechat::config_string( weechat::config_get("buffers.look.immune_detach_buffers") );
-    return weechat::WEECHAT_RC_OK if ( $immune_detach_buffers eq "" and $args eq "del" or $immune_detach_buffers eq "" and $args eq "reset" );
-
-    my @buffers_list = split( /,/, $immune_detach_buffers );
-    # get buffers name
-    my $infolist = weechat::infolist_get("buffer", weechat::current_buffer(), "");
-    weechat::infolist_next($infolist);
-    my $buffers_name = weechat::infolist_string($infolist, "name");
-    weechat::infolist_free($infolist);
-    return weechat::WEECHAT_RC_OK if ( $buffers_name eq "" );                   # should never happen
-
-    if ( $args eq "add" )
-    {
-        return weechat::WEECHAT_RC_OK if ( grep /^$buffers_name$/, @buffers_list );     # check if buffer already in list
-        push @buffers_list,( $buffers_name );
-        my $buffers_list = &create_whitelist(\@buffers_list);
-        weechat::config_option_set( weechat::config_get("buffers.look.immune_detach_buffers"), $buffers_list,1 );
-        weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" added to immune detach buffers");
-    }
-    elsif ( $args eq "del" )
-    {
-        return weechat::WEECHAT_RC_OK unless ( grep /^$buffers_name$/, @buffers_list );     # check if buffer is in list
-        @buffers_list = grep {$_ ne $buffers_name} @buffers_list;                           # delete entry
-        my $buffers_list = &create_whitelist(\@buffers_list);
-        weechat::config_option_set( weechat::config_get("buffers.look.immune_detach_buffers"), $buffers_list,1 );
-        weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" deleted from immune detach buffers");
-    }
-    elsif ( $args eq "reset" )
-    {
-        return weechat::WEECHAT_RC_OK if ( $immune_detach_buffers eq "" );
-        weechat::config_option_set( weechat::config_get("buffers.look.immune_detach_buffers"), "",1 );
-        weechat::print(weechat::current_buffer(), "immune detach buffers is empty, now...");
-    }
-    return weechat::WEECHAT_RC_OK;
-}
-
-sub create_whitelist
-{
-    my @buffers_list = @{$_[0]};
-    my $buffers_list = "";
-        foreach (@buffers_list)
-        {
-            $buffers_list .= $_ .",";
-        }
-        chop $buffers_list;                                                               # remove last ","
-    return $buffers_list;
-}
-
-# -------------------------------- [ config ] --------------------------------
-sub hook_timer_detach
-{
-    my $detach = $_[2];
-    if ( $detach eq 0 )
-    {
-        weechat::unhook($Hooks{timer_detach}) if $Hooks{timer_detach};
-        $Hooks{timer_detach} = "";
-    }
-    else
-    {
-        weechat::unhook($Hooks{timer_detach}) if $Hooks{timer_detach};
-        $Hooks{timer_detach} = weechat::hook_timer( weechat::config_integer( $options{"detach"}) * 1000, 60, 0, "buffers_signal_hotlist", "");
-    }
-    weechat::bar_item_update($SCRIPT_NAME);
-    return weechat::WEECHAT_RC_OK;
-}
-
-sub hook_timer_lag
-{
-    my $lag = $_[2];
-    if ( $lag eq "off" )
-    {
-        weechat::unhook($Hooks{timer_lag}) if $Hooks{timer_lag};
-        $Hooks{timer_lag} = "";
-    }
-    else
-    {
-        weechat::unhook($Hooks{timer_lag}) if $Hooks{timer_lag};
-        $Hooks{timer_lag} = weechat::hook_timer( weechat::config_integer(weechat::config_get("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "");
-    }
-    weechat::bar_item_update($SCRIPT_NAME);
-    return weechat::WEECHAT_RC_OK;
-}
-
-sub buffers_config_read
-{
-    return weechat::config_read($buffers_config_file) if ($buffers_config_file ne "");
-}
-sub buffers_config_write
-{
-    return weechat::config_write($buffers_config_file) if ($buffers_config_file ne "");
-}
-sub buffers_config_reload_cb
-{
-    my ($data,$config_file) = ($_[0], $_[1]);
-    return weechat::config_reload($config_file)
-}
-sub buffers_config_init
-{
-    $buffers_config_file = weechat::config_new($BUFFERS_CONFIG_FILE_NAME,"buffers_config_reload_cb","");
-    return if ($buffers_config_file eq "");
-
-my %default_options_color =
-("color_current_fg" => ["current_fg", "color", "foreground color for current buffer", "", 0, 0, "lightcyan", "lightcyan", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_current_bg" => ["current_bg", "color", "background color for current buffer", "", 0, 0, "red", "red", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_default_fg" => ["default_fg", "color", "default foreground color for buffer name", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_default_bg" => ["default_bg", "color", "default background color for buffer name", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_hotlist_highlight_fg" => ["hotlist_highlight_fg", "color", "change foreground color of buffer name if a highlight messaged received", "", 0, 0, "magenta", "magenta", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_hotlist_highlight_bg" => ["hotlist_highlight_bg", "color", "change background color of buffer name if a highlight messaged received", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_hotlist_low_fg" => ["hotlist_low_fg", "color", "change foreground color of buffer name if a low message received", "", 0, 0, "white", "white", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_hotlist_low_bg" => ["hotlist_low_bg", "color", "change background color of buffer name if a low message received", "", 0, 0,
-        "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_hotlist_message_fg" => ["hotlist_message_fg", "color", "change foreground color of buffer name if a normal message received", "", 0, 0, "yellow", "yellow", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_hotlist_message_bg" => ["hotlist_message_bg", "color", "change background color of buffer name if a normal message received", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_hotlist_private_fg" => ["hotlist_private_fg", "color", "change foreground color of buffer name if a private message received", "", 0, 0, "lightgreen", "lightgreen", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_hotlist_private_bg" => ["hotlist_private_bg", "color", "change background color of buffer name if a private message received", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_number" => ["number", "color", "color for buffer number", "", 0, 0, "lightgreen", "lightgreen", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_number_char" => ["number_char", "color", "color for buffer number char", "", 0, 0, "lightgreen", "lightgreen", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_default_fg" => ["whitelist_default_fg", "color", "default foreground color for whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_default_bg" => ["whitelist_default_bg", "color", "default background color for whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_low_fg" => ["whitelist_low_fg", "color", "low color of whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_low_bg" => ["whitelist_low_bg", "color", "low color of whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_message_fg" => ["whitelist_message_fg", "color", "message color of whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_message_bg" => ["whitelist_message_bg", "color", "message color of whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_private_fg" => ["whitelist_private_fg", "color", "private color of whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_private_bg" => ["whitelist_private_bg", "color", "private color of whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_highlight_fg" => ["whitelist_highlight_fg", "color", "highlight color of whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_whitelist_highlight_bg" => ["whitelist_highlight_bg", "color", "highlight color of whitelist buffer name", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_none_channel_fg" => ["none_channel_fg", "color", "foreground color for none channel buffer (e.g.: core/server/plugin buffer)", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_none_channel_bg" => ["none_channel_bg", "color", "background color for none channel buffer (e.g.: core/server/plugin buffer)", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "queries_default_fg" => ["queries_default_fg", "color", "foreground color for query buffer without message", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "queries_default_bg" => ["queries_default_bg", "color", "background color for query buffer without message", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "queries_message_fg" => ["queries_message_fg", "color", "foreground color for query buffer with unread message", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "queries_message_bg" => ["queries_message_bg", "color", "background color for query buffer with unread message", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "queries_highlight_fg" => ["queries_highlight_fg", "color", "foreground color for query buffer with unread highlight", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "queries_highlight_bg" => ["queries_highlight_bg", "color", "background color for query buffer with unread highlight", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_prefix_bufname" => ["prefix_bufname", "color", "color for prefix of buffer name", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
- "color_suffix_bufname" => ["suffix_bufname", "color", "color for suffix of buffer name", "", 0, 0, "default", "default", 0, "", "", "buffers_signal_config", "", "", ""],
-);
-
-my %default_options_look =
-(
- "hotlist_counter" => ["hotlist_counter", "boolean", "show number of message for the buffer (this option needs WeeChat >= 0.3.5). The relevant option for notification is \"weechat.look.buffer_notify_default\"", "", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_lag" => ["show_lag", "boolean", "show lag behind servername. This option is using \"irc.color.item_lag_finished\", \"irc.network.lag_min_show\" and \"irc.network.lag_refresh_interval\"", "", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "look_whitelist_buffers" => ["whitelist_buffers", "string", "comma separated list of buffers for using a differnt color scheme (for example: freenode.#weechat,freenode.#weechat-fr)", "", 0, 0, "", "", 0, "", "", "buffers_signal_config_whitelist", "", "", ""],
- "hide_merged_buffers" => ["hide_merged_buffers", "integer", "hide merged buffers. The value determines which merged buffers should be hidden, keepserver meaning 'all except server buffers'. Other values correspondent to the buffer type.", "server|channel|private|keepserver|all|none", 0, 0, "none", "none", 0, "", "", "buffers_signal_config", "", "", ""],
- "indenting" => ["indenting", "integer", "use indenting for channel and query buffers. This option only takes effect if bar is left/right positioned", "off|on|under_name", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "indenting_number" => ["indenting_number", "boolean", "use indenting for numbers. This option only takes effect if bar is left/right positioned", "", 0, 0, "on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
- "short_names" => ["short_names", "boolean", "display short names (remove text before first \".\" in buffer name)", "", 0, 0, "on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_number" => ["show_number", "boolean", "display channel number in front of buffername", "", 0, 0, "on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_number_char" => ["number_char", "string", "display a char behind channel number", "", 0, 0, ".", ".", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_prefix_bufname" => ["prefix_bufname", "string", "prefix displayed in front of buffername", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_suffix_bufname" => ["suffix_bufname", "string", "suffix displayed at end of buffername", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_prefix" => ["prefix", "boolean", "displays your prefix for channel in front of buffername", "", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_prefix_empty" => ["prefix_empty", "boolean", "use a placeholder for channels without prefix", "", 0, 0, "on", "on", 0, "", "",  "buffers_signal_config", "", "", ""],
- "show_prefix_query" => ["prefix_for_query", "string", "prefix displayed in front of query buffer", "", 0, 0, "", "", 0, "", "", "buffers_signal_config", "", "", ""],
- "sort" => ["sort", "integer", "sort buffer-list by \"number\" or \"name\"", "number|name", 0, 0, "number", "number", 0, "", "", "buffers_signal_config", "", "", ""],
- "core_to_front" => ["core_to_front", "boolean", "core buffer and buffers with free content will be listed first. Take only effect if buffer sort is by name", "", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "jump_prev_next_visited_buffer" => ["jump_prev_next_visited_buffer", "boolean", "jump to previously or next visited buffer if you click with left/right mouse button on currently visiting buffer", "", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "name_size_max" => ["name_size_max", "integer", "maximum size of buffer name. 0 means no limitation", "", 0, 256, 0, 0, 0, "", "", "buffers_signal_config", "", "", ""],
- "name_crop_suffix" => ["name_crop_suffix", "string", "contains an optional char(s) that is appended when buffer name is shortened", "", 0, 0, "+", "+", 0, "", "", "buffers_signal_config", "", "", ""],
- "detach" => ["detach", "integer", "detach channel from buffers list after a specific period of time (in seconds) without action (weechat ≥ 0.3.8 required) (0 means \"off\")", "", 0, 31536000, 0, "number", 0, "", "", "buffers_signal_config", "", "", ""],
- "immune_detach_buffers" => ["immune_detach_buffers", "string", "comma separated list of buffers to NOT automatically detatch. Allows \"*\" wildcard. Ex: \"BitlBee,freenode.*\"", "", 0, 0, "", "", 0, "", "", "buffers_signal_config_immune_detach_buffers", "", "", ""],
- "detach_query" => ["detach_query", "boolean", "query buffer will be detachted", "", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "detach_buffer_immediately" => ["detach_buffer_immediately", "string", "comma separated list of buffers to detach immediately. A query and highlight message will attach buffer again. Allows \"*\" wildcard. Ex: \"BitlBee,freenode.*\"", "", 0, 0, "", "", 0, "", "", "buffers_signal_config_detach_buffer_immediately", "", "", ""],
- "detach_free_content" => ["detach_free_content", "boolean", "buffers with free content will be detached (Ex: iset, chanmon)", "", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "detach_displayed_buffers" => ["detach_displayed_buffers", "boolean", "buffers displayed in a (split) window will be detached", "", 0, 0, "on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
- "detach_display_window_number" => ["detach_display_window_number", "boolean", "window number will be add, behind buffer name (this option takes only effect with \"detach_displayed_buffers\" option)", "", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "mark_inactive" => ["mark_inactive", "boolean", "if option is \"on\", inactive buffers (those you are not in) will have parentesis around them. An inactive buffer will not be detached.", "", 0, 0, "off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "toggle_bar" => ["toogle_bar", "boolean", "if option is \"on\", buffers bar will hide/show when script is (un)loaded.", "", 0, 0, "on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
- "mouse_move_buffer" => ["mouse_move_buffer", "boolean", "if option is \"on\", mouse gestures (drag & drop) can move buffers in list.", "", 0, 0, "on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
-);
-    # section "color"
-    my $section_color = weechat::config_new_section($buffers_config_file,"color", 0, 0, "", "", "", "", "", "", "", "", "", "");
-    if ($section_color eq "")
-    {
-        weechat::config_free($buffers_config_file);
-        return;
-    }
-    foreach my $option (keys %default_options_color)
-    {
-        $options{$option} = weechat::config_new_option($buffers_config_file, $section_color,
-        $default_options_color{$option}[0],$default_options_color{$option}[1],$default_options_color{$option}[2],
-        $default_options_color{$option}[3],$default_options_color{$option}[4],$default_options_color{$option}[5],
-        $default_options_color{$option}[6],$default_options_color{$option}[7],$default_options_color{$option}[8],
-        $default_options_color{$option}[9],$default_options_color{$option}[10],$default_options_color{$option}[11],
-        $default_options_color{$option}[12],$default_options_color{$option}[13],$default_options_color{$option}[14]);
-    }
-
-    # section "look"
-    my $section_look = weechat::config_new_section($buffers_config_file,"look", 0, 0, "", "", "", "", "", "", "", "", "", "");
-    if ($section_look eq "")
-    {
-        weechat::config_free($buffers_config_file);
-        return;
-    }
-    foreach my $option (keys %default_options_look)
-    {
-        $options{$option} = weechat::config_new_option($buffers_config_file, $section_look,
-        $default_options_look{$option}[0],$default_options_look{$option}[1],$default_options_look{$option}[2],
-        $default_options_look{$option}[3],$default_options_look{$option}[4],$default_options_look{$option}[5],
-        $default_options_look{$option}[6],$default_options_look{$option}[7],$default_options_look{$option}[8],
-        $default_options_look{$option}[9],$default_options_look{$option}[10],$default_options_look{$option}[11],
-        $default_options_look{$option}[12],$default_options_look{$option}[13],$default_options_look{$option}[14],
-        $default_options_look{$option}[15]);
-    }
-}
-
-sub build_buffers
-{
-    my $str = "";
-
-    # get bar position (left/right/top/bottom)
-    my $position = "left";
-    my $option_position = weechat::config_get("weechat.bar.buffers.position");
-    if ($option_position ne "")
-    {
-        $position = weechat::config_string($option_position);
-    }
-
-    # read hotlist
-    my %hotlist;
-    my $infolist = weechat::infolist_get("hotlist", "", "");
-    while (weechat::infolist_next($infolist))
-    {
-        $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")} =
-            weechat::infolist_integer($infolist, "priority");
-        if ( weechat::config_boolean( $options{"hotlist_counter"} ) eq 1 and $weechat_version >= 0x00030500)
-        {
-            $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_00"} =
-                weechat::infolist_integer($infolist, "count_00");   # low message
-            $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_01"} =
-                weechat::infolist_integer($infolist, "count_01");   # channel message
-            $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_02"} =
-                weechat::infolist_integer($infolist, "count_02");   # private message
-            $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_03"} =
-                weechat::infolist_integer($infolist, "count_03");   # highlight message
-        }
-    }
-    weechat::infolist_free($infolist);
-
-    # read buffers list
-    @buffers_focus = ();
-    my @buffers;
-    my @current1 = ();
-    my @current2 = ();
-    my $old_number = -1;
-    my $max_number = 0;
-    my $max_number_digits = 0;
-    my $active_seen = 0;
-    $infolist = weechat::infolist_get("buffer", "", "");
-    while (weechat::infolist_next($infolist))
-    {
-        my $buffer;
-        my $number = weechat::infolist_integer($infolist, "number");
-        if ($number ne $old_number)
-        {
-            @buffers = (@buffers, @current2, @current1);
-            @current1 = ();
-            @current2 = ();
-            $active_seen = 0;
-        }
-        if ($number > $max_number)
-        {
-            $max_number = $number;
-        }
-        $old_number = $number;
-        my $active = weechat::infolist_integer($infolist, "active");
-        if ($active)
-        {
-            $active_seen = 1;
-        }
-        $buffer->{"pointer"} = weechat::infolist_pointer($infolist, "pointer");
-        $buffer->{"number"} = $number;
-        $buffer->{"active"} = $active;
-        $buffer->{"current_buffer"} = weechat::infolist_integer($infolist, "current_buffer");
-        $buffer->{"num_displayed"} = weechat::infolist_integer($infolist, "num_displayed");
-        $buffer->{"plugin_name"} = weechat::infolist_string($infolist, "plugin_name");
-        $buffer->{"name"} = weechat::infolist_string($infolist, "name");
-        $buffer->{"short_name"} = weechat::infolist_string($infolist, "short_name");
-        $buffer->{"full_name"} = $buffer->{"plugin_name"}.".".$buffer->{"name"};
-        $buffer->{"type"} = weechat::buffer_get_string($buffer->{"pointer"},"localvar_type");
-#        weechat::print("",$buffer->{"type"});
-
-        # check if buffer is active (or maybe a /part, /kick channel)
-        if ($buffer->{"type"} eq "channel" and weechat::config_boolean( $options{"mark_inactive"} ) eq 1)
-        {
-            my $server = weechat::buffer_get_string($buffer->{"pointer"},"localvar_server");
-            my $channel = weechat::buffer_get_string($buffer->{"pointer"},"localvar_channel");
-            my $infolist_channel = weechat::infolist_get("irc_channel","",$server.",".$channel);
-            if ($infolist_channel)
-            {
-                weechat::infolist_next($infolist_channel);
-                $buffer->{"nicks_count"} = weechat::infolist_integer($infolist_channel,"nicks_count");
-            }else
-            {
-                $buffer->{"nicks_count"} = 0;
-            }
-            weechat::infolist_free($infolist_channel);
-        }
-
-        my $result = check_immune_detached_buffers($buffer->{"name"});          # checking for wildcard 
-
-        next if ( check_detach_buffer_immediately($buffer->{"name"}) eq 1
-                 and $buffer->{"current_buffer"} eq 0
-                 and ( not exists $hotlist{$buffer->{"pointer"}} or $hotlist{$buffer->{"pointer"}} < 2) );          # checking for buffer to immediately detach
-
-        unless ($result)
-        {
-            my $detach_time = weechat::config_integer( $options{"detach"});
-            my $current_time = time();
-            # set timer for buffers with no hotlist action
-            $buffers_timer{$buffer->{"pointer"}} = $current_time
-             if ( not exists $hotlist{$buffer->{"pointer"}}
-             and $buffer->{"type"} eq "channel"
-             and not exists $buffers_timer{$buffer->{"pointer"}}
-             and $detach_time > 0);
-
-            $buffers_timer{$buffer->{"pointer"}} = $current_time
-            if (weechat::config_boolean($options{"detach_query"}) eq 1
-            and not exists $hotlist{$buffer->{"pointer"}}
-            and $buffer->{"type"} eq "private"
-            and not exists $buffers_timer{$buffer->{"pointer"}}
-            and $detach_time > 0);
-
-            $detach_time = 0
-            if (weechat::config_boolean($options{"detach_query"}) eq 0
-            and $buffer->{"type"} eq "private");
-
-            # free content buffer
-            $buffers_timer{$buffer->{"pointer"}} = $current_time
-            if (weechat::config_boolean($options{"detach_free_content"}) eq 1
-            and not exists $hotlist{$buffer->{"pointer"}}
-            and $buffer->{"type"} eq ""
-            and not exists $buffers_timer{$buffer->{"pointer"}}
-            and $detach_time > 0);
-            $detach_time = 0
-            if (weechat::config_boolean($options{"detach_free_content"}) eq 0
-            and $buffer->{"type"} eq "");
-
-            $detach_time = 0 if (weechat::config_boolean($options{"mark_inactive"}) eq 1 and defined $buffer->{"nicks_count"} and $buffer->{"nicks_count"} == 0);
-
-            # check for detach
-            unless ( $buffer->{"current_buffer"} eq 0
-            and not exists $hotlist{$buffer->{"pointer"}}
-#            and $buffer->{"type"} eq "channel"
-            and exists $buffers_timer{$buffer->{"pointer"}}
-            and $detach_time > 0
-            and $weechat_version >= 0x00030800
-            and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
-            {
-                if ($active_seen)
-                {
-                    push(@current2, $buffer);
-                }
-                else
-                {
-                    push(@current1, $buffer);
-                }
-            }
-            elsif ( $buffer->{"current_buffer"} eq 0
-            and not exists $hotlist{$buffer->{"pointer"}}
-#            and $buffer->{"type"} eq "channel"
-            and exists $buffers_timer{$buffer->{"pointer"}}
-            and $detach_time > 0
-            and $weechat_version >= 0x00030800
-            and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
-            {   # check for option detach_displayed_buffers and if buffer is displayed in a split window
-                if ( $buffer->{"num_displayed"} eq 1
-                    and weechat::config_boolean($options{"detach_displayed_buffers"}) eq 0 )
-                {
-                    my $infolist_window = weechat::infolist_get("window","","");
-                    while (weechat::infolist_next($infolist_window))
-                    {
-                        my $buffer_ptr = weechat::infolist_pointer($infolist_window, "buffer");
-                        if ($buffer_ptr eq $buffer->{"pointer"})
-                        {
-                            $buffer->{"window"} = weechat::infolist_integer($infolist_window, "number");
-                        }
-                    }
-                    weechat::infolist_free($infolist_window);
-
-                    push(@current2, $buffer);
-                }
-            }
-        }
-        else    # buffer in "immune_detach_buffers"
-        {
-                if ($active_seen)
-                {
-                    push(@current2, $buffer);
-                }
-                else
-                {
-                    push(@current1, $buffer);
-                }
-        }
-    }   # while end
-
-
-    if ($max_number >= 1)
-    {
-        $max_number_digits = length(int($max_number));
-    }
-    @buffers = (@buffers, @current2, @current1);
-    weechat::infolist_free($infolist);
-
-    # sort buffers by number, name or shortname
-    my %sorted_buffers;
-    if (1)
-    {
-        my $number = 0;
-        for my $buffer (@buffers)
-        {
-            my $key;
-            if (weechat::config_integer( $options{"sort"} ) eq 1) # number = 0; name = 1
-            {
-                my $name = $buffer->{"name"};
-                $name = $buffer->{"short_name"} if (weechat::config_boolean( $options{"short_names"} ) eq 1);
-                if (weechat::config_integer($options{"name_size_max"}) >= 1){
-                    $name = encode("UTF-8", substr(decode("UTF-8", $name), 0, weechat::config_integer($options{"name_size_max"})));
-                }
-                if ( weechat::config_boolean($options{"core_to_front"}) eq 1)
-                {
-                    if ( (weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "private") )
-                    {
-                        my $type = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
-                        if ( $type eq "" and $name ne "weechat")
-                        {
-                            $name = " " . $name
-                        }else
-                        {
-                            $name = "  " . $name;
-                        }
-                    }
-                }
-                $key = sprintf("%s%08d", lc($name), $buffer->{"number"});
-            }
-            else
-            {
-                $key = sprintf("%08d", $number);
-            }
-            $sorted_buffers{$key} = $buffer;
-            $number++;
-        }
-    }
-
-    # build string with buffers
-    $old_number = -1;
-    foreach my $key (sort keys %sorted_buffers)
-    {
-        my $buffer = $sorted_buffers{$key};
-
-        if ( weechat::config_string($options{"hide_merged_buffers"}) eq "server" )
-        {
-            # buffer type "server" or merged with core?
-            if ( ($buffer->{"type"} eq "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
-            {
-                next;
-            }
-        }
-        if ( weechat::config_string($options{"hide_merged_buffers"}) eq "channel" )
-        {
-            # buffer type "channel" or merged with core?
-            if ( ($buffer->{"type"} eq "channel" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
-            {
-                next;
-            }
-        }
-        if ( weechat::config_string($options{"hide_merged_buffers"}) eq "private" )
-        {
-            # buffer type "private" or merged with core?
-            if ( ($buffer->{"type"} eq "private" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
-            {
-                next;
-            }
-        }
-        if ( weechat::config_string($options{"hide_merged_buffers"}) eq "keepserver" )
-        {
-            if ( ($buffer->{"type"} ne "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
-            {
-                next;
-            }
-        }
-        if ( weechat::config_string($options{"hide_merged_buffers"}) eq "all" )
-        {
-            if ( ! $buffer->{"active"} )
-            {
-                next;
-            }
-        }
-
-        push(@buffers_focus, $buffer);                                          # buffer > buffers_focus, for mouse support
-        my $color = "";
-        my $bg = "";
-
-        $color = weechat::config_color( $options{"color_default_fg"} );
-        $bg = weechat::config_color( $options{"color_default_bg"} );
-
-        if ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "private" )
-        {
-            if ( (weechat::config_color($options{"queries_default_bg"})) ne "default" || (weechat::config_color($options{"queries_default_fg"})) ne "default" )
-            {
-              $bg = weechat::config_color( $options{"queries_default_bg"} );
-              $color = weechat::config_color( $options{"queries_default_fg"} );
-            }
-        }
-        # check for core and buffer with free content
-        if ( (weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "private") )
-        {
-            $color = weechat::config_color( $options{"color_none_channel_fg"} );
-            $bg = weechat::config_color( $options{"color_none_channel_bg"} );
-        }
-        # default whitelist buffer?
-        if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
-        {
-                $color = weechat::config_color( $options{"color_whitelist_default_fg"} );
-                $bg = weechat::config_color( $options{"color_whitelist_default_bg"} );
-        }
-
-        $color = "default" if ($color eq "");
-
-        # color for channel and query buffer
-        if (exists $hotlist{$buffer->{"pointer"}})
-        {
-        delete $buffers_timer{$buffer->{"pointer"}};
-            # check if buffer is in whitelist buffer
-            if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
-            {
-                $bg = weechat::config_color( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
-                $color = weechat::config_color( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
-            }
-            elsif ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "private" )
-            {
-                # queries_default_fg/bg and buffers.color.queries_message_fg/bg
-                if ( (weechat::config_color($options{"queries_highlight_fg"})) ne "default" ||
-                      (weechat::config_color($options{"queries_highlight_bg"})) ne "default" ||
-                       (weechat::config_color($options{"queries_message_fg"})) ne "default" ||
-                        (weechat::config_color($options{"queries_message_bg"})) ne "default" )
-                {
-                  if ( ($hotlist{$buffer->{"pointer"}}) == 2 )
-                  {
-                      $bg = weechat::config_color( $options{"queries_message_bg"} );
-                      $color = weechat::config_color( $options{"queries_message_fg"} );
-                  }
-
-                  elsif ( ($hotlist{$buffer->{"pointer"}}) == 3 )
-                  {
-                      $bg = weechat::config_color( $options{"queries_highlight_bg"} );
-                      $color = weechat::config_color( $options{"queries_highlight_fg"} );
-                  }
-                }else
-                {
-                      $bg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
-                      $color = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"}  );
-                }
-            }else
-            {
-                      $bg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
-                      $color = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"}  );
-            }
-        }
-
-        if ($buffer->{"current_buffer"})
-        {
-            $color = weechat::config_color( $options{"color_current_fg"} );
-            $bg = weechat::config_color( $options{"color_current_bg"} );
-        }
-        my $color_bg = "";
-        $color_bg = weechat::color(",".$bg) if ($bg ne "");
-
-        # create channel number for output
-        if ( weechat::config_string( $options{"show_prefix_bufname"} ) ne "" )
-        {
-            $str .= $color_bg .
-                    weechat::color( weechat::config_color( $options{"color_prefix_bufname"} ) ).
-                    weechat::config_string( $options{"show_prefix_bufname"} ).
-                    weechat::color("default");
-        }
-
-        if ( weechat::config_boolean( $options{"show_number"} ) eq 1 )   # on
-        {
-            if (( weechat::config_boolean( $options{"indenting_number"} ) eq 1)
-                && (($position eq "left") || ($position eq "right")))
-            {
-                $str .= weechat::color("default").$color_bg
-                    .(" " x ($max_number_digits - length(int($buffer->{"number"}))));
-            }
-            if ($old_number ne $buffer->{"number"})
-            {
-                $str .= weechat::color( weechat::config_color( $options{"color_number"} ) )
-                    .$color_bg
-                    .$buffer->{"number"}
-                    .weechat::color("default")
-                    .$color_bg
-                    .weechat::color( weechat::config_color( $options{"color_number_char"} ) )
-                    .weechat::config_string( $options{"show_number_char"} )
-                    .$color_bg;
-            }
-            else
-            {
-                my $indent = "";
-                $indent = ((" " x length($buffer->{"number"}))." ") if (($position eq "left") || ($position eq "right"));
-                $str .= weechat::color("default")
-                    .$color_bg
-                    .$indent;
-            }
-        }
-
-        if (( weechat::config_integer( $options{"indenting"} ) ne 0 )            # indenting NOT off
-            && (($position eq "left") || ($position eq "right")))
-        {
-            my $type = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
-            if (($type eq "channel") || ($type eq "private"))
-            {
-                if ( weechat::config_integer( $options{"indenting"} ) eq 1 )
-                {
-                    $str .= "  ";
-                }
-                elsif ( (weechat::config_integer($options{"indenting"}) eq 2) and (weechat::config_integer($options{"indenting_number"}) eq 0) )        #under_name
-                {
-                    if ( weechat::config_boolean( $options{"show_number"} ) eq 0 )
-                    {
-                      $str .= "  ";
-                    }else
-                    {
-                      $str .= ( (" " x ( $max_number_digits - length($buffer->{"number"}) ))." " );
-                    }
-                }
-            }
-        }
-
-        $str .= weechat::config_string( $options{"show_prefix_query"}) if (weechat::config_string( $options{"show_prefix_query"} ) ne "" and  $buffer->{"type"} eq "private");
-
-        if (weechat::config_boolean( $options{"show_prefix"} ) eq 1)
-        {
-            my $nickname = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_nick");
-            if ($nickname ne "")
-            {
-                # with version >= 0.3.2, this infolist will return only nick
-                # with older versions, whole nicklist is returned for buffer, and this can be very slow
-                my $infolist_nick = weechat::infolist_get("nicklist", $buffer->{"pointer"}, "nick_".$nickname);
-                if ($infolist_nick ne "")
-                {
-                    while (weechat::infolist_next($infolist_nick))
-                    {
-                        if ((weechat::infolist_string($infolist_nick, "type") eq "nick")
-                            && (weechat::infolist_string($infolist_nick, "name") eq $nickname))
-                        {
-                            my $prefix = weechat::infolist_string($infolist_nick, "prefix");
-                            if (($prefix ne " ") or (weechat::config_boolean( $options{"show_prefix_empty"} ) eq 1))
-                            {
-                                # with version >= 0.3.5, it is now a color name (for older versions: option name with color)
-                                if (int($weechat_version) >= 0x00030500)
-                                {
-                                    $str .= weechat::color(weechat::infolist_string($infolist_nick, "prefix_color"));
-                                }
-                                else
-                                {
-                                    $str .= weechat::color(weechat::config_color(
-                                                               weechat::config_get(
-                                                                   weechat::infolist_string($infolist_nick, "prefix_color"))));
-                                }
-                                $str .= $prefix;
-                            }
-                            last;
-                        }
-                    }
-                    weechat::infolist_free($infolist_nick);
-                }
-            }
-        }
-        if ($buffer->{"type"} eq "channel" and weechat::config_boolean( $options{"mark_inactive"} ) eq 1 and $buffer->{"nicks_count"} == 0)
-        {
-            $str .= "(";
-        }
-
-        $str .= weechat::color($color) . weechat::color(",".$bg);
-
-        if (weechat::config_boolean( $options{"short_names"} ) eq 1)
-        {
-            if (weechat::config_integer($options{"name_size_max"}) >= 1)                # check max_size of buffer name
-            {
-                $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"short_name"}), 0, weechat::config_integer($options{"name_size_max"})));
-                $str .= weechat::color(weechat::config_color( $options{"color_number_char"})).weechat::config_string($options{"name_crop_suffix"}) if (length($buffer->{"short_name"}) > weechat::config_integer($options{"name_size_max"}));
-                $str .= add_inactive_parentless($buffer->{"type"},$buffer->{"nicks_count"});
-                $str .= add_hotlist_count($buffer->{"pointer"},%hotlist);
-            }
-            else
-            {
-                $str .= $buffer->{"short_name"};
-                $str .= add_inactive_parentless($buffer->{"type"},$buffer->{"nicks_count"});
-                $str .= add_hotlist_count($buffer->{"pointer"},%hotlist);
-            }
-        }
-        else
-        {
-            if (weechat::config_integer($options{"name_size_max"}) >= 1)                # check max_size of buffer name
-            {
-                $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"name"},), 0, weechat::config_integer($options{"name_size_max"})));
-                $str .= weechat::color(weechat::config_color( $options{"color_number_char"})).weechat::config_string($options{"name_crop_suffix"}) if (length($buffer->{"name"}) > weechat::config_integer($options{"name_size_max"}));
-                $str .= add_inactive_parentless($buffer->{"type"},$buffer->{"nicks_count"});
-                $str .= add_hotlist_count($buffer->{"pointer"},%hotlist);
-            }
-            else
-            {
-                $str .= $buffer->{"name"};
-                $str .= add_inactive_parentless($buffer->{"type"},$buffer->{"nicks_count"});
-                $str .= add_hotlist_count($buffer->{"pointer"},%hotlist);
-            }
-        }
-        if ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "server" and weechat::config_boolean($options{"show_lag"}) eq 1)
-        {
-            my $color_lag = weechat::config_color(weechat::config_get("irc.color.item_lag_finished"));
-            my $min_lag = weechat::config_integer(weechat::config_get("irc.network.lag_min_show"));
-            my $infolist_server = weechat::infolist_get("irc_server","",$buffer->{"short_name"});
-            weechat::infolist_next($infolist_server);
-            my $lag = (weechat::infolist_integer($infolist_server, "lag"));
-            weechat::infolist_free($infolist_server);
-            if ( int($lag) > int($min_lag) )
-            {
-                $lag = $lag / 1000;
-                $str .= weechat::color("default") . " (" . weechat::color($color_lag) . $lag . weechat::color("default") . ")";
-            }
-        }
-        if (weechat::config_boolean($options{"detach_displayed_buffers"}) eq 0
-            and weechat::config_boolean($options{"detach_display_window_number"}) eq 1)
-        {
-            if ($buffer->{"window"})
-            {
-                $str .= weechat::color("default") . " (" . weechat::color(weechat::config_color( $options{"color_number"})) . $buffer->{"window"} . weechat::color("default") . ")";
-            }
-        }
-        $str .= weechat::color("default");
-
-        if ( weechat::config_string( $options{"show_suffix_bufname"} ) ne "" )
-        {
-            $str .= weechat::color( weechat::config_color( $options{"color_suffix_bufname"} ) ).
-                    weechat::config_string( $options{"show_suffix_bufname"} ).
-                    weechat::color("default");
-        }
-
-        $str .= "\n";
-        $old_number = $buffer->{"number"};
-    }
-
-    # remove spaces and/or linefeed at the end
-    $str =~ s/\s+$//;
-    chomp($str);
-    return $str;
-}
-
-sub add_inactive_parentless
-{
-my ($buf_type, $buf_nicks_count) = @_;
-my $str = "";
-    if ($buf_type eq "channel" and weechat::config_boolean( $options{"mark_inactive"} ) eq 1 and $buf_nicks_count == 0)
-    {
-        $str .= weechat::color(weechat::config_color( $options{"color_number_char"}));
-        $str .= ")";
-    }
-return $str;
-}
-
-sub add_hotlist_count
-{
-my ($bufpointer,%hotlist) = @_;
-
-return "" if ( weechat::config_boolean( $options{"hotlist_counter"} ) eq 0 or ($weechat_version < 0x00030500));   # off
-my $col_number_char = weechat::color(weechat::config_color( $options{"color_number_char"}) );
-my $str = " ".$col_number_char."(";
-
-# 0 = low level
-if (defined $hotlist{$bufpointer."_count_00"})
-{
-    my $bg = weechat::config_color( $options{"color_hotlist_low_bg"} );
-    my $color = weechat::config_color( $options{"color_hotlist_low_fg"} );
-    $str .= weechat::color($bg).
-            weechat::color($color).
-            $hotlist{$bufpointer."_count_00"} if ($hotlist{$bufpointer."_count_00"} ne "0");
-}
-
-# 1 = message
-if (defined $hotlist{$bufpointer."_count_01"})
-{
-    my $bg = weechat::config_color( $options{"color_hotlist_message_bg"} );
-    my $color = weechat::config_color( $options{"color_hotlist_message_fg"} );
-    if ($str =~ /[0-9]$/)
-    {
-        $str .= ",".
-                weechat::color($bg).
-                weechat::color($color).
-                $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
-    }else
-    {
-        $str .= weechat::color($bg).
-                weechat::color($color).
-                $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
-    }
-}
-# 2 = private
-if (defined $hotlist{$bufpointer."_count_02"})
-{
-    my $bg = weechat::config_color( $options{"color_hotlist_private_bg"} );
-    my $color = weechat::config_color( $options{"color_hotlist_private_fg"} );
-    if ($str =~ /[0-9]$/)
-    {
-        $str .= ",".
-                weechat::color($bg).
-                weechat::color($color).
-                $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
-    }else
-    {
-        $str .= weechat::color($bg).
-                weechat::color($color).
-                $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
-    }
-}
-# 3 = highlight
-if (defined $hotlist{$bufpointer."_count_03"})
-{
-    my $bg = weechat::config_color( $options{"color_hotlist_highlight_bg"} );
-    my $color = weechat::config_color( $options{"color_hotlist_highlight_fg"} );
-    if ($str =~ /[0-9]$/)
-    {
-        $str .= ",".
-                weechat::color($bg).
-                weechat::color($color).
-                $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
-    }else
-    {
-        $str .= weechat::color($bg).
-                weechat::color($color).
-                $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
-    }
-}
-$str .= $col_number_char. ")";
-
-$str = "" if (weechat::string_remove_color($str, "") eq " ()");         # remove color and check for buffer with no messages
-return $str;
-}
-
-sub buffers_signal_buffer
-{
-    my ($data, $signal, $signal_data) = @_;
-
-    # check for buffer_switch and set or remove detach time
-    if ($weechat_version >= 0x00030800)
-    {
-        if ($signal eq "buffer_switch")
-        {
-            my $pointer = weechat::hdata_get_list (weechat::hdata_get("buffer"), "gui_buffer_last_displayed"); # get switched buffer
-            my $current_time = time();
-            if ( weechat::buffer_get_string($pointer, "localvar_type") eq "channel")
-            {
-                $buffers_timer{$pointer} = $current_time;
-            }
-            else
-            {
-                delete $buffers_timer{$pointer};
-            }
-        }
-        if ($signal eq "buffer_opened")
-        {
-            my $current_time = time();
-            $buffers_timer{$signal_data} = $current_time;
-        }
-        if ($signal eq "buffer_closing")
-        {
-            delete $buffers_timer{$signal_data};
-        }
-    }
-    weechat::bar_item_update($SCRIPT_NAME);
-    return weechat::WEECHAT_RC_OK;
-}
-
-sub buffers_signal_hotlist
-{
-    weechat::bar_item_update($SCRIPT_NAME);
-    return weechat::WEECHAT_RC_OK;
-}
-
-
-sub buffers_signal_config_whitelist
-{
-    @whitelist_buffers = ();
-    @whitelist_buffers = split( /,/, weechat::config_string( $options{"look_whitelist_buffers"} ) );
-    weechat::bar_item_update($SCRIPT_NAME);
-    return weechat::WEECHAT_RC_OK;
-}
-
-sub buffers_signal_config_immune_detach_buffers
-{
-    @immune_detach_buffers = ();
-    @immune_detach_buffers = split( /,/, weechat::config_string( $options{"immune_detach_buffers"} ) );
-    weechat::bar_item_update($SCRIPT_NAME);
-    return weechat::WEECHAT_RC_OK;
-}
-
-sub buffers_signal_config_detach_buffer_immediately
-{
-    @detach_buffer_immediately = ();
-    @detach_buffer_immediately = split( /,/, weechat::config_string( $options{"detach_buffer_immediately"} ) );
-    weechat::bar_item_update($SCRIPT_NAME);
-    return weechat::WEECHAT_RC_OK;
-}
-
-sub buffers_signal_config
-{
-    weechat::bar_item_update($SCRIPT_NAME);
-    return weechat::WEECHAT_RC_OK;
-}
-
-# called when mouse click occured in buffers item: this callback returns buffer
-# hash according to line of item where click occured
-sub buffers_focus_buffers
-{
-    my %info = %{$_[1]};
-    my $item_line = int($info{"_bar_item_line"});
-    undef my $hash;
-    if (($info{"_bar_item_name"} eq $SCRIPT_NAME) && ($item_line >= 0) && ($item_line <= $#buffers_focus))
-    {
-        $hash = $buffers_focus[$item_line];
-    }
-    else
-    {
-        $hash = {};
-        my $hash_focus = $buffers_focus[0];
-        foreach my $key (keys %$hash_focus)
-        {
-            $hash->{$key} = "?";
-        }
-    }
-    return $hash;
-}
-
-# called when a mouse action is done on buffers item, to execute action
-# possible actions: jump to a buffer or move buffer in list (drag & drop of buffer)
-sub buffers_hsignal_mouse
-{
-    my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
-    my $current_buffer = weechat::buffer_get_integer(weechat::current_buffer(), "number"); # get current buffer number
-
-    if ( $hash{"_key"} eq "button1" )           # left mouse button
-    {
-        if ($hash{"number"} eq $hash{"number2"})
-        {
-            if ( weechat::config_integer($options{"jump_prev_next_visited_buffer"}) eq 1 )
-            {
-                if ( $current_buffer eq $hash{"number"} )
-                {
-                    weechat::command("","/input jump_previously_visited_buffer");
-                }
-                else
-                {
-                    weechat::command("", "/buffer ".$hash{"full_name"});
-                }
-            }
-            else
-            {
-                weechat::command("", "/buffer ".$hash{"full_name"});
-            }
-        }
-        else
-        {
-            move_buffer(%hash) if (weechat::config_boolean($options{"mouse_move_buffer"}));
-        }
-    }
-    elsif ( ($hash{"_key"} eq "button2") && (weechat::config_integer($options{"jump_prev_next_visited_buffer"}) eq 1) )# right mouse button
-    {
-        if ( $current_buffer eq $hash{"number2"} )
-        {
-            weechat::command("","/input jump_next_visited_buffer");
-        }
-    }
-    else
-    {
-        my $infolist = weechat::infolist_get("hook", "", "command,menu");
-        my $has_menu_command = weechat::infolist_next($infolist);
-        weechat::infolist_free($infolist);
-
-        if ( $has_menu_command && $hash{"_key"} =~ /button2/ )
-        {
-            if ($hash{"number"} eq $hash{"number2"})
-            {
-                weechat::command($hash{"pointer"}, "/menu buffer1 $hash{short_name} $hash{number}");
-            }
-            else
-            {
-                weechat::command($hash{"pointer"}, "/menu buffer2 $hash{short_name}/$hash{short_name2} $hash{number} $hash{number2}")
-            }
-        }
-        else
-        {
-            move_buffer(%hash) if (weechat::config_boolean($options{"mouse_move_buffer"}));
-        }
-    }
-}
-
-sub move_buffer
-{
-  my %hash = @_;
-  my $number2 = $hash{"number2"};
-  if ($number2 eq "?")
-  {
-      # if number 2 is not known (end of gesture outside buffers list), then set it
-      # according to mouse gesture
-      $number2 = "1";
-      if (($hash{"_key"} =~ /gesture-right/) || ($hash{"_key"} =~ /gesture-down/))
-      {
-          $number2 = "999999";
-          if ($weechat_version >= 0x00030600)
-          {
-              my $hdata_buffer = weechat::hdata_get("buffer");
-              my $last_gui_buffer = weechat::hdata_get_list($hdata_buffer, "last_gui_buffer");
-              if ($last_gui_buffer)
-              {
-                  $number2 = weechat::hdata_integer($hdata_buffer, $last_gui_buffer, "number") + 1;
-              }
-          }
-      }
-  }
-  my $ptrbuf = weechat::current_buffer();
-  weechat::command($hash{"pointer"}, "/buffer move ".$number2);
-}
-
-sub check_immune_detached_buffers
-{
-    my ($buffername) = @_;
-    foreach ( @immune_detach_buffers ){
-        my $immune_buffer = weechat::string_mask_to_regex($_);
-        if ($buffername =~ /^$immune_buffer$/i)
-        {
-            return 1;
-        }
-    }
-    return 0;
-}
-
-sub check_detach_buffer_immediately
-{
-    my ($buffername) = @_;
-    foreach ( @detach_buffer_immediately ){
-        my $detach_buffer = weechat::string_mask_to_regex($_);
-        if ($buffername =~ /^$detach_buffer$/i)
-        {
-            return 1;
-        }
-    }
-    return 0;
-}
-
-sub shutdown_cb
-{
-    weechat::command("","/bar hide " . $SCRIPT_NAME) if ( weechat::config_boolean($options{"toggle_bar"}) eq 1 );
-    return weechat::WEECHAT_RC_OK
-}
-
-sub check_bar_item
-{
-    my $item = 0;
-    my $infolist = weechat::infolist_get("bar", "", "");
-    while (weechat::infolist_next($infolist))
-    {
-        my $bar_items = weechat::infolist_string($infolist, "items");
-        if (index($bar_items,$SCRIPT_NAME) != -1)
-        {
-            my $name = weechat::infolist_string($infolist, "name");
-            if ($name ne $SCRIPT_NAME)
-            {
-                $item = 1;
-                last;
-            }
-        }
-    }
-    weechat::infolist_free($infolist);
-    return $item;
-}
--- a/weechat/plugins.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/plugins.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,1 +1,89 @@
-/Users/sjl/Dropbox/Settings/plugins.conf
\ No newline at end of file
+#
+# weechat -- plugins.conf
+#
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
+
+[var]
+fifo.fifo = "on"
+lua.check_license = "off"
+perl.buffers.color_current = "black,green"
+perl.buffers.color_default = "default"
+perl.buffers.color_hotlist_highlight = "lightmagenta"
+perl.buffers.color_hotlist_low = "default"
+perl.buffers.color_hotlist_message = "green"
+perl.buffers.color_hotlist_private = "lightgreen"
+perl.buffers.color_number = "green"
+perl.buffers.color_whitelist_buffers = ""
+perl.buffers.color_whitelist_default = ""
+perl.buffers.color_whitelist_highlight = ""
+perl.buffers.color_whitelist_low = ""
+perl.buffers.color_whitelist_message = ""
+perl.buffers.color_whitelist_private = ""
+perl.buffers.hide_merged_buffers = "all"
+perl.buffers.indenting = "on"
+perl.buffers.indenting_number = "on"
+perl.buffers.short_names = "on"
+perl.buffers.show_category = "off"
+perl.buffers.show_number = "on"
+perl.buffers.show_prefix = "off"
+perl.buffers.show_prefix_empty = "on"
+perl.buffers.sort = "number"
+perl.check_license = "on"
+perl.colorize_lines.avail_buffer = "all"
+perl.colorize_lines.blacklist_buffers = ""
+perl.colorize_lines.blacklist_channels = ""
+perl.colorize_lines.buffer_autoset = "off"
+perl.colorize_lines.buffers = "all"
+perl.colorize_lines.chat = "off"
+perl.colorize_lines.highlight = "on"
+perl.colorize_lines.hotlist_max_level_nicks_add = "off"
+perl.colorize_lines.lines = "off"
+perl.colorize_lines.look_highlight = "on"
+perl.colorize_lines.look_highlight_regex = "on"
+perl.colorize_lines.nicks = ""
+perl.colorize_lines.own_lines = "off"
+perl.colorize_lines.shuffle = "off"
+python.check_license = "on"
+python.growl.hostname = ""
+python.growl.icon = "icon.png"
+python.growl.password = ""
+python.growl.show_channel_topic = "on"
+python.growl.show_dcc = "on"
+python.growl.show_highlighted_message = "on"
+python.growl.show_invite_message = "on"
+python.growl.show_notice_message = "off"
+python.growl.show_private_action_message = "on"
+python.growl.show_private_message = "on"
+python.growl.show_public_action_message = "off"
+python.growl.show_public_message = "off"
+python.growl.show_server = "on"
+python.growl.show_upgrade_ended = "on"
+python.growl.sticky = "off"
+python.growl.sticky_away = "on"
+python.notification_center.show_highlights = "on"
+python.notification_center.show_message_text = "on"
+python.notification_center.show_private_message = "on"
+python.notification_center.sound = "off"
+ruby.check_license = "on"
+tcl.check_license = "on"
+
+[desc]
+perl.colorize_lines.avail_buffer = "messages will be colored in buffer (all = all buffers, channel = channel buffers, query = query buffers (default: all "
+perl.colorize_lines.blacklist_buffers = "comma-separated list of channels to be ignored (e.g. freenode.#weechat,*.#python)"
+perl.colorize_lines.blacklist_channels = "comma separated list with channelname. Channels in this list will be ignored. (e.g.: freenode.#weechat,freenode.#weechat-fr)"
+perl.colorize_lines.buffer_autoset = "toggle highlight color in chat area for buffer_autoset (default: off)"
+perl.colorize_lines.buffers = "buffer type affected by the script (all/channel/query, default: all)"
+perl.colorize_lines.chat = "colors text in chat area with according nick color (default: on)"
+perl.colorize_lines.highlight = "highlight messages will be fully highlighted in chat area (on = whole line will be highlighted, off = only nick will be highlighted, always = a highlight will always color the whole message) (default: on)"
+perl.colorize_lines.hotlist_max_level_nicks_add = "toggle highlight for hotlist (default: off)"
+perl.colorize_lines.look_highlight = "toggle highlight color in chat area for option weechat.look.highlight (default: off)"
+perl.colorize_lines.look_highlight_regex = "toggle highlight color in chat area for option weechat.look.highlight_regex (default: off)"
+perl.colorize_lines.nicks = "comma separated list with nicknames. Only messages from nicks in this list will be colorized. (e.g.: freenode.nils_2,freenode.flashcode,freenode.weebot). You can also give a filename with nicks. The filename has to start with "/" (e.g.: /buddylist.txt). The format has to be: one nick each line with <servername>.<nickname>"
+perl.colorize_lines.own_lines = "colors own written messages (default: off)"
+perl.colorize_lines.shuffle = "toggle shuffle color mode for chats area (default: off)"
--- a/weechat/python/autoload/wee_slack.py	Fri Sep 08 19:37:36 2017 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3551 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from __future__ import unicode_literals
-
-from functools import wraps
-
-import time
-import json
-import pickle
-import sha
-import os
-import re
-import urllib
-import sys
-import traceback
-import collections
-import ssl
-import random
-import string
-
-from websocket import create_connection, WebSocketConnectionClosedException
-
-# hack to make tests possible.. better way?
-try:
-    import weechat
-except:
-    pass
-
-SCRIPT_NAME = "slack"
-SCRIPT_AUTHOR = "Ryan Huber <rhuber@gmail.com>"
-SCRIPT_VERSION = "1.99"
-SCRIPT_LICENSE = "MIT"
-SCRIPT_DESC = "Extends weechat for typing notification/search/etc on slack.com"
-
-BACKLOG_SIZE = 200
-SCROLLBACK_SIZE = 500
-
-RECORD_DIR = "/tmp/weeslack-debug"
-
-SLACK_API_TRANSLATOR = {
-    "channel": {
-        "history": "channels.history",
-        "join": "channels.join",
-        "leave": "channels.leave",
-        "mark": "channels.mark",
-        "info": "channels.info",
-    },
-    "im": {
-        "history": "im.history",
-        "join": "im.open",
-        "leave": "im.close",
-        "mark": "im.mark",
-    },
-    "group": {
-        "history": "groups.history",
-        "join": "channels.join",
-        "leave": "groups.leave",
-        "mark": "groups.mark",
-        "info": "groups.info"
-    },
-    "thread": {
-        "history": None,
-        "join": None,
-        "leave": None,
-        "mark": None,
-    }
-
-
-}
-
-###### Decorators have to be up here
-
-
-def slack_buffer_or_ignore(f):
-    """
-    Only run this function if we're in a slack buffer, else ignore
-    """
-    @wraps(f)
-    def wrapper(data, current_buffer, *args, **kwargs):
-        if current_buffer not in EVENTROUTER.weechat_controller.buffers:
-            return w.WEECHAT_RC_OK
-        return f(data, current_buffer, *args, **kwargs)
-    return wrapper
-
-
-def slack_buffer_required(f):
-    """
-    Only run this function if we're in a slack buffer, else print error
-    """
-    @wraps(f)
-    def wrapper(data, current_buffer, *args, **kwargs):
-        if current_buffer not in EVENTROUTER.weechat_controller.buffers:
-            return w.WEECHAT_RC_ERROR
-        return f(data, current_buffer, *args, **kwargs)
-    return wrapper
-
-
-NICK_GROUP_HERE = "0|Here"
-NICK_GROUP_AWAY = "1|Away"
-
-sslopt_ca_certs = {}
-if hasattr(ssl, "get_default_verify_paths") and callable(ssl.get_default_verify_paths):
-    ssl_defaults = ssl.get_default_verify_paths()
-    if ssl_defaults.cafile is not None:
-        sslopt_ca_certs = {'ca_certs': ssl_defaults.cafile}
-
-###### Unicode handling
-
-
-def encode_to_utf8(data):
-    if isinstance(data, unicode):
-        return data.encode('utf-8')
-    if isinstance(data, bytes):
-        return data
-    elif isinstance(data, collections.Mapping):
-        return dict(map(encode_to_utf8, data.iteritems()))
-    elif isinstance(data, collections.Iterable):
-        return type(data)(map(encode_to_utf8, data))
-    else:
-        return data
-
-
-def decode_from_utf8(data):
-    if isinstance(data, bytes):
-        return data.decode('utf-8')
-    if isinstance(data, unicode):
-        return data
-    elif isinstance(data, collections.Mapping):
-        return dict(map(decode_from_utf8, data.iteritems()))
-    elif isinstance(data, collections.Iterable):
-        return type(data)(map(decode_from_utf8, data))
-    else:
-        return data
-
-
-class WeechatWrapper(object):
-    def __init__(self, wrapped_class):
-        self.wrapped_class = wrapped_class
-
-    def __getattr__(self, attr):
-        orig_attr = self.wrapped_class.__getattribute__(attr)
-        if callable(orig_attr):
-            def hooked(*args, **kwargs):
-                result = orig_attr(*encode_to_utf8(args), **encode_to_utf8(kwargs))
-                # Prevent wrapped_class from becoming unwrapped
-                if result == self.wrapped_class:
-                    return self
-                return decode_from_utf8(result)
-            return hooked
-        else:
-            return decode_from_utf8(orig_attr)
-
-
-##### Helpers
-
-def get_nick_color_name(nick):
-    info_name_prefix = "irc_" if int(weechat_version) < 0x1050000 else ""
-    return w.info_get(info_name_prefix + "nick_color_name", nick)
-
-
-##### BEGIN NEW
-
-IGNORED_EVENTS = [
-    "hello",
-    # "pref_change",
-    # "reconnect_url",
-]
-
-###### New central Event router
-
-
-class EventRouter(object):
-
-    def __init__(self):
-        """
-        complete
-        Eventrouter is the central hub we use to route:
-        1) incoming websocket data
-        2) outgoing http requests and incoming replies
-        3) local requests
-        It has a recorder that, when enabled, logs most events
-        to the location specified in RECORD_DIR.
-        """
-        self.queue = []
-        self.slow_queue = []
-        self.slow_queue_timer = 0
-        self.teams = {}
-        self.context = {}
-        self.weechat_controller = WeechatController(self)
-        self.previous_buffer = ""
-        self.reply_buffer = {}
-        self.cmds = {k[8:]: v for k, v in globals().items() if k.startswith("command_")}
-        self.proc = {k[8:]: v for k, v in globals().items() if k.startswith("process_")}
-        self.handlers = {k[7:]: v for k, v in globals().items() if k.startswith("handle_")}
-        self.local_proc = {k[14:]: v for k, v in globals().items() if k.startswith("local_process_")}
-        self.shutting_down = False
-        self.recording = False
-        self.recording_path = "/tmp"
-
-    def record(self):
-        """
-        complete
-        Toggles the event recorder and creates a directory for data if enabled.
-        """
-        self.recording = not self.recording
-        if self.recording:
-            if not os.path.exists(RECORD_DIR):
-                os.makedirs(RECORD_DIR)
-
-    def record_event(self, message_json, file_name_field, subdir=None):
-        """
-        complete
-        Called each time you want to record an event.
-        message_json is a json in dict form
-        file_name_field is the json key whose value you want to be part of the file name
-        """
-        now = time.time()
-        if subdir:
-            directory = "{}/{}".format(RECORD_DIR, subdir)
-        else:
-            directory = RECORD_DIR
-        if not os.path.exists(directory):
-            os.makedirs(directory)
-        mtype = message_json.get(file_name_field, 'unknown')
-        f = open('{}/{}-{}.json'.format(directory, now, mtype), 'w')
-        f.write("{}".format(json.dumps(message_json)))
-        f.close()
-
-    def store_context(self, data):
-        """
-        A place to store data and vars needed by callback returns. We need this because
-        weechat's "callback_data" has a limited size and weechat will crash if you exceed
-        this size.
-        """
-        identifier = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(40))
-        self.context[identifier] = data
-        dbg("stored context {} {} ".format(identifier, data.url))
-        return identifier
-
-    def retrieve_context(self, identifier):
-        """
-        A place to retrieve data and vars needed by callback returns. We need this because
-        weechat's "callback_data" has a limited size and weechat will crash if you exceed
-        this size.
-        """
-        data = self.context.get(identifier, None)
-        if data:
-            # dbg("retrieved context {} ".format(identifier))
-            return data
-
-    def delete_context(self, identifier):
-        """
-        Requests can span multiple requests, so we may need to delete this as a last step
-        """
-        if identifier in self.context:
-            # dbg("deleted eontext {} ".format(identifier))
-            del self.context[identifier]
-
-    def shutdown(self):
-        """
-        complete
-        This toggles shutdown mode. Shutdown mode tells us not to
-        talk to Slack anymore. Without this, typing /quit will trigger
-        a race with the buffer close callback and may result in you
-        leaving every slack channel.
-        """
-        self.shutting_down = not self.shutting_down
-
-    def register_team(self, team):
-        """
-        complete
-        Adds a team to the list of known teams for this EventRouter.
-        """
-        if isinstance(team, SlackTeam):
-            self.teams[team.get_team_hash()] = team
-        else:
-            raise InvalidType(type(team))
-
-    def reconnect_if_disconnected(self):
-        for team_id, team in self.teams.iteritems():
-            if not team.connected:
-                team.connect()
-                dbg("reconnecting {}".format(team))
-
-    def receive_ws_callback(self, team_hash):
-        """
-        incomplete (reconnect)
-        This is called by the global method of the same name.
-        It is triggered when we have incoming data on a websocket,
-        which needs to be read. Once it is read, we will ensure
-        the data is valid JSON, add metadata, and place it back
-        on the queue for processing as JSON.
-        """
-        try:
-            # Read the data from the websocket associated with this team.
-            data = decode_from_utf8(self.teams[team_hash].ws.recv())
-            message_json = json.loads(data)
-            metadata = WeeSlackMetadata({
-                "team": team_hash,
-            }).jsonify()
-            message_json["wee_slack_metadata"] = metadata
-            if self.recording:
-                self.record_event(message_json, 'type', 'websocket')
-            self.receive_json(json.dumps(message_json))
-        except WebSocketConnectionClosedException:
-            # TODO: handle reconnect here
-            self.teams[team_hash].set_disconnected()
-            return w.WEECHAT_RC_OK
-        except Exception:
-            dbg("socket issue: {}\n".format(traceback.format_exc()))
-            return w.WEECHAT_RC_OK
-
-    def receive_httprequest_callback(self, data, command, return_code, out, err):
-        """
-        complete
-        Receives the result of an http request we previously handed
-        off to weechat (weechat bundles libcurl). Weechat can fragment
-        replies, so it buffers them until the reply is complete.
-        It is then populated with metadata here so we can identify
-        where the request originated and route properly.
-        """
-        request_metadata = self.retrieve_context(data)
-        try:
-            dbg("RECEIVED CALLBACK with request of {} id of {} and  code {} of length {}".format(request_metadata.request, request_metadata.response_id, return_code, len(out)))
-        except:
-            dbg(request_metadata)
-            return
-        if return_code == 0:
-            if len(out) > 0:
-                if request_metadata.response_id in self.reply_buffer:
-                    # dbg("found response id in reply_buffer", True)
-                    self.reply_buffer[request_metadata.response_id] += out
-                else:
-                    # dbg("didn't find response id in reply_buffer", True)
-                    self.reply_buffer[request_metadata.response_id] = ""
-                    self.reply_buffer[request_metadata.response_id] += out
-                try:
-                    j = json.loads(self.reply_buffer[request_metadata.response_id])
-                except:
-                    pass
-                    # dbg("Incomplete json, awaiting more", True)
-                try:
-                    j["wee_slack_process_method"] = request_metadata.request_normalized
-                    j["wee_slack_request_metadata"] = pickle.dumps(request_metadata)
-                    self.reply_buffer.pop(request_metadata.response_id)
-                    if self.recording:
-                        self.record_event(j, 'wee_slack_process_method', 'http')
-                    self.receive_json(json.dumps(j))
-                    self.delete_context(data)
-                except:
-                    dbg("HTTP REQUEST CALLBACK FAILED", True)
-                    pass
-            # We got an empty reply and this is weird so just ditch it and retry
-            else:
-                dbg("length was zero, probably a bug..")
-                self.delete_context(data)
-                self.receive(request_metadata)
-        elif return_code != -1:
-            self.reply_buffer.pop(request_metadata.response_id, None)
-            self.delete_context(data)
-        else:
-            if request_metadata.response_id not in self.reply_buffer:
-                self.reply_buffer[request_metadata.response_id] = ""
-            self.reply_buffer[request_metadata.response_id] += out
-
-    def receive_json(self, data):
-        """
-        complete
-        Receives a raw JSON string from and unmarshals it
-        as dict, then places it back on the queue for processing.
-        """
-        dbg("RECEIVED JSON of len {}".format(len(data)))
-        message_json = json.loads(data)
-        self.queue.append(message_json)
-
-    def receive(self, dataobj):
-        """
-        complete
-        Receives a raw object and places it on the queue for
-        processing. Object must be known to handle_next or
-        be JSON.
-        """
-        dbg("RECEIVED FROM QUEUE")
-        self.queue.append(dataobj)
-
-    def receive_slow(self, dataobj):
-        """
-        complete
-        Receives a raw object and places it on the slow queue for
-        processing. Object must be known to handle_next or
-        be JSON.
-        """
-        dbg("RECEIVED FROM QUEUE")
-        self.slow_queue.append(dataobj)
-
-    def handle_next(self):
-        """
-        complete
-        Main handler of the EventRouter. This is called repeatedly
-        via callback to drain events from the queue. It also attaches
-        useful metadata and context to events as they are processed.
-        """
-        if len(self.slow_queue) > 0 and ((self.slow_queue_timer + 1) < time.time()):
-            # for q in self.slow_queue[0]:
-            dbg("from slow queue", 0)
-            self.queue.append(self.slow_queue.pop())
-            # self.slow_queue = []
-            self.slow_queue_timer = time.time()
-        if len(self.queue) > 0:
-            j = self.queue.pop(0)
-            # Reply is a special case of a json reply from websocket.
-            kwargs = {}
-            if isinstance(j, SlackRequest):
-                if j.should_try():
-                    if j.retry_ready():
-                        local_process_async_slack_api_request(j, self)
-                    else:
-                        self.slow_queue.append(j)
-                else:
-                    dbg("Max retries for Slackrequest")
-
-            else:
-
-                if "reply_to" in j:
-                    dbg("SET FROM REPLY")
-                    function_name = "reply"
-                elif "type" in j:
-                    dbg("SET FROM type")
-                    function_name = j["type"]
-                elif "wee_slack_process_method" in j:
-                    dbg("SET FROM META")
-                    function_name = j["wee_slack_process_method"]
-                else:
-                    dbg("SET FROM NADA")
-                    function_name = "unknown"
-
-                # Here we are passing the actual objects. No more lookups.
-                meta = j.get("wee_slack_metadata", None)
-                if meta:
-                    try:
-                        if isinstance(meta, basestring):
-                            dbg("string of metadata")
-                        team = meta.get("team", None)
-                        if team:
-                            kwargs["team"] = self.teams[team]
-                            if "user" in j:
-                                kwargs["user"] = self.teams[team].users[j["user"]]
-                            if "channel" in j:
-                                kwargs["channel"] = self.teams[team].channels[j["channel"]]
-                    except:
-                        dbg("metadata failure")
-
-                if function_name not in IGNORED_EVENTS:
-                    dbg("running {}".format(function_name))
-                    if function_name.startswith("local_") and function_name in self.local_proc:
-                        self.local_proc[function_name](j, self, **kwargs)
-                    elif function_name in self.proc:
-                        self.proc[function_name](j, self, **kwargs)
-                    elif function_name in self.handlers:
-                        self.handlers[function_name](j, self, **kwargs)
-                    else:
-                        raise ProcessNotImplemented(function_name)
-
-
-def handle_next(*args):
-    """
-    complete
-    This is just a place to call the event router globally.
-    This is a dirty hack. There must be a better way.
-    """
-    try:
-        EVENTROUTER.handle_next()
-    except:
-        if config.debug_mode:
-            traceback.print_exc()
-        else:
-            pass
-    return w.WEECHAT_RC_OK
-
-
-class WeechatController(object):
-    """
-    Encapsulates our interaction with weechat
-    """
-
-    def __init__(self, eventrouter):
-        self.eventrouter = eventrouter
-        self.buffers = {}
-        self.previous_buffer = None
-        self.buffer_list_stale = False
-
-    def iter_buffers(self):
-        for b in self.buffers:
-            yield (b, self.buffers[b])
-
-    def register_buffer(self, buffer_ptr, channel):
-        """
-        complete
-        Adds a weechat buffer to the list of handled buffers for this EventRouter
-        """
-        if isinstance(buffer_ptr, basestring):
-            self.buffers[buffer_ptr] = channel
-        else:
-            raise InvalidType(type(buffer_ptr))
-
-    def unregister_buffer(self, buffer_ptr, update_remote=False, close_buffer=False):
-        """
-        complete
-        Adds a weechat buffer to the list of handled buffers for this EventRouter
-        """
-        if isinstance(buffer_ptr, basestring):
-            try:
-                self.buffers[buffer_ptr].destroy_buffer(update_remote)
-                if close_buffer:
-                    w.buffer_close(buffer_ptr)
-                del self.buffers[buffer_ptr]
-            except:
-                dbg("Tried to close unknown buffer")
-        else:
-            raise InvalidType(type(buffer_ptr))
-
-    def get_channel_from_buffer_ptr(self, buffer_ptr):
-        return self.buffers.get(buffer_ptr, None)
-
-    def get_all(self, buffer_ptr):
-        return self.buffers
-
-    def get_previous_buffer_ptr(self):
-        return self.previous_buffer
-
-    def set_previous_buffer(self, data):
-        self.previous_buffer = data
-
-    def check_refresh_buffer_list(self):
-        return self.buffer_list_stale and self.last_buffer_list_update + 1 < time.time()
-
-    def set_refresh_buffer_list(self, setting):
-        self.buffer_list_stale = setting
-
-###### New Local Processors
-
-
-def local_process_async_slack_api_request(request, event_router):
-    """
-    complete
-    Sends an API request to Slack. You'll need to give this a well formed SlackRequest object.
-    DEBUGGING!!! The context here cannot be very large. Weechat will crash.
-    """
-    if not event_router.shutting_down:
-        weechat_request = 'url:{}'.format(request.request_string())
-        weechat_request += '&nonce={}'.format(''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(4)))
-        params = {'useragent': 'wee_slack {}'.format(SCRIPT_VERSION)}
-        request.tried()
-        context = event_router.store_context(request)
-        # TODO: let flashcode know about this bug - i have to 'clear' the hashtable or retry requests fail
-        w.hook_process_hashtable('url:', params, config.slack_timeout, "", context)
-        w.hook_process_hashtable(weechat_request, params, config.slack_timeout, "receive_httprequest_callback", context)
-
-###### New Callbacks
-
-
-def receive_httprequest_callback(data, command, return_code, out, err):
-    """
-    complete
-    This is a dirty hack. There must be a better way.
-    """
-    # def url_processor_cb(data, command, return_code, out, err):
-    data = decode_from_utf8(data)
-    EVENTROUTER.receive_httprequest_callback(data, command, return_code, out, err)
-    return w.WEECHAT_RC_OK
-
-
-def receive_ws_callback(*args):
-    """
-    complete
-    The first arg is all we want here. It contains the team
-    hash which is set when we _hook the descriptor.
-    This is a dirty hack. There must be a better way.
-    """
-    EVENTROUTER.receive_ws_callback(args[0])
-    return w.WEECHAT_RC_OK
-
-
-def reconnect_callback(*args):
-    EVENTROUTER.reconnect_if_disconnected()
-    return w.WEECHAT_RC_OK
-
-
-def buffer_closing_callback(signal, sig_type, data):
-    """
-    complete
-    Receives a callback from weechat when a buffer is being closed.
-    We pass the eventrouter variable name in as a string, as
-    that is the only way we can do dependency injection via weechat
-    callback, hence the eval.
-    """
-    data = decode_from_utf8(data)
-    eval(signal).weechat_controller.unregister_buffer(data, True, False)
-    return w.WEECHAT_RC_OK
-
-
-def buffer_input_callback(signal, buffer_ptr, data):
-    """
-    incomplete
-    Handles everything a user types in the input bar. In our case
-    this includes add/remove reactions, modifying messages, and
-    sending messages.
-    """
-    data = decode_from_utf8(data)
-    eventrouter = eval(signal)
-    channel = eventrouter.weechat_controller.get_channel_from_buffer_ptr(buffer_ptr)
-    if not channel:
-        return w.WEECHAT_RC_ERROR
-
-    reaction = re.match("^\s*(\d*)(\+|-):(.*):\s*$", data)
-    substitute = re.match("^(\d*)s/", data)
-    if reaction:
-        if reaction.group(2) == "+":
-            channel.send_add_reaction(int(reaction.group(1) or 1), reaction.group(3))
-        elif reaction.group(2) == "-":
-            channel.send_remove_reaction(int(reaction.group(1) or 1), reaction.group(3))
-    elif substitute:
-        msgno = int(substitute.group(1) or 1)
-        try:
-            old, new, flags = re.split(r'(?<!\\)/', data)[1:]
-        except ValueError:
-            pass
-        else:
-            # Replacement string in re.sub() is a string, not a regex, so get
-            # rid of escapes.
-            new = new.replace(r'\/', '/')
-            old = old.replace(r'\/', '/')
-            channel.edit_nth_previous_message(msgno, old, new, flags)
-    else:
-        channel.send_message(data)
-        # this is probably wrong channel.mark_read(update_remote=True, force=True)
-    return w.WEECHAT_RC_OK
-
-
-def buffer_switch_callback(signal, sig_type, data):
-    """
-    incomplete
-    Every time we change channels in weechat, we call this to:
-    1) set read marker 2) determine if we have already populated
-    channel history data
-    """
-    data = decode_from_utf8(data)
-    eventrouter = eval(signal)
-
-    prev_buffer_ptr = eventrouter.weechat_controller.get_previous_buffer_ptr()
-    # this is to see if we need to gray out things in the buffer list
-    prev = eventrouter.weechat_controller.get_channel_from_buffer_ptr(prev_buffer_ptr)
-    if prev:
-        prev.mark_read()
-
-    new_channel = eventrouter.weechat_controller.get_channel_from_buffer_ptr(data)
-    if new_channel:
-        if not new_channel.got_history:
-            new_channel.get_history()
-
-    eventrouter.weechat_controller.set_previous_buffer(data)
-    return w.WEECHAT_RC_OK
-
-
-def buffer_list_update_callback(data, somecount):
-    """
-    incomplete
-    A simple timer-based callback that will update the buffer list
-    if needed. We only do this max 1x per second, as otherwise it
-    uses a lot of cpu for minimal changes. We use buffer short names
-    to indicate typing via "#channel" <-> ">channel" and
-    user presence via " name" <-> "+name".
-    """
-    data = decode_from_utf8(data)
-    eventrouter = eval(data)
-    # global buffer_list_update
-
-    for b in eventrouter.weechat_controller.iter_buffers():
-        b[1].refresh()
-#    buffer_list_update = True
-#    if eventrouter.weechat_controller.check_refresh_buffer_list():
-#        # gray_check = False
-#        # if len(servers) > 1:
-#        #    gray_check = True
-#        eventrouter.weechat_controller.set_refresh_buffer_list(False)
-    return w.WEECHAT_RC_OK
-
-
-def quit_notification_callback(signal, sig_type, data):
-    stop_talking_to_slack()
-
-
-def typing_notification_cb(signal, sig_type, data):
-    data = decode_from_utf8(data)
-    msg = w.buffer_get_string(data, "input")
-    if len(msg) > 8 and msg[:1] != "/":
-        global typing_timer
-        now = time.time()
-        if typing_timer + 4 < now:
-            current_buffer = w.current_buffer()
-            channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None)
-            if channel and channel.type != "thread":
-                identifier = channel.identifier
-                request = {"type": "typing", "channel": identifier}
-                channel.team.send_to_websocket(request, expect_reply=False)
-                typing_timer = now
-    return w.WEECHAT_RC_OK
-
-
-def typing_update_cb(data, remaining_calls):
-    data = decode_from_utf8(data)
-    w.bar_item_update("slack_typing_notice")
-    return w.WEECHAT_RC_OK
-
-
-def slack_never_away_cb(data, remaining_calls):
-    data = decode_from_utf8(data)
-    if config.never_away:
-        for t in EVENTROUTER.teams.values():
-            slackbot = t.get_channel_map()['slackbot']
-            channel = t.channels[slackbot]
-            request = {"type": "typing", "channel": channel.identifier}
-            channel.team.send_to_websocket(request, expect_reply=False)
-    return w.WEECHAT_RC_OK
-
-
-def typing_bar_item_cb(data, current_buffer, args):
-    """
-    Privides a bar item indicating who is typing in the current channel AND
-    why is typing a DM to you globally.
-    """
-    typers = []
-    current_buffer = w.current_buffer()
-    current_channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None)
-
-    # first look for people typing in this channel
-    if current_channel:
-        # this try is mostly becuase server buffers don't implement is_someone_typing
-        try:
-            if current_channel.type != 'im' and current_channel.is_someone_typing():
-                typers += current_channel.get_typing_list()
-        except:
-            pass
-
-    # here is where we notify you that someone is typing in DM
-    # regardless of which buffer you are in currently
-    for t in EVENTROUTER.teams.values():
-        for channel in t.channels.values():
-            if channel.type == "im":
-                if channel.is_someone_typing():
-                    typers.append("D/" + channel.slack_name)
-                pass
-
-    typing = ", ".join(typers)
-    if typing != "":
-        typing = w.color('yellow') + "typing: " + typing
-
-    return typing
-
-
-def nick_completion_cb(data, completion_item, current_buffer, completion):
-    """
-    Adds all @-prefixed nicks to completion list
-    """
-
-    data = decode_from_utf8(data)
-    completion = decode_from_utf8(completion)
-    current_buffer = w.current_buffer()
-    current_channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None)
-
-    if current_channel is None or current_channel.members is None:
-        return w.WEECHAT_RC_OK
-    for m in current_channel.members:
-        u = current_channel.team.users.get(m, None)
-        if u:
-            w.hook_completion_list_add(completion, "@" + u.slack_name, 1, w.WEECHAT_LIST_POS_SORT)
-    return w.WEECHAT_RC_OK
-
-
-def emoji_completion_cb(data, completion_item, current_buffer, completion):
-    """
-    Adds all :-prefixed emoji to completion list
-    """
-
-    data = decode_from_utf8(data)
-    completion = decode_from_utf8(completion)
-    current_buffer = w.current_buffer()
-    current_channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None)
-
-    if current_channel is None:
-        return w.WEECHAT_RC_OK
-    for e in EMOJI['emoji']:
-        w.hook_completion_list_add(completion, ":" + e + ":", 0, w.WEECHAT_LIST_POS_SORT)
-    return w.WEECHAT_RC_OK
-
-
-def complete_next_cb(data, current_buffer, command):
-    """Extract current word, if it is equal to a nick, prefix it with @ and
-    rely on nick_completion_cb adding the @-prefixed versions to the
-    completion lists, then let Weechat's internal completion do its
-    thing
-
-    """
-
-    data = decode_from_utf8(data)
-    command = decode_from_utf8(data)
-    current_buffer = w.current_buffer()
-    current_channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None)
-
-    # channel = channels.find(current_buffer)
-    if not hasattr(current_channel, 'members') or current_channel is None or current_channel.members is None:
-        return w.WEECHAT_RC_OK
-
-    line_input = w.buffer_get_string(current_buffer, "input")
-    current_pos = w.buffer_get_integer(current_buffer, "input_pos") - 1
-    input_length = w.buffer_get_integer(current_buffer, "input_length")
-
-    word_start = 0
-    word_end = input_length
-    # If we're on a non-word, look left for something to complete
-    while current_pos >= 0 and line_input[current_pos] != '@' and not line_input[current_pos].isalnum():
-        current_pos = current_pos - 1
-    if current_pos < 0:
-        current_pos = 0
-    for l in range(current_pos, 0, -1):
-        if line_input[l] != '@' and not line_input[l].isalnum():
-            word_start = l + 1
-            break
-    for l in range(current_pos, input_length):
-        if not line_input[l].isalnum():
-            word_end = l
-            break
-    word = line_input[word_start:word_end]
-
-    for m in current_channel.members:
-        u = current_channel.team.users.get(m, None)
-        if u and u.slack_name == word:
-            # Here, we cheat.  Insert a @ in front and rely in the @
-            # nicks being in the completion list
-            w.buffer_set(current_buffer, "input", line_input[:word_start] + "@" + line_input[word_start:])
-            w.buffer_set(current_buffer, "input_pos", str(w.buffer_get_integer(current_buffer, "input_pos") + 1))
-            return w.WEECHAT_RC_OK_EAT
-    return w.WEECHAT_RC_OK
-
-
-def script_unloaded():
-    stop_talking_to_slack()
-    return w.WEECHAT_RC_OK
-
-
-def stop_talking_to_slack():
-    """
-    complete
-    Prevents a race condition where quitting closes buffers
-    which triggers leaving the channel because of how close
-    buffer is handled
-    """
-    EVENTROUTER.shutdown()
-    return w.WEECHAT_RC_OK
-
-##### New Classes
-
-
-class SlackRequest(object):
-    """
-    complete
-    Encapsulates a Slack api request. Valuable as an object that we can add to the queue and/or retry.
-    makes a SHA of the requst url and current time so we can re-tag this on the way back through.
-    """
-
-    def __init__(self, token, request, post_data={}, **kwargs):
-        for key, value in kwargs.items():
-            setattr(self, key, value)
-        self.tries = 0
-        self.start_time = time.time()
-        self.domain = 'api.slack.com'
-        self.request = request
-        self.request_normalized = re.sub(r'\W+', '', request)
-        self.token = token
-        post_data["token"] = token
-        self.post_data = post_data
-        self.params = {'useragent': 'wee_slack {}'.format(SCRIPT_VERSION)}
-        self.url = 'https://{}/api/{}?{}'.format(self.domain, request, urllib.urlencode(encode_to_utf8(post_data)))
-        self.response_id = sha.sha("{}{}".format(self.url, self.start_time)).hexdigest()
-        self.retries = kwargs.get('retries', 3)
-#    def __repr__(self):
-#        return "URL: {} Tries: {} ID: {}".format(self.url, self.tries, self.response_id)
-
-    def request_string(self):
-        return "{}".format(self.url)
-
-    def tried(self):
-        self.tries += 1
-        self.response_id = sha.sha("{}{}".format(self.url, time.time())).hexdigest()
-
-    def should_try(self):
-        return self.tries < self.retries
-
-    def retry_ready(self):
-        return (self.start_time + (self.tries**2)) < time.time()
-
-
-class SlackTeam(object):
-    """
-    incomplete
-    Team object under which users and channels live.. Does lots.
-    """
-
-    def __init__(self, eventrouter, token, websocket_url, subdomain, nick, myidentifier, users, bots, channels, **kwargs):
-        self.ws_url = websocket_url
-        self.connected = False
-        self.connecting = False
-        # self.ws = None
-        self.ws_counter = 0
-        self.ws_replies = {}
-        self.eventrouter = eventrouter
-        self.token = token
-        self.team = self
-        self.subdomain = subdomain
-        self.domain = subdomain + ".slack.com"
-        self.preferred_name = self.domain
-        self.nick = nick
-        self.myidentifier = myidentifier
-        try:
-            if self.channels:
-                for c in channels.keys():
-                    if not self.channels.get(c):
-                        self.channels[c] = channels[c]
-        except:
-            self.channels = channels
-        self.users = users
-        self.bots = bots
-        self.team_hash = SlackTeam.generate_team_hash(self.nick, self.subdomain)
-        self.name = self.domain
-        self.channel_buffer = None
-        self.got_history = True
-        self.create_buffer()
-        self.set_muted_channels(kwargs.get('muted_channels', ""))
-        for c in self.channels.keys():
-            channels[c].set_related_server(self)
-            channels[c].check_should_open()
-        #    self.channel_set_related_server(c)
-        # Last step is to make sure my nickname is the set color
-        self.users[self.myidentifier].force_color(w.config_string(w.config_get('weechat.color.chat_nick_self')))
-        # This highlight step must happen after we have set related server
-        self.set_highlight_words(kwargs.get('highlight_words', ""))
-
-    def __eq__(self, compare_str):
-        if compare_str == self.token or compare_str == self.domain or compare_str == self.subdomain:
-            return True
-        else:
-            return False
-
-    def add_channel(self, channel):
-        self.channels[channel["id"]] = channel
-        channel.set_related_server(self)
-
-    # def connect_request_generate(self):
-    #    return SlackRequest(self.token, 'rtm.start', {})
-
-    # def close_all_buffers(self):
-    #    for channel in self.channels:
-    #        self.eventrouter.weechat_controller.unregister_buffer(channel.channel_buffer, update_remote=False, close_buffer=True)
-    #    #also close this server buffer
-    #    self.eventrouter.weechat_controller.unregister_buffer(self.channel_buffer, update_remote=False, close_buffer=True)
-
-    def create_buffer(self):
-        if not self.channel_buffer:
-            if config.short_buffer_names:
-                self.preferred_name = self.subdomain
-            elif config.server_aliases not in ['', None]:
-                name = config.server_aliases.get(self.subdomain, None)
-                if name:
-                    self.preferred_name = name
-            else:
-                self.preferred_name = self.domain
-            self.channel_buffer = w.buffer_new("{}".format(self.preferred_name), "buffer_input_callback", "EVENTROUTER", "", "")
-            self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self)
-            w.buffer_set(self.channel_buffer, "localvar_set_type", 'server')
-            w.buffer_set(self.channel_buffer, "localvar_set_nick", self.nick)
-            if w.config_string(w.config_get('irc.look.server_buffer')) == 'merge_with_core':
-                w.buffer_merge(self.channel_buffer, w.buffer_search_main())
-            w.buffer_set(self.channel_buffer, "nicklist", "1")
-
-    def set_muted_channels(self, muted_str):
-        self.muted_channels = {x for x in muted_str.split(',')}
-
-    def set_highlight_words(self, highlight_str):
-        self.highlight_words = {x for x in highlight_str.split(',')}
-        if len(self.highlight_words) > 0:
-            for v in self.channels.itervalues():
-                v.set_highlights()
-
-    def formatted_name(self, **kwargs):
-        return self.domain
-
-    def buffer_prnt(self, data):
-        w.prnt_date_tags(self.channel_buffer, SlackTS().major, tag("backlog"), data)
-
-    def get_channel_map(self):
-        return {v.slack_name: k for k, v in self.channels.iteritems()}
-
-    def get_username_map(self):
-        return {v.slack_name: k for k, v in self.users.iteritems()}
-
-    def get_team_hash(self):
-        return self.team_hash
-
-    @staticmethod
-    def generate_team_hash(nick, subdomain):
-        return str(sha.sha("{}{}".format(nick, subdomain)).hexdigest())
-
-    def refresh(self):
-        self.rename()
-
-    def rename(self):
-        pass
-
-    # def attach_websocket(self, ws):
-    #    self.ws = ws
-
-    def is_user_present(self, user_id):
-        user = self.users.get(user_id)
-        if user.presence == 'active':
-            return True
-        else:
-            return False
-
-    def mark_read(self):
-        pass
-
-    def connect(self):
-        if not self.connected and not self.connecting:
-            self.connecting = True
-            if self.ws_url:
-                try:
-                    ws = create_connection(self.ws_url, sslopt=sslopt_ca_certs)
-                    self.hook = w.hook_fd(ws.sock._sock.fileno(), 1, 0, 0, "receive_ws_callback", self.get_team_hash())
-                    ws.sock.setblocking(0)
-                    self.ws = ws
-                    # self.attach_websocket(ws)
-                    self.set_connected()
-                    self.connecting = False
-                except Exception as e:
-                    dbg("websocket connection error: {}".format(e))
-                    self.connecting = False
-                    return False
-            else:
-                # The fast reconnect failed, so start over-ish
-                for chan in self.channels:
-                    self.channels[chan].got_history = False
-                s = SlackRequest(self.token, 'rtm.start', {}, retries=999)
-                self.eventrouter.receive(s)
-                self.connecting = False
-                # del self.eventrouter.teams[self.get_team_hash()]
-            self.set_reconnect_url(None)
-
-    def set_connected(self):
-        self.connected = True
-
-    def set_disconnected(self):
-        w.unhook(self.hook)
-        self.connected = False
-
-    def set_reconnect_url(self, url):
-        self.ws_url = url
-
-    def next_ws_transaction_id(self):
-        if self.ws_counter > 999:
-            self.ws_counter = 0
-        self.ws_counter += 1
-        return self.ws_counter
-
-    def send_to_websocket(self, data, expect_reply=True):
-        data["id"] = self.next_ws_transaction_id()
-        message = json.dumps(data)
-        try:
-            if expect_reply:
-                self.ws_replies[data["id"]] = data
-            self.ws.send(encode_to_utf8(message))
-            dbg("Sent {}...".format(message[:100]))
-        except:
-            print "WS ERROR"
-            dbg("Unexpected error: {}\nSent: {}".format(sys.exc_info()[0], data))
-            self.set_connected()
-
-    def update_member_presence(self, user, presence):
-        user.presence = presence
-
-        for c in self.channels:
-            c = self.channels[c]
-            if user.id in c.members:
-                c.update_nicklist(user.id)
-
-
-class SlackChannel(object):
-    """
-    Represents an individual slack channel.
-    """
-
-    def __init__(self, eventrouter, **kwargs):
-        # We require these two things for a vaid object,
-        # the rest we can just learn from slack
-        self.active = False
-        for key, value in kwargs.items():
-            setattr(self, key, value)
-        self.members = set(kwargs.get('members', set()))
-        self.eventrouter = eventrouter
-        self.slack_name = kwargs["name"]
-        self.slack_topic = kwargs.get("topic", {"value": ""})
-        self.slack_purpose = kwargs.get("purpose", {"value": ""})
-        self.identifier = kwargs["id"]
-        self.last_read = SlackTS(kwargs.get("last_read", SlackTS()))
-        self.channel_buffer = None
-        self.team = kwargs.get('team', None)
-        self.got_history = False
-        self.messages = {}
-        self.hashed_messages = {}
-        self.new_messages = False
-        self.typing = {}
-        self.type = 'channel'
-        self.set_name(self.slack_name)
-        # short name relates to the localvar we change for typing indication
-        self.current_short_name = self.name
-        self.update_nicklist()
-        self.unread_count_display = 0
-
-    def __eq__(self, compare_str):
-        if compare_str == self.slack_name or compare_str == self.formatted_name() or compare_str == self.formatted_name(style="long_default"):
-            return True
-        else:
-            return False
-
-    def __repr__(self):
-        return "Name:{} Identifier:{}".format(self.name, self.identifier)
-
-    def set_name(self, slack_name):
-        self.name = "#" + slack_name
-
-    def refresh(self):
-        return self.rename()
-
-    def rename(self):
-        if self.channel_buffer:
-            new_name = self.formatted_name(typing=self.is_someone_typing(), style="sidebar")
-            if self.current_short_name != new_name:
-                self.current_short_name = new_name
-                w.buffer_set(self.channel_buffer, "short_name", new_name)
-                return True
-        return False
-
-    def set_unread_count_display(self, count):
-        self.unread_count_display = count
-        for c in range(self.unread_count_display):
-            if self.type == "im":
-                w.buffer_set(self.channel_buffer, "hotlist", "2")
-            else:
-                w.buffer_set(self.channel_buffer, "hotlist", "1")
-
-    def formatted_name(self, style="default", typing=False, **kwargs):
-        if config.channel_name_typing_indicator:
-            if not typing:
-                prepend = "#"
-            else:
-                prepend = ">"
-        else:
-            prepend = "#"
-        select = {
-            "default": prepend + self.slack_name,
-            "sidebar": prepend + self.slack_name,
-            "base": self.slack_name,
-            "long_default": "{}.{}{}".format(self.team.preferred_name, prepend, self.slack_name),
-            "long_base": "{}.{}".format(self.team.preferred_name, self.slack_name),
-        }
-        return select[style]
-
-    def render_topic(self, topic=None):
-        if self.channel_buffer:
-            if not topic:
-                if self.slack_topic['value'] != "":
-                    topic = self.slack_topic['value']
-                else:
-                    topic = self.slack_purpose['value']
-            w.buffer_set(self.channel_buffer, "title", topic)
-
-    def update_from_message_json(self, message_json):
-        for key, value in message_json.items():
-            setattr(self, key, value)
-
-    def open(self, update_remote=True):
-        if update_remote:
-            if "join" in SLACK_API_TRANSLATOR[self.type]:
-                s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["join"], {"name": self.name}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-                self.eventrouter.receive(s)
-        self.create_buffer()
-        self.active = True
-        self.get_history()
-        # self.create_buffer()
-
-    def check_should_open(self, force=False):
-        try:
-            if self.is_archived:
-                return
-        except:
-            pass
-        if force:
-            self.create_buffer()
-        else:
-            for reason in ["is_member", "is_open", "unread_count_display"]:
-                try:
-                    if eval("self." + reason):
-                        self.create_buffer()
-                        if config.background_load_all_history:
-                            self.get_history(slow_queue=True)
-                except:
-                    pass
-
-    def set_related_server(self, team):
-        self.team = team
-
-    def set_highlights(self):
-        # highlight my own name and any set highlights
-        if self.channel_buffer:
-            highlights = self.team.highlight_words.union({'@' + self.team.nick, "!here", "!channel", "!everyone"})
-            h_str = ",".join(highlights)
-            w.buffer_set(self.channel_buffer, "highlight_words", h_str)
-
-    def create_buffer(self):
-        """
-        incomplete (muted doesn't work)
-        Creates the weechat buffer where the channel magic happens.
-        """
-        if not self.channel_buffer:
-            self.active = True
-            self.channel_buffer = w.buffer_new(self.formatted_name(style="long_default"), "buffer_input_callback", "EVENTROUTER", "", "")
-            self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self)
-            if self.type == "im":
-                w.buffer_set(self.channel_buffer, "localvar_set_type", 'private')
-            else:
-                w.buffer_set(self.channel_buffer, "localvar_set_type", 'channel')
-            w.buffer_set(self.channel_buffer, "localvar_set_channel", self.formatted_name())
-            w.buffer_set(self.channel_buffer, "localvar_set_nick", self.team.nick)
-            w.buffer_set(self.channel_buffer, "short_name", self.formatted_name(style="sidebar", enable_color=True))
-            self.render_topic()
-            self.eventrouter.weechat_controller.set_refresh_buffer_list(True)
-            if self.channel_buffer:
-                # if self.team.server_alias:
-                #    w.buffer_set(self.channel_buffer, "localvar_set_server", self.team.server_alias)
-                # else:
-                w.buffer_set(self.channel_buffer, "localvar_set_server", self.team.preferred_name)
-        # else:
-        #    self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self)
-        self.update_nicklist()
-
-        if "info" in SLACK_API_TRANSLATOR[self.type]:
-            s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["info"], {"channel": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-            self.eventrouter.receive(s)
-
-        if self.type == "im":
-            if "join" in SLACK_API_TRANSLATOR[self.type]:
-                s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["join"], {"user": self.user, "return_im": "true"}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-                self.eventrouter.receive(s)
-
-    def destroy_buffer(self, update_remote):
-        if self.channel_buffer is not None:
-            self.channel_buffer = None
-        self.messages = {}
-        self.hashed_messages = {}
-        self.got_history = False
-        # if update_remote and not eventrouter.shutting_down:
-        self.active = False
-        if update_remote and not self.eventrouter.shutting_down:
-            s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["leave"], {"channel": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-            self.eventrouter.receive(s)
-
-    def buffer_prnt(self, nick, text, timestamp=str(time.time()), tagset=None, tag_nick=None, **kwargs):
-        data = "{}\t{}".format(nick, text)
-        ts = SlackTS(timestamp)
-        last_read = SlackTS(self.last_read)
-        # without this, DMs won't open automatically
-        if not self.channel_buffer and ts > last_read:
-            self.open(update_remote=False)
-        if self.channel_buffer:
-            # backlog messages - we will update the read marker as we print these
-            backlog = True if ts <= last_read else False
-            if tagset:
-                tags = tag(tagset, user=tag_nick)
-                self.new_messages = True
-
-            # we have to infer the tagset because we weren't told
-            elif ts <= last_read:
-                tags = tag("backlog", user=tag_nick)
-            elif self.type in ["im", "mpdm"]:
-                if nick != self.team.nick:
-                    tags = tag("dm", user=tag_nick)
-                    self.new_messages = True
-                else:
-                    tags = tag("dmfromme")
-            else:
-                tags = tag("default", user=tag_nick)
-                self.new_messages = True
-
-            try:
-                if config.unhide_buffers_with_activity and not self.is_visible() and (self.identifier not in self.team.muted_channels):
-                    w.buffer_set(self.channel_buffer, "hidden", "0")
-
-                w.prnt_date_tags(self.channel_buffer, ts.major, tags, data)
-                modify_print_time(self.channel_buffer, ts.minorstr(), ts.major)
-                if backlog:
-                    self.mark_read(ts, update_remote=False, force=True)
-            except:
-                dbg("Problem processing buffer_prnt")
-
-    def send_message(self, message, request_dict_ext={}):
-        # team = self.eventrouter.teams[self.team]
-        message = linkify_text(message, self.team, self)
-        dbg(message)
-        request = {"type": "message", "channel": self.identifier, "text": message, "_team": self.team.team_hash, "user": self.team.myidentifier}
-        request.update(request_dict_ext)
-        self.team.send_to_websocket(request)
-        self.mark_read(update_remote=False, force=True)
-
-    def store_message(self, message, team, from_me=False):
-        if not self.active:
-            return
-        if from_me:
-            message.message_json["user"] = team.myidentifier
-        self.messages[SlackTS(message.ts)] = message
-        if len(self.messages.keys()) > SCROLLBACK_SIZE:
-            mk = self.messages.keys()
-            mk.sort()
-            for k in mk[:SCROLLBACK_SIZE]:
-                msg_to_delete = self.messages[k]
-                if msg_to_delete.hash:
-                    del self.hashed_messages[msg_to_delete.hash]
-                del self.messages[k]
-
-    def change_message(self, ts, text=None, suffix=None):
-        ts = SlackTS(ts)
-        if ts in self.messages:
-            m = self.messages[ts]
-            if text:
-                m.change_text(text)
-            if suffix:
-                m.change_suffix(suffix)
-            text = m.render(force=True)
-        modify_buffer_line(self.channel_buffer, text, ts.major, ts.minor)
-        return True
-
-    def edit_nth_previous_message(self, n, old, new, flags):
-        message = self.my_last_message(n)
-        if new == "" and old == "":
-            s = SlackRequest(self.team.token, "chat.delete", {"channel": self.identifier, "ts": message['ts']}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-            self.eventrouter.receive(s)
-        else:
-            num_replace = 1
-            if 'g' in flags:
-                num_replace = 0
-            new_message = re.sub(old, new, message["text"], num_replace)
-            if new_message != message["text"]:
-                s = SlackRequest(self.team.token, "chat.update", {"channel": self.identifier, "ts": message['ts'], "text": new_message}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-                self.eventrouter.receive(s)
-
-    def my_last_message(self, msgno):
-        for message in reversed(self.sorted_message_keys()):
-            m = self.messages[message]
-            if "user" in m.message_json and "text" in m.message_json and m.message_json["user"] == self.team.myidentifier:
-                msgno -= 1
-                if msgno == 0:
-                    return m.message_json
-
-    def is_visible(self):
-        return w.buffer_get_integer(self.channel_buffer, "hidden") == 0
-
-    def get_history(self, slow_queue=False):
-        if not self.got_history:
-            # we have probably reconnected. flush the buffer
-            if self.team.connected:
-                w.buffer_clear(self.channel_buffer)
-            self.buffer_prnt('', 'getting channel history...', tagset='backlog')
-            s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["history"], {"channel": self.identifier, "count": BACKLOG_SIZE}, team_hash=self.team.team_hash, channel_identifier=self.identifier, clear=True)
-            if not slow_queue:
-                self.eventrouter.receive(s)
-            else:
-                self.eventrouter.receive_slow(s)
-            self.got_history = True
-
-    def send_add_reaction(self, msg_number, reaction):
-        self.send_change_reaction("reactions.add", msg_number, reaction)
-
-    def send_remove_reaction(self, msg_number, reaction):
-        self.send_change_reaction("reactions.remove", msg_number, reaction)
-
-    def send_change_reaction(self, method, msg_number, reaction):
-        if 0 < msg_number < len(self.messages):
-            timestamp = self.sorted_message_keys()[-msg_number]
-            data = {"channel": self.identifier, "timestamp": timestamp, "name": reaction}
-            s = SlackRequest(self.team.token, method, data)
-            self.eventrouter.receive(s)
-
-    def sorted_message_keys(self):
-        keys = []
-        for k in self.messages:
-            if type(self.messages[k]) == SlackMessage:
-                keys.append(k)
-        return sorted(keys)
-
-    # Typing related
-    def set_typing(self, user):
-        if self.channel_buffer and self.is_visible():
-            self.typing[user] = time.time()
-            self.eventrouter.weechat_controller.set_refresh_buffer_list(True)
-
-    def unset_typing(self, user):
-        if self.channel_buffer and self.is_visible():
-            u = self.typing.get(user, None)
-            if u:
-                self.eventrouter.weechat_controller.set_refresh_buffer_list(True)
-
-    def is_someone_typing(self):
-        """
-        Walks through dict of typing folks in a channel and fast
-        returns if any of them is actively typing. If none are,
-        nulls the dict and returns false.
-        """
-        for user, timestamp in self.typing.iteritems():
-            if timestamp + 4 > time.time():
-                return True
-        if len(self.typing) > 0:
-            self.typing = {}
-            self.eventrouter.weechat_controller.set_refresh_buffer_list(True)
-        return False
-
-    def get_typing_list(self):
-        """
-        Returns the names of everyone in the channel who is currently typing.
-        """
-        typing = []
-        for user, timestamp in self.typing.iteritems():
-            if timestamp + 4 > time.time():
-                typing.append(user)
-            else:
-                del self.typing[user]
-        return typing
-
-    def mark_read(self, ts=None, update_remote=True, force=False):
-        if not ts:
-            ts = SlackTS()
-        if self.new_messages or force:
-            if self.channel_buffer:
-                w.buffer_set(self.channel_buffer, "unread", "")
-                w.buffer_set(self.channel_buffer, "hotlist", "-1")
-            if update_remote:
-                s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["mark"], {"channel": self.identifier, "ts": ts}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-                self.eventrouter.receive(s)
-                self.new_messages = False
-
-    def user_joined(self, user_id):
-        # ugly hack - for some reason this gets turned into a list
-        self.members = set(self.members)
-        self.members.add(user_id)
-        self.update_nicklist(user_id)
-
-    def user_left(self, user_id):
-        self.members.discard(user_id)
-        self.update_nicklist(user_id)
-
-    def update_nicklist(self, user=None):
-        if not self.channel_buffer:
-            return
-        if self.type not in ["channel", "group"]:
-            return
-        w.buffer_set(self.channel_buffer, "nicklist", "1")
-        # create nicklists for the current channel if they don't exist
-        # if they do, use the existing pointer
-        here = w.nicklist_search_group(self.channel_buffer, '', NICK_GROUP_HERE)
-        if not here:
-           here = w.nicklist_add_group(self.channel_buffer, '', NICK_GROUP_HERE, "weechat.color.nicklist_group", 1)
-        afk = w.nicklist_search_group(self.channel_buffer, '', NICK_GROUP_AWAY)
-        if not afk:
-           afk = w.nicklist_add_group(self.channel_buffer, '', NICK_GROUP_AWAY, "weechat.color.nicklist_group", 1)
-
-        if user and len(self.members) < 1000:
-            user = self.team.users[user]
-            nick = w.nicklist_search_nick(self.channel_buffer, "", user.slack_name)
-            # since this is a change just remove it regardless of where it is
-            w.nicklist_remove_nick(self.channel_buffer, nick)
-            # now add it back in to whichever..
-            nick_group = afk
-            if self.team.is_user_present(user.identifier):
-                nick_group = here
-            if user.identifier in self.members:
-                w.nicklist_add_nick(self.channel_buffer, nick_group, user.name, user.color_name, "", "", 1)
-
-        # if we didn't get a user, build a complete list. this is expensive.
-        else:
-            if len(self.members) < 1000:
-                try:
-                    for user in self.members:
-                        user = self.team.users[user]
-                        if user.deleted:
-                            continue
-                        nick_group = afk
-                        if self.team.is_user_present(user.identifier):
-                            nick_group = here
-                        w.nicklist_add_nick(self.channel_buffer, nick_group, user.name, user.color_name, "", "", 1)
-                except Exception as e:
-                    dbg("DEBUG: {} {} {}".format(self.identifier, self.name, e))
-            else:
-                w.nicklist_remove_all(self.channel_buffer)
-                for fn in ["1| too", "2| many", "3| users", "4| to", "5| show"]:
-                    w.nicklist_add_group(self.channel_buffer, '', fn, w.color('white'), 1)
-
-    def hash_message(self, ts):
-        ts = SlackTS(ts)
-
-        def calc_hash(msg):
-            return sha.sha(str(msg.ts)).hexdigest()
-
-        if ts in self.messages and not self.messages[ts].hash:
-            message = self.messages[ts]
-            tshash = calc_hash(message)
-            hl = 3
-            shorthash = tshash[:hl]
-            while any(x.startswith(shorthash) for x in self.hashed_messages):
-                hl += 1
-                shorthash = tshash[:hl]
-
-            if shorthash[:-1] in self.hashed_messages:
-                col_msg = self.hashed_messages.pop(shorthash[:-1])
-                col_new_hash = calc_hash(col_msg)[:hl]
-                col_msg.hash = col_new_hash
-                self.hashed_messages[col_new_hash] = col_msg
-                self.change_message(str(col_msg.ts))
-                if col_msg.thread_channel:
-                    col_msg.thread_channel.rename()
-
-            self.hashed_messages[shorthash] = message
-            message.hash = shorthash
-
-
-class SlackDMChannel(SlackChannel):
-    """
-    Subclass of a normal channel for person-to-person communication, which
-    has some important differences.
-    """
-
-    def __init__(self, eventrouter, users, **kwargs):
-        dmuser = kwargs["user"]
-        kwargs["name"] = users[dmuser].name
-        super(SlackDMChannel, self).__init__(eventrouter, **kwargs)
-        self.type = 'im'
-        self.update_color()
-        self.set_name(self.slack_name)
-
-    def set_name(self, slack_name):
-        self.name = slack_name
-
-    def create_buffer(self):
-        if not self.channel_buffer:
-            super(SlackDMChannel, self).create_buffer()
-            w.buffer_set(self.channel_buffer, "localvar_set_type", 'private')
-
-    def update_color(self):
-        if config.colorize_private_chats:
-            self.color_name = get_nick_color_name(self.name)
-            self.color = w.color(self.color_name)
-        else:
-            self.color = ""
-            self.color_name = ""
-
-    def formatted_name(self, style="default", typing=False, present=True, enable_color=False, **kwargs):
-        if config.colorize_private_chats and enable_color:
-            print_color = self.color
-        else:
-            print_color = ""
-        if not present:
-            prepend = " "
-        else:
-            prepend = "+"
-        select = {
-            "default": self.slack_name,
-            "sidebar": prepend + self.slack_name,
-            "base": self.slack_name,
-            "long_default": "{}.{}".format(self.team.preferred_name, self.slack_name),
-            "long_base": "{}.{}".format(self.team.preferred_name, self.slack_name),
-        }
-        return print_color + select[style]
-
-    def open(self, update_remote=True):
-        self.create_buffer()
-        # self.active = True
-        self.get_history()
-        if "info" in SLACK_API_TRANSLATOR[self.type]:
-            s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["info"], {"name": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-            self.eventrouter.receive(s)
-        if update_remote:
-            if "join" in SLACK_API_TRANSLATOR[self.type]:
-                s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["join"], {"user": self.user}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-                self.eventrouter.receive(s)
-        self.create_buffer()
-
-    def rename(self):
-        if self.channel_buffer:
-            new_name = self.formatted_name(style="sidebar", present=self.team.is_user_present(self.user), enable_color=config.colorize_private_chats)
-            if self.current_short_name != new_name:
-                self.current_short_name = new_name
-                w.buffer_set(self.channel_buffer, "short_name", new_name)
-                return True
-        return False
-
-    def refresh(self):
-        return self.rename()
-
-
-class SlackGroupChannel(SlackChannel):
-    """
-    A group channel is a private discussion group.
-    """
-
-    def __init__(self, eventrouter, **kwargs):
-        super(SlackGroupChannel, self).__init__(eventrouter, **kwargs)
-        self.name = "#" + kwargs['name']
-        self.type = "group"
-        self.set_name(self.slack_name)
-
-    def set_name(self, slack_name):
-        self.name = "#" + slack_name
-
-    # def formatted_name(self, prepend="#", enable_color=True, basic=False):
-    #    return prepend + self.slack_name
-
-
-class SlackMPDMChannel(SlackChannel):
-    """
-    An MPDM channel is a special instance of a 'group' channel.
-    We change the name to look less terrible in weechat.
-    """
-
-    def __init__(self, eventrouter, **kwargs):
-        super(SlackMPDMChannel, self).__init__(eventrouter, **kwargs)
-        n = kwargs.get('name')
-        self.set_name(n)
-        self.type = "group"
-
-    def open(self, update_remote=False):
-        self.create_buffer()
-        self.active = True
-        self.get_history()
-        if "info" in SLACK_API_TRANSLATOR[self.type]:
-            s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["info"], {"name": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-            self.eventrouter.receive(s)
-        # self.create_buffer()
-
-    def set_name(self, n):
-        self.name = "|".join("-".join(n.split("-")[1:-1]).split("--"))
-
-    def formatted_name(self, style="default", typing=False, **kwargs):
-        adjusted_name = "|".join("-".join(self.slack_name.split("-")[1:-1]).split("--"))
-        if config.channel_name_typing_indicator:
-            if not typing:
-                prepend = "#"
-            else:
-                prepend = ">"
-        else:
-            prepend = "#"
-        select = {
-            "default": adjusted_name,
-            "sidebar": prepend + adjusted_name,
-            "base": adjusted_name,
-            "long_default": "{}.{}".format(self.team.preferred_name, adjusted_name),
-            "long_base": "{}.{}".format(self.team.preferred_name, adjusted_name),
-        }
-        return select[style]
-
-    def rename(self):
-        pass
-
-
-class SlackThreadChannel(object):
-    """
-    A thread channel is a virtual channel. We don't inherit from
-    SlackChannel, because most of how it operates will be different.
-    """
-
-    def __init__(self, eventrouter, parent_message):
-        self.eventrouter = eventrouter
-        self.parent_message = parent_message
-        self.channel_buffer = None
-        # self.identifier = ""
-        # self.name = "#" + kwargs['name']
-        self.type = "thread"
-        self.got_history = False
-        self.label = None
-        # self.set_name(self.slack_name)
-    # def set_name(self, slack_name):
-    #    self.name = "#" + slack_name
-
-    def formatted_name(self, style="default", **kwargs):
-        hash_or_ts = self.parent_message.hash or self.parent_message.ts
-        styles = {
-            "default": " +{}".format(hash_or_ts),
-            "long_default": "{}.{}".format(self.parent_message.channel.formatted_name(style="long_default"), hash_or_ts),
-            "sidebar": " +{}".format(hash_or_ts),
-        }
-        return styles[style]
-
-    def refresh(self):
-        self.rename()
-
-    def mark_read(self, ts=None, update_remote=True, force=False):
-        if self.channel_buffer:
-            w.buffer_set(self.channel_buffer, "unread", "")
-            w.buffer_set(self.channel_buffer, "hotlist", "-1")
-
-    def buffer_prnt(self, nick, text, timestamp, **kwargs):
-        data = "{}\t{}".format(nick, text)
-        ts = SlackTS(timestamp)
-        if self.channel_buffer:
-            # backlog messages - we will update the read marker as we print these
-            # backlog = False
-            # if ts <= SlackTS(self.last_read):
-            #    tags = tag("backlog")
-            #    backlog = True
-            # elif self.type in ["im", "mpdm"]:
-            #    tags = tag("dm")
-            #    self.new_messages = True
-            # else:
-            tags = tag("default")
-            # self.new_messages = True
-            w.prnt_date_tags(self.channel_buffer, ts.major, tags, data)
-            modify_print_time(self.channel_buffer, ts.minorstr(), ts.major)
-            # if backlog:
-            #    self.mark_read(ts, update_remote=False, force=True)
-
-    def get_history(self):
-        self.got_history = True
-        for message in self.parent_message.submessages:
-
-            # message = SlackMessage(message_json, team, channel)
-            text = message.render()
-            # print text
-
-            suffix = ''
-            if 'edited' in message.message_json:
-                suffix = ' (edited)'
-            # try:
-            #    channel.unread_count += 1
-            # except:
-            #    channel.unread_count = 1
-            self.buffer_prnt(message.sender, text + suffix, message.ts)
-
-    def send_message(self, message):
-        # team = self.eventrouter.teams[self.team]
-        message = linkify_text(message, self.parent_message.team, self)
-        dbg(message)
-        request = {"type": "message", "channel": self.parent_message.channel.identifier, "text": message, "_team": self.parent_message.team.team_hash, "user": self.parent_message.team.myidentifier, "thread_ts": str(self.parent_message.ts)}
-        self.parent_message.team.send_to_websocket(request)
-        self.mark_read(update_remote=False, force=True)
-
-    def open(self, update_remote=True):
-        self.create_buffer()
-        self.active = True
-        self.get_history()
-        # if "info" in SLACK_API_TRANSLATOR[self.type]:
-        #    s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["info"], {"name": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-        #    self.eventrouter.receive(s)
-        # if update_remote:
-        #    if "join" in SLACK_API_TRANSLATOR[self.type]:
-        #        s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["join"], {"name": self.name}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-        #        self.eventrouter.receive(s)
-        self.create_buffer()
-
-    def rename(self):
-        if self.channel_buffer and not self.label:
-            w.buffer_set(self.channel_buffer, "short_name", self.formatted_name(style="sidebar", enable_color=True))
-
-    def create_buffer(self):
-        """
-        incomplete (muted doesn't work)
-        Creates the weechat buffer where the thread magic happens.
-        """
-        if not self.channel_buffer:
-            self.channel_buffer = w.buffer_new(self.formatted_name(style="long_default"), "buffer_input_callback", "EVENTROUTER", "", "")
-            self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self)
-            w.buffer_set(self.channel_buffer, "localvar_set_type", 'channel')
-            w.buffer_set(self.channel_buffer, "localvar_set_nick", self.parent_message.team.nick)
-            w.buffer_set(self.channel_buffer, "localvar_set_channel", self.formatted_name())
-            w.buffer_set(self.channel_buffer, "short_name", self.formatted_name(style="sidebar", enable_color=True))
-            time_format = w.config_string(w.config_get("weechat.look.buffer_time_format"))
-            parent_time = time.localtime(SlackTS(self.parent_message.ts).major)
-            topic = '{} {} | {}'.format(time.strftime(time_format, parent_time), self.parent_message.sender, self.parent_message.render()	)
-            w.buffer_set(self.channel_buffer, "title", topic)
-
-            # self.eventrouter.weechat_controller.set_refresh_buffer_list(True)
-
-        # try:
-        #    if self.unread_count != 0:
-        #        for c in range(1, self.unread_count):
-        #            if self.type == "im":
-        #                w.buffer_set(self.channel_buffer, "hotlist", "2")
-        #            else:
-        #                w.buffer_set(self.channel_buffer, "hotlist", "1")
-        #    else:
-        #        pass
-        #        #dbg("no unread in {}".format(self.name))
-        # except:
-        #    pass
-        #    dbg("exception no unread count")
-        # if self.unread_count != 0 and not self.muted:
-        #    w.buffer_set(self.channel_buffer, "hotlist", "1")
-
-    def destroy_buffer(self, update_remote):
-        if self.channel_buffer is not None:
-            self.channel_buffer = None
-        self.got_history = False
-        # if update_remote and not eventrouter.shutting_down:
-        self.active = False
-
-
-class SlackUser(object):
-    """
-    Represends an individual slack user. Also where you set their name formatting.
-    """
-
-    def __init__(self, **kwargs):
-        # We require these two things for a vaid object,
-        # the rest we can just learn from slack
-        self.identifier = kwargs["id"]
-        self.slack_name = kwargs["name"]
-        self.name = kwargs["name"]
-        for key, value in kwargs.items():
-            setattr(self, key, value)
-        self.update_color()
-
-    def __repr__(self):
-        return "Name:{} Identifier:{}".format(self.name, self.identifier)
-
-    def force_color(self, color_name):
-        self.color_name = color_name
-        self.color = w.color(self.color_name)
-
-    def update_color(self):
-        # This will automatically be none/"" if the user has disabled nick
-        # colourization.
-        self.color_name = get_nick_color_name(self.name)
-        self.color = w.color(self.color_name)
-
-    def formatted_name(self, prepend="", enable_color=True):
-        if enable_color:
-            return self.color + prepend + self.name
-        else:
-            return prepend + self.name
-
-
-class SlackBot(SlackUser):
-    """
-    Basically the same as a user, but split out to identify and for future
-    needs
-    """
-    def __init__(self, **kwargs):
-        super(SlackBot, self).__init__(**kwargs)
-
-
-class SlackMessage(object):
-    """
-    Represents a single slack message and associated context/metadata.
-    These are modifiable and can be rerendered to change a message,
-    delete a message, add a reaction, add a thread.
-    Note: these can't be tied to a SlackUser object because users
-    can be deleted, so we have to store sender in each one.
-    """
-    def __init__(self, message_json, team, channel, override_sender=None):
-        self.team = team
-        self.channel = channel
-        self.message_json = message_json
-        self.submessages = []
-        self.thread_channel = None
-        self.hash = None
-        if override_sender:
-            self.sender = override_sender
-            self.sender_plain = override_sender
-        else:
-            senders = self.get_sender()
-            self.sender, self.sender_plain = senders[0], senders[1]
-        self.suffix = ''
-        self.ts = SlackTS(message_json['ts'])
-        text = self.message_json.get('text')
-        if text and text.startswith('_') and text.endswith('_') and 'subtype' not in message_json:
-            message_json['text'] = text[1:-1]
-            message_json['subtype'] = 'me_message'
-        if message_json.get('subtype') == 'me_message' and not message_json['text'].startswith(self.sender):
-            message_json['text'] = self.sender + ' ' + self.message_json['text']
-
-    def __hash__(self):
-        return hash(self.ts)
-
-    def render(self, force=False):
-        if len(self.submessages) > 0:
-            return "{} {} {}".format(render(self.message_json, self.team, self.channel, force), self.suffix, "{}[ Thread: {} Replies: {} ]".format(w.color(config.thread_suffix_color), self.hash or self.ts, len(self.submessages)))
-        return "{} {}".format(render(self.message_json, self.team, self.channel, force), self.suffix)
-
-    def change_text(self, new_text):
-        self.message_json["text"] = new_text
-        dbg(self.message_json)
-
-    def change_suffix(self, new_suffix):
-        self.suffix = new_suffix
-        dbg(self.message_json)
-
-    def get_sender(self):
-        name = ""
-        name_plain = ""
-        if self.message_json.get('bot_id') in self.team.bots:
-            name = "{} :]".format(self.team.bots[self.message_json["bot_id"]].formatted_name())
-            name_plain = "{}".format(self.team.bots[self.message_json["bot_id"]].formatted_name(enable_color=False))
-        elif 'user' in self.message_json:
-            if self.message_json['user'] == self.team.myidentifier:
-                name = self.team.users[self.team.myidentifier].name
-                name_plain = self.team.users[self.team.myidentifier].name
-            elif self.message_json['user'] in self.team.users:
-                u = self.team.users[self.message_json['user']]
-                if u.is_bot:
-                    name = "{} :]".format(u.formatted_name())
-                else:
-                    name = "{}".format(u.formatted_name())
-                name_plain = "{}".format(u.formatted_name(enable_color=False))
-        elif 'username' in self.message_json:
-            name = "-{}-".format(self.message_json["username"])
-            name_plain = "{}".format(self.message_json["username"])
-        elif 'service_name' in self.message_json:
-            name = "-{}-".format(self.message_json["service_name"])
-            name_plain = "{}".format(self.message_json["service_name"])
-        else:
-            name = ""
-            name_plain = ""
-        return (name, name_plain)
-
-    def add_reaction(self, reaction, user):
-        m = self.message_json.get('reactions', None)
-        if m:
-            found = False
-            for r in m:
-                if r["name"] == reaction and user not in r["users"]:
-                    r["users"].append(user)
-                    found = True
-            if not found:
-                self.message_json["reactions"].append({"name": reaction, "users": [user]})
-        else:
-            self.message_json["reactions"] = [{"name": reaction, "users": [user]}]
-
-    def remove_reaction(self, reaction, user):
-        m = self.message_json.get('reactions', None)
-        if m:
-            for r in m:
-                if r["name"] == reaction and user in r["users"]:
-                    r["users"].remove(user)
-        else:
-            pass
-
-
-class SlackThreadMessage(SlackMessage):
-
-    def __init__(self, parent_id, *args):
-        super(SlackThreadMessage, self).__init__(*args)
-        self.parent_id = parent_id
-
-
-class WeeSlackMetadata(object):
-    """
-    A simple container that we pickle/unpickle to hold data.
-    """
-
-    def __init__(self, meta):
-        self.meta = meta
-
-    def jsonify(self):
-        return self.meta
-
-
-class SlackTS(object):
-
-    def __init__(self, ts=None):
-        if ts:
-            self.major, self.minor = [int(x) for x in ts.split('.', 1)]
-        else:
-            self.major = int(time.time())
-            self.minor = 0
-
-    def __cmp__(self, other):
-        if isinstance(other, SlackTS):
-            if self.major < other.major:
-                return -1
-            elif self.major > other.major:
-                return 1
-            elif self.major == other.major:
-                if self.minor < other.minor:
-                    return -1
-                elif self.minor > other.minor:
-                    return 1
-                else:
-                    return 0
-        else:
-            s = self.__str__()
-            if s < other:
-                return -1
-            elif s > other:
-                return 1
-            elif s == other:
-                return 0
-
-    def __hash__(self):
-        return hash("{}.{}".format(self.major, self.minor))
-
-    def __repr__(self):
-        return str("{0}.{1:06d}".format(self.major, self.minor))
-
-    def split(self, *args, **kwargs):
-        return [self.major, self.minor]
-
-    def majorstr(self):
-        return str(self.major)
-
-    def minorstr(self):
-        return str(self.minor)
-
-###### New handlers
-
-
-def handle_rtmstart(login_data, eventrouter):
-    """
-    This handles the main entry call to slack, rtm.start
-    """
-    if login_data["ok"]:
-
-        metadata = pickle.loads(login_data["wee_slack_request_metadata"])
-
-        # Let's reuse a team if we have it already.
-        th = SlackTeam.generate_team_hash(login_data['self']['name'], login_data['team']['domain'])
-        if not eventrouter.teams.get(th):
-
-            users = {}
-            for item in login_data["users"]:
-                users[item["id"]] = SlackUser(**item)
-                # users.append(SlackUser(**item))
-
-            bots = {}
-            for item in login_data["bots"]:
-                bots[item["id"]] = SlackBot(**item)
-
-            channels = {}
-            for item in login_data["channels"]:
-                channels[item["id"]] = SlackChannel(eventrouter, **item)
-
-            for item in login_data["ims"]:
-                channels[item["id"]] = SlackDMChannel(eventrouter, users, **item)
-
-            for item in login_data["groups"]:
-                if item["name"].startswith('mpdm-'):
-                    channels[item["id"]] = SlackMPDMChannel(eventrouter, **item)
-                else:
-                    channels[item["id"]] = SlackGroupChannel(eventrouter, **item)
-
-            t = SlackTeam(
-                eventrouter,
-                metadata.token,
-                login_data['url'],
-                login_data["team"]["domain"],
-                login_data["self"]["name"],
-                login_data["self"]["id"],
-                users,
-                bots,
-                channels,
-                muted_channels=login_data["self"]["prefs"]["muted_channels"],
-                highlight_words=login_data["self"]["prefs"]["highlight_words"],
-            )
-            eventrouter.register_team(t)
-
-        else:
-            t = eventrouter.teams.get(th)
-            t.set_reconnect_url(login_data['url'])
-            t.connect()
-
-        # web_socket_url = login_data['url']
-        # try:
-        #    ws = create_connection(web_socket_url, sslopt=sslopt_ca_certs)
-        #    w.hook_fd(ws.sock._sock.fileno(), 1, 0, 0, "receive_ws_callback", t.get_team_hash())
-        #    #ws_hook = w.hook_fd(ws.sock._sock.fileno(), 1, 0, 0, "receive_ws_callback", pickle.dumps(t))
-        #    ws.sock.setblocking(0)
-        #    t.attach_websocket(ws)
-        #    t.set_connected()
-        # except Exception as e:
-        #    dbg("websocket connection error: {}".format(e))
-        #    return False
-
-        t.buffer_prnt('Connected to Slack')
-        t.buffer_prnt('{:<20} {}'.format("Websocket URL", login_data["url"]))
-        t.buffer_prnt('{:<20} {}'.format("User name", login_data["self"]["name"]))
-        t.buffer_prnt('{:<20} {}'.format("User ID", login_data["self"]["id"]))
-        t.buffer_prnt('{:<20} {}'.format("Team name", login_data["team"]["name"]))
-        t.buffer_prnt('{:<20} {}'.format("Team domain", login_data["team"]["domain"]))
-        t.buffer_prnt('{:<20} {}'.format("Team id", login_data["team"]["id"]))
-
-        dbg("connected to {}".format(t.domain))
-
-    # self.identifier = self.domain
-
-def handle_channelsinfo(channel_json, eventrouter, **kwargs):
-    request_metadata = pickle.loads(channel_json["wee_slack_request_metadata"])
-    team = eventrouter.teams[request_metadata.team_hash]
-    channel = team.channels[request_metadata.channel_identifier]
-    unread_count_display = channel_json['channel']['unread_count_display']
-    channel.set_unread_count_display(unread_count_display)
-
-def handle_groupsinfo(group_json, eventrouter, **kwargs):
-    request_metadata = pickle.loads(group_json["wee_slack_request_metadata"])
-    team = eventrouter.teams[request_metadata.team_hash]
-    group = team.channels[request_metadata.channel_identifier]
-    unread_count_display = group_json['group']['unread_count_display']
-    group_id = group_json['group']['id']
-    group.set_unread_count_display(unread_count_display)
-
-def handle_imopen(im_json, eventrouter, **kwargs):
-    request_metadata = pickle.loads(im_json["wee_slack_request_metadata"])
-    team = eventrouter.teams[request_metadata.team_hash]
-    im = team.channels[request_metadata.channel_identifier]
-    unread_count_display = im_json['channel']['unread_count_display']
-    im.set_unread_count_display(unread_count_display)
- 
-def handle_groupshistory(message_json, eventrouter, **kwargs):
-    handle_history(message_json, eventrouter, **kwargs)
-
-
-def handle_channelshistory(message_json, eventrouter, **kwargs):
-    handle_history(message_json, eventrouter, **kwargs)
-
-
-def handle_imhistory(message_json, eventrouter, **kwargs):
-    handle_history(message_json, eventrouter, **kwargs)
-
-
-def handle_history(message_json, eventrouter, **kwargs):
-    request_metadata = pickle.loads(message_json["wee_slack_request_metadata"])
-    kwargs['team'] = eventrouter.teams[request_metadata.team_hash]
-    kwargs['channel'] = kwargs['team'].channels[request_metadata.channel_identifier]
-    try:
-        clear = request_metadata.clear
-    except:
-        clear = False
-    dbg(clear)
-    kwargs['output_type'] = "backlog"
-    if clear:
-        w.buffer_clear(kwargs['channel'].channel_buffer)
-    for message in reversed(message_json["messages"]):
-        process_message(message, eventrouter, **kwargs)
-
-###### New/converted process_ and subprocess_ methods
-
-
-def process_reconnect_url(message_json, eventrouter, **kwargs):
-    kwargs['team'].set_reconnect_url(message_json['url'])
-
-
-def process_manual_presence_change(message_json, eventrouter, **kwargs):
-    process_presence_change(message_json, eventrouter, **kwargs)
-
-
-def process_presence_change(message_json, eventrouter, **kwargs):
-    if "user" in kwargs:
-        user = kwargs["user"]
-        team = kwargs["team"]
-        team.update_member_presence(user, message_json["presence"])
-
-
-def process_pref_change(message_json, eventrouter, **kwargs):
-    team = kwargs["team"]
-    if message_json['name'] == 'muted_channels':
-        team.set_muted_channels(message_json['value'])
-    elif message_json['name'] == 'highlight_words':
-        team.set_highlight_words(message_json['value'])
-    else:
-        dbg("Preference change not implemented: {}\n".format(message_json['name']))
-
-
-def process_user_typing(message_json, eventrouter, **kwargs):
-    channel = kwargs["channel"]
-    team = kwargs["team"]
-    if channel:
-        channel.set_typing(team.users.get(message_json["user"]).name)
-        w.bar_item_update("slack_typing_notice")
-
-
-def process_team_join(message_json, eventrouter, **kwargs):
-    user = message_json['user']
-    team = kwargs["team"]
-    team.users[user["id"]] = SlackUser(**user)
-
-
-def process_pong(message_json, eventrouter, **kwargs):
-    pass
-
-
-def process_message(message_json, eventrouter, store=True, **kwargs):
-    channel = kwargs["channel"]
-    team = kwargs["team"]
-    # try:
-    #  send these subtype messages elsewhere
-    known_subtypes = [
-        'thread_message',
-        'message_replied',
-        'message_changed',
-        'message_deleted',
-        'channel_join',
-        'channel_leave',
-        'channel_topic',
-        # 'group_join',
-        # 'group_leave',
-    ]
-    if "thread_ts" in message_json and "reply_count" not in message_json:
-        message_json["subtype"] = "thread_message"
-
-    subtype = message_json.get("subtype", None)
-    if subtype and subtype in known_subtypes:
-        f = eval('subprocess_' + subtype)
-        f(message_json, eventrouter, channel, team)
-
-    else:
-        message = SlackMessage(message_json, team, channel)
-        text = message.render()
-        dbg("Rendered message: %s" % text)
-        dbg("Sender: %s (%s)" % (message.sender, message.sender_plain))
-
-        # Handle actions (/me).
-        # We don't use `subtype` here because creating the SlackMessage may
-        # have changed the subtype based on the detected message contents.
-        if message.message_json.get('subtype') == 'me_message':
-            try:
-                channel.unread_count_display += 1
-            except:
-                channel.unread_count_display = 1
-            channel.buffer_prnt(w.prefix("action").rstrip(), text, message.ts, tag_nick=message.sender_plain, **kwargs)
-
-        else:
-            suffix = ''
-            if 'edited' in message_json:
-                suffix = ' (edited)'
-            try:
-                channel.unread_count_display += 1
-            except:
-                channel.unread_count_display = 1
-            channel.buffer_prnt(message.sender, text + suffix, message.ts, tag_nick=message.sender_plain, **kwargs)
-
-        if store:
-            channel.store_message(message, team)
-        dbg("NORMAL REPLY {}".format(message_json))
-    # except:
-    #    channel.buffer_prnt("WEE-SLACK-ERROR", json.dumps(message_json), message_json["ts"], **kwargs)
-    #    traceback.print_exc()
-
-
-def subprocess_thread_message(message_json, eventrouter, channel, team):
-    # print ("THREADED: " + str(message_json))
-    parent_ts = message_json.get('thread_ts', None)
-    if parent_ts:
-        parent_message = channel.messages.get(SlackTS(parent_ts), None)
-        if parent_message:
-            message = SlackThreadMessage(parent_ts, message_json, team, channel)
-            parent_message.submessages.append(message)
-            channel.hash_message(parent_ts)
-            channel.store_message(message, team)
-            channel.change_message(parent_ts)
-
-            text = message.render()
-            # channel.buffer_prnt(message.sender, text, message.ts, **kwargs)
-            if parent_message.thread_channel:
-                parent_message.thread_channel.buffer_prnt(message.sender, text, message.ts)
-
-#    channel = channels.find(message_json["channel"])
-#    server = channel.server
-#    #threadinfo = channel.get_message(message_json["thread_ts"])
-#    message = Message(message_json, server=server, channel=channel)
-#    dbg(message, main_buffer=True)
-#
-#    orig = channel.get_message(message_json['thread_ts'])
-#    if orig[0]:
-#        channel.get_message(message_json['thread_ts'])[2].add_thread_message(message)
-#    else:
-#        dbg("COULDN'T find orig message {}".format(message_json['thread_ts']), main_buffer=True)
-
-    # if threadinfo[0]:
-    #    channel.messages[threadinfo[1]].become_thread()
-    #    message_json["item"]["ts"], message_json)
-    # channel.change_message(message_json["thread_ts"], None, message_json["text"])
-    # channel.become_thread(message_json["item"]["ts"], message_json)
-
-
-def subprocess_channel_join(message_json, eventrouter, channel, team):
-    joinprefix = w.prefix("join")
-    message = SlackMessage(message_json, team, channel, override_sender=joinprefix)
-    channel.buffer_prnt(joinprefix, message.render(), message_json["ts"], tagset='joinleave')
-    channel.user_joined(message_json['user'])
-
-
-def subprocess_channel_leave(message_json, eventrouter, channel, team):
-    leaveprefix = w.prefix("quit")
-    message = SlackMessage(message_json, team, channel, override_sender=leaveprefix)
-    channel.buffer_prnt(leaveprefix, message.render(), message_json["ts"], tagset='joinleave')
-    channel.user_left(message_json['user'])
-    # channel.update_nicklist(message_json['user'])
-    # channel.update_nicklist()
-
-
-def subprocess_message_replied(message_json, eventrouter, channel, team):
-    pass
-
-
-def subprocess_message_changed(message_json, eventrouter, channel, team):
-    m = message_json.get("message", None)
-    if m:
-        new_message = m
-        # message = SlackMessage(new_message, team, channel)
-        if "attachments" in m:
-            message_json["attachments"] = m["attachments"]
-        if "text" in m:
-            if "text" in message_json:
-                message_json["text"] += m["text"]
-                dbg("added text!")
-            else:
-                message_json["text"] = m["text"]
-        if "fallback" in m:
-            if "fallback" in message_json:
-                message_json["fallback"] += m["fallback"]
-            else:
-                message_json["fallback"] = m["fallback"]
-
-    text_before = (len(new_message['text']) > 0)
-    new_message["text"] += unwrap_attachments(message_json, text_before)
-    if "edited" in new_message:
-        channel.change_message(new_message["ts"], new_message["text"], ' (edited)')
-    else:
-        channel.change_message(new_message["ts"], new_message["text"])
-
-
-def subprocess_message_deleted(message_json, eventrouter, channel, team):
-    channel.change_message(message_json["deleted_ts"], "(deleted)", '')
-
-
-def subprocess_channel_topic(message_json, eventrouter, channel, team):
-    text = unhtmlescape(unfurl_refs(message_json["text"], ignore_alt_text=False))
-    channel.buffer_prnt(w.prefix("network").rstrip(), text, message_json["ts"], tagset="muted")
-    channel.render_topic(unhtmlescape(message_json["topic"]))
-
-
-def process_reply(message_json, eventrouter, **kwargs):
-    dbg('processing reply')
-    team = kwargs["team"]
-    identifier = message_json["reply_to"]
-    try:
-        original_message_json = team.ws_replies[identifier]
-        del team.ws_replies[identifier]
-        if "ts" in message_json:
-            original_message_json["ts"] = message_json["ts"]
-        else:
-            dbg("no reply ts {}".format(message_json))
-
-        c = original_message_json.get('channel', None)
-        channel = team.channels[c]
-        m = SlackMessage(original_message_json, team, channel)
-
-        # if "type" in message_json:
-        #    if message_json["type"] == "message" and "channel" in message_json.keys():
-        #        message_json["ts"] = message_json["ts"]
-        #        channels.find(message_json["channel"]).store_message(m, from_me=True)
-
-        #        channels.find(message_json["channel"]).buffer_prnt(server.nick, m.render(), m.ts)
-
-        process_message(m.message_json, eventrouter, channel=channel, team=team)
-        channel.mark_read(update_remote=True, force=True)
-        dbg("REPLY {}".format(message_json))
-    except KeyError:
-        dbg("Unexpected reply {}".format(message_json))
-
-
-def process_channel_marked(message_json, eventrouter, **kwargs):
-    """
-    complete
-    """
-    channel = kwargs["channel"]
-    ts = message_json.get("ts", None)
-    if ts:
-        channel.mark_read(ts=ts, force=True, update_remote=False)
-    else:
-        dbg("tried to mark something weird {}".format(message_json))
-
-
-def process_group_marked(message_json, eventrouter, **kwargs):
-    process_channel_marked(message_json, eventrouter, **kwargs)
-
-
-def process_im_marked(message_json, eventrouter, **kwargs):
-    process_channel_marked(message_json, eventrouter, **kwargs)
-
-
-def process_mpim_marked(message_json, eventrouter, **kwargs):
-    process_channel_marked(message_json, eventrouter, **kwargs)
-
-
-def process_channel_joined(message_json, eventrouter, **kwargs):
-    item = message_json["channel"]
-    kwargs['team'].channels[item["id"]].update_from_message_json(item)
-    kwargs['team'].channels[item["id"]].open()
-
-
-def process_channel_created(message_json, eventrouter, **kwargs):
-    item = message_json["channel"]
-    c = SlackChannel(eventrouter, team=kwargs["team"], **item)
-    kwargs['team'].channels[item["id"]] = c
-    kwargs['team'].buffer_prnt('Channel created: {}'.format(c.slack_name))
-
-
-def process_channel_rename(message_json, eventrouter, **kwargs):
-    item = message_json["channel"]
-    channel = kwargs['team'].channels[item["id"]]
-    channel.slack_name = message_json['channel']['name']
-
-
-def process_im_created(message_json, eventrouter, **kwargs):
-    team = kwargs['team']
-    item = message_json["channel"]
-    c = SlackDMChannel(eventrouter, team=team, users=team.users, **item)
-    team.channels[item["id"]] = c
-    kwargs['team'].buffer_prnt('IM channel created: {}'.format(c.name))
-
-
-def process_im_open(message_json, eventrouter, **kwargs):
-    channel = kwargs['channel']
-    item = message_json
-    kwargs['team'].channels[item["channel"]].check_should_open(True)
-    w.buffer_set(channel.channel_buffer, "hotlist", "2")
-
-
-def process_im_close(message_json, eventrouter, **kwargs):
-    item = message_json
-    cbuf = kwargs['team'].channels[item["channel"]].channel_buffer
-    eventrouter.weechat_controller.unregister_buffer(cbuf, False, True)
-
-
-def process_group_joined(message_json, eventrouter, **kwargs):
-    item = message_json["channel"]
-    if item["name"].startswith("mpdm-"):
-        c = SlackMPDMChannel(eventrouter, team=kwargs["team"], **item)
-    else:
-        c = SlackGroupChannel(eventrouter, team=kwargs["team"], **item)
-    kwargs['team'].channels[item["id"]] = c
-    kwargs['team'].channels[item["id"]].open()
-
-
-def process_reaction_added(message_json, eventrouter, **kwargs):
-    channel = kwargs['team'].channels[message_json["item"]["channel"]]
-    if message_json["item"].get("type") == "message":
-        ts = SlackTS(message_json['item']["ts"])
-
-        message = channel.messages.get(ts, None)
-        if message:
-            message.add_reaction(message_json["reaction"], message_json["user"])
-            channel.change_message(ts)
-    else:
-        dbg("reaction to item type not supported: " + str(message_json))
-
-
-def process_reaction_removed(message_json, eventrouter, **kwargs):
-    channel = kwargs['team'].channels[message_json["item"]["channel"]]
-    if message_json["item"].get("type") == "message":
-        ts = SlackTS(message_json['item']["ts"])
-
-        message = channel.messages.get(ts, None)
-        if message:
-            message.remove_reaction(message_json["reaction"], message_json["user"])
-            channel.change_message(ts)
-    else:
-        dbg("Reaction to item type not supported: " + str(message_json))
-
-###### New module/global methods
-
-def render_formatting(text):
-    text = re.sub(r'(^| )\*([^*]+)\*([^a-zA-Z0-9_]|$)',
-                  r'\1{}\2{}\3'.format(w.color(config.render_bold_as),
-                                       w.color('-' + config.render_bold_as)),
-                  text)
-    text = re.sub(r'(^| )_([^_]+)_([^a-zA-Z0-9_]|$)',
-                  r'\1{}\2{}\3'.format(w.color(config.render_italic_as),
-                                       w.color('-' + config.render_italic_as)),
-                  text)
-    return text
-
-
-def render(message_json, team, channel, force=False):
-    # If we already have a rendered version in the object, just return that.
-    if not force and message_json.get("_rendered_text", ""):
-        return message_json["_rendered_text"]
-    else:
-        # server = servers.find(message_json["_server"])
-
-        if "fallback" in message_json:
-            text = message_json["fallback"]
-        elif "text" in message_json:
-            if message_json['text'] is not None:
-                text = message_json["text"]
-            else:
-                text = ""
-        else:
-            text = ""
-
-        text = unfurl_refs(text, ignore_alt_text=config.unfurl_ignore_alt_text)
-
-        text_before = (len(text) > 0)
-        text += unfurl_refs(unwrap_attachments(message_json, text_before), ignore_alt_text=config.unfurl_ignore_alt_text)
-
-        text = text.lstrip()
-        text = unhtmlescape(text.replace("\t", "    "))
-        if message_json.get('mrkdwn', True):
-            text = render_formatting(text)
-
-#        if self.threads:
-#            text += " [Replies: {} Thread ID: {} ] ".format(len(self.threads), self.thread_id)
-#            #for thread in self.threads:
-
-        text += create_reaction_string(message_json.get("reactions", ""))
-        message_json["_rendered_text"] = text
-        return text
-
-
-def linkify_text(message, team, channel):
-    # The get_username_map function is a bit heavy, but this whole
-    # function is only called on message send..
-    usernames = team.get_username_map()
-    channels = team.get_channel_map()
-    message = (message
-        # Replace IRC formatting chars with Slack formatting chars.
-        .replace('\x02', '*')
-        .replace('\x1D', '_')
-        .replace('\x1F', config.map_underline_to)
-        # Escape chars that have special meaning to Slack. Note that we do not
-        # (and should not) perform full HTML entity-encoding here.
-        # See https://api.slack.com/docs/message-formatting for details.
-        .replace('&', '&amp;')
-        .replace('<', '&lt;')
-        .replace('>', '&gt;')
-        .split(' '))
-    for item in enumerate(message):
-        targets = re.match('^\s*([@#])([\w.-]+[\w. -])(\W*)', item[1])
-        if targets and targets.groups()[0] == '@':
-            named = targets.groups()
-            if named[1] in ["group", "channel", "here"]:
-                message[item[0]] = "<!{}>".format(named[1])
-            else:
-                try:
-                    if usernames[named[1]]:
-                        message[item[0]] = "<@{}>{}".format(usernames[named[1]], named[2])
-                except:
-                    message[item[0]] = "@{}{}".format(named[1], named[2])
-        if targets and targets.groups()[0] == '#':
-            named = targets.groups()
-            try:
-                if channels[named[1]]:
-                    message[item[0]] = "<#{}|{}>{}".format(channels[named[1]], named[1], named[2])
-            except:
-                message[item[0]] = "#{}{}".format(named[1], named[2])
-
-    # dbg(message)
-    return " ".join(message)
-
-
-def unfurl_refs(text, ignore_alt_text=False):
-    """
-    input : <@U096Q7CQM|someuser> has joined the channel
-    ouput : someuser has joined the channel
-    """
-    # Find all strings enclosed by <>
-    #  - <https://example.com|example with spaces>
-    #  - <#C2147483705|#otherchannel>
-    #  - <@U2147483697|@othernick>
-    # Test patterns lives in ./_pytest/test_unfurl.py
-    matches = re.findall(r"(<[@#]?(?:[^<]*)>)", text)
-    for m in matches:
-        # Replace them with human readable strings
-        text = text.replace(m, unfurl_ref(m[1:-1], ignore_alt_text))
-    return text
-
-
-def unfurl_ref(ref, ignore_alt_text=False):
-    id = ref.split('|')[0]
-    display_text = ref
-    if ref.find('|') > -1:
-        if ignore_alt_text:
-            display_text = resolve_ref(id)
-        else:
-            if id.startswith("#C"):
-                display_text = "#{}".format(ref.split('|')[1])
-            elif id.startswith("@U"):
-                display_text = ref.split('|')[1]
-            else:
-                url, desc = ref.split('|', 1)
-                display_text = "{} ({})".format(url, desc)
-    else:
-        display_text = resolve_ref(ref)
-    return display_text
-
-
-def unhtmlescape(text):
-    return text.replace("&lt;", "<") \
-               .replace("&gt;", ">") \
-               .replace("&amp;", "&")
-
-
-def unwrap_attachments(message_json, text_before):
-    attachment_text = ''
-    a = message_json.get("attachments", None)
-    if a:
-        if text_before:
-            attachment_text = '\n'
-        for attachment in a:
-            # Attachments should be rendered roughly like:
-            #
-            # $pretext
-            # $author: (if rest of line is non-empty) $title ($title_link) OR $from_url
-            # $author: (if no $author on previous line) $text
-            # $fields
-            t = []
-            prepend_title_text = ''
-            if 'author_name' in attachment:
-                prepend_title_text = attachment['author_name'] + ": "
-            if 'pretext' in attachment:
-                t.append(attachment['pretext'])
-            title = attachment.get('title', None)
-            title_link = attachment.get('title_link', None)
-            if title and title_link:
-                t.append('%s%s (%s)' % (prepend_title_text, title, title_link,))
-                prepend_title_text = ''
-            elif title and not title_link:
-                t.append(prepend_title_text + title)
-                prepend_title_text = ''
-            t.append(attachment.get("from_url", ""))
-
-            atext = attachment.get("text", None)
-            if atext:
-                tx = re.sub(r' *\n[\n ]+', '\n', atext)
-                t.append(prepend_title_text + tx)
-                prepend_title_text = ''
-            fields = attachment.get("fields", None)
-            if fields:
-                for f in fields:
-                    if f['title'] != '':
-                        t.append('%s %s' % (f['title'], f['value'],))
-                    else:
-                        t.append(f['value'])
-            fallback = attachment.get("fallback", None)
-            if t == [] and fallback:
-                t.append(fallback)
-            attachment_text += "\n".join([x.strip() for x in t if x])
-    return attachment_text
-
-
-def resolve_ref(ref):
-    # TODO: This hack to use eventrouter needs to go
-    # this resolver should probably move to the slackteam or eventrouter itself
-    # global EVENTROUTER
-    if 'EVENTROUTER' in globals():
-        e = EVENTROUTER
-        if ref.startswith('@U') or ref.startswith('@W'):
-            for t in e.teams.keys():
-                if ref[1:] in e.teams[t].users:
-                    # try:
-                    return "@{}".format(e.teams[t].users[ref[1:]].name)
-                    # except:
-                    #    dbg("NAME: {}".format(ref))
-        elif ref.startswith('#C'):
-            for t in e.teams.keys():
-                if ref[1:] in e.teams[t].channels:
-                    # try:
-                    return "{}".format(e.teams[t].channels[ref[1:]].name)
-                    # except:
-                    #    dbg("CHANNEL: {}".format(ref))
-
-        # Something else, just return as-is
-    return ref
-
-
-def create_reaction_string(reactions):
-    count = 0
-    if not isinstance(reactions, list):
-        reaction_string = " [{}]".format(reactions)
-    else:
-        reaction_string = ' ['
-        for r in reactions:
-            if len(r["users"]) > 0:
-                count += 1
-                if config.show_reaction_nicks:
-                    nicks = [resolve_ref("@{}".format(user)) for user in r["users"]]
-                    users = "({})".format(",".join(nicks))
-                else:
-                    users = len(r["users"])
-                reaction_string += ":{}:{} ".format(r["name"], users)
-        reaction_string = reaction_string[:-1] + ']'
-    if count == 0:
-        reaction_string = ''
-    return reaction_string
-
-
-def modify_buffer_line(buffer, new_line, timestamp, time_id):
-    # get a pointer to this buffer's lines
-    own_lines = w.hdata_pointer(w.hdata_get('buffer'), buffer, 'own_lines')
-    if own_lines:
-        # get a pointer to the last line
-        line_pointer = w.hdata_pointer(w.hdata_get('lines'), own_lines, 'last_line')
-        # hold the structure of a line and of line data
-        struct_hdata_line = w.hdata_get('line')
-        struct_hdata_line_data = w.hdata_get('line_data')
-
-        while line_pointer:
-            # get a pointer to the data in line_pointer via layout of struct_hdata_line
-            data = w.hdata_pointer(struct_hdata_line, line_pointer, 'data')
-            if data:
-                line_timestamp = w.hdata_time(struct_hdata_line_data, data, 'date')
-                line_time_id = w.hdata_integer(struct_hdata_line_data, data, 'date_printed')
-                # prefix = w.hdata_string(struct_hdata_line_data, data, 'prefix')
-
-                if timestamp == int(line_timestamp) and int(time_id) == line_time_id:
-                    # w.prnt("", "found matching time date is {}, time is {} ".format(timestamp, line_timestamp))
-                    w.hdata_update(struct_hdata_line_data, data, {"message": new_line})
-                    break
-                else:
-                    pass
-            # move backwards one line and try again - exit the while if you hit the end
-            line_pointer = w.hdata_move(struct_hdata_line, line_pointer, -1)
-    return w.WEECHAT_RC_OK
-
-
-def modify_print_time(buffer, new_id, time):
-    """
-    This overloads the time printed field to let us store the slack
-    per message unique id that comes after the "." in a slack ts
-    """
-
-    # get a pointer to this buffer's lines
-    own_lines = w.hdata_pointer(w.hdata_get('buffer'), buffer, 'own_lines')
-    if own_lines:
-        # get a pointer to the last line
-        line_pointer = w.hdata_pointer(w.hdata_get('lines'), own_lines, 'last_line')
-        # hold the structure of a line and of line data
-        struct_hdata_line = w.hdata_get('line')
-        struct_hdata_line_data = w.hdata_get('line_data')
-
-        # get a pointer to the data in line_pointer via layout of struct_hdata_line
-        data = w.hdata_pointer(struct_hdata_line, line_pointer, 'data')
-        if data:
-            w.hdata_update(struct_hdata_line_data, data, {"date_printed": new_id})
-
-    return w.WEECHAT_RC_OK
-
-
-def tag(tagset, user=None):
-    if user:
-        user.replace(" ", "_")
-        default_tag = "nick_" + user
-    else:
-        default_tag = 'nick_unknown'
-    tagsets = {
-        # when replaying something old
-        "backlog": "no_highlight,notify_none,logger_backlog_end",
-        # when posting messages to a muted channel
-        "muted": "no_highlight,notify_none,logger_backlog_end",
-        # when my nick is in the message
-        "highlightme": "notify_highlight,log1",
-        # when receiving a direct message
-        "dm": "notify_private,notify_message,log1,irc_privmsg",
-        "dmfromme": "notify_none,log1,irc_privmsg",
-        # when this is a join/leave, attach for smart filter ala:
-        # if user in [x.strip() for x in w.prefix("join"), w.prefix("quit")]
-        "joinleave": "irc_smart_filter,no_highlight",
-        # catchall ?
-        "default": "notify_message,log1",
-    }
-    return default_tag + "," + tagsets[tagset]
-
-###### New/converted command_ commands
-
-
-@slack_buffer_or_ignore
-def part_command_cb(data, current_buffer, args):
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    e = EVENTROUTER
-    args = args.split()
-    if len(args) > 1:
-        team = e.weechat_controller.buffers[current_buffer].team
-        cmap = team.get_channel_map()
-        channel = "".join(args[1:])
-        if channel in cmap:
-            buffer_ptr = team.channels[cmap[channel]].channel_buffer
-            e.weechat_controller.unregister_buffer(buffer_ptr, update_remote=True, close_buffer=True)
-    else:
-        e.weechat_controller.unregister_buffer(current_buffer, update_remote=True, close_buffer=True)
-    return w.WEECHAT_RC_OK_EAT
-
-
-@slack_buffer_or_ignore
-def topic_command_cb(data, current_buffer, args):
-    n = len(args.split())
-    if n < 2:
-        channel = channels.find(current_buffer)
-        if channel:
-            w.prnt(current_buffer, 'Topic for {} is "{}"'.format(channel.name, channel.topic))
-        return w.WEECHAT_RC_OK_EAT
-    elif command_topic(data, current_buffer, args.split(None, 1)[1]):
-        return w.WEECHAT_RC_OK_EAT
-    else:
-        return w.WEECHAT_RC_ERROR
-
-
-@slack_buffer_required
-def command_topic(data, current_buffer, args):
-    """
-    Change the topic of a channel
-    /slack topic [<channel>] [<topic>|-delete]
-    """
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    e = EVENTROUTER
-    team = e.weechat_controller.buffers[current_buffer].team
-    # server = servers.find(current_domain_name())
-    args = args.split(' ')
-    if len(args) > 2 and args[1].startswith('#'):
-        cmap = team.get_channel_map()
-        channel_name = args[1][1:]
-        channel = team.channels[cmap[channel_name]]
-        topic = " ".join(args[2:])
-    else:
-        channel = e.weechat_controller.buffers[current_buffer]
-        topic = " ".join(args[1:])
-
-    if channel:
-        if topic == "-delete":
-            topic = ''
-        s = SlackRequest(team.token, "channels.setTopic", {"channel": channel.identifier, "topic": topic}, team_hash=team.team_hash)
-        EVENTROUTER.receive(s)
-        return w.WEECHAT_RC_OK_EAT
-    else:
-        return w.WEECHAT_RC_ERROR_EAT
-
-
-@slack_buffer_or_ignore
-def me_command_cb(data, current_buffer, args):
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    message = "_{}_".format(args.split(' ', 1)[1])
-    buffer_input_callback("EVENTROUTER", current_buffer, message)
-    return w.WEECHAT_RC_OK_EAT
-
-
-@slack_buffer_or_ignore
-def msg_command_cb(data, current_buffer, args):
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    dbg("msg_command_cb")
-    aargs = args.split(None, 2)
-    who = aargs[1]
-    if who == "*":
-        who = EVENTROUTER.weechat_controller.buffers[current_buffer].slack_name
-    else:
-        command_talk(data, current_buffer, who)
-
-    if len(aargs) > 2:
-        message = aargs[2]
-        team = EVENTROUTER.weechat_controller.buffers[current_buffer].team
-        cmap = team.get_channel_map()
-        if who in cmap:
-            channel = team.channels[cmap[who]]
-            channel.send_message(message)
-    return w.WEECHAT_RC_OK_EAT
-
-
-@slack_buffer_or_ignore
-def command_talk(data, current_buffer, args):
-    """
-    Open a chat with the specified user
-    /slack talk [user]
-    """
-
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    e = EVENTROUTER
-    team = e.weechat_controller.buffers[current_buffer].team
-    channel_name = args.split(' ')[1]
-    c = team.get_channel_map()
-    if channel_name not in c:
-        u = team.get_username_map()
-        if channel_name in u:
-            s = SlackRequest(team.token, "im.open", {"user": u[channel_name]}, team_hash=team.team_hash)
-            EVENTROUTER.receive(s)
-            dbg("found user")
-            # refresh channel map here
-            c = team.get_channel_map()
-
-    if channel_name.startswith('#'):
-        channel_name = channel_name[1:]
-    if channel_name in c:
-        chan = team.channels[c[channel_name]]
-        chan.open()
-        if config.switch_buffer_on_join:
-            w.buffer_set(chan.channel_buffer, "display", "1")
-        return w.WEECHAT_RC_OK_EAT
-    return w.WEECHAT_RC_OK_EAT
-
-
-def command_showmuted(data, current_buffer, args):
-    current = w.current_buffer()
-    w.prnt(EVENTROUTER.weechat_controller.buffers[current].team.channel_buffer, str(EVENTROUTER.weechat_controller.buffers[current].team.muted_channels))
-
-
-def thread_command_callback(data, current_buffer, args):
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    current = w.current_buffer()
-    channel = EVENTROUTER.weechat_controller.buffers.get(current)
-    if channel:
-        args = args.split()
-        if args[0] == '/thread':
-            if len(args) == 2:
-                try:
-                    pm = channel.messages[SlackTS(args[1])]
-                except:
-                    pm = channel.hashed_messages[args[1]]
-                tc = SlackThreadChannel(EVENTROUTER, pm)
-                pm.thread_channel = tc
-                tc.open()
-                # tc.create_buffer()
-                return w.WEECHAT_RC_OK_EAT
-        elif args[0] == '/reply':
-            count = int(args[1])
-            msg = " ".join(args[2:])
-            mkeys = channel.sorted_message_keys()
-            mkeys.reverse()
-            parent_id = str(mkeys[count - 1])
-            channel.send_message(msg, request_dict_ext={"thread_ts": parent_id})
-            return w.WEECHAT_RC_OK_EAT
-        w.prnt(current, "Invalid thread command.")
-        return w.WEECHAT_RC_OK_EAT
-
-
-def rehistory_command_callback(data, current_buffer, args):
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    current = w.current_buffer()
-    channel = EVENTROUTER.weechat_controller.buffers.get(current)
-    channel.got_history = False
-    w.buffer_clear(channel.channel_buffer)
-    channel.get_history()
-    return w.WEECHAT_RC_OK_EAT
-
-
-@slack_buffer_required
-def hide_command_callback(data, current_buffer, args):
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    c = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None)
-    if c:
-        name = c.formatted_name(style='long_default')
-        if name in config.distracting_channels:
-            w.buffer_set(c.channel_buffer, "hidden", "1")
-    return w.WEECHAT_RC_OK_EAT
-
-
-def slack_command_cb(data, current_buffer, args):
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    a = args.split(' ', 1)
-    if len(a) > 1:
-        function_name, args = a[0], args
-    else:
-        function_name, args = a[0], args
-
-    try:
-        EVENTROUTER.cmds[function_name]("", current_buffer, args)
-    except KeyError:
-        w.prnt("", "Command not found: " + function_name)
-    return w.WEECHAT_RC_OK
-
-
-@slack_buffer_required
-def command_distracting(data, current_buffer, args):
-    channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None)
-    if channel:
-        fullname = channel.formatted_name(style="long_default")
-    if config.distracting_channels.count(fullname) == 0:
-        config.distracting_channels.append(fullname)
-    else:
-        config.distracting_channels.pop(config.distracting_channels.index(fullname))
-    save_distracting_channels()
-
-
-def save_distracting_channels():
-    w.config_set_plugin('distracting_channels', ','.join(config.distracting_channels))
-
-
-@slack_buffer_required
-def command_slash(data, current_buffer, args):
-    """
-    Support for custom slack commands
-    /slack slash /customcommand arg1 arg2 arg3
-    """
-    e = EVENTROUTER
-    channel = e.weechat_controller.buffers.get(current_buffer, None)
-    if channel:
-        team = channel.team
-
-        if args is None:
-            server.buffer_prnt("Usage: /slack slash /someslashcommand [arguments...].")
-            return
-
-        split_args = args.split(None, 2)
-        command = split_args[1]
-        text = split_args[2] if len(split_args) > 2 else ""
-
-        s = SlackRequest(team.token, "chat.command", {"command": command, "text": text, 'channel': channel.identifier}, team_hash=team.team_hash, channel_identifier=channel.identifier)
-        EVENTROUTER.receive(s)
-
-
-@slack_buffer_required
-def command_mute(data, current_buffer, args):
-    current = w.current_buffer()
-    channel_id = EVENTROUTER.weechat_controller.buffers[current].identifier
-    team = EVENTROUTER.weechat_controller.buffers[current].team
-    if channel_id not in team.muted_channels:
-        team.muted_channels.add(channel_id)
-    else:
-        team.muted_channels.discard(channel_id)
-    s = SlackRequest(team.token, "users.prefs.set", {"name": "muted_channels", "value": ",".join(team.muted_channels)}, team_hash=team.team_hash, channel_identifier=channel_id)
-    EVENTROUTER.receive(s)
-
-
-@slack_buffer_required
-def command_openweb(data, current_buffer, args):
-    # if done from server buffer, open slack for reals
-    channel = EVENTROUTER.weechat_controller.buffers[current_buffer]
-    if isinstance(channel, SlackTeam):
-        url = "https://{}".format(channel.team.domain)
-    else:
-        now = SlackTS()
-        url = "https://{}/archives/{}/p{}000000".format(channel.team.domain, channel.slack_name, now.majorstr())
-    w.prnt_date_tags(channel.team.channel_buffer, SlackTS().major, "openweb,logger_backlog_end,notify_none", url)
-
-
-def command_nodistractions(data, current_buffer, args):
-    global hide_distractions
-    hide_distractions = not hide_distractions
-    if config.distracting_channels != ['']:
-        for channel in config.distracting_channels:
-            dbg('hiding channel {}'.format(channel))
-            # try:
-            for c in EVENTROUTER.weechat_controller.buffers.itervalues():
-                if c == channel:
-                    dbg('found channel {} to hide'.format(channel))
-                    w.buffer_set(c.channel_buffer, "hidden", str(int(hide_distractions)))
-            # except:
-            #    dbg("Can't hide channel {} .. removing..".format(channel), main_buffer=True)
-#                config.distracting_channels.pop(config.distracting_channels.index(channel))
-#                save_distracting_channels()
-
-
-@slack_buffer_required
-def command_upload(data, current_buffer, args):
-    channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer)
-    url = 'https://slack.com/api/files.upload'
-    fname = args.split(' ', 1)
-    file_path = os.path.expanduser(fname[1])
-    team = EVENTROUTER.weechat_controller.buffers[current_buffer].team
-    if ' ' in file_path:
-        file_path = file_path.replace(' ', '\ ')
-
-    command = 'curl -F file=@{} -F channels={} -F token={} {}'.format(file_path, channel.identifier, team.token, url)
-    w.hook_process(command, config.slack_timeout, '', '')
-
-
-def away_command_cb(data, current_buffer, args):
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    # TODO: reimplement all.. maybe
-    (all, message) = re.match("^/away(?:\s+(-all))?(?:\s+(.+))?", args).groups()
-    if message is None:
-        command_back(data, current_buffer, args)
-    else:
-        command_away(data, current_buffer, args)
-    return w.WEECHAT_RC_OK
-
-
-@slack_buffer_required
-def command_away(data, current_buffer, args):
-    """
-    Sets your status as 'away'
-    /slack away
-    """
-    team = EVENTROUTER.weechat_controller.buffers[current_buffer].team
-    s = SlackRequest(team.token, "presence.set", {"presence": "away"}, team_hash=team.team_hash)
-    EVENTROUTER.receive(s)
-
-
-@slack_buffer_required
-def command_status(data, current_buffer, args):
-    """
-    Lets you set your Slack Status (not to be confused with away/here)
-    /slack status [emoji] [status_message]
-    """
-    e = EVENTROUTER
-    channel = e.weechat_controller.buffers.get(current_buffer, None)
-    if channel:
-        team = channel.team
-
-        if args is None:
-            server.buffer_prnt("Usage: /slack status [status emoji] [status text].")
-            return
-
-        split_args = args.split(None, 2)
-        emoji = split_args[1] if len(split_args) > 1 else ""
-        text = split_args[2] if len(split_args) > 2 else ""
-
-        profile = {"status_text":text,"status_emoji":emoji}
-
-        s = SlackRequest(team.token, "users.profile.set", {"profile": profile}, team_hash=team.team_hash)
-        EVENTROUTER.receive(s)
-
-
-@slack_buffer_required
-def command_back(data, current_buffer, args):
-    """
-    Sets your status as 'back'
-    /slack back
-    """
-    team = EVENTROUTER.weechat_controller.buffers[current_buffer].team
-    s = SlackRequest(team.token, "presence.set", {"presence": "active"}, team_hash=team.team_hash)
-    EVENTROUTER.receive(s)
-
-
-@slack_buffer_required
-def label_command_cb(data, current_buffer, args):
-    data = decode_from_utf8(data)
-    args = decode_from_utf8(args)
-    channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer)
-    if channel and channel.type == 'thread':
-        aargs = args.split(None, 2)
-        new_name = " +" + aargs[1]
-        channel.label = new_name
-        w.buffer_set(channel.channel_buffer, "short_name", new_name)
-
-
-def command_p(data, current_buffer, args):
-    args = args.split(' ', 1)[1]
-    w.prnt("", "{}".format(eval(args)))
-
-###### NEW EXCEPTIONS
-
-
-class ProcessNotImplemented(Exception):
-    """
-    Raised when we try to call process_(something), but
-    (something) has not been defined as a function.
-    """
-    def __init__(self, function_name):
-        super(ProcessNotImplemented, self).__init__(function_name)
-
-
-class InvalidType(Exception):
-    """
-    Raised when we do type checking to ensure objects of the wrong
-    type are not used improperly.
-    """
-    def __init__(self, type_str):
-        super(InvalidType, self).__init__(type_str)
-
-###### New but probably old and need to migrate
-
-
-def closed_slack_debug_buffer_cb(data, buffer):
-    global slack_debug
-    slack_debug = None
-    return w.WEECHAT_RC_OK
-
-
-def create_slack_debug_buffer():
-    global slack_debug, debug_string
-    if slack_debug is not None:
-        w.buffer_set(slack_debug, "display", "1")
-    else:
-        debug_string = None
-        slack_debug = w.buffer_new("slack-debug", "", "", "closed_slack_debug_buffer_cb", "")
-        w.buffer_set(slack_debug, "notify", "0")
-
-
-def load_emoji():
-    try:
-        global EMOJI
-        DIR = w.info_get("weechat_dir", "")
-        # no idea why this does't work w/o checking the type?!
-        dbg(type(DIR), 0)
-        ef = open('{}/weemoji.json'.format(DIR), 'r')
-        EMOJI = json.loads(ef.read())
-        ef.close()
-    except:
-        dbg("Unexpected error: {}".format(sys.exc_info()), 5)
-    return w.WEECHAT_RC_OK
-
-
-def setup_hooks():
-    cmds = {k[8:]: v for k, v in globals().items() if k.startswith("command_")}
-
-    w.bar_item_new('slack_typing_notice', 'typing_bar_item_cb', '')
-
-    w.hook_timer(1000, 0, 0, "typing_update_cb", "")
-    w.hook_timer(1000, 0, 0, "buffer_list_update_callback", "EVENTROUTER")
-    w.hook_timer(3000, 0, 0, "reconnect_callback", "EVENTROUTER")
-    w.hook_timer(1000 * 60 * 5, 0, 0, "slack_never_away_cb", "")
-
-    w.hook_signal('buffer_closing', "buffer_closing_callback", "EVENTROUTER")
-    w.hook_signal('buffer_switch', "buffer_switch_callback", "EVENTROUTER")
-    w.hook_signal('window_switch', "buffer_switch_callback", "EVENTROUTER")
-    w.hook_signal('quit', "quit_notification_cb", "")
-    w.hook_signal('input_text_changed', "typing_notification_cb", "")
-
-    w.hook_command(
-        # Command name and description
-        'slack', 'Plugin to allow typing notification and sync of read markers for slack.com',
-        # Usage
-        '[command] [command options]',
-        # Description of arguments
-        'Commands:\n' +
-        '\n'.join(cmds.keys()) +
-        '\nUse /slack help [command] to find out more\n',
-        # Completions
-        '|'.join(cmds.keys()),
-        # Function name
-        'slack_command_cb', '')
-    # w.hook_command('me', '', 'stuff', 'stuff2', '', 'me_command_cb', '')
-
-    w.hook_command_run('/me', 'me_command_cb', '')
-    w.hook_command_run('/query', 'command_talk', '')
-    w.hook_command_run('/join', 'command_talk', '')
-    w.hook_command_run('/part', 'part_command_cb', '')
-    w.hook_command_run('/leave', 'part_command_cb', '')
-    w.hook_command_run('/topic', 'command_topic', '')
-    w.hook_command_run('/thread', 'thread_command_callback', '')
-    w.hook_command_run('/reply', 'thread_command_callback', '')
-    w.hook_command_run('/rehistory', 'rehistory_command_callback', '')
-    w.hook_command_run('/hide', 'hide_command_callback', '')
-    w.hook_command_run('/msg', 'msg_command_cb', '')
-    w.hook_command_run('/label', 'label_command_cb', '')
-    w.hook_command_run("/input complete_next", "complete_next_cb", "")
-    w.hook_command_run('/away', 'away_command_cb', '')
-
-    w.hook_completion("nicks", "complete @-nicks for slack", "nick_completion_cb", "")
-    w.hook_completion("emoji", "complete :emoji: for slack", "emoji_completion_cb", "")
-
-    # Hooks to fix/implement
-    # w.hook_signal('buffer_opened', "buffer_opened_cb", "")
-    # w.hook_signal('window_scrolled', "scrolled_cb", "")
-    # w.hook_timer(3000, 0, 0, "slack_connection_persistence_cb", "")
-
-##### END NEW
-
-
-def dbg(message, level=0, main_buffer=False, fout=False):
-    """
-    send debug output to the slack-debug buffer and optionally write to a file.
-    """
-    # TODO: do this smarter
-    # return
-    if level >= config.debug_level:
-        global debug_string
-        message = "DEBUG: {}".format(message)
-        if fout:
-            file('/tmp/debug.log', 'a+').writelines(message + '\n')
-        if main_buffer:
-                # w.prnt("", "---------")
-                w.prnt("", "slack: " + message)
-        else:
-            if slack_debug and (not debug_string or debug_string in message):
-                # w.prnt(slack_debug, "---------")
-                w.prnt(slack_debug, message)
-
-###### Config code
-
-Setting = collections.namedtuple('Setting', ['default', 'desc'])
-
-class PluginConfig(object):
-    # Default settings.
-    # These are, initially, each a (default, desc) tuple; the former is the
-    # default value of the setting, in the (string) format that weechat
-    # expects, and the latter is the user-friendly description of the setting.
-    # At __init__ time these values are extracted, the description is used to
-    # set or update the setting description for use with /help, and the default
-    # value is used to set the default for any settings not already defined.
-    # Following this procedure, the keys remain the same, but the values are
-    # the real (python) values of the settings.
-    default_settings = {
-        'background_load_all_history': Setting(
-            default='false',
-            desc='Load history for each channel in the background as soon as it'
-            ' opens, rather than waiting for the user to look at it.'),
-        'channel_name_typing_indicator': Setting(
-            default='true',
-            desc='Change the prefix of a channel from # to > when someone is'
-            ' typing in it. Note that this will (temporarily) affect the sort'
-            ' order if you sort buffers by name rather than by number.'),
-        'colorize_private_chats': Setting(
-            default='false',
-            desc='Whether to use nick-colors in DM windows.'),
-        'debug_mode': Setting(
-            default='false',
-            desc='Open a dedicated buffer for debug messages and start logging'
-            ' to it. How verbose the logging is depends on log_level.'),
-        'debug_level': Setting(
-            default='3',
-            desc='Show only this level of debug info (or higher) when'
-            ' debug_mode is on. Lower levels -> more messages.'),
-        'distracting_channels': Setting(
-            default='',
-            desc='List of channels to hide.'),
-        'map_underline_to': Setting(
-            default='_',
-            desc='When sending underlined text to slack, use this formatting'
-            ' character for it. The default ("_") sends it as italics. Use'
-            ' "*" to send bold instead.'),
-        'never_away': Setting(
-            default='false',
-            desc='Poke Slack every five minutes so that it never marks you "away".'),
-        'record_events': Setting(
-            default='false',
-            desc='Log all traffic from Slack to disk as JSON.'),
-        'render_bold_as': Setting(
-            default='bold',
-            desc='When receiving bold text from Slack, render it as this in weechat.'),
-        'render_italic_as': Setting(
-            default='italic',
-            desc='When receiving bold text from Slack, render it as this in weechat.'
-            ' If your terminal lacks italic support, consider using "underline" instead.'),
-        'server_aliases': Setting(
-            default='',
-            desc='A comma separated list of `subdomain:alias` pairs. The alias'
-            ' will be used instead of the actual name of the slack (in buffer'
-            ' names, logging, etc). E.g `work:no_fun_allowed` would make your'
-            ' work slack show up as `no_fun_allowed` rather than `work.slack.com`.'),
-        'short_buffer_names': Setting(
-            default='false',
-            desc='Use `foo.#channel` rather than `foo.slack.com.#channel` as the'
-            ' internal name for Slack buffers. Overrides server_aliases.'),
-        'show_reaction_nicks': Setting(
-            default='false',
-            desc='Display the name of the reacting user(s) alongside each reactji.'),
-        'slack_api_token': Setting(
-            default='INSERT VALID KEY HERE!',
-            desc='List of Slack API tokens, one per Slack instance you want to'
-            ' connect to. See the README for details on how to get these.'),
-        'slack_timeout': Setting(
-            default='20000',
-            desc='How long (ms) to wait when communicating with Slack.'),
-        'switch_buffer_on_join': Setting(
-            default='true',
-            desc='When /joining a channel, automatically switch to it as well.'),
-        'thread_suffix_color': Setting(
-            default='lightcyan',
-            desc='Color to use for the [thread: XXX] suffix on messages that'
-            ' have threads attached to them.'),
-        'unfurl_ignore_alt_text': Setting(
-            default='false',
-            desc='When displaying ("unfurling") links to channels/users/etc,'
-            ' ignore the "alt text" present in the message and instead use the'
-            ' canonical name of the thing being linked to.'),
-        'unhide_buffers_with_activity': Setting(
-            default='false',
-            desc='When activity occurs on a buffer, unhide it even if it was'
-            ' previously hidden (whether by the user or by the'
-            ' distracting_channels setting).'),
-    }
-
-    # Set missing settings to their defaults. Load non-missing settings from
-    # weechat configs.
-    def __init__(self):
-        self.settings = {}
-        # Set all descriptions, replace the values in the dict with the
-        # default setting value rather than the (setting,desc) tuple.
-        # Use items() rather than iteritems() so we don't need to worry about
-        # invalidating the iterator.
-        for key, (default, desc) in self.default_settings.items():
-            w.config_set_desc_plugin(key, desc)
-            self.settings[key] = default
-
-        # Migrate settings from old versions of Weeslack...
-        self.migrate()
-        # ...and then set anything left over from the defaults.
-        for key, default in self.settings.iteritems():
-            if not w.config_get_plugin(key):
-                w.config_set_plugin(key, default)
-        self.config_changed(None, None, None)
-
-    def __str__(self):
-        return "".join([x + "\t" + str(self.settings[x]) + "\n" for x in self.settings.keys()])
-
-    def config_changed(self, data, key, value):
-        for key in self.settings:
-            self.settings[key] = self.fetch_setting(key)
-        if self.debug_mode:
-            create_slack_debug_buffer()
-        return w.WEECHAT_RC_OK
-
-    def fetch_setting(self, key):
-        if hasattr(self, 'get_' + key):
-            try:
-                return getattr(self, 'get_' + key)(key)
-            except:
-                return self.settings[key]
-        else:
-            # Most settings are on/off, so make get_boolean the default
-            return self.get_boolean(key)
-
-    def __getattr__(self, key):
-        return self.settings[key]
-
-    def get_boolean(self, key):
-        return w.config_string_to_boolean(w.config_get_plugin(key))
-
-    def get_string(self, key):
-        return w.config_get_plugin(key)
-
-    def get_int(self, key):
-        return int(w.config_get_plugin(key))
-
-    get_debug_level = get_int
-    get_map_underline_to = get_string
-    get_render_bold_as = get_string
-    get_render_italic_as = get_string
-    get_slack_timeout = get_int
-    get_thread_suffix_color = get_string
-
-    def get_distracting_channels(self, key):
-        return [x.strip() for x in w.config_get_plugin(key).split(',')]
-
-    def get_server_aliases(self, key):
-        alias_list = w.config_get_plugin(key)
-        if len(alias_list) > 0:
-            return dict(item.split(":") for item in alias_list.split(","))
-
-    def get_slack_api_token(self, key):
-        token = w.config_get_plugin("slack_api_token")
-        if token.startswith('${sec.data'):
-            return w.string_eval_expression(token, {}, {}, {})
-        else:
-            return token
-
-    def migrate(self):
-        """
-        This is to migrate the extension name from slack_extension to slack
-        """
-        if not w.config_get_plugin("migrated"):
-            for k in self.settings.keys():
-                if not w.config_is_set_plugin(k):
-                    p = w.config_get("plugins.var.python.slack_extension.{}".format(k))
-                    data = w.config_string(p)
-                    if data != "":
-                        w.config_set_plugin(k, data)
-            w.config_set_plugin("migrated", "true")
-
-
-# to Trace execution, add `setup_trace()` to startup
-# and  to a function and sys.settrace(trace_calls)  to a function
-def setup_trace():
-    global f
-    now = time.time()
-    f = open('{}/{}-trace.json'.format(RECORD_DIR, now), 'w')
-
-
-def trace_calls(frame, event, arg):
-    global f
-    if event != 'call':
-        return
-    co = frame.f_code
-    func_name = co.co_name
-    if func_name == 'write':
-        # Ignore write() calls from print statements
-        return
-    func_line_no = frame.f_lineno
-    func_filename = co.co_filename
-    caller = frame.f_back
-    caller_line_no = caller.f_lineno
-    caller_filename = caller.f_code.co_filename
-    print >> f, 'Call to %s on line %s of %s from line %s of %s' % \
-        (func_name, func_line_no, func_filename,
-         caller_line_no, caller_filename)
-    f.flush()
-    return
-
-
-# Main
-if __name__ == "__main__":
-
-    w = WeechatWrapper(weechat)
-
-    if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
-                  SCRIPT_DESC, "script_unloaded", ""):
-
-        weechat_version = w.info_get("version_number", "") or 0
-        if int(weechat_version) < 0x1030000:
-            w.prnt("", "\nERROR: Weechat version 1.3+ is required to use {}.\n\n".format(SCRIPT_NAME))
-        else:
-
-            global EVENTROUTER
-            EVENTROUTER = EventRouter()
-            # setup_trace()
-
-            # WEECHAT_HOME = w.info_get("weechat_dir", "")
-            # STOP_TALKING_TO_SLACK = False
-
-            # Global var section
-            slack_debug = None
-            config = PluginConfig()
-            config_changed_cb = config.config_changed
-
-            typing_timer = time.time()
-            # domain = None
-            # previous_buffer = None
-            # slack_buffer = None
-
-            # never_away = False
-            hide_distractions = False
-            # hotlist = w.infolist_get("hotlist", "", "")
-            # main_weechat_buffer = w.info_get("irc_buffer", "{}.{}".format(domain, "DOESNOTEXIST!@#$"))
-
-            w.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_changed_cb", "")
-
-            load_emoji()
-            setup_hooks()
-
-            # attach to the weechat hooks we need
-
-            tokens = config.slack_api_token.split(',')
-            for t in tokens:
-                s = SlackRequest(t, 'rtm.start', {})
-                EVENTROUTER.receive(s)
-            if config.record_events:
-                EVENTROUTER.record()
-            EVENTROUTER.handle_next()
-            w.hook_timer(10, 0, 0, "handle_next", "")
-            # END attach to the weechat hooks we need
--- a/weechat/relay.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/relay.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- relay.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [look]
 auto_open_buffer = on
@@ -18,6 +25,7 @@
 text_selected = white
 
 [network]
+allow_empty_password = off
 allowed_ips = ""
 bind_address = ""
 clients_purge_delay = 0
@@ -33,6 +41,7 @@
 backlog_max_minutes = 1440
 backlog_max_number = 256
 backlog_since_last_disconnect = on
+backlog_since_last_message = off
 backlog_tags = "irc_privmsg"
 backlog_time_format = "[%H:%M] "
 
--- a/weechat/script.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/script.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- script.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [look]
 columns = "%s %n %V %v %u | %d | %t"
@@ -43,7 +50,7 @@
 [scripts]
 autoload = on
 cache_expire = 60
+download_timeout = 30
 hold = ""
 path = "%h/script"
 url = "http://www.weechat.org/files/plugins.xml.gz"
-url_force_https = on
--- a/weechat/sec.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/sec.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- sec.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [crypt]
 cipher = aes256
--- a/weechat/trigger.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/trigger.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- trigger.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [look]
 enabled = on
@@ -9,6 +16,7 @@
 [color]
 flag_command = lightgreen
 flag_conditions = yellow
+flag_post_action = lightblue
 flag_regex = lightcyan
 flag_return_code = lightmagenta
 regex = white
@@ -22,6 +30,7 @@
 beep.conditions = "${tg_highlight} || ${tg_msg_pv}"
 beep.enabled = on
 beep.hook = print
+beep.post_action = none
 beep.regex = ""
 beep.return_code = ok
 cmd_pass.arguments = "5000|input_text_display;5000|history_add;5000|irc_command_auth"
@@ -29,6 +38,7 @@
 cmd_pass.conditions = ""
 cmd_pass.enabled = on
 cmd_pass.hook = modifier
+cmd_pass.post_action = none
 cmd_pass.regex = "==^((/(msg|quote) +nickserv +(id|identify|register|ghost +[^ ]+|release +[^ ]+|regain +[^ ]+) +)|/oper +[^ ]+ +|/quote +pass +|/set +[^ ]*password[^ ]* +|/secure +(passphrase|decrypt|set +[^ ]+) +)(.*)==$1$.*+"
 cmd_pass.return_code = ok
 dumbass_buffer.arguments = "4000|input_text_for_buffer;4000|history_add"
@@ -36,6 +46,7 @@
 dumbass_buffer.conditions = ""
 dumbass_buffer.enabled = on
 dumbass_buffer.hook = modifier
+dumbass_buffer.post_action = none
 dumbass_buffer.regex = "==^ +/?b (.+)==/b ${re:1}"
 dumbass_buffer.return_code = ok
 idiot_buffer.arguments = "4000|input_text_for_buffer;4000|history_add"
@@ -43,6 +54,7 @@
 idiot_buffer.conditions = ""
 idiot_buffer.enabled = on
 idiot_buffer.hook = modifier
+idiot_buffer.post_action = none
 idiot_buffer.regex = "==^b (.+)==/b ${re:1}"
 idiot_buffer.return_code = ok
 msg_auth.arguments = "5000|irc_message_auth"
@@ -50,6 +62,7 @@
 msg_auth.conditions = ""
 msg_auth.enabled = on
 msg_auth.hook = modifier
+msg_auth.post_action = none
 msg_auth.regex = "==^(.*(id|identify|register|ghost +[^ ]+|release +[^ ]+) +)(.*)==$1$.*+"
 msg_auth.return_code = ok
 server_pass.arguments = "5000|input_text_display;5000|history_add"
@@ -57,5 +70,6 @@
 server_pass.conditions = ""
 server_pass.enabled = on
 server_pass.hook = modifier
+server_pass.post_action = none
 server_pass.regex = "==^(/(server|connect) .*-(sasl_)?password=)([^ ]+)(.*)==$1$.*4$5"
 server_pass.return_code = ok
--- a/weechat/urlgrab.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/urlgrab.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- urlgrab.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [color]
 color_bg_selected = green
--- a/weechat/weechat.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/weechat.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -190,7 +190,9 @@
 [network]
 connection_timeout = 60
 # gnutls_ca_file = "%h/ssl/CAs.pem"
-gnutls_ca_file = "~/.weechat/certs/ca-bundle.crt"
+# gnutls_ca_file = "~/.weechat/certs/ca-bundle.crt"
+# gnutls_ca_file = "/usr/local/etc/openssl/cert.pem"
+gnutls_ca_file = "/Users/sjl/src/sighborg/certs/ssl_ca_bundle.pem"
 gnutls_handshake_timeout = 30
 proxy_curl = ""
 
--- a/weechat/xfer.conf	Fri Sep 08 19:37:36 2017 -0400
+++ b/weechat/xfer.conf	Fri Sep 29 10:28:47 2017 -0400
@@ -1,6 +1,13 @@
 #
 # weechat -- xfer.conf
 #
+# WARNING: It is NOT recommended to edit this file by hand,
+# especially if WeeChat is running.
+#
+# Use /set or similar command to change settings in WeeChat.
+#
+# For more info, see: https://weechat.org/doc/quickstart
+#
 
 [look]
 auto_open_buffer = on