-
Notifications
You must be signed in to change notification settings - Fork 1
/
ideas.go
106 lines (86 loc) · 2.66 KB
/
ideas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"strings"
"github.com/bwmarrin/discordgo"
)
var (
modQueueChannel *discordgo.Channel
ideasChannel *discordgo.Channel
)
type modQueueItem struct {
AuthorID string `json:"authorID"`
AuthorName string `json:"authorName"`
GuildID string `json:"guildID"`
GuildName string `json:"guildName"`
PostingChannelID string `json:"postingChannelID"`
Content string `json:"content"`
}
func initIdeasChannel(s *discordgo.Session) {
channelId := os.Getenv("VPBOT_MOD_QUEUE_CHANNEL")
ideasChannelId := os.Getenv("VPBOT_IDEAS_CHANNEL")
if(len(channelId) <= 0) {
return
}
var err error
modQueueChannel, err = s.Channel(channelId)
if err != nil {
log.Printf("Couldn't find the ideas channel with ID: %s or %s", channelId, ideasChannelId)
return
}
ideasChannel, err = s.Channel(ideasChannelId)
if err != nil {
log.Printf("Couldn't find the ideas channel with ID: %s or %s", channelId, ideasChannelId)
return
}
}
func addIdeasHandler(session *discordgo.Session, msg *discordgo.MessageCreate) {
if modQueueChannel == nil {
session.ChannelMessageSend(msg.ChannelID, "Guild does not have an ideas channel, ask a mod to add one")
return
}
guild, _ := session.State.Guild(msg.GuildID)
idea := strings.TrimPrefix(msg.Content, "!addidea")
idea = strings.TrimSpace(idea)
item := modQueueItem{
msg.Author.ID,
fmt.Sprintf("%s#%s", msg.Author.Username, msg.Author.Discriminator),
guild.ID,
guild.Name,
ideasChannel.ID,
idea,
}
data, _ := json.MarshalIndent(item, "", " ")
session.ChannelMessageSend(modQueueChannel.ID, string(data))
}
func ideasQueueReactionAdd(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
if r.UserID == s.State.User.ID {
return
}
guild, _ := s.State.Guild(r.GuildID)
channel, _ := s.State.Channel(r.ChannelID)
user, _ := s.User(r.UserID)
log.Printf("[%s|%s|%s#%s] (%s) Reaction added: %+v\n", guild.Name, channel.Name, user.Username, user.Discriminator, r.MessageID, r.Emoji)
if r.ChannelID == modQueueChannel.ID {
if r.Emoji.Name == "yes" {
m, _ := s.ChannelMessage(r.ChannelID, r.MessageID)
// Already moderated?
for _, e := range m.Reactions {
if (e.Emoji.Name == "yes" || e.Emoji.Name == "no") && e.Emoji.Name != r.Emoji.Name {
return
}
}
var item modQueueItem
if err := json.Unmarshal([]byte(m.Content), &item); err != nil {
s.ChannelMessageSend(r.ChannelID, err.Error())
} else {
member, _ := s.GuildMember(item.GuildID, item.AuthorID)
message := fmt.Sprintf("%s's idea: %s", member.User.Mention(), item.Content)
s.ChannelMessageSend(item.PostingChannelID, message)
}
}
}
}