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