How graw bots and event handling work
masterThe core design of graw follows an event-driven model:
- Reddit acts as the source of events.
- graw connects the source to your logic.
- Your bot acts as a handler for those events.
To create a bot, you define a struct and implement specific methods (handlers) that correspond to the events you want to process. For example, to handle new posts, you implement a Post method that accepts a *reddit.Post pointer. You then register this handler with an API handle from the github.com/turnage/graw/reddit package and specify which events to subscribe to.
type announcer struct {}
func (a *announcer) Post(post *reddit.Post) error {
fmt.Printf("%s posted \"%s\"\n", post.Author, post.Title)
return nil
}