// From rfc2812 section 5.2 (Error Replies)
//
// 433    ERR_NICKNAMEINUSE
//        "<nick> :Nickname is already in use"
//
// - Returned when a NICK message is processed that results
//   in an attempt to change to a currently existing
//   nickname.
511301
func handle433(c *Client, m *Message) {
	// We only want to try and handle nick collisions during the initial
	// handshake.
	if c.connected {
		return
	}
	c.currentNick = c.currentNick + "_"
	c.Writef("NICK :%s", c.currentNick)
}
205971
func (api *Client) RenameChannel(channelID, name string) (*Channel, error) {
	return api.RenameChannelContext(context.Background(), channelID, name)
}
696964
func (conn *Conn) h_NICK(line *Line) {
	if conn.st == nil && line.Nick == conn.cfg.Me.Nick {
		conn.cfg.Me.Nick = line.Args[0]
	}
}
320423
func (c *syncClient) Rename(arg0 string, arg1 string) (err Error) {
	arg0bytes := []byte(arg0)
	arg1bytes := []byte(arg1)

	_, err = c.conn.ServiceRequest(&RENAME, [][]byte{arg0bytes, arg1bytes})
	return
}
389538
func (api *Client) RenameConversationContext(ctx context.Context, channelID, channelName string) (*Channel, error) {
	values := url.Values{
		"token":   {api.token},
		"channel": {channelID},
		"name":    {channelName},
	}
	response := struct {
		SlackResponse
		Channel *Channel `json:"channel"`
	}{}
	err := api.postMethod(ctx, "conversations.rename", values, &response)
	if err != nil {
		return nil, err
	}

	return response.Channel, response.Err()
}
1324429
func (conn *Conn) h_353(line *Line) {
	if !line.argslen(2) {
		return
	}
	if ch := conn.st.GetChannel(line.Args[2]); ch != nil {
		nicks := strings.Split(line.Args[len(line.Args)-1], " ")
		for _, nick := range nicks {
			// UnrealIRCd's coders are lazy and leave a trailing space
			if nick == "" {
				continue
			}
			switch c := nick[0]; c {
			case '~', '&', '@', '%', '+':
				nick = nick[1:]
				fallthrough
			default:
				if conn.st.GetNick(nick) == nil {
					// we don't know this nick yet!
					conn.st.NewNick(nick)
				}
				if _, ok := conn.st.IsOn(ch.Name, nick); !ok {
					// This nick isn't associated with this channel yet!
					conn.st.Associate(ch.Name, nick)
				}
				switch c {
				case '~':
					conn.st.ChannelModes(ch.Name, "+q", nick)
				case '&':
					conn.st.ChannelModes(ch.Name, "+a", nick)
				case '@':
					conn.st.ChannelModes(ch.Name, "+o", nick)
				case '%':
					conn.st.ChannelModes(ch.Name, "+h", nick)
				case '+':
					conn.st.ChannelModes(ch.Name, "+v", nick)
				}
			}
		}
	} else {
		logging.Warn("irc.353(): received NAMES list for unknown channel %s",
			line.Args[2])
	}
}
685907
func (c *client) offlineTokenName(userID string, connID string) string {
	return offlineTokenName(userID, connID, c.hash)
}
471182
func Usage(name string) string {
	if name == "" {
		name = "Listen address"
	}
	if !strings.HasSuffix(name, " address") {
		name += " address"
	}
	return name + "; may be port, :port, ip:port, or FD:<fd_num>"
}
453256
func (s *ChannelsService) Rename(channel string, name string) *ChannelsRenameCall {
	var call ChannelsRenameCall
	call.service = s
	call.channel = channel
	call.name = name
	return &call
}
397482
func (c *ChatUpdateCall) LinkNames(linkNames bool) *ChatUpdateCall {
	c.linkNames = linkNames
	return c
}
1112120
func (c *Conn) Categories(nick string) ([]*Category, error) {
	var out struct {
		Categories []*Category
	}
	if err := c.do("smugmug.categories.get", &out, "NickName", nick); err != nil {
		return nil, err
	}
	return out.Categories, nil
}
670868
func (st *stateTracker) ReNick(old, neu string) *Nick {
	st.mu.Lock()
	defer st.mu.Unlock()
	nk, ok := st.nicks[old]
	if !ok {
		logging.Warn("Tracker.ReNick(): %s not tracked.", old)
		return nil
	}
	if _, ok := st.nicks[neu]; ok {
		logging.Warn("Tracker.ReNick(): %s already exists.", neu)
		return nil
	}

	nk.nick = neu
	delete(st.nicks, old)
	st.nicks[neu] = nk
	for ch, _ := range nk.chans {
		// We also need to update the lookup maps of all the channels
		// the nick is on, to keep things in sync.
		delete(ch.lookup, old)
		ch.lookup[neu] = nk
	}
	return nk.Nick()
}
572175
func (nk *nick) Nick() *Nick {
	n := &Nick{
		Nick:     nk.nick,
		Ident:    nk.ident,
		Host:     nk.host,
		Name:     nk.name,
		Modes:    nk.modes.Copy(),
		Channels: make(map[string]*ChanPrivs),
	}
	for c, cp := range nk.chans {
		n.Channels[c.name] = cp.Copy()
	}
	return n
}
1339485
func GetRouteName(r *http.Request) string {
	if params := r.Context().Value(ParamsKey); params != nil {
		params := params.(Params)
		if param := params["rname"]; param != nil {
			return param.(string)
		}
	}
	return ""
}
901668
func (st *stateTracker) Me() *Nick {
	st.mu.Lock()
	defer st.mu.Unlock()
	return st.me.Nick()
}
1103841
func conversionNamer() *namer.NameStrategy {
	return &namer.NameStrategy{
		Join: func(pre string, in []string, post string) string {
			return strings.Join(in, "_")
		},
		PrependPackageNames: 1,
	}
}
508384
func (c *ChatRPC) ChatSubteamRename(
	_ context.Context, _ chat1.ChatSubteamRenameArg) error {
	return nil
}