-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
98 lines (79 loc) · 1.67 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
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
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
)
var (
Token string
)
var dataPath = "data/"
var keys = map[string]int{
"ok": 0,
"entaksei": 1,
"gamw": 2,
"fyge": 3,
}
func init() {
flag.StringVar(&Token, "t", "", "Bot Token")
flag.Parse()
}
func main() {
discord, _ := discordgo.New("Bot " + Token)
for _, val := range keys {
err := loadSounds(val)
if err != nil {
fmt.Println("error lol, ", err)
return
}
}
discord.AddHandler(messageCreate)
err := discord.Open()
if err != nil {
fmt.Println("error opening connection,", err)
return
}
fmt.Println("Bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
discord.Close()
}
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
if word := synonym(m.Content); word != "" {
c, err := s.State.Channel(m.ChannelID)
if err != nil {
return
}
g, err := s.State.Guild(c.GuildID)
if err != nil {
return
}
for _, vs := range g.VoiceStates {
if vs.UserID == m.Author.ID {
err = keywordSound[word].playSound(s, g.ID, vs.ChannelID)
if err != nil {
fmt.Println("Error playing sound:", err)
}
return
}
}
}
}
func guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
if event.Guild.Unavailable {
return
}
for _, channel := range event.Guild.Channels {
if channel.ID == event.Guild.ID {
_, _ = s.ChannelMessageSend(channel.ID, "Airhorn is ready! Type !airhorn while in a voice channel to play a sound.")
return
}
}
}