コード例 #1
0
ファイル: util.go プロジェクト: THUNDERGROOVE/stats-bot
func lookupStatsChar(c *census.Census, name string) (string, error) {
	char, err := c.GetCharacterByName(name)
	if err != nil {
		return "", err
	}
	buf := bytes.NewBufferString("")

	// This is ugly and terrible and idc
	var cleared int
	var reported int
	reports := []db.Report{}
	db.DB.Where("name = ?", char.Name.First).Find(&reports)
	for _, v := range reports {
		if v.Cleared {
			cleared += 1
		} else {
			reported += 1
		}
	}

	if err := lookupTmpl.Execute(buf, Global{
		Character:     char,
		Dev:           Dev,
		TimesReported: reported,
		TimesCleared:  cleared,
		Reports:       reports}); err != nil {
		return "", err
	}
	return buf.String(), nil
}
コード例 #2
0
ファイル: report.go プロジェクト: THUNDERGROOVE/stats-bot
// NewReport creates a new report with the provided information
//
// Additionally, it creates an outfit instance if possible to reference
// if we need to.
func NewReport(reporter, player, PSN, info string, c *census.Census) error {
	report := Report{
		Reporter:       reporter,
		Name:           player,
		PSNName:        PSN,
		AdditionalInfo: info,
	}

	char, err := c.GetCharacterByName(player)
	if err != nil {
		return err
	}

	report.OutfitCID = char.Outfit.ID

	outfit := new(Outfit)

	// Create an outfit instace if we can
	DB.Where(Outfit{CID: char.Outfit.ID, Name: char.Outfit.Name}).FirstOrCreate(outfit)

	DB.Create(&report)
	return nil
}