Skip to content

Commit

Permalink
Merge branch 'bwmarrin:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
HaynarCool authored Sep 1, 2022
2 parents 47554c9 + fea3d77 commit f4e6032
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 413 deletions.
87 changes: 87 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Getting started

To start off you can check out existing Pull Requests and Issues to get a gasp of what problems we’re currently solving and what features you can implement.

## Issues

Our issues are mostly used for bugs, however we welcome refactoring and conceptual issues.

Any other conversation would belong and would be moved into “Discussions”.

## Discussions

We use discussions for ideas, polls, announcements and help questions.

Don’t hesitate to ask, we always would try to help.

## Pull Requests

If you want to help us by improving existing or adding new features, you create what’s called a Pull Request (aka PR). It allows us to review your code, suggest changes and merge it.

Here are some tips on how to make a good first PR:

- When creating a PR, please consider a distinctive name and description for it, so the maintainers can understand what your PR changes / adds / removes.
- It’s always a good idea to link documentation when implementing a new feature / endpoint
- If you’re resolving an issue, don’t forget to [link it](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) in the description.
- Enable the checkbox to allow maintainers to edit your PR and make commits in the PR branch when necessary.
- We may ask for changes, usually through suggestions or pull request comments. You can apply suggestions right in the UI. Any other change needs to be done manually.
- Don’t forget to mark PR comments resolved when you’re done applying the changes.
- Be patient and don’t close and reopen your PR when no one responds, sometimes it might be held for a while. There might be a lot of reasons: release preparation, the feature is not significant, maintainers are busy, etc.


When your changes are still incomplete (i.e. in Work In Progress state), you can still create a PR, but consider making it a draft.
To make a draft PR, you can change the type of PR by clicking to a triangle next to the “Create Pull Request” button.

Once you’re done, you can mark it as “Ready for review”, and we’ll get right on it.


# Code style

To standardize and make things less messy we have a certain code style, that is persistent throughout the codebase.

## Naming

### REST methods

When naming a REST method, while it might seem counterintuitive, we specify the entity before the action verb (for GET endpoints we don’t specify one however). Here’s an example:

> Endpoint name: Get Channel Message
>
> Method name: `ChannelMessage`
> Endpoint name: Edit Channel Message
>
> Method name: `ChannelMessageEdit`
### Parameter structures

When making a complex REST endpoint, sometimes you might need to implement a `Param` structure. This structure contains parameters for certain endpoint/set of endpoints.

- If an endpoint/set of endpoints have mostly same parameters, it’s a good idea to use a single `Param` structure for them. Here’s an example:

> Endpoint: `GuildMemberEdit`
>
> `Param` structure: `GuildMemberParams`
- If an endpoint/set of endpoints have differentiating parameters, `Param` structure can be named after the endpoint’s verb. Here’s an example:

> Endpoint: `ChannelMessageSendComplex`
>
> `Param` structure: `MessageSend`
> Endpoint: `ChannelMessageEditComplex`
>
> `Param` structure: `MessageEdit`
### Events

When naming an event, we follow gateway’s internal naming (which often matches with the official event name in the docs). Here’s an example:

> Event name: Interaction Create (`INTERACTION_CREATE`)
>
> Structure name: `InteractionCreate`
## Returns

In our REST functions we usually favor named returns instead of regular anonymous returns. This helps readability.

Additionally we try to avoid naked return statements for functions with a long body. Since it’s easier to loose track of the return result.
7 changes: 5 additions & 2 deletions discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import (
"net/http"
"runtime"
"time"

"github.com/gorilla/websocket"
)

// VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
const VERSION = "0.25.0"
const VERSION = "0.26.1"

// New creates a new Discord session with provided token.
// If the token is for a bot, it must be prefixed with "Bot "
Expand All @@ -41,12 +43,13 @@ func New(token string) (s *Session, err error) {
ShardCount: 1,
MaxRestRetries: 3,
Client: &http.Client{Timeout: (20 * time.Second)},
Dialer: websocket.DefaultDialer,
UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")",
sequence: new(int64),
LastHeartbeatAck: time.Now().UTC(),
}

// Initilize the Identify Package with defaults
// Initialize the Identify Package with defaults
// These can be modified prior to calling Open()
s.Identify.Compress = true
s.Identify.LargeThreshold = 250
Expand Down
3 changes: 1 addition & 2 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ var (
EndpointVoice = EndpointAPI + "/voice/"
EndpointVoiceRegions = EndpointVoice + "regions"

// TODO: EndpointUserGuildMember

EndpointUser = func(uID string) string { return EndpointUsers + uID }
EndpointUserAvatar = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".png" }
EndpointUserAvatarAnimated = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".gif" }
Expand All @@ -64,6 +62,7 @@ var (

EndpointUserGuilds = func(uID string) string { return EndpointUsers + uID + "/guilds" }
EndpointUserGuild = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID }
EndpointUserGuildMember = func(uID, gID string) string { return EndpointUserGuild(uID, gID) + "/member" }
EndpointUserChannels = func(uID string) string { return EndpointUsers + uID + "/channels" }
EndpointUserConnections = func(uID string) string { return EndpointUsers + uID + "/connections" }

Expand Down
144 changes: 0 additions & 144 deletions eventhandlers.go

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

Loading

0 comments on commit f4e6032

Please sign in to comment.