BeeBot/cmd/beebot/main.go

64 lines
1.3 KiB
Go
Raw Normal View History

2020-04-11 17:51:10 +00:00
package main
import (
"flag"
"fmt"
2020-04-11 17:51:10 +00:00
"log"
"github.com/jzelinskie/geddit"
2020-04-11 17:51:10 +00:00
)
const version = 1.0
2020-04-22 14:59:33 +00:00
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")
2020-04-22 14:59:33 +00:00
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
2020-04-11 17:51:10 +00:00
func main() {
flag.Parse()
log.Printf("BeeBot v%.2f", version)
var err error
o, err = geddit.NewOAuthSession(
*clientID,
*clientSecret,
2020-04-22 14:59:33 +00:00
userAgent,
fmt.Sprintf("http://%s/cb", *baseAddr),
)
if err != nil {
log.Fatal(1, err)
}
2020-04-22 14:59:33 +00:00
err = o.LoginAuth(*userName, *password)
if err != nil {
log.Fatal(2, err)
}
2020-04-22 14:59:33 +00:00
me, err := o.AboutRedditor("_beebot_")
if err != nil {
log.Fatal(3, err)
}
2020-04-22 14:59:33 +00:00
log.Printf("%+v", me)
2020-04-22 14:59:33 +00:00
cap, err := o.NewCaptcha()
if err != nil {
log.Fatal(4, err)
}
2020-04-22 14:59:33 +00:00
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)
}
2020-04-11 17:51:10 +00:00
}