示例#1
0
// Broadcast listens for private messages and broadcasts them to a list of targets
func Broadcast(chac chan api.Action, chev chan api.Event, config Config) {
	a := api.Action{
		Type:     api.A_SAY,
		Priority: api.PRIORITY_LOW,
	}
	for {
		e := <-chev
		if e.Type == api.E_PRIVMSG && len(e.Channel) == 0 {
			for server, targets := range config.Targets {
				a.Server = server
				a.Channel = ""
				a.User = ""
				for _, target := range targets {
					if strings.Index(target, "#") == 1 {
						a.Channel = target
					} else {
						a.User = target
					}
					a.Data = fmt.Sprintf("broadcast> %s: %s", e.User, e.Data)
					chac <- a
				}
			}
		}
	}
}
示例#2
0
func newActionKICK(srv *string, channel *string, user *string, msg *string) *api.Action {
	result := new(api.Action)
	result.Server = *srv
	result.Channel = *channel
	result.User = *user
	if msg != nil {
		result.Data = *msg
	}
	result.Type = api.A_KICK
	return result
}
示例#3
0
func newActionPRIVMSG(srv *string, channel *string, msg *string) *api.Action {
	result := new(api.Action)
	result.Server = *srv
	if strings.Index(*channel, "#") == 0 {
		result.Channel = *channel
	} else {
		result.User = *channel
	}
	result.Data = *msg
	result.Type = api.A_SAY
	return result
}