diff options
author | Wim <wim@42.be> | 2017-06-22 01:00:27 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-06-22 01:00:27 +0200 |
commit | 1f914618538920db4bfec7b106ee97038b157c9b (patch) | |
tree | 6bd0ab107fe1673dbacdf9dfd10004289cd7bfab /vendor/github.com/Philipp15b/go-steam/trade/actions.go | |
parent | 1f9874102aaca09ce5e0289beff376c307b8c57b (diff) | |
download | matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.tar.gz matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.tar.bz2 matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.zip |
Add vendor (steam)
Diffstat (limited to 'vendor/github.com/Philipp15b/go-steam/trade/actions.go')
-rw-r--r-- | vendor/github.com/Philipp15b/go-steam/trade/actions.go | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/github.com/Philipp15b/go-steam/trade/actions.go b/vendor/github.com/Philipp15b/go-steam/trade/actions.go new file mode 100644 index 00000000..e9301940 --- /dev/null +++ b/vendor/github.com/Philipp15b/go-steam/trade/actions.go @@ -0,0 +1,84 @@ +package trade + +import ( + "github.com/Philipp15b/go-steam/economy/inventory" + "github.com/Philipp15b/go-steam/trade/tradeapi" + "time" +) + +type Slot uint + +func (t *Trade) action(status *tradeapi.Status, err error) error { + if err != nil { + return err + } + t.onStatus(status) + return nil +} + +// Returns the next batch of events to process. These can be queued from calls to methods +// like `AddItem` or, if there are no queued events, from a new HTTP request to Steam's API (blocking!). +// If the latter is the case, this method may also sleep before the request +// to conform to the polling interval of the official Steam client. +func (t *Trade) Poll() ([]interface{}, error) { + if t.queuedEvents != nil { + return t.Events(), nil + } + + if d := time.Since(t.lastPoll); d < pollTimeout { + time.Sleep(pollTimeout - d) + } + t.lastPoll = time.Now() + + err := t.action(t.api.GetStatus()) + if err != nil { + return nil, err + } + + return t.Events(), nil +} + +func (t *Trade) GetTheirInventory(contextId uint64, appId uint32) (*inventory.Inventory, error) { + return inventory.GetFullInventory(func() (*inventory.PartialInventory, error) { + return t.api.GetForeignInventory(contextId, appId, nil) + }, func(start uint) (*inventory.PartialInventory, error) { + return t.api.GetForeignInventory(contextId, appId, &start) + }) +} + +func (t *Trade) GetOwnInventory(contextId uint64, appId uint32) (*inventory.Inventory, error) { + return t.api.GetOwnInventory(contextId, appId) +} + +func (t *Trade) GetMain() (*tradeapi.Main, error) { + return t.api.GetMain() +} + +func (t *Trade) AddItem(slot Slot, item *Item) error { + return t.action(t.api.AddItem(uint(slot), item.AssetId, item.ContextId, item.AppId)) +} + +func (t *Trade) RemoveItem(slot Slot, item *Item) error { + return t.action(t.api.RemoveItem(uint(slot), item.AssetId, item.ContextId, item.AppId)) +} + +func (t *Trade) Chat(message string) error { + return t.action(t.api.Chat(message)) +} + +func (t *Trade) SetCurrency(amount uint, currency *Currency) error { + return t.action(t.api.SetCurrency(amount, currency.CurrencyId, currency.ContextId, currency.AppId)) +} + +func (t *Trade) SetReady(ready bool) error { + return t.action(t.api.SetReady(ready)) +} + +// This may only be called after a successful `SetReady(true)`. +func (t *Trade) Confirm() error { + return t.action(t.api.Confirm()) +} + +func (t *Trade) Cancel() error { + return t.action(t.api.Cancel()) +} |