-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.go
104 lines (85 loc) · 2.01 KB
/
sound.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
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
96
97
98
99
100
101
102
103
104
package main
import (
"encoding/binary"
"fmt"
"io"
"os"
"time"
"github.com/bwmarrin/discordgo"
)
type buffer [][]byte
type sound struct {
b buffer
path string
}
type keyword string
var sounds = []sound{
sound{make(buffer, 0), dataPath + "EEEEEEEEEEEEEEEEEEEEEE.dca"},
sound{make(buffer, 0), dataPath + "EIMAI_ENTAKSEI.dca"},
sound{make(buffer, 0), dataPath + "gamw_tis_katares.dca"},
sound{make(buffer, 0), dataPath + "re_fyge.dca"},
}
var keywordSound = map[keyword]*sound{
"ok": &sounds[0],
"entaksei": &sounds[1],
"gamw": &sounds[2],
"fyge": &sounds[3],
}
func loadSounds(key int) error {
file, err := os.Open(sounds[key].path)
if err != nil {
fmt.Println("Error opening dca file :", err)
return err
}
fmt.Println("load file: ", key, sounds[key].path, file)
var opuslen int16
for {
err = binary.Read(file, binary.LittleEndian, &opuslen)
if err == io.EOF || err == io.ErrUnexpectedEOF {
err := file.Close()
if err != nil {
return err
}
return nil
}
if err != nil {
fmt.Println("Error reading from dca file :", err)
return err
}
InBuf := make([]byte, opuslen)
err = binary.Read(file, binary.LittleEndian, &InBuf)
if err != nil {
fmt.Println("Error reading from dca file :", err)
return err
}
sounds[key].b = append(sounds[key].b, InBuf)
}
}
func (s sound) playSound(session *discordgo.Session, guildID, channelID string) (err error) {
vc, err := session.ChannelVoiceJoin(guildID, channelID, false, true)
if err != nil {
return err
}
time.Sleep(250 * time.Millisecond)
vc.Speaking(true)
for _, buff := range s.b {
vc.OpusSend <- buff
}
vc.Speaking(false)
time.Sleep(250 * time.Millisecond)
vc.Disconnect()
return nil
}
func synonym(word string) keyword {
switch word {
case "!ok", "!okey", "!e", "!ee", "!eee":
return "ok"
case "!entaksei", "!eimaidaksei", "!daksei":
return "entaksei"
case "!fyge", "!fige", "!refigeremalakapodorebro":
return "fyge"
case "!gamw", "!katares", "!manoules":
return "gamw"
}
return ""
}