Exemple #1
0
func (ag *Samishi) PreExec(ctx coa.Context) error {
	ag.MsgHistory.LastMinutes = 90
	ag.MsgHistory.Scope = func(db *gorm.DB) *gorm.DB {
		return db.Where("from_user != ?", store.UserByName("takobot").ID)
	}
	return nil
}
Exemple #2
0
func (a *MsgHistory) Do(ctx coa.Context) error {
	log.Action("==> msg history")
	ag := ctx.ActionGroup()
	db := ag.(db.HasDB).DB()
	if a.Scope != nil {
		db = db.Scopes(a.Scope)
	}
	if a.LastMinutes > 0 {
		db.Where(
			"created_at > ?",
			time.Now().Add(time.Duration(-1*a.LastMinutes)*time.Minute),
		).Find(&a.Msgs)
		return nil
	}

	if a.LastMsgNum > 0 {
		db.Order("id desc").Limit(a.LastMsgNum).Find(&a.Msgs)
	}
	return nil
}