-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (49 loc) · 1.34 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
package main
import (
"fmt"
"log"
"os"
"runtime"
"github.com/NicoFgrx/palbot/api"
"github.com/NicoFgrx/palbot/bot"
"github.com/joho/godotenv"
)
func Config() api.Client {
err := godotenv.Load()
if err != nil {
log.Fatal("[-] Error loading .env file")
}
url := os.Getenv("PROXMOX_VE_ENDPOINT") // must be https://x.x.x.x:8006/api2/json
id := os.Getenv("PROXMOX_VE_API_TOKEN_ID") // must be user@pve!id
secret := os.Getenv("PROXMOX_VE_API_TOKEN_SECRET") // must be xxx-xxx-xx
fmt.Println("[+] Creating client")
client := api.NewClient(url, id, secret)
return *client
}
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("[ERROR] Error loading .env file")
}
// Setup Proxmox api client
client := Config()
node := os.Getenv("PROXMOX_NODE")
lxc := os.Getenv("PROXMOX_LXC_VMID")
// Setup Bot
botToken, ok := os.LookupEnv("DISCORD_TOKEN")
if !ok {
log.Fatal("[ERROR] Must set Discord token as env variable: DISCORD_TOKEN")
}
channelID, ok := os.LookupEnv("DISCORD_CHANNEL")
if !ok {
log.Fatal("[ERROR] Must set Discord channel ID as env variable: DISCORD_CHANNEL")
}
fmt.Printf("[INFO] Currently running on %s/%s\n", runtime.GOOS, runtime.GOARCH)
// Save API keys & start bot
bot.BotToken = botToken
bot.ChannelID = channelID
bot.Client = client
bot.Node = node
bot.Lxc = lxc
bot.Run()
}