BeeBot/cmd/beebot/main.go

64 lines
1.3 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"github.com/jzelinskie/geddit"
)
const version = 1.0
var userAgent = fmt.Sprintf("BeeBot:%.2f (by u/phlyingpenguin)", version)
var scopes = "identity read edit"
var clientID = flag.String("id", "", "Client ID")
var clientSecret = flag.String("secret", "", "Client Secret")
var baseAddr = flag.String("url", "127.0.0.1:9595", "Base address")
var userName = flag.String("user", "_BeeBot_", "Login name")
var password = flag.String("password", "nope", "Login password")
var reddit = flag.String("reddit", "MeadTest", "Default reddit")
var o *geddit.OAuthSession
func main() {
flag.Parse()
log.Printf("BeeBot v%.2f", version)
var err error
o, err = geddit.NewOAuthSession(
*clientID,
*clientSecret,
userAgent,
fmt.Sprintf("http://%s/cb", *baseAddr),
)
if err != nil {
log.Fatal(1, err)
}
err = o.LoginAuth(*userName, *password)
if err != nil {
log.Fatal(2, err)
}
me, err := o.AboutRedditor("_beebot_")
if err != nil {
log.Fatal(3, err)
}
log.Printf("%+v", me)
cap, err := o.NewCaptcha()
if err != nil {
log.Fatal(4, err)
}
post := geddit.NewTextSubmission(*reddit, "Monthly challenge", "Hey this is a monthly challenge", false, cap)
sub, err := o.Submit(post)
if err != nil {
log.Fatal(5, err)
}
}