This repository has been archived by the owner on Feb 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discord.go
73 lines (64 loc) · 2.26 KB
/
discord.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
package dhelpers
import (
"time"
"strings"
"gitlab.com/Cacophony/dhelpers/cache"
)
// GoType starts a goroutine to start a typing indicator in a channel
// it will use the channelID if given, if not it will try to use the channelID from the event,
// the following events are supported at the moment:
// MESSAGE_CREATE, MESSAGE_UPDATE, MESSAGE_DELETE, MESSAGE_REACTION_ADD, MESSAGE_REACTION_REMOVE,
// MESSAGE_REACTION_REMOVE_ALL, CHANNEL_CREATE, CHANNEL_UPDATE, CHANNEL_DELETE, CHANNEL_PINS_UPDATE
func (event EventContainer) GoType(channelID ...string) {
go func() {
defer func() {
recover() // nolint: errcheck, gas
}()
var typingChannel string
if len(channelID) > 0 {
// use channel ID if given
typingChannel = channelID[0]
} else {
// or try to use channel from event
switch event.Type {
case MessageCreateEventType:
typingChannel = event.MessageCreate.ChannelID
case MessageUpdateEventType:
typingChannel = event.MessageUpdate.ChannelID
case MessageDeleteEventType:
typingChannel = event.MessageDelete.ChannelID
case MessageReactionAddEventType:
typingChannel = event.MessageReactionAdd.ChannelID
case MessageReactionRemoveEventType:
typingChannel = event.MessageReactionRemove.ChannelID
case MessageReactionRemoveAllEventType:
typingChannel = event.MessageReactionRemoveAll.ChannelID
case ChannelCreateEventType:
typingChannel = event.ChannelCreate.ID
case ChannelUpdateEventType:
typingChannel = event.ChannelUpdate.ID
case ChannelDeleteEventType:
typingChannel = event.ChannelDelete.ID
case ChannelPinsUpdateEventType:
typingChannel = event.ChannelPinsUpdate.ChannelID
}
}
if typingChannel != "" {
cache.GetEDiscord(event.BotUserID).ChannelTyping(typingChannel) // nolint: errcheck, gas
}
}()
}
// DiscordTime returns a time formatted to be used in Embeds
func DiscordTime(theTime time.Time) string {
return theTime.Format(time.RFC3339)
}
// CleanURL makes a URL posted in discord ready to use for further usage
func CleanURL(uncleanedURL string) (url string) {
if strings.HasPrefix(uncleanedURL, "<") {
uncleanedURL = strings.TrimLeft(uncleanedURL, "<")
}
if strings.HasSuffix(uncleanedURL, ">") {
uncleanedURL = strings.TrimRight(uncleanedURL, ">")
}
return uncleanedURL
}