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


Golang Bot.Configuration方法代碼示例

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


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

示例1: fetchJiraIssues

func (j *Jira) fetchJiraIssues(b core.Bot, issueIds []string) ([]*external.JiraIssue, error) {
	issues := []*external.JiraIssue{}
	credentials, hasCredentials := b.Configuration()[ConfigJiraCredentials]

	if !hasCredentials {
		return issues, exception.New("Jarvis is not configured with Jira credentials.")
	}

	credentialPieces := strings.Split(credentials, ":")

	if len(credentialPieces) != 2 {
		return issues, exception.New("Jira credentials are not formatted correctly.")
	}

	jiraUser := credentialPieces[0]
	jiraPassword := credentialPieces[1]

	jiraHost, hasJiraHost := b.Configuration()[ConfigJiraHost]
	if !hasJiraHost {
		return issues, exception.New("Jarvis is not configured with a Jira host.")
	}

	var err error
	var issue *external.JiraIssue
	for _, issueID := range issueIds {
		issue, err = external.GetJiraIssue(jiraUser, jiraPassword, jiraHost, issueID)
		if err == nil {
			issues = append(issues, issue)
		} else {
			return issues, err
		}
	}

	return issues, nil
}
開發者ID:wcharczuk,項目名稱:jarvis,代碼行數:35,代碼來源:jira.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: handlePassiveCatchAll

func (c *Core) handlePassiveCatchAll(b core.Bot, m *slack.Message) error {
	message := util.TrimWhitespace(core.LessMentions(m.Text))
	if optionValue, hasOption := b.Configuration()[ConfigOptionPassiveCatchAll]; hasOption && optionValue == "true" {
		if core.IsAngry(message) {
			user := b.FindUser(m.User)
			response := []string{"slow down %s", "maybe calm down %s", "%s you should really relax", "chill %s", "it's ok %s, let it out"}
			return b.Sayf(m.Channel, core.Random(response), strings.ToLower(user.Profile.FirstName))
		}
	}

	return nil
}
開發者ID:wcharczuk,項目名稱:jarvis,代碼行數:12,代碼來源:core.go

示例4: handleConfigGet

func (c *Config) handleConfigGet(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	parts := core.ExtractSubMatches(messageWithoutMentions, "^config:(.+)")

	if len(parts) < 2 {
		return exception.Newf("malformed message for `%s`", ActionConfigGet)
	}

	key := parts[1]
	value := b.Configuration()[key]
	return b.Sayf(m.Channel, "> %s: `%s` = %s", ActionConfigGet, key, value)
}
開發者ID:wcharczuk,項目名稱:jarvis,代碼行數:12,代碼來源:config.go

示例5: handleJira

func (j *Jira) handleJira(b core.Bot, m *slack.Message) error {
	text := core.LessMentions(m.Text)

	issueIds := j.extractJiraIssues(text)
	if len(issueIds) == 0 {
		return nil
	}

	issues, err := j.fetchJiraIssues(b, issueIds)
	if err != nil {
		return err
	}
	if len(issues) == 0 {
		return nil
	}

	user := b.FindUser(m.User)

	leadText := fmt.Sprintf("*%s* has mentioned the following jira issues (%d): ", user.Profile.FirstName, len(issues))
	message := slack.NewChatMessage(m.Channel, leadText)
	message.AsUser = slack.OptionalBool(true)
	message.UnfurlLinks = slack.OptionalBool(false)
	for _, issue := range issues {
		if !util.IsEmpty(issue.Key) {
			var itemText string
			if issue.Fields != nil {
				assignee := "Unassigned"
				if issue.Fields.Assignee != nil {
					assignee = issue.Fields.Assignee.DisplayName
				}
				itemText = fmt.Sprintf("%s %s\nAssigned To: %s",
					fmt.Sprintf("https://%s/browse/%s", b.Configuration()[ConfigJiraHost], issue.Key),
					issue.Fields.Summary,
					assignee,
				)
			} else {
				itemText = fmt.Sprintf("%s\n%s", issue.Key, fmt.Sprintf("https://%s/browse/%s", b.Configuration()[ConfigJiraHost], issue.Key))
			}

			item := slack.ChatMessageAttachment{
				Color: slack.OptionalString("#3572b0"),
				Text:  slack.OptionalString(itemText),
			}
			message.Attachments = append(message.Attachments, item)
		}
	}

	_, err = b.Client().ChatPostMessage(message)
	if err != nil {
		fmt.Printf("issue posting message: %v\n", err)
	}
	return err
}
開發者ID:wcharczuk,項目名稱:jarvis,代碼行數:53,代碼來源:jira.go

示例6: handleConfigSet

func (c *Config) handleConfigSet(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	parts := core.ExtractSubMatches(messageWithoutMentions, "^config:(.+) (.+)")

	if len(parts) < 3 {
		return exception.Newf("malformed message for `%s`", ActionConfigSet)
	}

	key := parts[1]
	value := parts[2]

	setting := value
	if core.LikeAny(value, "true", "yes", "on", "1") {
		setting = "true"
	} else if core.LikeAny(value, "false", "off", "0") {
		setting = "false"
	}
	b.Configuration()[key] = setting
	return b.Sayf(m.Channel, "> %s: `%s` = %s", ActionConfigSet, key, setting)
}
開發者ID:wcharczuk,項目名稱:jarvis,代碼行數:20,代碼來源:config.go

示例7: Init

// Init for this module does nothing.
func (j *Jira) Init(b core.Bot) error {
	if _, hasEntry := b.Configuration()[ConfigJiraCredentials]; !hasEntry {
		envCredentials := os.Getenv(EnvironmentJiraCredentials)
		if len(envCredentials) != 0 {
			b.Configuration()[ConfigJiraCredentials] = envCredentials
		} else {
			b.Logf("No `%s` provided, module `%s` cannot load.", EnvironmentJiraHost, ModuleJira)
			return nil
		}
	}

	if _, hasEntry := b.Configuration()[ConfigJiraHost]; !hasEntry {
		envHost := os.Getenv(EnvironmentJiraHost)
		if len(envHost) != 0 {
			b.Configuration()[ConfigJiraHost] = envHost
		} else {
			b.Logf("No `%s` provided, module `%s` cannot load.", EnvironmentJiraHost, ModuleJira)
			return nil
		}
	}

	return nil
}
開發者ID:wcharczuk,項目名稱:jarvis,代碼行數:24,代碼來源:jira.go

示例8: Init

// Init for this module does nothing.
func (c *Config) Init(b core.Bot) error {
	b.Configuration()[ConfigOptionPassive] = "true"
	return nil
}
開發者ID:wcharczuk,項目名稱:jarvis,代碼行數:5,代碼來源:config.go


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