-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
62 lines (53 loc) · 1.5 KB
/
main.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
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
)
const (
dir = "downloads"
outputFormat = "mp4"
originalExt = "." + outputFormat
convertedExt = ".webm"
messageSizeLimit = 8_000_000
)
// TODO: use go embed for token
// Run the bot client
func main() {
flag.StringVar(&TOKEN, "t", TOKEN, "Bot token")
flag.Parse()
if //goland:noinspection GoBoolExpressions
TOKEN == "" {
log.Fatal(
"Secret token is missing. The token can be stored in token.go, or can be passed as\n " +
"a command line argument when the bot is run.\n" +
"Your token can be found at https://discord.com/developers/applications/")
}
err := os.MkdirAll(dir, 0755)
if err != nil {
log.Printf("Error creating base download directory: %v", err)
}
dg, err := discordgo.New("Bot " + TOKEN)
if err != nil {
log.Fatal("Error creating session: ", err)
}
dg.AddHandler(messageCreate)
dg.Identify.Intents = discordgo.IntentsGuildMessages
err = dg.Open()
if err != nil {
log.Fatalf("Error opening Discord connection, %v", err)
}
log.Print("dvembed bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, syscall.SIGTERM)
<-sc
_ = dg.Close()
//app := &discordgo.Application{}
//app.Name = "dvembed"
//app.Description = "Properly embeds media from v.redd.it"
//app, err = dg.ApplicationCreate(app)
//log.Printf("ApplicationCreate: err: %+v, app: %+v", err, app)
}