from util import hook, strip_formatting
from collections import OrderedDict
from datetime import datetime
import re

taned = { '#lf': False, '#sa-minecraft': False }

@hook.event('*', limit=1)
def tane_event(paraml, chan=None, conn=None):
  global taned
  today = datetime.today()
  if today.weekday() == 4 and today.hour == 18 and chan in taned and not taned[chan]:
    taned[chan] = True
    conn.cmd('PRIVMSG {} {}'.format(chan, rainbow("I CAN'T WAIT")))
    conn.cmd('PRIVMSG {} {}'.format(chan, 'http://tane.us/weekend.html'))
    conn.cmd('PRIVMSG {} {}'.format(chan, rainbow("FOR THE WEEKEND TO BEGIN")))

  if today.weekday() != 4:
    taned[chan] = False

@hook.command
def tane(inp, say=None):
  today = datetime.today()
  if today.weekday() == 4:
    say(rainbow("I CAN'T WAIT"))
    say('http://tane.us/weekend.html')
    say(rainbow("FOR THE WEEKEND TO BEGIN"))
  else:
    return rainbow('с м е р т ь   ж д е т   в с е х   н а с')

colors = OrderedDict([
  ('red',    '\x0304'),
  ('ornage', '\x0307'),
  ('yellow', '\x0308'),
  ('green',  '\x0309'),
  ('cyan',   '\x0303'),
  ('ltblue', '\x0310'),
  ('rylblue','\x0312'),
  ('blue',   '\x0302'),
  ('magenta','\x0306'),
  ('pink',   '\x0313'),
  ('maroon', '\x0305')
])
def rainbow(inp):
  inp = inp.decode('utf-8')
  inp = strip_formatting.strip(inp)
  col = colors.items()
  out = ""
  l = len(colors)
  for i, t in enumerate(inp):
      out += col[i % l][1] + t
  return out
