gossip

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KarmaBest = &SyncTrigger{
	Cond: func(g *Bot, msg *irc.Message) bool {
		return msg.Command == irc.PRIVMSG && len(msg.Params) == 2 && msg.Params[1] == "!karma best"
	},
	Act: func(g *Bot, msg *irc.Message) bool {
		var karma []data.Karma

		g.db.Model(&data.Karma{}).Order("value desc").Limit(5).Where(&data.Karma{
			Location: mirrorMsg(g, msg),
		}).Find(&karma)

		for _, k := range karma {
			g.msgChan <- &irc.Message{
				Command: irc.PRIVMSG,
				Params:  []string{mirrorMsg(g, msg), fmt.Sprintf("%d: %s", k.Value, k.Object)},
			}
		}
		return false
	},
	meta: &data.TriggerMeta{
		Disabled: false,
		Priority: 0,
		Name:     "karmaBest",
	},
}
View Source
var KarmaWorst = &SyncTrigger{
	Cond: func(g *Bot, msg *irc.Message) bool {
		return msg.Command == irc.PRIVMSG && len(msg.Params) == 2 && msg.Params[1] == "!karma worst"
	},
	Act: func(g *Bot, msg *irc.Message) bool {
		var karma []data.Karma

		g.db.Model(&data.Karma{}).Order("value asc").Limit(5).Where(&data.Karma{
			Location: mirrorMsg(g, msg),
		}).Find(&karma)

		for _, k := range karma {
			g.msgChan <- &irc.Message{
				Command: irc.PRIVMSG,
				Params:  []string{mirrorMsg(g, msg), fmt.Sprintf("%d: %s", k.Value, k.Object)},
			}
		}
		return false
	},
	meta: &data.TriggerMeta{
		Disabled: false,
		Priority: 0,
		Name:     "karmaWorst",
	},
}

Functions

This section is empty.

Types

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

func New

func New(cfg *conf.Cfg) *Bot

func (*Bot) Begin

func (g *Bot) Begin()

will block

type ComposedTrigger

type ComposedTrigger struct {
	// contains filtered or unexported fields
}

func (*ComposedTrigger) Action

func (t *ComposedTrigger) Action(b *Bot, msg *irc.Message) (shouldContinue bool)

func (*ComposedTrigger) Condition

func (t *ComposedTrigger) Condition(b *Bot, msg *irc.Message) (shouldApply bool)

func (*ComposedTrigger) GetMeta

func (t *ComposedTrigger) GetMeta() *data.TriggerMeta

func (*ComposedTrigger) Meta

func (t *ComposedTrigger) Meta(m *data.TriggerMeta)

type SyncTrigger

type SyncTrigger struct {
	// Returns true if this trigger applies to the passed in message
	Cond func(*Bot, *irc.Message) (shouldApply bool)

	// The action to perform if Cond is true
	// return true if processing should continue
	Act func(*Bot, *irc.Message) (shouldContinue bool)
	// contains filtered or unexported fields
}

pattern stolen from https://github.com/whyrusleeping/hellabot/blob/master/hellabot.go

func (*SyncTrigger) Action

func (t *SyncTrigger) Action(b *Bot, msg *irc.Message) (shouldContinue bool)

func (*SyncTrigger) Condition

func (t *SyncTrigger) Condition(b *Bot, msg *irc.Message) (shouldApply bool)

func (*SyncTrigger) GetMeta

func (t *SyncTrigger) GetMeta() *data.TriggerMeta

func (*SyncTrigger) Meta

func (t *SyncTrigger) Meta(m *data.TriggerMeta)

type Trigger

type Trigger interface {
	Condition(*Bot, *irc.Message) (shouldApply bool)
	Action(*Bot, *irc.Message) (shouldContinue bool)
	GetMeta() *data.TriggerMeta
	Meta(*data.TriggerMeta)
}

func NewJoin

func NewJoin(channels []string) Trigger

func NewReminder

func NewReminder(g *Bot) Trigger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL