Compare commits

..

4 Commits

Author SHA1 Message Date
68981e9eb5 add Dockerfile 2025-10-26 16:53:07 +09:00
b8152b3c6a remove redundant stdout 2025-03-20 14:49:46 +09:00
c25735f9c9 add StdOutput 2025-03-20 14:48:08 +09:00
5f9b838af5 change channel struct 2025-03-20 14:40:52 +09:00
4 changed files with 47 additions and 6 deletions

18
Dockerfile Normal file
View File

@@ -0,0 +1,18 @@
FROM golang:alpine AS build-env
RUN apk --no-cache add git make build-base
RUN git clone --depth 1 https://git.sirrow.work/sirrow/tweetdistributor.git
WORKDIR tweetdistributor
RUN mkdir -p /build
RUN go mod tidy
RUN go build -a -tags "netgo" -tags timetzdata -installsuffix netgo -ldflags="-s -w -extldflags \"-static\"" -o=/build/tweetdistributor main.go
FROM alpine:3.22
RUN apk --no-cache add ca-certificates
COPY --from=build-env /build/tweetdistributor /tweetdistributor
RUN chmod u+x /tweetdistributor
CMD ["/tweetdistributor"]

View File

@@ -19,11 +19,11 @@ func Discord(token string, channelId string) *discord {
}
}
func (d *discord) BeginRead(tweetchannel chan<- string) {
func (d *discord) BeginRead(tweetchannel chan<- *discordgo.MessageCreate) {
d.read(tweetchannel)
}
func (d *discord) read(tweetchannel chan<- string) {
func (d *discord) read(tweetchannel chan<- *discordgo.MessageCreate) {
dgsession, err := discordgo.New("Bot " + d.Token)
if err != nil {
return
@@ -31,7 +31,7 @@ func (d *discord) read(tweetchannel chan<- string) {
dgsession.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.ChannelID == d.ChannelID && m.Author.ID != s.State.User.ID {
tweetchannel <- m.Content
tweetchannel <- m
}
})
d.dgsession = dgsession

View File

@@ -5,24 +5,26 @@ import (
"os"
"tweetdistributor/discord"
"tweetdistributor/output"
"github.com/bwmarrin/discordgo"
)
func main() {
d := discord.Discord(os.Getenv("DISCORD_TOKEN"), os.Getenv("DISCORD_CHANNEL"))
tweetchannel := make(chan string, 1)
tweetchannel := make(chan *discordgo.MessageCreate, 1)
d.BeginRead(tweetchannel)
d.Write("Tweetdistributor Started")
var outputs []output.OutputInterface
outputs = append(outputs, output.StdOutput())
outputs = append(outputs, output.TwitterOutput(os.Getenv("TW_ACCESS_TOKEN"), os.Getenv("TW_ACCESS_SECRET")))
outputs = append(outputs, output.BlueskyOutput(os.Getenv("BSKY_IDENTIFIER"), os.Getenv("BSKY_PASSWORD")))
for tweet := range tweetchannel {
fmt.Println(tweet)
for _, output := range outputs {
err := output.Write(tweet)
err := output.Write(tweet.Content)
if err != nil {
errstr := fmt.Sprintf("%s Error: %s", output.GetName(), err)
fmt.Fprintln(os.Stderr, errstr)

21
output/stdout.go Normal file
View File

@@ -0,0 +1,21 @@
package output
import (
"fmt"
)
type stdoutput struct {
}
func StdOutput() *stdoutput {
return &stdoutput{}
}
func (so *stdoutput) Write(str string) error {
fmt.Println(str)
return nil
}
func (so *stdoutput) GetName() string {
return "stdout"
}