<commit_before>// Copyright 2016 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package client

import (
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"time"

	"golang.org/x/net/context"

	"github.com/keybase/cli"
	"github.com/keybase/client/go/chat/globals"
	"github.com/keybase/client/go/chat/msgchecker"
	"github.com/keybase/client/go/libcmdline"
	"github.com/keybase/client/go/libkb"
	"github.com/keybase/client/go/protocol/chat1"
	"github.com/keybase/client/go/protocol/keybase1"
	isatty "github.com/mattn/go-isatty"
)

// NOTE if you change these values you should change them in
// go/chatbase/storage/ephemeral.go as well.
const maxEphemeralLifetime = time.Hour * 24 * 7
const minEphemeralLifetime = time.Second * 30

type CmdChatSend struct {
	libkb.Contextified
	resolvingRequest chatConversationResolvingRequest
	// Only one of these should be set
	message           string
	setHeadline       string
	ephemeralLifetime time.Duration
	clearHeadline     bool
	hasTTY            bool
	nonBlock          bool
	team              bool
}

func NewCmdChatSendRunner(g *libkb.GlobalContext) *CmdChatSend {
	return &CmdChatSend{
		Contextified: libkb.NewContextified(g),
	}
}

func (c *CmdChatSend) SetTeamChatForTest(n string) {
	c.team = true
	c.resolvingRequest = chatConversationResolvingRequest{
		TlfName:     n,
		TopicName:   globals.DefaultTeamTopic,
		MembersType: chat1.ConversationMembersType_TEAM,
		TopicType:   chat1.TopicType_CHAT,
		Visibility:  keybase1.TLFVisibility_PRIVATE,
	}
}

func (c *CmdChatSend) SetMessage(m string) {
	c.message = m
}

func newCmdChatSend(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
	flags := append(getConversationResolverFlags(),
		mustGetChatFlags("set-headline", "clear-headline", "nonblock")...,
	)
	if g.Env.GetRunMode() == libkb.DevelRunMode {
		flags = append(flags, cli.DurationFlag{
			Name: "exploding-lifetime",
			Usage: `Make this message an exploding message and set the
				lifetime for the given duration.  The maximum lifetime is 168h
				(one week) and the minimum lifetime is 5s.`,
		})
	}
	return cli.Command{
		Name:         "send",
		Usage:        "Send a message to a conversation",
		ArgumentHelp: "[conversation [message]]",
		Action: func(c *cli.Context) {
			cl.ChooseCommand(NewCmdChatSendRunner(g), "send", c)
			cl.SetNoStandalone()
		},
		Flags: flags,
	}
}<commit_msg>Enable exploding flag for admin builds (#11557)<commit_after>// Copyright 2016 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package client

import (
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"time"

	"golang.org/x/net/context"

	"github.com/keybase/cli"
	"github.com/keybase/client/go/chat/globals"
	"github.com/keybase/client/go/chat/msgchecker"
	"github.com/keybase/client/go/libcmdline"
	"github.com/keybase/client/go/libkb"
	"github.com/keybase/client/go/protocol/chat1"
	"github.com/keybase/client/go/protocol/keybase1"
	isatty "github.com/mattn/go-isatty"
)

// NOTE if you change these values you should change them in
// go/chatbase/storage/ephemeral.go as well.
const maxEphemeralLifetime = time.Hour * 24 * 7
const minEphemeralLifetime = time.Second * 30

type CmdChatSend struct {
	libkb.Contextified
	resolvingRequest chatConversationResolvingRequest
	// Only one of these should be set
	message           string
	setHeadline       string
	ephemeralLifetime time.Duration
	clearHeadline     bool
	hasTTY            bool
	nonBlock          bool
	team              bool
}

func NewCmdChatSendRunner(g *libkb.GlobalContext) *CmdChatSend {
	return &CmdChatSend{
		Contextified: libkb.NewContextified(g),
	}
}

func (c *CmdChatSend) SetTeamChatForTest(n string) {
	c.team = true
	c.resolvingRequest = chatConversationResolvingRequest{
		TlfName:     n,
		TopicName:   globals.DefaultTeamTopic,
		MembersType: chat1.ConversationMembersType_TEAM,
		TopicType:   chat1.TopicType_CHAT,
		Visibility:  keybase1.TLFVisibility_PRIVATE,
	}
}

func (c *CmdChatSend) SetMessage(m string) {
	c.message = m
}

func newCmdChatSend(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
	flags := append(getConversationResolverFlags(),
		mustGetChatFlags("set-headline", "clear-headline", "nonblock")...,
	)
	if g.Env.GetRunMode() == libkb.DevelRunMode || g.Env.GetFeatureFlags().Admin() {
		flags = append(flags, cli.DurationFlag{
			Name: "exploding-lifetime",
			Usage: `Make this message an exploding message and set the
				lifetime for the given duration.  The maximum lifetime is 168h
				(one week) and the minimum lifetime is 5s.`,
		})
	}
	return cli.Command{
		Name:         "send",
		Usage:        "Send a message to a conversation",
		ArgumentHelp: "[conversation [message]]",
		Action: func(c *cli.Context) {
			cl.ChooseCommand(NewCmdChatSendRunner(g), "send", c)
			cl.SetNoStandalone()
		},
		Flags: flags,
	}
}
{'fraction_non_alphanumeric': 0.10990806945863126, 'fraction_numerical': 0.008375893769152196, 'mean_word_length': 3.8667992047713717, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '89868', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1693, 'n_words': 391}