-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (52 loc) · 1.36 KB
/
Copy pathmain.go
File metadata and controls
64 lines (52 loc) · 1.36 KB
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"
"github.com/bwmarrin/discordgo"
"os"
"os/signal"
"syscall"
)
func main() {
token := os.Getenv("DISCORD_TOKEN")
discord, err := discordgo.New("Bot " + token)
if err != nil {
fmt.Println("Error creating discord session")
return
}
discord.AddHandler(messageHandler)
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 messageHandler(session *discordgo.Session, msg *discordgo.MessageCreate) {
if msg.Author.ID != session.State.User.ID {
log.Println("Received Message: ", msg.Content)
}
if !IsValidBotCommand(session, msg) {
return
} else if MessageIsTestRequest(msg) {
go Test(session, msg)
} else if MessageIsHelpRequest(msg) {
go Help(session, msg)
} else if MessageIsCollageRequest(msg) {
go Collage(session, msg)
} else if MessageIsMinecraftRequest(msg) {
go Minecraft(session, msg)
} else if MessageIsWeatherTodayRequest(msg) {
go WeatherToday(session, msg)
} else if MessageIsWeatherTomorrowRequest(msg) {
go WeatherTomorrow(session, msg)
} else if MessageIsWeatherWeekRequest(msg) {
go WeatherWeek(session, msg)
} else {
go Fallback(session, msg)
}
}