Skip to content

Instantly share code, notes, and snippets.

@DDRBoxman
Created August 4, 2016 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DDRBoxman/4da3c6f07f915da85b91485499d05ef6 to your computer and use it in GitHub Desktop.
Save DDRBoxman/4da3c6f07f915da85b91485499d05ef6 to your computer and use it in GitHub Desktop.
Twitch Highlight Email
func highlight(conn *irc.Conn, channel string, user string, line string, args []string) {
rconn := pool.Get()
defer rconn.Close()
if !isMod(rconn, channel, user) {
log.Printf("User %s tried to access !quote on %s add and wasn't a mod\n", user, channel)
return
}
c := channel[1:]
resp, err := twitchClient.GetChannelVideos(c, true, 1)
if err != nil {
log.Println(err)
return
}
if len(resp.Videos) != 1 || resp.Videos[0].Status != "recording" {
conn.Privmsg(channel, "Looks like there isn't a stream right now.")
return
}
diff := time.Now().Sub(resp.Videos[0].CreatedAt)
hours := diff.Hours()
minutes := int64(math.Floor(diff.Minutes() - (math.Floor(hours) * 60)))
seconds := int64(math.Floor(diff.Seconds() - (float64(minutes) * 60) - (math.Floor(hours) * 60 * 60)))
timestamp := ""
if int64(hours) > 0 {
timestamp = fmt.Sprintf("%dh", int64(hours))
}
if minutes > 0 {
timestamp += fmt.Sprintf("%dm", int64(minutes))
}
if seconds > 0 {
timestamp += fmt.Sprintf("%ds", int64(seconds))
}
description := strings.Join(args[1:], " ")
description = description + "\n" + resp.Videos[0].URL + "?t=" + timestamp
message := mailGunClient.NewMessage("BOT <bot@streamtogether.us>", "Highlight!", description, "crasskittyhighlights@gmail.com")
_, _, err = mailGunClient.Send(message)
if err != nil {
log.Println(err)
}
conn.Privmsg(channel, "Highlight time recorded.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment