当前位置: 首页>>代码示例>>Golang>>正文


Golang Bot.ID方法代码示例

本文整理汇总了Golang中github.com/wcharczuk/jarvis/jarvis/core.Bot.ID方法的典型用法代码示例。如果您正苦于以下问题:Golang Bot.ID方法的具体用法?Golang Bot.ID怎么用?Golang Bot.ID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/wcharczuk/jarvis/jarvis/core.Bot的用法示例。


在下文中一共展示了Bot.ID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: handleUserID

func (u Util) handleUserID(b core.Bot, m *slack.Message) error {
	messageText := core.LessSpecificMention(m.Text, b.ID())
	mentionedUserIDs := core.Mentions(messageText)

	outputText := "I looked up the following users:\n"
	for _, userID := range mentionedUserIDs {
		user := b.FindUser(userID)
		outputText = outputText + fmt.Sprintf("> %s : %s %s", userID, user.Profile.FirstName, user.Profile.LastName)
	}

	return b.Say(m.Channel, outputText)
}
开发者ID:wcharczuk,项目名称:jarvis,代码行数:12,代码来源:util.go

示例2: handleTell

func (c *Core) handleTell(b core.Bot, m *slack.Message) error {
	messageText := core.LessSpecificMention(m.Text, b.ID())
	words := strings.Split(messageText, " ")

	destinationUser := ""
	tellMessage := ""

	for x := 0; x < len(words); x++ {
		word := words[x]
		if core.Like(word, "tell") {
			continue
		} else if core.IsMention(word) {
			destinationUser = word
			tellMessage = strings.Join(words[x+1:], " ")
		}
	}
	tellMessage = core.ReplaceAny(tellMessage, "you are", "shes", "she's", "she is", "hes", "he's", "he is", "theyre", "they're", "they are")
	resultMessage := fmt.Sprintf("%s %s", destinationUser, tellMessage)
	return b.Say(m.Channel, resultMessage)
}
开发者ID:wcharczuk,项目名称:jarvis,代码行数:20,代码来源:core.go

示例3: handleConsoleRunnerRun

func (cr *ConsoleRunner) handleConsoleRunnerRun(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessSpecificMention(m.Text, b.ID()))
	cleanedMessage := core.FixLinks(messageWithoutMentions)

	pieces := strings.Split(cleanedMessage, " ")
	if len(pieces) < 2 {
		return exception.Newf("invalid arguments for `%s`", ActionConsoleRunnerRun)
	}

	commandWithArguments := pieces[1:]
	command := commandWithArguments[0]
	args := []string{}
	if len(commandWithArguments) > 1 {
		args = commandWithArguments[1:]
	}

	if !cr.isWhitelistedCommand(command) {
		return exception.Newf("`%s` cannot run %s", ActionConsoleRunnerRun, command)
	}

	cmdFullPath, lookErr := exec.LookPath(command)
	if lookErr != nil {
		return exception.Wrap(lookErr)
	}

	stdoutBuffer := bytes.NewBuffer([]byte{})
	subCmd := exec.Command(cmdFullPath, args...)
	subCmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
	subCmd.StdoutPipe()
	subCmd.StderrPipe()
	subCmd.Stdout = stdoutBuffer
	subCmd.Stderr = stdoutBuffer

	startErr := subCmd.Start()
	if startErr != nil {
		return startErr
	}

	started := time.Now().UTC()

	didTimeout := false
	go func() {
		for {
			now := time.Now().UTC()
			if now.Sub(started) > ConsoleRunnerTimeout {
				didTimeout = true
				pgid, err := syscall.Getpgid(subCmd.Process.Pid)
				if err != nil {
					return
				}
				syscall.Kill(-pgid, 15)
			}
			time.Sleep(50 * time.Millisecond)
		}
	}()

	subCmd.Wait()

	timedOutText := ""
	if didTimeout {
		timedOutText = " (timed out)"
	}

	stdout := stdoutBuffer.String()
	outputText := fmt.Sprintf("console runner stdout%s:\n", timedOutText)
	if len(stdout) != 0 {
		prefixed := strings.Replace(stdout, "\n", "\n>", -1)
		outputText = outputText + fmt.Sprintf(">%s", prefixed)
	} else {
		outputText = "> empty"
	}

	return b.Say(m.Channel, outputText)
}
开发者ID:wcharczuk,项目名称:jarvis,代码行数:74,代码来源:console_runner.go


注:本文中的github.com/wcharczuk/jarvis/jarvis/core.Bot.ID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。