-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (50 loc) · 1.52 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
63
package main
import (
"encoding/json"
"github.com/disgoorg/disgo/rest"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
"github.com/rotisserie/eris"
"github.com/spf13/viper"
)
func main() {
// config stuff
viper.AddConfigPath(".")
viper.SetConfigFile(".env")
viper.SetConfigType("env")
err := viper.ReadInConfig()
if err != nil {
err = eris.Wrap(err, "failed to read config")
log.Panic(err)
}
viper.AutomaticEnv()
log.Infof("Starting %s...", viper.GetString("TRIAL_NAME"))
// create rest client
client := rest.New(rest.NewClient(viper.GetString("DISCORD_TOKEN")))
// create snowflakes for ids
channelId := snowflake.ID(viper.GetUint("CHANNEL_ID"))
startId := snowflake.ID(viper.GetUint("START_MSG_ID"))
// new transcript manager
transcript := NewTranscript(getNameOverrides())
// add messages to transcript
transcript.AddMessages(client, channelId, startId)
log.Info("Done getting messages")
// save transcript
transcript.SaveTranscript()
stats := transcript.GetStats()
log.Info("Stats:")
log.Infof("\tTotal messages: %d", stats.TotalMessages)
log.Infof("\tTotal users: %d", stats.TotalUsers)
log.Infof("\tStart date: %s", stats.StartDate)
log.Infof("\tEnd date: %s", stats.EndDate)
}
// parse name override into map
func getNameOverrides() (nameOverride map[string]interface{}) {
// parse override into map
err := json.Unmarshal([]byte(viper.GetString("NAME_OVERRIDE")), &nameOverride)
if err != nil {
err = eris.Wrap(err, "failed to unmarshal name override")
log.Panic(err)
}
return
}