change channel struct

This commit is contained in:
2025-03-20 14:40:52 +09:00
parent d510488d3f
commit 5f9b838af5
2 changed files with 8 additions and 6 deletions

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,12 +5,14 @@ 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")
@@ -20,9 +22,9 @@ func main() {
outputs = append(outputs, output.BlueskyOutput(os.Getenv("BSKY_IDENTIFIER"), os.Getenv("BSKY_PASSWORD")))
for tweet := range tweetchannel {
fmt.Println(tweet)
fmt.Println(tweet.Content)
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)