# coding=utf-8
import logging

HELP_MESSAGE = '''Actions are voted on using :+1: and :-1:. I support the following commands:
```–  .help
–  .ping
–  .pong
–  .update
-  .intersect <CHANNEL>
–  .vote <STRING> <INT>
–  .rename <CHANNEL> <STRING>
–  .kick <USER> <CHANNEL>
–  .invite <EMAIL>
–  .rename_slack <REST_OF_INPUT>```'''


# TODO(tso): use https://api.slack.com/methods/chat.postEphemeral for help messages etc

def help(channel, args):
    logging.info('help: {}'.format(args))
    channel.send_message(HELP_MESSAGE)


def ping(channel, args):
    logging.info('ping: {}'.format(args))
    channel.send_message('pong')


def pong(channel, args):
    logging.info('pong: {}'.format(args))
    channel.send_message('ping')


def intersect(channel, args):
    logging.info('intersect: {}'.format(args))
    this_channel = channel.list_users()
    other_channel = args[1].list_users()
    message = ''
    for user in this_channel.intersection(other_channel):
        # if self.client.is_active_and_human(user):
        message += '<@{}>'.format(user)
    if message == '':
        message = 'No intersection.'

    channel.send_message(message)


def vote(channel, args):
    logging.info('vote: {}'.format(args))


def rename(channel, args):
    logging.info('rename: {}'.format(args))


def kick(channel, args):
    logging.info('kick: {}'.format(args))


def invite(channel, args):
    logging.info('invite: {}'.format(args))


def rename_slack(channel, args):
    logging.info('rename_slack: {}'.format(args))


mapping = {
    '.help': help,
    '.ping': ping,
    '.pong': pong,
    '.intersect': intersect,
    '.vote': vote,
    '.rename': rename,
    '.kick': kick,
    '.invite': invite,
    'rename_slack': rename_slack
}
