コード例 #1
0
ファイル: action.go プロジェクト: episeclab/gorobot
func newActionJOIN(srv *string, channel *string) *api.Action {
	result := new(api.Action)
	result.Server = *srv
	result.Channel = *channel
	result.Type = api.A_JOIN
	return result
}
コード例 #2
0
ファイル: action.go プロジェクト: episeclab/gorobot
func newActionPART(srv *string, channel *string, msg *string) *api.Action {
	result := new(api.Action)
	result.Server = *srv
	result.Channel = *channel
	if msg != nil {
		result.Data = *msg
	}
	result.Type = api.A_PART
	return result
}
コード例 #3
0
ファイル: broadcast.go プロジェクト: episeclab/gorobot
// 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
				}
			}
		}
	}
}
コード例 #4
0
ファイル: example.go プロジェクト: episeclab/gorobot
// Example is a gorobot module which responds to the !hej command
func Example(chac chan api.Action, chev chan api.Event, config Config) {
	// action which will be sent to the robot
	a := api.Action{
		Type:     api.A_SAY,
		Data:     config.HelloWorld,
		Priority: api.PRIORITY_LOW,
	}

	for {
		e := <-chev
		// if the event is a message !hej, reply by sending an action
		if e.Type == api.E_PRIVMSG && len(e.Channel) > 0 && e.Data == "!hej" {
			a.Server = e.Server
			a.Channel = e.Channel
			go func(a api.Action) { chac <- a }(a)
		}
	}
}
コード例 #5
0
ファイル: action.go プロジェクト: episeclab/gorobot
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
}
コード例 #6
0
ファイル: action.go プロジェクト: episeclab/gorobot
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
}
コード例 #7
0
ファイル: netadmin.go プロジェクト: episeclab/gorobot
// creates a new api.action from what was sent on the admin port
func netAdminCraftAction(output string) api.Action {
	var a api.Action
	shellapi := strings.SplitN(output, " ", 3)
	a.Type = api.A_RAW
	if len(shellapi) == 3 {
		a.Server = shellapi[0]
		a.Priority, _ = strconv.Atoi(shellapi[1])
		if a.Priority != api.PRIORITY_LOW &&
			a.Priority != api.PRIORITY_MEDIUM &&
			a.Priority != api.PRIORITY_HIGH {
			a.Priority = api.PRIORITY_LOW
		}
		a.Data = shellapi[2]
	} else {
		a.Data = output
		a.Priority = api.PRIORITY_LOW
	}
	return a
}
コード例 #8
0
ファイル: grobot.go プロジェクト: episeclab/gorobot
func (robot *Grobot) HandleAction(ac *api.Action) {
	// if the command is RAW, we need to parse it first to be able
	// to correctly handle it.
	if ac.Type == api.A_RAW {
		new_action := ExtractAction(ac)
		if new_action != nil {
			p := ac.Priority
			*ac = *new_action
			ac.Priority = p
		} else {
			log.Printf("raw command ignored [%s]", ac.Raw)
			return
		}
	}

	switch ac.Type {
	case api.A_NEWMODULE:
		robot.NewModule(ac)
	case api.A_SAY:
		if serv := robot.Irc.GetServer(ac.Server); serv != nil {
			serv.Say(ac)
		}
	case api.A_JOIN:
		if serv := robot.Irc.GetServer(ac.Server); serv != nil {
			serv.JoinChannel(ac.Channel)
		}
	case api.A_PART:
		if serv := robot.Irc.GetServer(ac.Server); serv != nil {
			serv.LeaveChannel(ac.Channel, ac.Data)
		}
	case api.A_KICK:
		if serv := robot.Irc.GetServer(ac.Server); serv != nil {
			serv.KickUser(ac.Channel, ac.User, ac.Data)
		}
	}
}