-
Notifications
You must be signed in to change notification settings - Fork 21
/
cringe.go
87 lines (78 loc) · 2.5 KB
/
cringe.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
package main
import (
"fmt"
"net/url"
"github.com/bwmarrin/discordgo"
)
// this file is the story of my life lol
func handleCringe(_ *discordgo.Member, msg *discordgo.Message, _ []string) error {
var rngCringe string
err := DB.QueryRow("SELECT image FROM cringe ORDER BY RANDOM() LIMIT 1").Scan(&rngCringe)
if err != nil {
return err
}
reply := discordgo.MessageEmbed{
Title: ":camera_with_flash:",
Image: &discordgo.MessageEmbedImage{
URL: rngCringe,
},
Color: prettyembedcolor,
}
_, err = discord.ChannelMessageSendEmbed(msg.ChannelID, &reply)
go cringeReact(msg.ChannelID, msg.ID)
return err
}
func handleAddCringe(caller *discordgo.Member, msg *discordgo.Message, args []string) error {
if caller.User.ID == "488400748296667147" {
return fmt.Errorf("cringe vini does not get to add cringe because cringe vini himself is cringe")
}
if caller.User.ID == "162848980647018496" {
return fmt.Errorf("berrely is too cringe to add cringe")
}
if len(args) < 2 {
if len(msg.Attachments) > 0 {
return cringe(msg.Attachments[0].URL, msg.ChannelID, msg.ID)
}
return fmt.Errorf("error : no attachments / links found to add")
}
_, err := url.ParseRequestURI(args[1])
if err != nil {
return fmt.Errorf("invalid url scheme")
}
return cringe(args[1], msg.ChannelID, msg.ID)
}
func handleDelCringe(caller *discordgo.Member, msg *discordgo.Message, args []string) error {
if len(args) < 2 {
return fmt.Errorf("give url")
}
_, err := url.ParseRequestURI(args[1])
if err != nil {
return fmt.Errorf("invalid url scheme")
}
var count int
err = DB.QueryRow("SELECT COUNT(*) FROM cringe WHERE image = $1", args[1]).Scan(&count)
if err != nil {
return err
}
if count == 0 {
return fmt.Errorf("that is not cringe")
}
_, err = DB.Exec("DELETE FROM cringe WHERE image = $1", args[1])
if err != nil {
return err
}
return resp(msg.ChannelID, "cringe deleted successfully")
}
func cringe(url string, channelID string, messageID string) error {
_, err := DB.Exec("INSERT INTO cringe(image) VALUES($1)", url)
if err == nil {
go cringeReact(channelID, messageID)
}
return err
}
func cringeReact(channelID string, messageID string) {
_ = discord.MessageReactionAdd(channelID, messageID, "why_steve_a_pig:558474255776481291")
_ = discord.MessageReactionAdd(channelID, messageID, "im_stuff:558474787031351339")
_ = discord.MessageReactionAdd(channelID, messageID, "alex_omg_no:558475172022059009")
_ = discord.MessageReactionAdd(channelID, messageID, "steve_your_sister_is_awesome:558475291454996510")
}