// package ignore is a Hugot handler that will force any messages received from // a set of matching idents to be ignored package ignore import ( "github.com/tcolgate/hugot" "golang.org/x/net/context" ) type IgnoreHearsHandler struct { hugot.HearsHandler Ignores map[string]struct{} } type IgnoreCommandHandler struct { hugot.CommandHandler Ignores map[string]struct{} } func NewCommand(list []string, next hugot.CommandHandler) hugot.CommandHandler { return &IgnoreCommandHandler{ CommandHandler: next, Ignores: buildIgnores(list), } } func NewHears(list []string, next hugot.HearsHandler) hugot.HearsHandler { return &IgnoreHearsHandler{ HearsHandler: next, Ignores: buildIgnores(list), } } func buildIgnores(ignores []string) map[string]struct{} { out := make(map[string]struct{}, len(ignores)) for _, nick := range ignores { out[nick] = struct{}{} } return out } func (i *IgnoreHearsHandler) Heard(ctx context.Context, w hugot.ResponseWriter, m *hugot.Message, matches [][]string) { if _, present := i.Ignores[m.From]; present { return } i.HearsHandler.Heard(ctx, w, m, matches) } func (i *IgnoreCommandHandler) Command(ctx context.Context, w hugot.ResponseWriter, m *hugot.Message) error { if _, present := i.Ignores[m.From]; present { return nil } return i.CommandHandler.Command(ctx, w, m) }