aboutsummaryrefslogtreecommitdiff
path: root/util.go
blob: bd44d8dca754fdd760b4d67634af777dedb76ada (plain) (blame)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package thulani

import (
	"encoding/json"
	"os"

	"net/url"

	"strconv"

	"sync"

	"github.com/bwmarrin/discordgo"
	"github.com/op/go-logging"
)

const help = `wew lad. you should know these commands already.

Usage: ` + "`!thulani [command]`" + `

commands:
**help**:				print this help message
**[url]**:			   a url with media that thulani can play. queued up to play after everything that's already waiting.
**list, queue**:	list items in the queue, as well as the currently-playing item.
**pause**:			pause sound.
**resume**:		 resume sound.
**die**:				 empty the queue and stop playing.
**skip**:			   skip the current item.
`

var log = logging.MustGetLogger("thulani")

type Config struct {
	Trigger      string `json:"trigger"`
	QueueSize    uint   `json:"queue_size"`
	Admin        uint   `json:"admin"`
	OpRole       string `json:"op_role"`
	Server       string `json:"server"`
	VoiceChannel string `json:"voice_channel"`
	Token        string `json:"token"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

func handle(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func LoadConfig(filename string) (*Config, error) {
	file, err := os.Open("config.json")
	if err != nil {
		return nil, err
	}

	var conf Config
	err = json.NewDecoder(file).Decode(&conf)
	return &conf, err
}

var _oauthUrl string
var oauthOnce sync.Once

const requestedPerms = discordgo.PermissionEmbedLinks |
	discordgo.PermissionReadMessages |
	discordgo.PermissionAddReactions |
	discordgo.PermissionSendMessages |
	discordgo.PermissionSendTTSMessages |
	discordgo.PermissionMentionEveryone |
	discordgo.PermissionUseExternalEmojis |
	discordgo.PermissionVoiceConnect |
	discordgo.PermissionVoiceSpeak |
	discordgo.PermissionChangeNickname |
	discordgo.PermissionVoiceUseVAD |
	discordgo.PermissionAttachFiles

func oauthUrl() string {
	oauthOnce.Do(func() {
		oUrl, err := url.Parse("https://discordapp.com/api/oauth2/authorize")
		if err != nil {
			panic(err)
		}

		q := oUrl.Query()
		q.Add("scope", "bot")
		q.Add("permissions", strconv.Itoa(requestedPerms))
		q.Add("client_id", config.ClientID)
		oUrl.RawQuery = q.Encode()

		_oauthUrl = oUrl.String()
	})

	return _oauthUrl
}