-
Notifications
You must be signed in to change notification settings - Fork 910
/
createinvite.go
57 lines (50 loc) · 1.41 KB
/
createinvite.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
package createinvite
import (
"github.com/jonas747/dcmd"
"github.com/jonas747/discordgo"
"github.com/jonas747/yagpdb/bot"
"github.com/jonas747/yagpdb/commands"
"github.com/jonas747/yagpdb/common"
"github.com/jonas747/yagpdb/stdcommands/util"
)
var Command = &commands.YAGCommand{
Cooldown: 2,
CmdCategory: commands.CategoryDebug,
HideFromCommandsPage: true,
Name: "createinvite",
Description: "Maintenance command, creates a invite for the specified server",
HideFromHelp: true,
RequiredArgs: 1,
Arguments: []*dcmd.ArgDef{
{Name: "server", Type: dcmd.Int},
},
RunFunc: util.RequireBotAdmin(func(data *dcmd.Data) (interface{}, error) {
gs := bot.State.Guild(true, data.Args[0].Int64())
if gs == nil {
return "Unknown server", nil
}
channelID := int64(0)
gs.RLock()
for _, v := range gs.Channels {
if channelID == 0 || v.Type != discordgo.ChannelTypeGuildVoice {
channelID = v.ID
if v.Type != discordgo.ChannelTypeGuildVoice {
break
}
}
}
gs.RUnlock()
if channelID == 0 {
return "No possible channel :(", nil
}
invite, err := common.BotSession.ChannelInviteCreate(channelID, discordgo.Invite{
MaxAge: 120,
MaxUses: 1,
})
if err != nil {
return nil, err
}
bot.SendDM(data.Msg.Author.ID, "discord.gg/"+invite.Code)
return "Sent invite expiring in 120 seconds and with 1 use in DM", nil
}),
}