當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Command.Arg方法代碼示例

本文整理匯總了Golang中github.com/gistia/slackbot/utils.Command.Arg方法的典型用法代碼示例。如果您正苦於以下問題:Golang Command.Arg方法的具體用法?Golang Command.Arg怎麽用?Golang Command.Arg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gistia/slackbot/utils.Command的用法示例。


在下文中一共展示了Command.Arg方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: rename

func (r bot) rename(p *robots.Payload, cmd utils.Command) error {
	old := cmd.Arg(0)
	new := cmd.Arg(1)
	if new == "" || old == "" {
		r.handler.Send(p, "You need to provide the old and new name. Usage: `!project rename <old-name> <new-name>`")
		return nil
	}

	pr, err := db.GetProjectByName(old)
	if err != nil {
		return err
	}

	if pr == nil {
		r.handler.Send(p, "Project *"+old+"* not found.")
		return nil
	}

	pr.Name = new
	err = db.UpdateProject(*pr)
	if err != nil {
		return err
	}

	r.handler.Send(p, "Project *"+old+"* renamed to *"+new+"*")
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:27,代碼來源:project.go

示例2: sendProjects

func (r bot) sendProjects(payload *robots.Payload, cmd utils.Command) error {
	var ps []pivotal.Project
	var err error

	term := cmd.Arg(0)

	pvt, err := conn(payload.UserName)
	if err != nil {
		return err
	}
	s := "Projects"

	if len(term) > 0 {
		fmt.Printf("Retrieving projects with term \"%s\"...\n\n", term)
		s += fmt.Sprintf(" matching '%s':\n", term)
		// ps, err = pvt.SearchProject(term)
	} else {
		s += ":\n"
		fmt.Println("Retrieving projects...\n")
		ps, err = pvt.Projects()
	}

	if err != nil {
		msg := fmt.Sprintf("Error: %s", err.Error())
		r.handler.Send(payload, msg)
		return nil
	}

	r.handler.Send(payload, s+projectTable(ps))
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:31,代碼來源:pivotal.go

示例3: users

func (r bot) users(p *robots.Payload, cmd utils.Command) error {
	projectId := cmd.Arg(0)
	if projectId == "" {
		r.handler.Send(p, "Missing project id. Use !pvt users <project-id>")
		return nil
	}

	pvt, err := conn(p.UserName)
	if err != nil {
		return err
	}

	project, err := pvt.GetProject(projectId)
	if err != nil {
		return err
	}
	if project == nil {
		r.handler.Send(p, "Project with id "+projectId+" doesn't exist.")
		return nil
	}

	memberships, err := pvt.GetProjectMemberships(projectId)
	if err != nil {
		return err
	}

	s := "Current users for project *" + project.Name + "*:\n"
	for _, m := range memberships {
		pp := m.Person
		s += fmt.Sprintf("%d - %s (%s)\n", pp.Id, pp.Name, pp.Email)
	}

	r.handler.Send(p, s)
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:35,代碼來源:pivotal.go

示例4: StopTimer

func StopTimer(bot *UserBot, cmd utils.Command) error {
	name := cmd.Arg(0)
	if name == "" {
		return errors.New("Missing timer name")
	}
	timer, err := db.GetStartedTimerByName(bot.lastMessage.User.Name, name)
	if err != nil {
		return err
	}
	if timer == nil {
		return errors.New("You have no started timer with name *" + name + "*")
	}

	err = timer.Stop()
	if err != nil {
		return err
	}

	timer, err = timer.Reload()
	if err != nil {
		return err
	}

	bot.reply("Your timer *" + name + "* has stopped. It ran for *" + timer.Duration() + "*.")
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:26,代碼來源:commands.go

示例5: addToTeam

func (r bot) addToTeam(p *robots.Payload, cmd utils.Command) error {
	user := cmd.Arg(0)
	if user == "" {
		return errors.New("Missing user name. Use `!github addtoteam <user> <team>`")
	}
	team := cmd.Arg(1)
	if team == "" {
		return errors.New("Missing team name. Use `!github addtoteam <user> <team>`")
	}
	// role := "member"
	client, err := r.getClient(p.UserName)
	if err != nil {
		return err
	}
	id, err := strconv.Atoi(team)
	if err != nil {
		return err
	}

	_, _, err = client.Organizations.AddTeamMembership(id, user)
	if err != nil {
		return err
	}

	r.handler.Send(p, "User *"+user+"* added to team.")
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:27,代碼來源:github.go

示例6: teamInfo

func (r bot) teamInfo(p *robots.Payload, cmd utils.Command) error {
	teamID := cmd.Arg(0)
	if teamID == "" {
		return errors.New("Missing team name. Use `!github teaminfo <team>`")
	}

	client, err := r.getClient(p.UserName)
	if err != nil {
		return err
	}

	id, err := strconv.Atoi(teamID)
	if err != nil {
		return err
	}

	team, _, err := client.Organizations.GetTeam(id)
	if err != nil {
		return err
	}

	s := "Members for *" + *team.Name + "*:\n"
	// opts := &OrganizationListTeamMembersOptions{}
	users, _, err := client.Organizations.ListTeamMembers(id, nil)
	if err != nil {
		return err
	}

	for _, u := range users {
		s += fmt.Sprintf("- %s\n", *u.Login)
	}

	r.handler.Send(p, s)
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:35,代碼來源:github.go

示例7: members

func (r bot) members(p *robots.Payload, cmd utils.Command) error {
	name := cmd.Arg(0)
	if name == "" {
		err := errors.New(
			"Missing project name. Use `!project addtask <project> <task-name>`")
		return err
	}
	pr, err := getProject(name)
	if err != nil {
		return err
	}

	pvt, err := pivotal.NewFor(p.UserName)
	if err != nil {
		return err
	}

	if pr == nil {
		r.handler.Send(p, "Project *"+name+"* not found")
		return nil
	}

	members, err := pvt.GetProjectMemberships(pr.StrPivotalId())
	if err != nil {
		return err
	}

	s := "Pivotal members for project *" + pr.Name + "*:\n"
	for _, m := range members {
		s += fmt.Sprintf("%d - %s\n", m.Person.Id, m.Person.Name)
	}

	r.handler.Send(p, s)
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:35,代碼來源:project.go

示例8: set

func (r bot) set(p *robots.Payload, cmd utils.Command) error {
	name := cmd.Arg(0)
	if name == "" {
		r.handler.Send(p, "Missing Slack user name. Use `!user set <user-name> [mvn:<mavenlink-id>] [pvt:<pivotal-id>]`")
		return nil
	}

	mvnId := cmd.Param("mvn")
	pvtId := cmd.Param("pvt")

	user := db.User{Name: name}

	if mvnId != "" {
		mvnInt, err := strconv.ParseInt(mvnId, 10, 64)
		if err != nil {
			return err
		}
		user.MavenlinkId = &mvnInt
	}

	if pvtId != "" {
		pvtInt, err := strconv.ParseInt(pvtId, 10, 64)
		if err != nil {
			return err
		}
		user.PivotalId = &pvtInt
	}

	if err := db.SaveUser(user); err != nil {
		return err
	}

	r.handler.Send(p, "User *"+name+"* saved")
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:35,代碼來源:user.go

示例9: startTask

func (r bot) startTask(p *robots.Payload, cmd utils.Command) error {
	// pr, err := getProject(cmd.Arg(0))
	// if err != nil {
	// 	return err
	// }
	mvn, err := mavenlink.NewFor(p.UserName)
	if err != nil {
		return err
	}
	pvt, err := pivotal.NewFor(p.UserName)
	if err != nil {
		return err
	}

	if storyId := cmd.Arg(0); storyId != "" {
		pvtStory, err := pvt.GetStory(storyId)
		if err != nil {
			return err
		}

		pvtStory, err = pvt.SetStoryState(pvtStory.GetStringId(), "started")
		if err != nil {
			return err
		}

		if mvnId := pvtStory.GetMavenlinkId(); mvnId != "" {
			mvnStory, err := mvn.GetStory(mvnId)
			if err != nil {
				return err
			}

			fmt.Printf(" ** Got story: %+v\n", mvnStory)

			mvnStory.State = "started"
			mvnStory, err = mvn.SetStoryState(mvnStory.Id, "started")
			if err != nil {
				return err
			}
		}

		r.handler.Send(p, "Story *"+pvtStory.Name+"* started")
		return nil
	}

	// stories, err := mvn.ChildStories(pr.MvnSprintStoryId)
	// if err != nil {
	// 	return err
	// }

	// r.handler.Send(p, "Click the story you want to start on *"+pr.Name+"*:")
	// url := os.Getenv("APP_URL")
	// atts := mavenlink.CustomFormatStories(stories, url+"selection/startTask/")
	// for _, a := range atts {
	// 	r.handler.SendWithAttachments(p, "", []robots.Attachment{a})
	// }
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:57,代碼來源:project.go

示例10: myStories

func (r bot) myStories(p *robots.Payload, cmd utils.Command) error {
	name := cmd.Arg(0)
	var pr *db.Project
	var err error

	if name == "" {
		pr, err = db.GetProjectByChannel(p.ChannelName)
	} else {
		pr, err = db.GetProjectByName(name)
	}

	if err != nil {
		return err
	}

	if pr == nil {
		r.handler.Send(p, "Missing project name.")
		return nil
	}

	pvt, err := pivotal.NewFor(p.UserName)
	if err != nil {
		return err
	}

	user, err := db.GetUserByName(p.UserName)
	if err != nil {
		return err
	}

	filter := map[string]string{
		"owned_by": user.StrPivotalId(),
		"state":    "started,finished",
	}
	stories, err := pvt.FilteredStories(pr.StrPivotalId(), filter)
	if err != nil {
		return err
	}

	if len(stories) < 1 {
		r.handler.Send(p, "No open stories in project *"+pr.Name+"* for *"+p.UserName+"*")
		return nil
	}

	str := "Current stories in project *" + pr.Name + "* for *" + p.UserName + "*:\n"
	atts := []robots.Attachment{}
	for _, s := range stories {
		fallback := fmt.Sprintf("%d - %s - %s\n", s.Id, s.Name, s.State)
		title := fmt.Sprintf("%d - %s\n", s.Id, s.Name)
		a := utils.FmtAttachment(fallback, title, s.Url, s.State)
		atts = append(atts, a)
	}

	r.handler.SendWithAttachments(p, str, atts)
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:56,代碼來源:project.go

示例11: StartTimer

func StartTimer(bot *UserBot, cmd utils.Command) error {
	name := cmd.Arg(0)
	if name == "" {
		return errors.New("Missing timer name")
	}
	err := db.CreateTimer(bot.lastMessage.User.Name, name)
	if err != nil {
		return err
	}
	bot.reply("Created timer *" + name + "*")
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:12,代碼來源:commands.go

示例12: create

func (r bot) create(p *robots.Payload, cmd utils.Command) error {
	alias := cmd.Arg(0)
	if alias == "" {
		r.handler.Send(p, "Missing project alias. Usage: `!project createproject <alias> <long-name>`")
		return nil
	}
	name := cmd.StrFrom(1)
	if name == "" {
		r.handler.Send(p, "Missing project name. Usage: `!project createproject <alias> <long-name>`")
		return nil
	}
	mvn, err := mavenlink.NewFor(p.UserName)
	if err != nil {
		return err
	}
	pvt, err := pivotal.NewFor(p.UserName)
	if err != nil {
		return err
	}
	pvtProject := pivotal.Project{
		Name: name,
		// PointScale: "1,2,3,4,5,6,7,8,9,10,16,20",
	}
	pvtNewProject, err := pvt.CreateProject(pvtProject)
	if err != nil {
		return err
	}
	mvnProject := mavenlink.Project{
		Title:       name,
		Description: fmt.Sprintf("[pvt:%s]", pvtNewProject.Id),
		CreatorRole: "maven",
	}
	mvnNewProject, err := mvn.CreateProject(mvnProject)
	if err != nil {
		return err
	}
	if mvnNewProject == nil {
		return errors.New("Mavenlink returned a nil project")
	}
	pvtNewProject.Description = "[mvn:" + mvnNewProject.Id + "]"
	pvtNewProject, err = pvt.UpdateProject(*pvtNewProject)
	if err != nil {
		return err
	}

	err = r.makeLink(p, alias, mvnNewProject.Id, strconv.FormatInt(pvtNewProject.Id, 10))
	if err != nil {
		return err
	}

	r.handler.Send(p, "Project *"+name+"* created on Pivotal and Mavenlink.")
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:53,代碼來源:project.go

示例13: addmember

func (r bot) addmember(p *robots.Payload, cmd utils.Command) error {
	name := cmd.Arg(0)
	if name == "" {
		err := errors.New(
			"Missing project name. Use `!project addmember <project> <username>`")
		return err
	}
	username := cmd.Arg(1)
	if name == "" {
		err := errors.New(
			"Missing user name. Use `!project addmember <project> <username>`")
		return err
	}

	pr, err := getProject(name)
	if err != nil {
		return err
	}

	pvt, err := pivotal.NewFor(p.UserName)
	if err != nil {
		return err
	}

	if pr == nil {
		r.handler.Send(p, "Project *"+name+"* not found")
		return nil
	}

	user, err := db.GetUserByName(username)
	if pr == nil {
		r.handler.Send(p, "Project *"+name+"* not found")
		return nil
	}
	if user == nil {
		r.handler.Send(p, "User *"+username+"* not found")
		return nil
	}

	_, err = pvt.CreateProjectMembership(pr.StrPivotalId(), *user.PivotalId, "member")
	if err != nil {
		return err
	}

	r.handler.Send(p, "New member *"+username+"* added to *"+name+"*")
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:47,代碼來源:project.go

示例14: setStoryState

func (r bot) setStoryState(p *robots.Payload, cmd utils.Command) error {
	state := cmd.Command
	id := cmd.Arg(0)
	pvt, err := conn(p.UserName)
	if err != nil {
		return err
	}

	state = fmt.Sprintf("%sed", state)
	story, err := pvt.SetStoryState(id, state)
	if err != nil {
		return err
	}

	r.handler.Send(p, fmt.Sprintf("Story %s - %s %s successfully",
		id, story.Name, state))
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:18,代碼來源:pivotal.go

示例15: set

func (r bot) set(p *robots.Payload, cmd utils.Command) error {
	s := cmd.Arg(0)
	parts := strings.Split(s, "=")
	if len(parts) < 2 {
		r.handler.Send(p, "Malformed setting. Use /store set PARAM=value.\n")
		return nil
	}

	name := strings.TrimSpace(parts[0])
	value := strings.TrimSpace(parts[1])
	err := db.SetSetting(p.UserName, name, value)
	if err != nil {
		return err
	}

	r.handler.Send(p, fmt.Sprintf("Successfully set %s\n", name))
	return nil
}
開發者ID:gistia,項目名稱:slackbot,代碼行數:18,代碼來源:store.go


注:本文中的github.com/gistia/slackbot/utils.Command.Arg方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。