Skip to content

Commit

Permalink
fixes syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Seklfreak committed Jul 9, 2022
1 parent 09b9f20 commit 0d8ae01
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 267 deletions.
7 changes: 1 addition & 6 deletions discord/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,8 @@ func DeleteSmart(

var messageIDsToBulkDelete []string // nolint: prealloc
for _, message := range messages {
createdAt, err := message.Timestamp.Parse()
if err != nil {
return err
}

// delete one by one, if older than 14 Days
if time.Since(createdAt) > 24*time.Hour*14 {
if time.Since(message.Timestamp) > 24*time.Hour*14 {
err = Delete(
redis,
session,
Expand Down
6 changes: 2 additions & 4 deletions discord/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// UserHasPermission returns true if the User has all of th egiven permissions in the given channel
func UserHasPermission(
state interfaces.State, userID, channelID string, firstPermission int, permissions ...int,
state interfaces.State, userID, channelID string, firstPermission int64, permissions ...int64,
) bool {
if userID == "" || channelID == "" {
return false
Expand All @@ -23,7 +23,6 @@ func UserHasPermission(
}

for _, permission := range append(permissions, firstPermission) {

if userChannelPermissions&permission != permission {
return false
}
Expand All @@ -34,7 +33,7 @@ func UserHasPermission(

// UserHasPermissionOr returns true if the User has any of the given permissions in the given channel
func UserHasPermissionOr(
state *state.State, userID, channelID string, firstPermission int, permissions ...int,
state *state.State, userID, channelID string, firstPermission int64, permissions ...int64,
) bool {
if userID == "" || channelID == "" {
return false
Expand All @@ -50,7 +49,6 @@ func UserHasPermissionOr(
}

for _, permission := range append(permissions, firstPermission) {

if userChannelPermissions&permission == permission {
return true
}
Expand Down
3 changes: 3 additions & 0 deletions events/generating.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ func GenerateEventFromDiscordgoEvent(
event.GuildID = t.GuildID
event.ChannelID = t.ChannelID
event.CacheKey, err = hash(string(event.Type) + t.GuildID + t.ChannelID + t.Token)
if err != nil {
return nil, expiration, err
}
case *discordgo.TypingStart, *discordgo.Ready, *discordgo.Event, *discordgo.Connect:
// ignored events
return nil, expiration, nil
Expand Down
31 changes: 9 additions & 22 deletions events/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,10 @@ func presenceUpdateKey(event *discordgo.PresenceUpdate) string {
key += event.User.Avatar
}

key += event.Nick
key += string(event.Status)
key += strings.Join(event.Roles, "")

if event.Game != nil {
key += event.Game.State
key += strconv.Itoa(int(event.Game.Type))
key += event.Game.Name
key += event.Game.URL
key += event.Game.ApplicationID
key += event.Game.Details

if event.Since != nil {
key += strconv.Itoa(*event.Since)
}

return key
Expand All @@ -59,8 +52,6 @@ func guildKey(event *discordgo.Guild) string {
event.AfkChannelID +
strconv.Itoa(event.AfkTimeout) +
strconv.Itoa(int(event.DefaultMessageNotifications)) +
event.EmbedChannelID +
strconv.FormatBool(event.EmbedEnabled) +
strconv.Itoa(int(event.ExplicitContentFilter)) +
strings.Join(event.Features, "") +
strconv.Itoa(int(event.MfaLevel)) +
Expand All @@ -75,8 +66,8 @@ func memberKey(event *discordgo.Member) string {
key := event.GuildID +
strings.Join(event.Roles, "") +
event.Nick +
string(event.PremiumSince) +
string(event.JoinedAt) +
event.PremiumSince.String() +
event.JoinedAt.String() +
strconv.FormatBool(event.Deaf) +
strconv.FormatBool(event.Mute)

Expand Down Expand Up @@ -104,12 +95,11 @@ func roleKey(event *discordgo.Role) string {
return event.ID +
strconv.Itoa(event.Color) +
event.Name +
strconv.Itoa(event.Permissions) +
strconv.FormatInt(event.Permissions, 10) +
strconv.FormatBool(event.Hoist) +
strconv.FormatBool(event.Managed) +
strconv.FormatBool(event.Mentionable) +
strconv.Itoa(event.Position)

}

func emojisUpdateKey(event *discordgo.GuildEmojisUpdate) string {
Expand Down Expand Up @@ -164,15 +154,12 @@ func channelKey(event *discordgo.Channel) string {
}

func permissionOverwriteKey(event *discordgo.PermissionOverwrite) string {
return event.ID +
event.Type +
strconv.Itoa(event.Allow) +
strconv.Itoa(event.Deny)
return event.ID + strconv.Itoa(int(event.Type)) +
strconv.FormatInt(event.Allow, 10) + strconv.FormatInt(event.Deny, 10)
}

func messageUpdateKey(event *discordgo.MessageUpdate) string {
return event.ID +
string(event.EditedTimestamp)
return event.ID + event.EditedTimestamp.String()
}

func messageReactionKey(event *discordgo.MessageReaction) string {
Expand Down
2 changes: 1 addition & 1 deletion external/iexcloud/stocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (iex *IEX) StocksPrice(ctx context.Context, symbol string) (float64, error)
return 0, err
}

return strconv.ParseFloat(string(raw), 10)
return strconv.ParseFloat(string(raw), 64)
}

// OHLC models the open, high, low, close for a stock.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
go.uber.org/zap v1.10.0
gocloud.dev v0.20.0
gocloud.dev/pubsub/rabbitpubsub v0.20.0
golang.org/x/text v0.3.6
mvdan.cc/xurls/v2 v2.0.0
)

Expand Down Expand Up @@ -59,7 +60,6 @@ require (
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520 // indirect
golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/tools v0.0.0-20200608174601-1b747fd94509 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.26.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions interfaces/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ type State interface {
Member(guildID, userID string) (member *discordgo.Member, err error)
Role(guildID, roleID string) (role *discordgo.Role, err error)

UserPermissions(userID, guildID string) (apermissions int, err error)
UserChannelPermissions(userID, channelID string) (apermissions int, err error)
UserPermissions(userID, guildID string) (apermissions int64, err error)
UserChannelPermissions(userID, channelID string) (apermissions int64, err error)
}
Loading

0 comments on commit 0d8ae01

Please sign in to comment.