-
Notifications
You must be signed in to change notification settings - Fork 92
/
main.go
68 lines (61 loc) · 1.94 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
64
65
66
67
68
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/bwmarrin/discordgo"
cmd "github.com/post04/dr-docso/bot"
)
var c Config
func ready(session *discordgo.Session, evt *discordgo.Ready) {
fmt.Printf("Logged in under: %s#%s\n", evt.User.Username, evt.User.Discriminator)
session.UpdateGameStatus(0, fmt.Sprintf("%shelp for information!", c.Prefix))
go cmd.CheckListeners(5 * time.Minute)
go cmd.CleanTempDocs(5 * time.Minute)
}
func getConfig() {
fileBytes, err := os.ReadFile("config.json")
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(fileBytes, &c)
if err != nil {
log.Fatal(err)
}
}
func main() {
getConfig()
cmd.DocsHelpEmbed.Description = fmt.Sprintf(`__**Examples:**__
%sdocs strings
%sdocs strings equalfold
%sdocs strings builder
%sdocs strings builder.*
%sdocs strings *.writestring`,
c.Prefix, c.Prefix, c.Prefix, c.Prefix, c.Prefix)
bot, err := discordgo.New("Bot " + c.Token)
if err != nil {
log.Fatal("ERROR LOGGING IN", err)
}
bot.AddHandler(ready)
bot.AddHandler(cmd.ReactionListen)
cmdhandler := New(c.Prefix, true)
cmdhandler.AddCommand("docs", "{prefix}docs github.com/bwmarrin/discordgo", "Get the documentation of a package from pkg.go.dev", cmd.HandleDocSend)
cmdhandler.AddCommand("funcs", "{prefix}funcs github.com/bwmarrin/discordgo", "Get all the functions in a package from pkg.go.dev", cmd.HandleFuncsPages)
cmdhandler.AddCommand("types", "{prefix}types github.com/bwmarrin/discordgo", "Get all the types in a package from pkg.go.dev", cmd.HandleTypesPages)
cmdhandler.AddCommand("info", "{prefix}info", "shows information about dr-docso", nil)
cmdhandler.GenHelp()
bot.AddHandler(cmdhandler.OnMessage)
bot.AddHandler(cmdhandler.OnEdit)
err = bot.Open()
if err != nil {
log.Fatal("ERROR OPENING CONNECTION", err)
}
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, syscall.SIGTERM)
<-sc
bot.Close()
}