-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package discord | ||
|
||
// DefaultActivityConfig returns a ActivityConfig with sensible defaults. | ||
func DefaultActivityConfig(activityType ActivityType, name string, url *string) *ActivityConfig { | ||
return &ActivityConfig{ | ||
Name: name, | ||
Type: activityType, | ||
URL: url, | ||
} | ||
} | ||
|
||
// ActivityConfig lets you configure an Activity. | ||
type ActivityConfig struct { | ||
Name string | ||
Type ActivityType | ||
URL *string | ||
State *string | ||
} | ||
|
||
// ActivityConfigOpt is a type alias for a function that takes a ActivityConfig and is used to configure an Activity. | ||
type ActivityConfigOpt func(config *ActivityConfig) | ||
|
||
// Apply applies the given ActivityConfigOpt(s) to the ActivityConfig | ||
func (c *ActivityConfig) Apply(opts []ActivityConfigOpt) { | ||
for _, opt := range opts { | ||
opt(c) | ||
} | ||
} | ||
|
||
// WithActivityURL sets the URL of the Activity. | ||
func WithActivityURL(url string) ActivityConfigOpt { | ||
return func(config *ActivityConfig) { | ||
if url == "" { | ||
config.URL = nil | ||
return | ||
} | ||
config.URL = &url | ||
} | ||
} | ||
|
||
// WithActivityState sets the State of the Activity. | ||
func WithActivityState(state string) ActivityConfigOpt { | ||
return func(config *ActivityConfig) { | ||
if state == "" { | ||
config.State = nil | ||
return | ||
} | ||
config.State = &state | ||
} | ||
} | ||
|
||
// WithActivityName sets the Name of the Activity. | ||
func WithActivityName(name string) ActivityConfigOpt { | ||
return func(config *ActivityConfig) { | ||
config.Name = name | ||
} | ||
} | ||
|
||
// WithActivityType sets the Type of the Activity. | ||
func WithActivityType(activityType ActivityType) ActivityConfigOpt { | ||
return func(config *ActivityConfig) { | ||
config.Type = activityType | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters