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


Golang Bot.Client方法代碼示例

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


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

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

示例2: announceStocks

func (s *Stocks) announceStocks(b core.Bot, destinationID string, stockInfo []external.StockInfo) error {
	tickersLabels := []string{}
	for _, stock := range stockInfo {
		tickersLabels = append(tickersLabels, fmt.Sprintf("`%s`", stock.Ticker))
	}
	tickersLabel := strings.Join(tickersLabels, " ")
	leadText := fmt.Sprintf("current equity price info for %s", tickersLabel)
	message := slack.NewChatMessage(destinationID, leadText)
	message.AsUser = slack.OptionalBool(true)
	message.UnfurlLinks = slack.OptionalBool(false)
	message.Parse = util.OptionalString("full")
	for _, stock := range stockInfo {
		change := stock.Change
		changePct := stock.ChangePercent
		volume := stock.Volume
		tickerText := fmt.Sprintf("`%s`", stock.Ticker)
		nameText := fmt.Sprintf("%s", stock.Name)
		lastPriceText := fmt.Sprintf("%0.2f USD", stock.LastPrice)
		volumeText := humanize.Comma(volume)
		changeText := fmt.Sprintf("%.2f USD", change)
		changePctText := util.StripQuotes(changePct)

		var barColor = "#00FF00"
		if change < 0 {
			barColor = "#FF0000"
		}

		item := slack.ChatMessageAttachment{
			Color: slack.OptionalString(barColor),
			Fields: []slack.Field{
				slack.Field{Title: "Ticker", Value: tickerText, Short: true},
				slack.Field{Title: "Name", Value: nameText, Short: true},
				slack.Field{Title: "Last", Value: lastPriceText, Short: true},
				slack.Field{Title: "Volume", Value: volumeText, Short: true},
				slack.Field{Title: "Change ∆", Value: changeText, Short: true},
				slack.Field{Title: "Change %", Value: changePctText, Short: true},
			},
		}

		message.Attachments = append(message.Attachments, item)
	}
	_, err := b.Client().ChatPostMessage(message)
	return err
}
開發者ID:wcharczuk,項目名稱:jarvis,代碼行數:44,代碼來源:stocks.go

示例3: handleTime

func (c *Core) handleTime(b core.Bot, m *slack.Message) error {
	timeText := fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.Kitchen))
	message := slack.NewChatMessage(m.Channel, "")
	message.AsUser = slack.OptionalBool(true)
	message.UnfurlLinks = slack.OptionalBool(false)
	message.UnfurlMedia = slack.OptionalBool(false)
	message.Attachments = []slack.ChatMessageAttachment{
		slack.ChatMessageAttachment{
			Fallback: slack.OptionalString(fmt.Sprintf("The time is now:\n>%s", timeText)),
			Color:    slack.OptionalString("#4099FF"),
			Pretext:  slack.OptionalString("The time is now:"),
			Text:     slack.OptionalString(timeText),
		},
	}

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

示例4: handleStockChart

func (s *Stocks) handleStockChart(b core.Bot, m *slack.Message) error {
	messageWithoutMentions := util.TrimWhitespace(core.LessMentions(m.Text))
	args := core.ExtractSubMatches(messageWithoutMentions, "^stock:chart (.*)")

	if len(args) < 2 {
		return exception.Newf("invalid input for %s", ActionStockPrice)
	}

	pieces := strings.Split(args[1], " ")
	ticker := pieces[0]
	timeframe := "1M"
	if len(pieces) > 1 {
		timeframe = pieces[1]
	}
	var imageURL string
	if strings.Contains(ticker, "+") {
		tickerPieces := strings.Split(ticker, "+")
		if len(tickerPieces) < 2 {
			return errors.New("invalid combination ticker")
		}
		imageURL = fmt.Sprintf("https://chart-service.charczuk.com/stock/chart/%s/%s?width=768&height=280&use_pct=true&add_sma=true&format=png&compare=%s", tickerPieces[0], timeframe, tickerPieces[1])
	} else {
		imageURL = fmt.Sprintf("https://chart-service.charczuk.com/stock/chart/%s/%s?width=768&height=280&add_sma=true&format=png", ticker, timeframe)
	}

	leadText := fmt.Sprintf("Historical Chart for `%s`", ticker)
	message := slack.NewChatMessage(m.Channel, leadText)
	message.AsUser = slack.OptionalBool(true)
	message.UnfurlLinks = slack.OptionalBool(false)
	message.Parse = util.OptionalString("full")
	message.Attachments = []slack.ChatMessageAttachment{
		slack.ChatMessageAttachment{
			Title:    util.OptionalString("Chart"),
			ImageURL: util.OptionalString(imageURL),
		},
	}
	_, err := b.Client().ChatPostMessage(message)
	return err
}
開發者ID:wcharczuk,項目名稱:jarvis,代碼行數:39,代碼來源:stocks.go


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