Ejemplo n.º 1
0
def rip(inp, say=None):
  if inp == '': return

  if '\n' in inp:
    txt = inp.split('\n')
    width = len(max(txt, key=lambda x: len(x)))
  elif '\\n' in inp:
    txt = strip_formatting.strip(inp).split('\\n')
    width = len(max(txt, key=lambda x: len(x))) + 4
    if len(txt) > 10:
      return 'too long mate'
  else:
    stripped = strip_formatting.strip(inp)
    inp = inp.strip()
    og = inp
    width = WIDTH + 4

    if len(stripped) > WIDTH:
      txt = wrap(inp, WIDTH)
    else:
      width = len(stripped) + 4
      txt = [inp]

  topfiller = str.center('', width-5, '-')

  headstone = []
  headstone.append('  _.' + topfiller + '-._')
  headstone.append(' |' + str.center('RIP', width) + '|')
  for line in txt:
    headstone.append(' |' + str.center(line.upper().encode('utf-8'), width) + '|')
  headstone.append(' |' + str.center('', width, '_') + '|')
  headstone.append('|' + str.center('', width+2, '_') + '|')

  for l in headstone:
    say(l.decode('utf-8'))
Ejemplo n.º 2
0
def pipe(inp, db=None, input=None, bot=None):
  ".pipe <cmd> | <cmd> etc etc. pipe commands into each other. if the first word after the pipe isnt a command the text gets sent to the next command"
  cmds = inp.split('|')

  output = Fifo()
  nxt = Fifo()

  def f(x):
    nxt.push(x)

  # function overriding
  say = input.say
  reply = input.reply
  input.say = f
  input.reply = f

  for cmd in cmds:
    nxt = Fifo()

    cmd = cmd.strip()

    if cmd[0] == '"' and cmd[-1] == '"':
      cmd = cmd[1:-1]
      output.push(strip_formatting.strip(cmd))
      continue

    func_name, args = split_cmd(cmd)

    # if the first word doesnt map to a func push the whole thing into the queue
    try:
      funcs = [i[0] for i in bot.plugs['command'] if i[1]['name'].startswith(func_name)]
      if len(funcs) > 1:
        funcs = [f.func_name for f in funcs]
        say("did you mean %s or %s?" % (', '.join(funcs[:-1]), funcs[-1]))
        return
      func = funcs[0]
    except IndexError, e:
      output.push(strip_formatting.strip(cmd))
      continue

    args = strip_formatting.strip(args)

    if output.empty():
      output.push(args)

    for line in output:
      res = call(func, func_name, line, input)
      if res:
        nxt.push(res)

    output = nxt
Ejemplo n.º 3
0
def usa(inp):
  inp = strip_formatting.strip(inp)
  c = [colors['red'], '\x0300', colors['blue']]
  l = len(c)
  out = ''
  for i, t in enumerate(inp):
    out += c[i % l] + t
  return out
Ejemplo n.º 4
0
def rainbow(text):
    c =['\x0304', '\x0307', '\x0309', '\x0310', '\x0306']
    text = strip_formatting.strip(text)
    out = ""
    l = len(c)
    for i, t in enumerate(text):
        out += c[i % l] + t
    return out
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
def wrainbow(inp):
  inp = unicode(inp)
  col = colors.items()
  inp = strip_formatting.strip(inp).split(' ')
  out = []
  l = len(colors)
  for i, t in enumerate(inp):
      out.append(col[i % l][1] + t)
  return ' '.join(out)
Ejemplo n.º 7
0
def bread(inp, say=None):
  og = inp
  inp = inp.encode('utf-8')
  topfiller = str.center('', len(strip_formatting.strip(og))-1, '-')

  top = '  .' + topfiller + '-.\n'

  width = len(top)-3

  rip = ' |' + str.center('', width) + '|\n'
  nmr = ' |' + str.center(inp.upper(), width) + '|\n'
  lsr = ' |' + str.center('', width, '_') + '|\n'

  headstone = [top, rip, nmr, lsr]
  for l in headstone:
    say(l.decode('utf-8'))
Ejemplo n.º 8
0
def pipe(inp, db=None, input=None, bot=None):
  ".pipe <cmd> | <cmd> etc etc. pipe commands into each other. if the first word after the pipe isnt a command the text gets sent to the next command"
  # cmds = inp.split('|')
  if input.chan == '#dota' or not input.chan.startswith('#'):
    return

  output = Fifo()
  nxt = Fifo()

  def f(x):
    nxt.push(x)

  # function overriding
  say = input.say
  reply = input.reply
  input.say = f
  input.reply = f

  # build the cmd list from the shlex
  cmdshlex = shlex.shlex(inp)
  cmdshlex.commenters = ''
  cmdshlex.wordchars += '#-'
  cmdbuf = ''
  cmds = []
  for token in cmdshlex:
    if token == '|':
      cmds.append(cmdbuf)
      cmdbuf = ''
    else:
      cmdbuf += ' ' + token
  cmds.append(cmdbuf)

  print cmds

  for cmd in cmds:
    nxt = Fifo()

    cmd = cmd.strip()

    if cmd[0] == '"' and cmd[-1] == '"':
      cmd = cmd[1:-1]
      output.push(strip_formatting.strip(cmd))
      continue

    func_name, args = split_cmd(cmd)

    # if the first word doesnt map to a func push the whole thing into the queue
    # also do this if we just have a string
    if cmd[0] == '"' and cmd[-1] == '"':
      output.push(strip_formatting.strip(cmd)[1:-1])
      continue
    else:
      try:
        command = match_command(func_name, bot)
        if isinstance(command, list):
          say("did you mean %s or %s?" %
                      (', '.join(command[:-1]), command[-1]))
          return
        func = bot.commands[command]
      except IndexError, e:
        output.push(strip_formatting.strip(cmd))
        continue

    args = strip_formatting.strip(args)

    if output.empty():
      output.push(args)

    if 'multiline' in func[1]:
      res = call(bot, func, func_name, '\n'.join(output), input)
      if res:
        nxt.push(res)
    else:
      for line in output:
        res = call(bot, func, func_name, line, input)
        if res:
          nxt.push(res)

    output = nxt