added a few more library references into main.go

reddit and masto client creation works properly(?)
updated gitignore for masto config files
master
Zachary Epps 4 years ago
parent 82eee17d11
commit 8709c1cc6d
  1. 2
      .gitignore
  2. 49
      main.go

2
.gitignore vendored

@ -16,3 +16,5 @@
# project things
*.agent
*.mconfig
*.toml

@ -6,9 +6,11 @@ import (
"github.com/McKael/madon"
"github.com/turnage/graw"
"github.com/turnage/graw/reddit"
"strings"
// "strings"
"log"
"flag"
"github.com/pelletier/go-toml"
"io/ioutil"
)
type Crossposter struct {
@ -28,31 +30,64 @@ func (p *Crossposter) Post(post *reddit.Post) error {
return nil
}
const AppName string = "OWP Crossposter"
type MastoConfig struct {
Instance string
Secret string
Key string
AccessToken string
}
func main() {
var ClientSecret, ClientKey, AccessToken, MastoConfigFile, RedditConfigFile string
var MastoConfigFile, RedditConfigFile string
var mClient *madon.Client
mConfig := MastoConfig{}
// first we check for mastodon and reddit config files
flag.StringVar(&MastoConfigFile, "mc", "", "relative file path to file containing mastodon client/user tokens")
flag.StringVar(&RedditConfigFile, "rc", "", "relative file path to file containing reddit client tokens")
flag.Parse()
// if we don't have a config file specified check the other flags
// but if we do then we read it and parse it
if MastoConfigFile == "" {
flag.StringVar(&ClientSecret, "ms", "",
flag.StringVar(&mConfig.Secret, "ms", "",
"mastodon client secret, needs to be supplied if mastodon config file isn't specified")
flag.StringVar(&ClientKey, "mk", "",
flag.StringVar(&mConfig.Key, "mk", "",
"mastodon client key, needs to be supplied if mastodon config file isn't specified")
flag.StringVar(&mConfig.AccessToken, "ma", "",
"mastodon access token, needs to be supplied if mastodon config file isn't specified")
flag.Parse()
} else {
// parse mastodon config file here
if dat, err := ioutil.ReadFile(MastoConfigFile); err == nil {
toml.Unmarshal(dat, &mConfig)
} else {
log.Fatal("error opening mastodon config file")
}
}
if RedditConfigFile == "" || ClientSecret == "" || ClientKey == "" {
// if we don't have the neccesary files we print the usage info
if RedditConfigFile == "" || mConfig.Secret == "" || mConfig.Key == "" || mConfig.AccessToken == "" {
flag.Usage()
return
}
if redditBot, err := reddit.NewBotFromAgentFile(RedditConfigFile, 0); err != nil {
if redditBot, err := reddit.NewBotFromAgentFile(RedditConfigFile, 0); err == nil {
log.Fatal("failed to create the reddit bot")
} else {
redditCfg := graw.Config{Subreddits: []string{"Overwatch_Porn"}}
mClient, err = madon.RestoreApp(AppName,
mConfig.Instance,
mConfig.Key,
mConfig.Secret,
&madon.UserToken{ AccessToken: mConfig.AccessToken, Scope: "write" })
if err != nil {
log.Fatal("error restoring app from credentials")
}
}

Loading…
Cancel
Save