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


Golang Bot.Say方法代码示例

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


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

示例1: handleModule

func (c *Config) handleModule(b core.Bot, m *slack.Message) error {
	moduleText := "currently loaded modules:\n"
	for key := range b.LoadedModules() {
		moduleText = moduleText + fmt.Sprintf("> `%s`\n", key)
	}
	return b.Say(m.Channel, moduleText)
}
开发者ID:wcharczuk,项目名称:jarvis,代码行数:7,代码来源:config.go

示例2: handleConfig

func (c *Config) handleConfig(b core.Bot, m *slack.Message) error {
	configText := "current config:\n"
	for key, value := range b.Configuration() {
		if strings.HasPrefix(key, "option.") {
			configText = configText + fmt.Sprintf("> `%s` = %s\n", key, value)
		}
	}

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

示例3: handleJobsStatus

func (j *Jobs) handleJobsStatus(b core.Bot, m *slack.Message) error {
	statusText := "current job statuses:\n"
	for _, status := range b.JobManager().Status() {
		if len(status.RunningFor) != 0 {
			statusText = statusText + fmt.Sprintf(">`%s` - state: %s running for: %s\n", status.Name, status.State, status.RunningFor)
		} else {
			statusText = statusText + fmt.Sprintf(">`%s` - state: %s\n", status.Name, status.State)
		}
	}
	return b.Say(m.Channel, statusText)
}
开发者ID:wcharczuk,项目名称:jarvis,代码行数:11,代码来源:jobs.go

示例4: handleChannels

func (c *Core) handleChannels(b core.Bot, m *slack.Message) error {
	if len(b.ActiveChannels()) == 0 {
		return b.Say(m.Channel, "currently listening to *no* channels.")
	}
	activeChannelsText := "currently listening to the following channels:\n"
	for _, channelID := range b.ActiveChannels() {
		if channel := b.FindChannel(channelID); channel != nil {
			activeChannelsText = activeChannelsText + fmt.Sprintf(">#%s (id:%s)\n", channel.Name, channel.ID)
		}
	}
	return b.Say(m.Channel, activeChannelsText)
}
开发者ID:wcharczuk,项目名称:jarvis,代码行数:12,代码来源:core.go

示例5: 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

示例6: handleJobRun

func (j *Jobs) handleJobRun(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	pieces := strings.Split(messageWithoutMentions, " ")
	if len(pieces) > 1 {
		jobName := pieces[len(pieces)-1]
		b.JobManager().RunJob(jobName)
		return b.Sayf(m.Channel, "ran job `%s`", jobName)
	}

	b.JobManager().RunAllJobs()
	return b.Say(m.Channel, "ran all jobs")
}
开发者ID:wcharczuk,项目名称:jarvis,代码行数:12,代码来源:jobs.go

示例7: 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

示例8: handleHelp

func (c *Core) handleHelp(b core.Bot, m *slack.Message) error {
	responseText := "Here are the commands that are currently configured:"
	for _, actionHandler := range b.Actions() {
		if !actionHandler.Passive {
			if len(actionHandler.MessagePattern) != 0 {
				responseText = responseText + fmt.Sprintf("\n>`%s` - %s", actionHandler.MessagePattern, actionHandler.Description)
			} else {
				responseText = responseText + fmt.Sprintf("\n>`*` - %s", actionHandler.Description)
			}
		}
	}
	responseText = responseText + "\nWith the following passive commands:"
	for _, actionHandler := range b.Actions() {
		if actionHandler.Passive {
			if len(actionHandler.MessagePattern) != 0 {
				responseText = responseText + fmt.Sprintf("\n>`%s` - %s", actionHandler.MessagePattern, actionHandler.Description)
			} else {
				responseText = responseText + fmt.Sprintf("\n>`*` - %s", actionHandler.Description)
			}
		}
	}
	return b.Say(m.Channel, responseText)
}
开发者ID:wcharczuk,项目名称:jarvis,代码行数:23,代码来源:core.go

示例9: 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.Say方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。