|
|
|
@ -3,6 +3,7 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
@ -11,6 +12,8 @@ import (
|
|
|
|
|
const starEmoji = "⭐"
|
|
|
|
|
const starChannel = "645551408283648000"
|
|
|
|
|
|
|
|
|
|
var starboardMutex sync.Mutex
|
|
|
|
|
|
|
|
|
|
func listenToStarboardReact(s *discordgo.Session, m *discordgo.MessageReactionAdd) {
|
|
|
|
|
if m.ChannelID == starChannel {
|
|
|
|
|
return
|
|
|
|
@ -26,6 +29,12 @@ func listenToStarboardReact(s *discordgo.Session, m *discordgo.MessageReactionAd
|
|
|
|
|
if time.Now().Sub(messageTimestamp) > 24*time.Hour {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
starboardMutex.Lock()
|
|
|
|
|
defer starboardMutex.Unlock()
|
|
|
|
|
|
|
|
|
|
if checkStarredBefore(s, m.MessageID) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reacter, err := s.MessageReactions(m.ChannelID, m.MessageID, starEmoji, 5)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -78,7 +87,25 @@ func listenToStarboardReact(s *discordgo.Session, m *discordgo.MessageReactionAd
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
err = s.MessageReactionAdd(msg.ChannelID, msg.ID, starEmoji)
|
|
|
|
|
noteStarred(s, msg.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logError(s, "listenToStarboardReact", "messageReactionAdd", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func checkStarredBefore(s *discordgo.Session, discordID string) bool {
|
|
|
|
|
rows, err := db.Query("SELECT id FROM starred WHERE id=?", discordID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logError(s, "checkStarredBefore", "query", err)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
defer rows.Close()
|
|
|
|
|
return rows.Next()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func noteStarred(s *discordgo.Session, discordID string) {
|
|
|
|
|
_, err := db.Exec("INSERT INTO starred(id) VALUES(?)", discordID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logError(s, "noteStarred", "exec", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|