Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
fix go generate for activity types and add func AllEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
andersfylling committed Oct 26, 2019
1 parent 66aee69 commit 6f89ac5
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 2 deletions.
81 changes: 81 additions & 0 deletions events_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions generate/events/events.gotpl → generate/events/events.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ import (
"github.com/andersfylling/disgord/internal/event"
)

func AllEvents(except ...string) []string {
evtsMap := map[string]int8{
{{- range .}}
{{if .IsDiscordEvent }}
Evt{{.}}: 0,
{{ end}}
{{- end}}
}

for i := range except {
delete(evtsMap, except[i])
}

evts := make([]string, 0, len(evtsMap))
for k := range evtsMap {
evts = append(evts, k)
}
return evts
}

// ---------------------------

{{range .}}
Expand Down
2 changes: 1 addition & 1 deletion generate/events/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func main() {
}

// And finally pass the event information to different templates to generate some files
makeFile(events, "generate/events/events.gotpl", "events_gen.go")
makeFile(events, "generate/events/events.gohtml", "events_gen.go")
makeFile(events, "generate/events/reactor.gotpl", "reactor_gen.go")
}

Expand Down
2 changes: 1 addition & 1 deletion generate/interfaces/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func getZeroVal(s string) (result string, success bool) {
case "nil":
result = s
// TODO: find out what the original data type is
case "VerificationLvl", "DefaultMessageNotificationLvl", "ExplicitContentFilterLvl", "MFALvl", "Discriminator", "PremiumType", "PermissionBits", "PermissionBit":
case "VerificationLvl", "DefaultMessageNotificationLvl", "ExplicitContentFilterLvl", "MFALvl", "Discriminator", "PremiumType", "PermissionBits", "PermissionBit", "activityFlag", "acitivityType":
result = "0"
}

Expand Down
1 change: 1 addition & 0 deletions iface_reseter_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions sort_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ func derefSliceP(v interface{}) (s interface{}) {
s = *t
case *[]*ActivityAssets:
s = *t
case *[]*ActivityEmoji:
s = *t
case *[]*ActivityParty:
s = *t
case *[]*ActivitySecrets:
Expand Down Expand Up @@ -505,6 +507,12 @@ func sortByID(v interface{}, flags Flag) {
} else {
less = func(i, j int) bool { return s[i].ID < s[j].ID }
}
case []*ActivityEmoji:
if descending {
less = func(i, j int) bool { return s[i].ID > s[j].ID }
} else {
less = func(i, j int) bool { return s[i].ID < s[j].ID }
}
case []*ActivityParty:
if descending {
less = func(i, j int) bool { return s[i].ID > s[j].ID }
Expand Down Expand Up @@ -913,6 +921,12 @@ func sortByName(v interface{}, flags Flag) {
} else {
less = func(i, j int) bool { return strings.ToLower(s[i].Name) < strings.ToLower(s[j].Name) }
}
case []*ActivityEmoji:
if descending {
less = func(i, j int) bool { return strings.ToLower(s[i].Name) > strings.ToLower(s[j].Name) }
} else {
less = func(i, j int) bool { return strings.ToLower(s[i].Name) < strings.ToLower(s[j].Name) }
}
case []*UserConnection:
if descending {
less = func(i, j int) bool { return strings.ToLower(s[i].Name) > strings.ToLower(s[j].Name) }
Expand Down

0 comments on commit 6f89ac5

Please sign in to comment.