Update to snappy v0.4.1

This commit is contained in:
ekzyis 2024-04-07 05:37:31 +02:00
parent ee95aa89bd
commit 3bf5c8baba
5 changed files with 23 additions and 24 deletions

View File

@ -8,7 +8,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/dustin/go-humanize"
"github.com/ekzyis/sn-goapi"
sn "github.com/ekzyis/snappy"
"github.com/joho/godotenv"
"github.com/namsral/flag"
)
@ -124,7 +124,7 @@ func SendDupesErrorToDiscord(hackerNewsId int, dupesErr *sn.DupesError) {
},
&discordgo.MessageEmbedField{
Name: "Id",
Value: sn.FormatLink(dupe.Id),
Value: fmt.Sprintf("https://stacker.news/items/%d", dupe.Id),
Inline: true,
},
&discordgo.MessageEmbedField{

4
go.mod
View File

@ -3,15 +3,15 @@ module gitlab.com/ekzyis/hnbot
go 1.20
require (
github.com/bwmarrin/discordgo v0.27.1
github.com/bwmarrin/discordgo v0.28.1
github.com/dustin/go-humanize v1.0.1
github.com/ekzyis/sn-goapi v0.3.3
github.com/joho/godotenv v1.5.1
github.com/mattn/go-sqlite3 v1.14.22
github.com/namsral/flag v1.7.4-pre
)
require (
github.com/ekzyis/snappy v0.4.2-0.20240407032738-17878b2f32ba
github.com/gorilla/websocket v1.4.2 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect

8
go.sum
View File

@ -1,9 +1,9 @@
github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY=
github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4=
github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/ekzyis/sn-goapi v0.3.3 h1:5WHGLyYVPwZ12lQrRD40eM+gjWEpDdgdWTshwL8CDEE=
github.com/ekzyis/sn-goapi v0.3.3/go.mod h1:FObbYr/NXgnXNWU+EwiWKoWQy+wAaRS6AoW3NgsJ/Oo=
github.com/ekzyis/snappy v0.4.2-0.20240407032738-17878b2f32ba h1:myhgV9ECBhDPx0juj+td6U/5PIf0Bvj4x1hMBQFCZ1Q=
github.com/ekzyis/snappy v0.4.2-0.20240407032738-17878b2f32ba/go.mod h1:BxJwdGlCwUw0Q5pQzBr59weAIS6pkVdivBBaZkkWTSo=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=

View File

@ -5,7 +5,7 @@ import (
"log"
"time"
"github.com/ekzyis/sn-goapi"
sn "github.com/ekzyis/snappy"
)
func SyncStories() {

29
sn.go
View File

@ -8,7 +8,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/dustin/go-humanize"
"github.com/ekzyis/sn-goapi"
sn "github.com/ekzyis/snappy"
)
func CurateContentForStackerNews() (*[]Story, error) {
@ -54,6 +54,7 @@ type PostStoryOptions struct {
}
func PostStoryToStackerNews(story *Story, options PostStoryOptions) (int, error) {
c := sn.NewClient()
url := story.Url
if url == "" {
url = HackerNewsItemLink(story.ID)
@ -61,7 +62,7 @@ func PostStoryToStackerNews(story *Story, options PostStoryOptions) (int, error)
log.Printf("Posting to SN (url=%s) ...\n", url)
if !options.SkipDupes {
dupes, err := sn.Dupes(url)
dupes, err := c.Dupes(url)
if err != nil {
return -1, err
}
@ -75,7 +76,16 @@ func PostStoryToStackerNews(story *Story, options PostStoryOptions) (int, error)
title = title[0:80]
}
parentId, err := sn.PostLink(url, title, "tech")
comment := fmt.Sprintf(
"This link was posted by [%s](%s) %s on [HN](%s). It received %d points and %d comments.",
story.By,
HackerNewsUserLink(story.By),
humanize.Time(time.Unix(int64(story.Time), 0)),
HackerNewsItemLink(story.ID),
story.Score, story.Descendants,
)
parentId, err := c.PostLink(url, title, comment, "tech")
if err != nil {
return -1, fmt.Errorf("error posting link: %w", err)
}
@ -87,23 +97,12 @@ func PostStoryToStackerNews(story *Story, options PostStoryOptions) (int, error)
SendStackerNewsEmbedToDiscord(story.Title, parentId)
comment := fmt.Sprintf(
"This link was posted by [%s](%s) %s on [HN](%s). It received %d points and %d comments.",
story.By,
HackerNewsUserLink(story.By),
humanize.Time(time.Unix(int64(story.Time), 0)),
HackerNewsItemLink(story.ID),
story.Score, story.Descendants,
)
if _, err := sn.CreateComment(parentId, comment); err != nil {
return -1, fmt.Errorf("error posting comment :%w", err)
}
return parentId, nil
}
func SendStackerNewsEmbedToDiscord(title string, id int) {
Timestamp := time.Now().Format(time.RFC3339)
url := sn.FormatLink(id)
url := fmt.Sprintf("https://stacker.news/items/%d", id)
color := 0xffc107
embed := discordgo.MessageEmbed{
Title: title,