Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
zekroTJA committed Jul 17, 2023
2 parents da8d160 + 503db9c commit b63bbbf
Show file tree
Hide file tree
Showing 23 changed files with 905 additions and 917 deletions.
30 changes: 13 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module github.com/zekroTJA/shinpuru
go 1.18

require (
github.com/bwmarrin/discordgo v0.27.1
github.com/bwmarrin/discordgo v0.27.2-0.20230704233747-e39e715086d2
github.com/bwmarrin/snowflake v0.3.0
github.com/esimov/stackblur-go v1.1.0
github.com/gabriel-vasile/mimetype v1.4.2
github.com/generaltso/vibrant v0.0.0-20230605224344-08d3d20033fc
github.com/go-ping/ping v1.1.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-sql-driver/mysql v1.7.1
github.com/gofiber/fiber/v2 v2.46.0
github.com/gofiber/fiber/v2 v2.48.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/joho/godotenv v1.5.1
github.com/kataras/hcaptcha v0.0.2
Expand All @@ -27,7 +27,7 @@ require (
github.com/sarulabs/di/v2 v2.4.2
github.com/stretchr/testify v1.8.4
github.com/traefik/paerser v0.2.0
github.com/valyala/fasthttp v1.47.0
github.com/valyala/fasthttp v1.48.0
github.com/wcharczuk/go-chart v2.0.1+incompatible
github.com/zekroTJA/colorname v1.0.0
github.com/zekroTJA/ratelimit v1.1.1
Expand All @@ -36,10 +36,10 @@ require (
github.com/zekrotja/jwt v0.0.0-20220515133240-d66362c9fbc9
github.com/zekrotja/ken v0.18.0
github.com/zekrotja/promtail v0.0.0-20230303162843-4e609d577b74
github.com/zekrotja/rogu v0.5.0
github.com/zekrotja/rogu v0.5.1
github.com/zekrotja/sop v0.3.1
golang.org/x/image v0.8.0
golang.org/x/sys v0.9.0
golang.org/x/image v0.9.0
golang.org/x/sys v0.10.0
golang.org/x/time v0.3.0
gopkg.in/yaml.v2 v2.4.0
)
Expand All @@ -63,33 +63,29 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/klauspost/compress v1.16.6 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.1 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/text v0.10.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
107 changes: 26 additions & 81 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/listeners/autovc.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (l *ListenerAutoVoice) createAutoVC(s *discordgo.Session, userID, guildID,
}
ch, err = s.ChannelEditComplex(ch.ID, &discordgo.ChannelEdit{
ParentID: parentCh.ParentID,
Position: parentCh.Position,
Position: &parentCh.Position,
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/listeners/voiceupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (l *ListenerVoiceUpdate) sendVLCMessage(s *discordgo.Session, channelID, us
Color: color,
Description: content,
Author: &discordgo.MessageEmbedAuthor{
Name: user.Username + "#" + user.Discriminator,
Name: user.String(),
IconURL: user.AvatarURL("16x16"),
},
Timestamp: l.tp.Now().Format(time.RFC3339),
Expand Down
2 changes: 1 addition & 1 deletion internal/services/backup/guildbackups.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (bck *GuildBackups) RestoreBackup(guildID, fileID string, statusC chan stri
asyncWriteStatus(statusC, "re-positioning channels")
for cID, pos := range channelsPos {
_, err = bck.session.ChannelEditComplex(cID, &discordgo.ChannelEdit{
Position: pos,
Position: &pos,
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/slashcommands/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (c *Id) Run(ctx ken.Context) (err error) {
if user != nil {
emb.Fields = append(emb.Fields, &discordgo.MessageEmbedField{
Name: "Member",
Value: fmt.Sprintf("<@%s> (%s#%s)\n```\n%s\n```", user.ID, user.Username, user.Discriminator, user.ID),
Value: fmt.Sprintf("<@%s> (%s)\n```\n%s\n```", user.ID, user.String(), user.ID),
})
}
if role != nil {
Expand Down
7 changes: 3 additions & 4 deletions internal/slashcommands/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ func (c *Quote) Run(ctx ken.Context) (err error) {
}
if quoteMsg.Author == nil {
quoteMsg.Author = &discordgo.User{
ID: "000000000000000000",
Username: "Discord doesn't want to give the author of this message :(",
Avatar: "",
Discriminator: "0000",
ID: "000000000000000000",
Username: "Discord doesn't want to give the author of this message :(",
Avatar: "",
}
}
st.SetMessage(quoteMsg)
Expand Down
3 changes: 1 addition & 2 deletions internal/slashcommands/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ func (c *Report) list(ctx ken.SubCommandContext) (err error) {

emb := &discordgo.MessageEmbed{
Color: static.ColorEmbedDefault,
Title: fmt.Sprintf("Reports for %s#%s",
victim.Username, victim.Discriminator),
Title: fmt.Sprintf("Reports for %s", victim.String()),
Description: fmt.Sprintf("[**Here**](%s/guilds/%s/%s) you can find this users reports in the web interface.",
cfg.Config().WebServer.PublicAddr, ctx.GetEvent().GuildID, victim.ID),
}
Expand Down
4 changes: 2 additions & 2 deletions internal/slashcommands/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *User) Run(ctx ken.Context) (err error) {

embed := &discordgo.MessageEmbed{
Color: roleColor,
Title: fmt.Sprintf("Info about member %s#%s", member.User.Username, member.User.Discriminator),
Title: fmt.Sprintf("Info about member %s", member.User.String()),
Description: fmt.Sprintf("[**Here**](%s/guilds/%s/%s) you can find this users profile in the web interface.",
cfg.Config().WebServer.PublicAddr, guild.ID, member.User.ID),
Thumbnail: &discordgo.MessageEmbedThumbnail{
Expand All @@ -153,7 +153,7 @@ func (c *User) Run(ctx ken.Context) (err error) {
{
Inline: true,
Name: "Tag",
Value: member.User.Username + "#" + member.User.Discriminator,
Value: member.User.String(),
},
{
Inline: true,
Expand Down
174 changes: 87 additions & 87 deletions internal/util/tag/tag.go
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
package tag

import (
"fmt"
"time"

"github.com/bwmarrin/discordgo"
"github.com/zekroTJA/shinpuru/internal/util/static"
"github.com/zekrotja/dgrs"

"github.com/bwmarrin/snowflake"
)

// Tag wraps a chat tag object.
type Tag struct {
ID snowflake.ID
Ident string
CreatorID string
GuildID string
Content string
Created time.Time
LastEdit time.Time
}

// author wraps a name tag and avatar imageURL
// of an author user.
type author struct {
nameTag string
imageURL string
}

// AsEmbed creates a discordgo.MessageEmbed from
// the tag information.
func (t *Tag) AsEmbed(s *dgrs.State) *discordgo.MessageEmbed {
footer := ""

author := t.formattedAuthor(s)

if t.Created == t.LastEdit {
footer = fmt.Sprintf("Created %s",
t.Created.Format(time.RFC822))
} else {
footer = fmt.Sprintf("Created %s | Last edit %s",
t.Created.Format(time.RFC822), t.LastEdit.Format(time.RFC822))
}

return &discordgo.MessageEmbed{
Author: &discordgo.MessageEmbedAuthor{
Name: author.nameTag,
IconURL: author.imageURL,
},
Description: t.Content,
Color: static.ColorEmbedDefault,
Footer: &discordgo.MessageEmbedFooter{
Text: footer,
},
}
}

// AsEntry returns a single formatted string line
// to represent a tag.
func (t *Tag) AsEntry(s *dgrs.State) string {
author := t.formattedAuthor(s)

return fmt.Sprintf("**%s** by %s [`%s`]", t.Ident, author.nameTag, t.ID)
}

// RawContent returns the content of the tags body
// in a markdown code embed for a discord message.
func (t *Tag) RawContent() string {
return fmt.Sprintf("```md\n%s\n```", t.Content)
}

// formattedAuthor returns an author object from the
// CreatorID of the tag.
func (t *Tag) formattedAuthor(s *dgrs.State) *author {
authorF := new(author)
author, err := s.Member(t.GuildID, t.CreatorID)
if err == nil && author != nil {
authorF.nameTag = fmt.Sprintf("%s#%s", author.User.Username, author.User.Discriminator)
authorF.imageURL = author.User.AvatarURL("")
} else {
authorF.nameTag = fmt.Sprintf("<not on guild> (%s)", t.CreatorID)
}

return authorF
}
package tag

import (
"fmt"
"time"

"github.com/bwmarrin/discordgo"
"github.com/zekroTJA/shinpuru/internal/util/static"
"github.com/zekrotja/dgrs"

"github.com/bwmarrin/snowflake"
)

// Tag wraps a chat tag object.
type Tag struct {
ID snowflake.ID
Ident string
CreatorID string
GuildID string
Content string
Created time.Time
LastEdit time.Time
}

// author wraps a name tag and avatar imageURL
// of an author user.
type author struct {
nameTag string
imageURL string
}

// AsEmbed creates a discordgo.MessageEmbed from
// the tag information.
func (t *Tag) AsEmbed(s *dgrs.State) *discordgo.MessageEmbed {
footer := ""

author := t.formattedAuthor(s)

if t.Created == t.LastEdit {
footer = fmt.Sprintf("Created %s",
t.Created.Format(time.RFC822))
} else {
footer = fmt.Sprintf("Created %s | Last edit %s",
t.Created.Format(time.RFC822), t.LastEdit.Format(time.RFC822))
}

return &discordgo.MessageEmbed{
Author: &discordgo.MessageEmbedAuthor{
Name: author.nameTag,
IconURL: author.imageURL,
},
Description: t.Content,
Color: static.ColorEmbedDefault,
Footer: &discordgo.MessageEmbedFooter{
Text: footer,
},
}
}

// AsEntry returns a single formatted string line
// to represent a tag.
func (t *Tag) AsEntry(s *dgrs.State) string {
author := t.formattedAuthor(s)

return fmt.Sprintf("**%s** by %s [`%s`]", t.Ident, author.nameTag, t.ID)
}

// RawContent returns the content of the tags body
// in a markdown code embed for a discord message.
func (t *Tag) RawContent() string {
return fmt.Sprintf("```md\n%s\n```", t.Content)
}

// formattedAuthor returns an author object from the
// CreatorID of the tag.
func (t *Tag) formattedAuthor(s *dgrs.State) *author {
authorF := new(author)
author, err := s.Member(t.GuildID, t.CreatorID)
if err == nil && author != nil {
authorF.nameTag = fmt.Sprintf("%s", author.User.String())
authorF.imageURL = author.User.AvatarURL("")
} else {
authorF.nameTag = fmt.Sprintf("<not on guild> (%s)", t.CreatorID)
}

return authorF
}
2 changes: 1 addition & 1 deletion internal/util/vote/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (v *Vote) AsEmbed(s *discordgo.Session, voteState ...VoteState) (*discordgo
Description: description,
Author: &discordgo.MessageEmbedAuthor{
IconURL: creator.AvatarURL("16x16"),
Name: creator.Username + "#" + creator.Discriminator,
Name: creator.String(),
},
Footer: &discordgo.MessageEmbedFooter{
Text: footerText,
Expand Down
22 changes: 5 additions & 17 deletions mocks/ISession.go

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

2 changes: 1 addition & 1 deletion pkg/discordutil/isession.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type ISession interface {
GuildChannelsReorder(guildID string, channels []*Channel, options ...RequestOption) (err error)
GuildCreate(name string, options ...RequestOption) (st *Guild, err error)
GuildCreateWithTemplate(templateCode, name, icon string, options ...RequestOption) (st *Guild, err error)
GuildDelete(guildID string, options ...RequestOption) (st *Guild, err error)
GuildDelete(guildID string, options ...RequestOption) (err error)
GuildEdit(guildID string, g *GuildParams, options ...RequestOption) (st *Guild, err error)
GuildEmbed(guildID string, options ...RequestOption) (st *GuildEmbed, err error)
GuildEmbedEdit(guildID string, data *GuildEmbed, options ...RequestOption) (err error)
Expand Down
Loading

0 comments on commit b63bbbf

Please sign in to comment.