本文整理汇总了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)
}
示例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)
}
示例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)
}