-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
56 lines (46 loc) · 1.64 KB
/
context.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
package bear
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
// Context holds useful functions for a handler.
type Context struct {
ChannelID string
Session *discordgo.Session
Message *discordgo.MessageCreate
}
// This is a collection of the standard colors used for messages.
const (
SuccessColor int = 5025616
ErrorColor int = 16007990
InfoColor int = 2201331
)
// SendEmbed sends a custom embed message.
func (ctx Context) SendEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error) {
return ctx.Session.ChannelMessageSendEmbed(ctx.ChannelID, embed)
}
// SendMessage sends an embed message with a message and color.
func (ctx Context) SendMessage(color int, title, format string, a ...interface{}) (*discordgo.Message, error) {
messageEmbed := &discordgo.MessageEmbed{
Color: color,
Fields: []*discordgo.MessageEmbedField{
{
Name: title,
Value: fmt.Sprintf(format, a...),
},
},
}
return ctx.SendEmbed(messageEmbed)
}
// SendErrorMessage is a quick way to send an error.
func (ctx Context) SendErrorMessage(format string, a ...interface{}) (*discordgo.Message, error) {
return ctx.SendMessage(ErrorColor, "Error", format, a...)
}
// SendSuccessMessage is a shortcut for sending a message with the success colors.
func (ctx Context) SendSuccessMessage(format string, a ...interface{}) (*discordgo.Message, error) {
return ctx.SendMessage(SuccessColor, "Success", format, a...)
}
// SendInfoMessage is a shortcut for sending a message with the info colors.
func (ctx Context) SendInfoMessage(format string, a ...interface{}) (*discordgo.Message, error) {
return ctx.SendMessage(InfoColor, "Info", format, a...)
}