You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 4, 2019. It is now read-only.
// Groups contains data on the various dev groups.
17
20
typeGroupsstruct {
18
-
// Name of the group
21
+
Group []Group`json:"groups"`
22
+
}
23
+
24
+
// Group contains data from the "groups" array in the JSON object.
25
+
typeGroupstruct {
26
+
Namestring`json:"name"`
27
+
GitHubstring`json:"github"`
28
+
CodeofConductstring`json:"code-of-conduct"`
29
+
Urls []URLs`json:"urls"`
30
+
meetupstring
31
+
}
32
+
33
+
// URLs contains the name and url to the group website
34
+
typeURLsstruct {
19
35
Namestring`json:"name"`
20
-
// URL for the group page/meetup page
21
-
URLstring`json:"url"`
22
-
// Meetup is the group name from the meetup URL
23
-
// this is used for Meetup API calls.
24
-
Meetupstring`json:"meetup_name"`
36
+
URLstring`json:"url"`
25
37
}
26
38
27
-
vargroupListHandler=hear(`(groups|meetups) list`, "(groups|meetups) list", "Lists all groups that are known to Ash", func(res*hal.Response) error {
28
-
groups, err:=res.Robot.Store.Get("GROUPS")
39
+
funcparseGroups() (Groups, error) {
40
+
vargGroups
41
+
r, err:=http.Get("http://chadev.com/groups.json")
29
42
iferr!=nil {
30
-
res.Send("I am currently unaware of any groups, try adding some")
31
-
returnerr
43
+
returng, err
44
+
}
45
+
deferr.Body.Close()
46
+
47
+
b, err:=ioutil.ReadAll(r.Body)
48
+
iferr!=nil {
49
+
returng, err
32
50
}
33
51
34
-
varg []Groups
35
-
err=json.Unmarshal(groups, &g)
52
+
err=json.Unmarshal(b, &g)
36
53
iferr!=nil {
37
-
hal.Logger.Errorf("error parsing JSON: %v", err)
38
-
returnres.Send("I had an error parsing the groups")
54
+
returnGroups{}, err
55
+
}
56
+
57
+
returng, nil
58
+
}
59
+
60
+
vargroupListHandler=hear(`(groups|meetups) list`, "(groups|meetups) list", "Lists all groups that are known to Ash", func(res*hal.Response) error {
61
+
g, err:=parseGroups()
62
+
iferr!=nil {
63
+
hal.Logger.Errorf("failed parsing group list: %v", err)
64
+
res.Send("Sorry, I encountered an error while parsing the groups list")
65
+
returnerr
39
66
}
40
67
41
68
vargn []string
42
-
for_, val:=rangeg {
69
+
for_, val:=rangeg.Group {
43
70
gn=append(gn, val.Name)
44
71
}
45
72
names:=strings.Join(gn, ", ")
46
73
47
74
returnres.Send(fmt.Sprintf("Here is a list of groups: %s", names))
48
75
})
49
76
50
-
vargroupAddHandler=hear(`(groups|meetups) add (.+): (.+)`, "(groups|meetups) add [group name]: [group url]", "Adds a new group to Ash", func(res*hal.Response) error {
77
+
vargroupDetailsHandler=hear(`(group|meetup) details (.+)`, "(group|meetup) details [group name]", "Returns details about a group", func(res*hal.Response) error {
51
78
name:=res.Match[2]
52
-
url:=res.Match[3]
53
79
54
-
ifname=="" {
55
-
hal.Logger.Warn("no group name given")
56
-
returnres.Send("I need a name for the group to add it.")
57
-
}
58
-
ifurl=="" {
59
-
hal.Logger.Warn("no group url given")
60
-
returnres.Send("I need the url for the groups webpage or meetup group")
80
+
g, err:=parseGroups()
81
+
iferr!=nil {
82
+
hal.Logger.Errorf("failed parsing group list: %v", err)
83
+
res.Send("Sorry, I encountered an error while parsing the groups list")
@@ -130,31 +118,32 @@ var groupDetailsHandler = hear(`(group|meetup) details (.+)`, "(group|meetup) de
130
118
vargroupRSVPHandler=hear(`(group|meetup) rsvps (.+)`, "(group|meetup) rsvps [group name]", "Gets the RSVP count for the named group's next meeting", func(res*hal.Response) error {
131
119
name:=res.Match[2]
132
120
133
-
varg []Groups
134
-
groups, _:=res.Robot.Store.Get("GROUPS")
135
-
iflen(groups) >0 {
136
-
err:=json.Unmarshal(groups, &g)
137
-
iferr!=nil {
138
-
hal.Logger.Errorf("faild to parse json: %v", err)
139
-
returnres.Send("Failed to parse groups list")
140
-
}
121
+
g, err:=parseGroups()
122
+
iferr!=nil {
123
+
hal.Logger.Errorf("failed parsing group list: %v", err)
124
+
res.Send("Sorry, I encountered an error while parsing the groups list")
125
+
returnerr
141
126
}
142
127
143
-
iflen(groups) ==0 {
144
-
hal.Logger.Error("no groups currently defined")
145
-
returnres.Send("I currently don't know of any groups, try adding some first")
128
+
group:=searchGroups(g, name)
129
+
for_, u:=rangegroup.Urls {
130
+
ifu.Name=="website"||u.Name=="meetup" {
131
+
m:=parseMeetupName(u.URL)
132
+
ifm!="" {
133
+
group.meetup=m
134
+
}
135
+
}
146
136
}
147
137
148
-
group:=searchGroups(g, strings.ToLower(name))
149
-
ifgroup.Name=="" {
150
-
hal.Logger.Warnf("no group with the name %s found", name)
151
-
returnres.Send(fmt.Sprintf("I could not find a group with the name %s", name))
138
+
ifgroup.meetup=="" {
139
+
res.Send(fmt.Sprintf("%s is using an unsupported event system, can't fetch RSVP information", group.Name))
0 commit comments