This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
PermissionGacha/starboard.go

62 lines
1.6 KiB
Go

package main
import (
"time"
"github.com/bwmarrin/discordgo"
)
const starEmoji = "⭐"
func listenToStarboardReact(s *discordgo.Session, m *discordgo.MessageReactionAdd) {
if m.Emoji.Name != starEmoji {
return
}
messageTimestamp, err := discordgo.SnowflakeTimestamp(m.MessageID)
if err != nil {
logError(s, "listenToStarboardReact", "snowflakeTimestamp", m.MessageID, err)
return
}
if time.Now().Sub(messageTimestamp) > 24*time.Hour {
return
}
reacter, err := s.MessageReactions(m.ChannelID, m.MessageID, starEmoji, 5)
if err != nil {
logError(s, "listenToStarboardReact", "messageReactions", m.ChannelID, m.MessageID, err)
return
}
if len(reacter) < 3 {
return
}
msg, err := s.ChannelMessage(m.ChannelID, m.MessageID)
if err != nil {
logError(s, "listenToStarboardReact", "channelMessage", m.ChannelID, m.MessageID, err)
return
}
color := s.State.UserColor(msg.Author.ID, m.ChannelID)
if color == 0 {
//White as fallback
color = 0xFFFFFF
}
_, err = s.ChannelMessageSendEmbed(
"645551408283648000",
&discordgo.MessageEmbed{
Title: "Starred Message",
Description: msg.Content,
URL: "https://discordapp.com/channels/" + m.GuildID + "/" + m.ChannelID + "/" + m.MessageID,
Color: color,
Timestamp: messageTimestamp.Format(time.RFC3339),
Author: &discordgo.MessageEmbedAuthor{
Name: msg.Author.Username + "#" + msg.Author.Discriminator,
IconURL: "https://cdn.discordapp.com/avatars/" + msg.Author.ID + "/" + msg.Author.Avatar + ".png",
},
},
)
if err != nil {
logError(s, "listenToStarboardReact", "channelMessageSendEmbed", err)
}
}