Module functions
(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag)
| 122 | |
| 123 | // Module functions |
| 124 | func (mod *AuctionsModule) auctionCommand(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag) (bool, error) { |
| 125 | |
| 126 | if on := user.GetConfigOption(`auction`); on != nil && !on.(bool) { |
| 127 | |
| 128 | user.SendText( |
| 129 | `Auctions are disabled. See <ansi fg="command">help set</ansi> for learn how to change this.`, |
| 130 | ) |
| 131 | |
| 132 | return true, nil |
| 133 | } |
| 134 | |
| 135 | currentAuction := mod.auctionMgr.GetCurrentAuction() |
| 136 | |
| 137 | args := util.SplitButRespectQuotes(strings.ToLower(rest)) |
| 138 | |
| 139 | if len(args) == 0 { |
| 140 | |
| 141 | if currentAuction != nil { |
| 142 | auctionTxt, _ := templates.Process("auctions/auction-update", currentAuction, user.UserId) |
| 143 | user.SendText(auctionTxt) |
| 144 | } else { |
| 145 | user.SendText(`No current auctions. You can auction something, though!`) |
| 146 | } |
| 147 | return true, nil |
| 148 | } |
| 149 | |
| 150 | if args[0] == `history` { |
| 151 | |
| 152 | headers := []string{"Date", "Item", "Seller", "Buyer", "Winning Bid"} |
| 153 | formatting := []string{ |
| 154 | `<ansi fg="magenta">%s</ansi>`, |
| 155 | `<ansi fg="item">%s</ansi>`, |
| 156 | `<ansi fg="username">%s</ansi>`, |
| 157 | `<ansi fg="username">%s</ansi>`, |
| 158 | `<ansi fg="gold">%s</ansi>`, |
| 159 | } |
| 160 | |
| 161 | rows := [][]string{} |
| 162 | |
| 163 | auctionHistory := mod.auctionMgr.GetAuctionHistory(0) |
| 164 | |
| 165 | for i := len(auctionHistory) - 1; i >= 0; i-- { |
| 166 | aItem := auctionHistory[i] |
| 167 | |
| 168 | buyerName := aItem.BuyerName |
| 169 | sellerName := aItem.SellerName |
| 170 | if aItem.Anonymous { |
| 171 | buyerName = `Anonymous` |
| 172 | sellerName = `Anonymous` |
| 173 | } |
| 174 | rows = append(rows, []string{ |
| 175 | aItem.EndTime.Format("2006-01-02 15:04:05"), |
| 176 | aItem.ItemName, |
| 177 | sellerName, |
| 178 | buyerName, |
| 179 | strconv.Itoa(aItem.WinningBid) + " gold", |
| 180 | }) |
| 181 | } |
nothing calls this directly
no test coverage detected