// 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 }
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) } } }