-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.WhosOn.go
159 lines (136 loc) · 4.69 KB
/
command.WhosOn.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package main
import (
"fmt"
"github.com/lordmortis/DiscordDestinyInfo/discord"
"github.com/lordmortis/goBungieNet"
"github.com/bwmarrin/discordgo"
)
func init() {
discord.RegisterCommand("WhosOn", "Tell me who is on and what they are doing", handleWhosOn)
}
func handleWhosOn(session *discordgo.Session, message *discordgo.Message, parameters string) {
channel, err := session.UserChannelCreate(message.Author.ID)
if err != nil {
discord.LogPMCreateError(message.Author)
return
}
discord.LogChatCommand(message.Author, "WhosOn")
session.ChannelMessageSend(message.ChannelID, "Checking Who is online...")
var regos *[]Registration
regos, err = loadRegos()
if err != nil {
discord.LogPMError(session, message.Author, channel, "Couldn't get registrations: %s", err.Error())
return
}
msg := "I think the following players are online:\n"
components := []goBungieNet.DestinyComponentType{
goBungieNet.ComponentCharacters,
goBungieNet.ComponentCharacterActivities,
}
onlineCount := 0
for _, rego := range *regos {
var response *goBungieNet.GetProfileResponse
response, err = rego.GetProfile(components)
if err != nil {
discord.LogPMError(session, message.Author, channel, "Couldn't get profile info for %d because: %s", rego.bungieID, err.Error())
continue
}
charID := response.CharacterActivities.MostRecentCharacterID()
currentCharacter := response.Characters.Data[charID]
currentActivity := response.CharacterActivities.Data[charID]
// if the hash is 0 they aren't playing at the moment.
if currentActivity.CurrentActivityHash == 0 {
continue
}
var currentActivityData *goBungieNet.DestinyActivity
currentActivityData, err = currentActivity.ActivityDefinition("en")
if err != nil {
discord.LogPMError(
session,
message.Author,
channel,
"Couldn't get activity details for %d because: %s",
currentActivity.CurrentActivityModeHash,
rego.bungieID,
err.Error(),
)
continue
}
activityName := currentActivityData.DisplayProperties.Name
activityModeName := ""
var currentActivityModeData *goBungieNet.DestinyActivityModeDefinition
if currentActivity.CurrentActivityModeType != goBungieNet.DestinyActivityModeNone {
currentActivityModeData, err = currentActivity.ActivityModeDefinition("en")
if err != nil {
discord.LogPMError(
session,
message.Author,
channel,
"Couldn't get activity mode details %d for %d because: %s",
currentActivity.CurrentActivityModeHash,
rego.bungieID,
err.Error(),
)
continue
}
activityModeName = currentActivityModeData.DisplayProperties.Name
}
var class *goBungieNet.DestinyClassDefinition
class, err = currentCharacter.Class("en")
if err != nil {
discord.LogPMError(session, message.Author, channel, "Couldn't get class details for %d because: %s", rego.bungieID, err.Error())
continue
}
levelString := ""
if currentCharacter.LevelProgression.Level == currentCharacter.LevelProgression.LevelCap {
levelString = fmt.Sprintf("%d Light", currentCharacter.Light)
} else {
levelString = fmt.Sprintf("Level %d", currentCharacter.LevelProgression.Level)
}
msgString := "<@%s> playing their %s %s on %s"
msg += fmt.Sprintf(msgString,
rego.discordID,
levelString,
class.DisplayProperties.Name,
currentCharacter.MembershipType,
)
switch currentActivity.CurrentActivityModeType {
case goBungieNet.DestinyActivityModeNone:
msg += fmt.Sprintf(" and they're In Orbit")
case goBungieNet.DestinyActivityModePatrol:
msg += fmt.Sprintf(" doing %s %s", activityName, activityModeName)
case goBungieNet.DestinyActivityModeStory:
msg += fmt.Sprintf(" doing story mission: %s", activityModeName)
case goBungieNet.DestinyActivityModeSocial:
msg += fmt.Sprintf(" and they're at the %s", activityName)
case goBungieNet.DestinyActivityModeRaid:
msg += fmt.Sprintf(" doing the %s Raid", activityName)
case goBungieNet.DestinyActivityModeStrike:
msg += fmt.Sprintf(" doing the %s Strike", activityName)
case goBungieNet.DestinyActivityModeClash:
fallthrough
case goBungieNet.DestinyActivityModeControl:
fallthrough
case goBungieNet.DestinyActivityModeSupremacy:
fallthrough
case goBungieNet.DestinyActivityModeCountdown:
fallthrough
case goBungieNet.DestinyActivityModeSurvival:
msg += fmt.Sprintf(" is playing %s on the %s map", currentActivityModeData.ModeType, activityName)
default:
msg += fmt.Sprintf(
" doing %s %s %s",
currentActivityModeData.ModeType,
activityName,
activityModeName,
)
}
msg += "\n"
onlineCount++
session.ChannelMessageSend(message.ChannelID, msg)
msg = ""
}
if onlineCount == 0 {
session.ChannelMessageSend(message.ChannelID, "No one is online!")
}
}