Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Find, MessageSends #52

Merged
merged 39 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c0f111b
refactor: Organized regex patterns of providers
XangelMusic Jun 3, 2024
44add1d
refactor: Find, NewError functions
XangelMusic Jun 4, 2024
f4418f8
refactor: error.go created
XangelMusic Jun 4, 2024
a10572c
fix: Twitter regex
XangelMusic Jun 6, 2024
024b96a
refactor: MessageSends functions, new embed.go file and Embed struct
XangelMusic Jun 6, 2024
d6688d1
fix: Embed package
XangelMusic Jun 7, 2024
55bc7b2
fix: Embed package
XangelMusic Jun 7, 2024
5d2b37e
fix: Embed package
XangelMusic Jun 7, 2024
36135a0
fix: Embed package
XangelMusic Jun 7, 2024
5ec4c05
Merge remote-tracking branch 'upstream/dev' into dev
XangelMusic Jun 7, 2024
69f8a6d
fix: Adjusted Pixiv for testing
XangelMusic Jun 7, 2024
08fb2cb
Update pixiv.go
XangelMusic Jun 8, 2024
dfc6879
boost: Internal utility functions
XangelMusic Jun 11, 2024
16306a8
boost: added Slices pkg
XangelMusic Jun 11, 2024
61f7b6c
Merge remote-tracking branch 'upstream/dev' into dev
XangelMusic Sep 12, 2024
23bdab7
boost: added Slices pkg
XangelMusic Sep 12, 2024
93db915
boost: added Slices pkg
XangelMusic Sep 12, 2024
1b97db2
Merge remote-tracking branch 'upstream/dev' into dev
XangelMusic Sep 12, 2024
975e236
refactor: Trimmer functions
XangelMusic Sep 17, 2024
d560d4f
refactor: Trimmer functions
XangelMusic Sep 17, 2024
aeb94fa
Merge remote-tracking branch 'upstream/dev' into dev
XangelMusic Sep 17, 2024
8164a2a
boost: added OnChannelDelete and manual deletion of missing Art Channels
XangelMusic Sep 17, 2024
ff00199
boost: added OnChannelDelete and manual deletion of missing Art Channels
XangelMusic Sep 17, 2024
4dededa
Merge remote-tracking branch 'upstream/dev' into dev
XangelMusic Sep 18, 2024
8d47ab4
Update handlers.go
XangelMusic Sep 18, 2024
1365b93
Merge remote-tracking branch 'upstream/dev' into dev
XangelMusic Sep 18, 2024
7ba4722
refactor: cleanup RepostDetector code in fetch()
XangelMusic Sep 18, 2024
180e41a
refactor: cleanup RepostDetector code in fetch()
XangelMusic Sep 18, 2024
6cefbef
Merge remote-tracking branch 'upstream/dev' into dev
XangelMusic Sep 19, 2024
a27e17a
refactor: Repost message appears last
XangelMusic Sep 19, 2024
98e5f75
boost: Repost Detector won't appear for deleted posts
XangelMusic Sep 23, 2024
ca45fe2
Update post.go
XangelMusic Oct 13, 2024
e155fd3
fix: Repost Detector delete messages
XangelMusic Oct 14, 2024
6b6079d
revert artworks
VTGare Nov 17, 2024
8e5c6f2
remove artstation/restore some changes
VTGare Nov 17, 2024
8e7f2ad
restore twitter matcher
VTGare Nov 17, 2024
6dd68bc
twitter tests
VTGare Nov 17, 2024
f2a58cb
fix pixiv tests
VTGare Nov 17, 2024
2687357
fix typo
VTGare Nov 17, 2024
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
207 changes: 0 additions & 207 deletions artworks/artstation/artstation.go

This file was deleted.

28 changes: 0 additions & 28 deletions artworks/artstation/artstation_suite_test.go

This file was deleted.

21 changes: 1 addition & 20 deletions artworks/artworks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package artworks

import (
"errors"
"fmt"
"regexp"
"strings"
Expand All @@ -19,36 +18,18 @@ type Provider interface {
type Artwork interface {
StoreArtwork() *store.Artwork
MessageSends(footer string, tags bool) ([]*discordgo.MessageSend, error)
ID() string
URL() string
Len() int
}

type Error struct {
provider string
cause error
}

func (e *Error) Error() string {
return fmt.Sprintf("provider %v returned an error: %v", e.provider, e.cause.Error())
}

func (e *Error) Unwrap() error {
return e.cause
}

func NewError(p Provider, err error) error {
return &Error{
provider: fmt.Sprintf("%T", p),
cause: err,
}
}

// Common errors
var (
ErrArtworkNotFound = errors.New("artwork not found")
ErrRateLimited = errors.New("provider rate limited")
)

func EscapeMarkdown(content string) string {
contents := strings.Split(content, "\n")
regex := regexp.MustCompile("^#{1,3}")
Expand Down
18 changes: 13 additions & 5 deletions artworks/deviant/deviant.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ type Artwork struct {
Comments int
AIGenerated bool
CreatedAt time.Time
url string

id string
url string
}

type Author struct {
Expand Down Expand Up @@ -78,7 +80,7 @@ func (d *DeviantArt) Find(id string) (artworks.Artwork, error) {
return artwork, nil
}

func (d *DeviantArt) _find(id string) (artworks.Artwork, error) {
func (*DeviantArt) _find(id string) (artworks.Artwork, error) {
reqURL := "https://backend.deviantart.com/oembed?url=" + url.QueryEscape("deviantart.com/art/"+id)
resp, err := http.Get(reqURL)
if err != nil {
Expand All @@ -105,7 +107,9 @@ func (d *DeviantArt) _find(id string) (artworks.Artwork, error) {
Favorites: res.Community.Statistics.Attributes.Favorites,
Comments: res.Community.Statistics.Attributes.Comments,
CreatedAt: res.Pubdate,
url: res.AuthorURL + "/art/" + id,

id: id,
url: res.AuthorURL + "/art/" + id,
}

artwork.AIGenerated = artworks.IsAIGenerated(artwork.Tags...)
Expand All @@ -122,7 +126,7 @@ func (d *DeviantArt) Match(s string) (string, bool) {
return res[1], true
}

func (d *DeviantArt) Enabled(g *store.Guild) bool {
func (*DeviantArt) Enabled(g *store.Guild) bool {
return g.Deviant
}

Expand Down Expand Up @@ -172,6 +176,10 @@ func (a *Artwork) URL() string {
return a.url
}

func (a *Artwork) Len() int {
func (a *Artwork) ID() string {
return a.id
}

func (*Artwork) Len() int {
return 1
}
37 changes: 37 additions & 0 deletions artworks/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package artworks

import (
"errors"
"fmt"
)

// Common errors
var (
ErrArtworkNotFound = errors.New("artwork not found")
ErrRateLimited = errors.New("provider rate limited")
)

type Error struct {
provider string
cause error
}

func (e *Error) Error() string {
return fmt.Sprintf("provider %v returned an error: %v", e.provider, e.cause.Error())
}

func (e *Error) Unwrap() error {
return e.cause
}

func WrapError(p Provider, find func() (Artwork, error)) (Artwork, error) {
artwork, err := find()
if err != nil {
return nil, &Error{
provider: fmt.Sprintf("%T", p),
cause: err,
}
}

return artwork, nil
}
Loading
Loading