-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_invite.go
59 lines (47 loc) · 1.41 KB
/
get_invite.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
// SPDX-License-Identifier: AGPL-3.0-only
package info
import (
"fmt"
"regexp"
"github.com/diamondburned/arikawa/v3/discord"
"github.com/starshine-sys/bcr"
)
var inviteRegexp = regexp.MustCompile(`https:\/\/discord.gg\/(\w+)`)
func (bot *Bot) inviteInfo(ctx *bcr.Context) (err error) {
code := ctx.RawArgs
// if the argument is a link, use that instead
groups := inviteRegexp.FindStringSubmatch(ctx.RawArgs)
if len(groups) == 2 {
code = groups[1]
}
g, err := ctx.State.InviteWithCounts(code)
if err != nil {
_, err = ctx.Send("You did not give a valid invite.")
return
}
e := discord.Embed{
Color: ctx.Router.EmbedColor,
Title: fmt.Sprintf("Invite for %v", g.Guild.Name),
Description: fmt.Sprintf("This invite points to the #%v channel (%v).", g.Channel.Name, g.Channel.Mention()),
Thumbnail: &discord.EmbedThumbnail{
URL: g.Guild.IconURL(),
},
Footer: &discord.EmbedFooter{
Text: fmt.Sprintf("Server ID: %v", g.Guild.ID),
},
}
if g.Inviter != nil {
e.Fields = append(e.Fields, discord.EmbedField{
Name: "Created by",
Value: fmt.Sprintf("%v\n%v\nID: %v", g.Inviter.Tag(), g.Inviter.Mention(), g.Inviter.ID),
Inline: true,
})
}
e.Fields = append(e.Fields, discord.EmbedField{
Name: "Members",
Value: fmt.Sprintf("👥 %v\n<:online2:826545116838756412> %v", g.ApproximateMembers, g.ApproximatePresences),
Inline: true,
})
_, err = ctx.Send("", e)
return
}