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

chore: Remove unused methods #516

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ type idHolder struct {
ChannelID Snowflake `json:"channel_id"`
}

type userHolder struct {
User *User `json:"user"`
}

/*
type userHolder struct {
User *User `json:"user"`
}
*/
func NewBasicCache() *BasicCache {
cache := &BasicCache{
CurrentUser: &User{},
Expand Down Expand Up @@ -859,7 +860,7 @@ func (c *BasicCache) GetMember(guildID, userID Snowflake) (*Member, error) {
defer c.Guilds.Unlock()

if container, ok := c.Guilds.Store[guildID]; ok {
if member, _ = container.Members[userID]; member != nil {
if member = container.Members[userID]; member != nil {
member = DeepCopy(member).(*Member)
}
}
Expand Down
16 changes: 0 additions & 16 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,6 @@ func (c *Channel) String() string {
return "channel{name:'" + c.Name + "', id:" + c.ID.String() + "}"
}

func (c *Channel) valid() bool {
if c.RateLimitPerUser > 120 {
return false
}

if len(c.Topic) > 1024 {
return false
}

if c.Name != "" && (len(c.Name) > 100 || len(c.Name) < 2) {
return false
}

return true
}

// GetPermissions is used to get a members permissions in a channel.
func (c *Channel) GetPermissions(ctx context.Context, s GuildQueryBuilderCaller, member *Member) (permissions PermissionBit, err error) {
// Get the guild permissions.
Expand Down
7 changes: 3 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func createClient(ctx context.Context, conf *Config) (c *Client, err error) {
return nil, fmt.Errorf("you can not reject the READY event when LoadMembersQuietly is set to true")
}
conf.RejectEvents = make([]string, 0, len(uniqueEventNames))
for eventName, _ := range uniqueEventNames {
for eventName := range uniqueEventNames {
conf.RejectEvents = append(conf.RejectEvents, eventName)
}

Expand Down Expand Up @@ -311,8 +311,6 @@ type Client struct {
config *Config
botToken string

permissions PermissionBit

handlers internalHandlers

// reactor demultiplexer for events
Expand All @@ -321,7 +319,8 @@ type Client struct {
// cancelRequestWhenRateLimited by default the Client waits until either the HTTPClient.timeout or
// the rate limit ends before closing a request channel. If activated, in stead, requests will
// instantly be denied, and the process ended with a rate limited error.
cancelRequestWhenRateLimited bool
// TODO: Implement cancelRequestWhenRateLimited into request logic
// cancelRequestWhenRateLimited bool

// req holds the rate limiting logic and error parsing unique for Discord
req *httd.Client
Expand Down
8 changes: 0 additions & 8 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ func (d *dispatcher) nrOfAliveHandlers() (counter int) {
return
}

func ensure(inputs ...interface{}) {
for i := range inputs {
if err, ok := inputs[i].(error); ok && err != nil {
panic(err)
}
}
}

//////////////////////////////////////////////////////
//
// Tests
Expand Down
50 changes: 6 additions & 44 deletions disgord.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,13 @@ func (e *ErrorMissingSnowflake) Error() string {
return e.info
}

/*
func newErrorEmptyValue(message string) *ErrorEmptyValue {
return &ErrorEmptyValue{
info: message,
}
}

*/
// ErrorEmptyValue when a required value was set as empty
type ErrorEmptyValue struct {
info string
Expand All @@ -242,37 +243,17 @@ func (e *ErrorUnsupportedType) Error() string {
return e.info
}

// hasher creates a hash for comparing objects. This excludes the identifier and object type as those are expected
// to be the same during a comparison.
type hasher interface {
hash() string
}

type guilder interface {
getGuildIDs() []Snowflake
}

// Mentioner can be implemented by any type that is mentionable.
// https://discord.com/developers/docs/reference#message-formatting-formats
type Mentioner interface {
Mention() string
}

// zeroInitialiser zero initializes a struct by setting all the values to the default initialization values.
// Used in the flyweight pattern.
type zeroInitialiser interface {
zeroInitialize()
}

// internalUpdater is called whenever a socket event or a REST response is created.
type internalUpdater interface {
updateInternals()
}

type internalClientUpdater interface {
updateInternalsWithClient(*Client)
}

// Discord types

// helperTypes: timestamp, levels, etc.
Expand Down Expand Up @@ -545,6 +526,7 @@ func ShardID(guildID Snowflake, nrOfShards uint) uint {

// https://discord.com/developers/docs/resources/user#avatar-data
func validAvatarPrefix(avatar string) (valid bool) {
valid = true
if avatar == "" {
return false
}
Expand All @@ -560,6 +542,7 @@ func validAvatarPrefix(avatar string) (valid bool) {
encodings := []string{
"jpeg", "png", "gif",
}

for _, encoding := range encodings {
prefix := construct(encoding)
if strings.HasPrefix(avatar, prefix) {
Expand All @@ -568,7 +551,7 @@ func validAvatarPrefix(avatar string) (valid bool) {
}
}

return true
return
}

// ValidateUsername uses Discords rule-set to verify user-names and nicknames
Expand Down Expand Up @@ -641,30 +624,9 @@ func ValidateUsername(name string) (err error) {
return nil
}

func validateChannelName(name string) (err error) {
if name == "" {
return ErrMissingChannelName
}

// attributes
length := len(name)

// Names must be of length of minimum 2 and maximum 100 characters long.
if length < 2 {
err = fmt.Errorf("name is too short: %w", ErrIllegalValue)
} else if length > 100 {
err = fmt.Errorf("name is too long: %w", ErrIllegalValue)
}
if err != nil {
return err
}

return nil
}

// CreateTermSigListener create a channel to listen for termination signals (graceful shutdown)
func CreateTermSigListener() <-chan os.Signal {
termSignal := make(chan os.Signal, 1)
signal.Notify(termSignal, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
signal.Notify(termSignal, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, syscall.SIGTERM)
return termSignal
}
13 changes: 1 addition & 12 deletions disgord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ func (g *mockerWSReceiveOnly) Disconnected() bool {

var _ gateway.Conn = (*mockerWSReceiveOnly)(nil)

var sink1 int = 1

// TODO
// TODO:
// BenchmarkDiscordEventToHandler from the time Disgord gets the raw byte event data, to the event handler is triggered
//func Benchmark1000DiscordEventToHandler_cacheDisabled(b *testing.B) {
// mocker := mockerWSReceiveOnly{
Expand Down Expand Up @@ -267,15 +265,6 @@ func TestCtrl(t *testing.T) {

}

func check(err error, t *testing.T) {
// Hide function from stacktrace, PR#3
t.Helper()

if err != nil {
t.Error(err)
}
}

func TestError_InterfaceImplementations(t *testing.T) {
var u interface{} = &ErrorUnsupportedType{}

Expand Down
2 changes: 1 addition & 1 deletion events.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ type GuildDelete struct {

// UserWasRemoved ... TODO
func (obj *GuildDelete) UserWasRemoved() bool {
return obj.UnavailableGuild.Unavailable == false
return !obj.UnavailableGuild.Unavailable
}

// UnmarshalJSON ...
Expand Down
4 changes: 3 additions & 1 deletion gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ func (g gatewayQueryBuilder) Get() (gateway *gateway.Gateway, err error) {
}

err = json.Unmarshal(body, &gateway)

if err != nil {
return nil, errors.New("error unmarshaling json response: " + err.Error())
}
if gateway.URL, err = ensureDiscordGatewayURLHasQueryParams(gateway.URL); err != nil {
return gateway, err
}
Expand Down
6 changes: 3 additions & 3 deletions guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ type Guild struct {
Emojis []*Emoji `json:"emojis"`
Features []string `json:"features"`
MFALevel MFALvl `json:"mfa_level"`
WidgetEnabled bool `json:"widget_enabled,omit_empty"` // |
WidgetChannelID Snowflake `json:"widget_channel_id,omit_empty"` // |?
SystemChannelID Snowflake `json:"system_channel_id,omitempty"` // |?
WidgetEnabled bool `json:"widget_enabled,omitempty"` // |
WidgetChannelID Snowflake `json:"widget_channel_id,omitempty"` // |?
SystemChannelID Snowflake `json:"system_channel_id,omitempty"` // |?
DiscoverySplash string `json:"discovery_splash,omitempty"`
VanityUrl string `json:"vanity_url_code,omitempty"`
Description string `json:"description,omitempty"`
Expand Down
15 changes: 1 addition & 14 deletions reactor.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package disgord

import (
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -231,18 +230,6 @@ type handlerSpec struct {
ctrl HandlerCtrl
}

func (hs *handlerSpec) next() bool {
hs.Lock()
defer hs.Unlock()

if hs.ctrl.IsDead() {
return false
}

hs.ctrl.Update()
return true
}

// populate is essentially the constructor for a handlerSpec
func (hs *handlerSpec) populate(inputs ...interface{}) (err error) {
var i int
Expand Down Expand Up @@ -279,7 +266,7 @@ func (hs *handlerSpec) populate(inputs ...interface{}) (err error) {

if len(inputs) != i {
format := "unable to add all handlers/middlewares (%d/%d). Are they in correct order? middlewares, then handlers"
err = errors.New(fmt.Sprintf(format, i, len(inputs)))
err = fmt.Errorf(format, i, len(inputs))
}

return err
Expand Down
6 changes: 0 additions & 6 deletions rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ func (r *rest) init() {
r.doRequest = r.stepDoRequest
}

func (r *rest) bindParams(params interface{}) {
if params == nil {
return
}
}

func (r *rest) stepDoRequest() (resp *http.Response, body []byte, err error) {
if r.conf == nil {
err = errors.New("missing httd.Request configuration")
Expand Down
2 changes: 1 addition & 1 deletion webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (w webhookWithTokenQueryBuilder) Execute(params *ExecuteWebhook, wait *bool
ContentType: contentType,
}, w.flags)
// Discord only returns the message when wait=true.
if wait != nil && *wait == true {
if wait != nil && *wait {
r.pool = w.client.pool.message
return getMessage(r.Execute)
}
Expand Down