Compare commits
3 Commits
d510488d3f
...
b8152b3c6a
| Author | SHA1 | Date | |
|---|---|---|---|
| b8152b3c6a | |||
| c25735f9c9 | |||
| 5f9b838af5 |
@@ -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)
|
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)
|
dgsession, err := discordgo.New("Bot " + d.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -31,7 +31,7 @@ func (d *discord) read(tweetchannel chan<- string) {
|
|||||||
|
|
||||||
dgsession.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
|
dgsession.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
if m.ChannelID == d.ChannelID && m.Author.ID != s.State.User.ID {
|
if m.ChannelID == d.ChannelID && m.Author.ID != s.State.User.ID {
|
||||||
tweetchannel <- m.Content
|
tweetchannel <- m
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
d.dgsession = dgsession
|
d.dgsession = dgsession
|
||||||
|
|||||||
8
main.go
8
main.go
@@ -5,24 +5,26 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"tweetdistributor/discord"
|
"tweetdistributor/discord"
|
||||||
"tweetdistributor/output"
|
"tweetdistributor/output"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
d := discord.Discord(os.Getenv("DISCORD_TOKEN"), os.Getenv("DISCORD_CHANNEL"))
|
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.BeginRead(tweetchannel)
|
||||||
|
|
||||||
d.Write("Tweetdistributor Started")
|
d.Write("Tweetdistributor Started")
|
||||||
|
|
||||||
var outputs []output.OutputInterface
|
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.TwitterOutput(os.Getenv("TW_ACCESS_TOKEN"), os.Getenv("TW_ACCESS_SECRET")))
|
||||||
outputs = append(outputs, output.BlueskyOutput(os.Getenv("BSKY_IDENTIFIER"), os.Getenv("BSKY_PASSWORD")))
|
outputs = append(outputs, output.BlueskyOutput(os.Getenv("BSKY_IDENTIFIER"), os.Getenv("BSKY_PASSWORD")))
|
||||||
|
|
||||||
for tweet := range tweetchannel {
|
for tweet := range tweetchannel {
|
||||||
fmt.Println(tweet)
|
|
||||||
for _, output := range outputs {
|
for _, output := range outputs {
|
||||||
err := output.Write(tweet)
|
err := output.Write(tweet.Content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errstr := fmt.Sprintf("%s Error: %s", output.GetName(), err)
|
errstr := fmt.Sprintf("%s Error: %s", output.GetName(), err)
|
||||||
fmt.Fprintln(os.Stderr, errstr)
|
fmt.Fprintln(os.Stderr, errstr)
|
||||||
|
|||||||
21
output/stdout.go
Normal file
21
output/stdout.go
Normal 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"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user