old_contents: import socket
  import subprocess
  import time
  
  from util import hook, http
  
  socket.setdefaulttimeout(10)  # global setting
  
  
  def get_version():
      try:
          stdout = subprocess.check_output(['git', 'log', '--format=%h'])
      except:
          revnumber = 0
          shorthash = '????'
      else:
          revs = stdout.splitlines()
          revnumber = len(revs)
          shorthash = revs[0]
  
      shorthash = shorthash.decode('utf-8')
  
      http.ua_skybot = 'Skybot/r%d %s (http://github.com/rmmh/skybot)' \
          % (revnumber, shorthash)
  
      return shorthash, revnumber
  
  
  # autorejoin channels
  @hook.event('KICK')
  def rejoin(paraml, conn=None):
      if paraml[1] == conn.nick:
          if paraml[0].lower() in conn.channels:
              conn.join(paraml[0])
  
  
  # join channels when invited
  @hook.event('INVITE')
  def invite(paraml, conn=None):
      conn.join(paraml[-1])
  
  
  @hook.event('004')
  def onjoin(paraml, conn=None):
      # identify to services
      nickserv_password = conn.nickserv_password
      nickserv_name = conn.nickserv_name
      nickserv_command = conn.nickserv_command
      if nickserv_password:
          conn.msg(nickserv_name, nickserv_command % nickserv_password)
          time.sleep(1)
  
      # set mode on self
      mode = conn.user_mode
      if mode:
          conn.cmd('MODE', [conn.nick, mode])
  
      conn.join_channels()
  
      # set user-agent as a side effect of reading the version
      get_version()
  
  
  @hook.regex(r'^\x01VERSION\x01$')
  def version(inp, notice=None):
      ident, rev = get_version()
      notice('\x01VERSION skybot %s r%d - http://github.com/rmmh/'
             'skybot/\x01' % (ident, rev))
  
new_contents: import socket
  import subprocess
  import time
  
  from util import hook, http
  
  socket.setdefaulttimeout(10)  # global setting
  
  
  def get_version():
      try:
          stdout = subprocess.check_output(['git', 'log', '--format=%h'])
      except:
          revnumber = 0
          shorthash = '????'
      else:
          revs = stdout.splitlines()
          revnumber = len(revs)
          shorthash = revs[0]
  
      shorthash = shorthash.decode('utf-8')
  
      http.ua_skybot = 'Skybot/r%d %s (http://github.com/rmmh/skybot)' \
          % (revnumber, shorthash)
  
      return shorthash, revnumber
  
  
  # autorejoin channels
  @hook.event('KICK')
  def rejoin(paraml, conn=None):
      if paraml[1] == conn.nick:
          if paraml[0].lower() in conn.channels:
              conn.join(paraml[0])
  
  
  # join channels when invited
  @hook.event('INVITE')
  def invite(paraml, conn=None):
      conn.join(paraml[-1])
  
  
  @hook.event('004')
  def onjoin(paraml, conn=None):
      # set mode on self
      mode = conn.user_mode
      if mode:
          conn.cmd('MODE', [conn.nick, mode])
  
      # identify to services
      nickserv_password = conn.nickserv_password
      nickserv_name = conn.nickserv_name
      nickserv_command = conn.nickserv_command
      if nickserv_password:
          conn.msg(nickserv_name, nickserv_command % nickserv_password)
          time.sleep(1)
  
      conn.join_channels()
  
      # set user-agent as a side effect of reading the version
      get_version()
  
  
  @hook.regex(r'^\x01VERSION\x01$')
  def version(inp, notice=None):
      ident, rev = get_version()
      notice('\x01VERSION skybot %s r%d - http://github.com/rmmh/'
             'skybot/\x01' % (ident, rev))
  
subject: set modes on server before trying to identify