예제 #1
0
파일: slack.go 프로젝트: GenPage/slack-cli
func (s *Slack) handleIM(action string, params map[string]string) (interface{}, error) {
	var v interface{}
	var err error

	switch action {
	case "close":
		noop, closed, err := s.s.CloseIMChannel(params["channel"])
		if err != nil {
			return nil, err
		}

		v = map[string]bool{
			"no_op":          noop,
			"already_closed": closed,
		}
	case "history":
		historyParms := slack.HistoryParameters{}
		historyParms.Latest = getStringParam(params, "latest", slack.DEFAULT_HISTORY_LATEST)

		historyParms.Oldest = getStringParam(params, "oldest", slack.DEFAULT_HISTORY_OLDEST)

		historyParms.Count = getIntParam(params, "count", slack.DEFAULT_HISTORY_COUNT)

		v, err = s.s.GetIMHistory(params["channel"], historyParms)

	case "list":
		ims, err := s.s.GetIMChannels()
		if err != nil {
			return nil, err
		}

		v = map[string]interface{}{
			"ims": ims,
		}
	case "mark":
		err = s.s.MarkIMChannel(params["channel"], params["ts"])
	case "open":
		noop, opened, ch, err := s.s.OpenIMChannel(params["user"])
		if err != nil {
			return nil, err
		}

		v = map[string]interface{}{
			"no_op":        noop,
			"already_open": opened,
			"channel": map[string]string{
				"id": ch,
			},
		}

	default:
		return nil, fmt.Errorf("invalid im action %s", action)
	}

	return v, err
}
예제 #2
0
파일: slack.go 프로젝트: GenPage/slack-cli
func (s *Slack) handleGroups(action string, params map[string]string) (interface{}, error) {
	var v interface{}
	var err error

	switch action {
	case "archive":
		err = s.s.ArchiveGroup(params["channel"])
	case "close":
		noop, closed, err := s.s.CloseGroup(params["channel"])
		if err != nil {
			return nil, err
		}
		v = map[string]bool{
			"no_op":          noop,
			"already_closed": closed,
		}
	case "create":
		group, err := s.s.CreateGroup(params["name"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"group": group,
		}
	case "createchild":
		group, err := s.s.CreateChildGroup(params["channel"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"group": group,
		}
	case "history":
		historyParam := slack.HistoryParameters{}
		historyParam.Latest = getStringParam(params, "latest", slack.DEFAULT_HISTORY_LATEST)
		historyParam.Oldest = getStringParam(params, "latest", slack.DEFAULT_HISTORY_OLDEST)
		historyParam.Count = getIntParam(params, "count", slack.DEFAULT_HISTORY_COUNT)
		v, err = s.s.GetGroupHistory(params["channel"], historyParam)
	case "invite":
		group, in, err := s.s.InviteUserToGroup(params["channel"], params["user"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"already_in_group": in,
			"group":            group,
		}
	case "kick":
		err = s.s.KickUserFromGroup(params["channel"], params["user"])
	case "leave":
		err = s.s.LeaveGroup(params["channel"])
	case "list":
		exclude := getIntParam(params, "exclude_archived", 0)
		groups, err := s.s.GetGroups(exclude == 1)
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"groups": groups,
		}
	case "open":
		noop, opened, err := s.s.OpenGroup(params["channel"])
		if err != nil {
			return nil, err
		}
		v = map[string]bool{
			"no_op":        noop,
			"already_open": opened,
		}
	case "mark":
		err = s.s.SetGroupReadMark(params["channel"], params["ts"])
	case "rename":
		group, err := s.s.RenameGroup(params["channel"], params["name"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"group": group,
		}
	case "setpurpose":
		purpose, err := s.s.SetGroupPurpose(params["channel"], params["purpose"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"purpose": purpose,
		}
	case "settopic":
		topic, err := s.s.SetGroupTopic(params["channel"], params["topic"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"topic": topic,
		}
	case "unarchive":
		err = s.s.UnarchiveGroup(params["channel"])
	default:
		return nil, fmt.Errorf("invalid groups action %s", action)
	}

	return v, err
}
예제 #3
0
파일: slack.go 프로젝트: GenPage/slack-cli
func (s *Slack) handleChannels(action string, params map[string]string) (interface{}, error) {
	var v interface{}
	var err error

	switch action {
	case "archive":
		err = s.s.ArchiveChannel(params["channel"])
	case "create":
		ch, err := s.s.CreateChannel(params["name"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"channel": ch,
		}
	case "history":
		historyParam := slack.HistoryParameters{}
		historyParam.Latest = getStringParam(params, "latest", slack.DEFAULT_HISTORY_LATEST)
		historyParam.Oldest = getStringParam(params, "latest", slack.DEFAULT_HISTORY_OLDEST)
		historyParam.Count = getIntParam(params, "count", slack.DEFAULT_HISTORY_COUNT)
		v, err = s.s.GetChannelHistory(params["channel"], historyParam)
	case "info":
		ch, err := s.s.GetChannelInfo(params["channel"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"channel": ch,
		}
	case "invite":
		ch, err := s.s.InviteUserToChannel(params["channel"], params["user"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"channel": ch,
		}
	case "join":
		ch, err := s.s.JoinChannel(params["name"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"channel": ch,
		}
	case "kick":
		err = s.s.KickUserFromChannel(params["channel"], params["user"])
	case "leave":
		_, err = s.s.LeaveChannel(params["channel"])
	case "list":
		exclude := getIntParam(params, "exclude_archived", 0)
		chs, err := s.s.GetChannels(exclude == 1)
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"channels": chs,
		}
	case "mark":
		err = s.s.SetChannelReadMark(params["channel"], params["ts"])
	case "rename":
		ch, err := s.s.RenameChannel(params["channel"], params["name"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"channel": ch,
		}
	case "setpurpose":
		purpose, err := s.s.SetChannelPurpose(params["channel"], params["purpose"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"purpose": purpose,
		}
	case "settopic":
		topic, err := s.s.SetChannelTopic(params["channel"], params["topic"])
		if err != nil {
			return nil, err
		}
		v = map[string]interface{}{
			"topic": topic,
		}
	case "unarchive":
		err = s.s.UnarchiveChannel(params["channel"])
	default:
		return nil, fmt.Errorf("invalid files action %s", action)
	}

	return v, err
}