mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Cryptolive extracted to new config format
This commit is contained in:
63
modules/cryptoexchanges/cryptolive/price/settings.go
Normal file
63
modules/cryptoexchanges/cryptolive/price/settings.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package price
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type colors struct {
|
||||
from struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
to struct {
|
||||
name string
|
||||
price string
|
||||
}
|
||||
top struct {
|
||||
from struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
to struct {
|
||||
name string
|
||||
field string
|
||||
value string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
colors
|
||||
common *cfg.Common
|
||||
currencies map[string]interface{}
|
||||
top map[string]interface{}
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.cryptolive")
|
||||
|
||||
currencies, _ := localConfig.Map("currencies")
|
||||
top, _ := localConfig.Map("top")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
currencies: currencies,
|
||||
top: top,
|
||||
}
|
||||
|
||||
settings.colors.from.name = localConfig.UString("colors.from.name")
|
||||
settings.colors.from.displayName = localConfig.UString("colors.from.displayName")
|
||||
|
||||
settings.colors.to.name = localConfig.UString("colors.to.name")
|
||||
settings.colors.to.price = localConfig.UString("colors.to.price")
|
||||
|
||||
settings.colors.top.from.name = localConfig.UString("colors.top.from.name")
|
||||
settings.colors.top.from.displayName = localConfig.UString("colors.top.from.displayName")
|
||||
|
||||
settings.colors.top.to.name = localConfig.UString("colors.top.to.name")
|
||||
settings.colors.top.to.field = localConfig.UString("colors.top.to.field")
|
||||
settings.colors.top.to.value = localConfig.UString("colors.top.to.value")
|
||||
|
||||
return &settings
|
||||
}
|
||||
@@ -16,6 +16,7 @@ var ok = true
|
||||
// Widget define wtf widget to register widget later
|
||||
type Widget struct {
|
||||
*list
|
||||
settings *Settings
|
||||
|
||||
Result string
|
||||
|
||||
@@ -23,8 +24,10 @@ type Widget struct {
|
||||
}
|
||||
|
||||
// NewWidget Make new instance of widget
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{}
|
||||
func NewWidget(settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.setList()
|
||||
|
||||
@@ -32,11 +35,9 @@ func NewWidget() *Widget {
|
||||
}
|
||||
|
||||
func (widget *Widget) setList() {
|
||||
currenciesMap, _ := wtf.Config.Map("wtf.mods.cryptolive.currencies")
|
||||
|
||||
widget.list = &list{}
|
||||
|
||||
for currency := range currenciesMap {
|
||||
for currency := range widget.settings.currencies {
|
||||
displayName, _ := wtf.Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName")
|
||||
toList := getToList(currency)
|
||||
widget.list.addItem(currency, displayName, toList)
|
||||
@@ -66,16 +67,23 @@ func (widget *Widget) Refresh(wg *sync.WaitGroup) {
|
||||
|
||||
func (widget *Widget) display() {
|
||||
str := ""
|
||||
var (
|
||||
fromNameColor = wtf.Config.UString("wtf.mods.cryptolive.colors.from.name", "coral")
|
||||
fromDisplayNameColor = wtf.Config.UString("wtf.mods.cryptolive.colors.from.displayName", "grey")
|
||||
toNameColor = wtf.Config.UString("wtf.mods.cryptolive.colors.to.name", "white")
|
||||
toPriceColor = wtf.Config.UString("wtf.mods.cryptolive.colors.to.price", "green")
|
||||
)
|
||||
|
||||
for _, item := range widget.list.items {
|
||||
str += fmt.Sprintf(" [%s]%s[%s] (%s)\n", fromNameColor, item.displayName, fromDisplayNameColor, item.name)
|
||||
str += fmt.Sprintf(
|
||||
" [%s]%s[%s] (%s)\n",
|
||||
widget.settings.colors.from.name,
|
||||
item.displayName,
|
||||
widget.settings.colors.from.name,
|
||||
item.name,
|
||||
)
|
||||
for _, toItem := range item.to {
|
||||
str += fmt.Sprintf("\t[%s]%s: [%s]%f\n", toNameColor, toItem.name, toPriceColor, toItem.price)
|
||||
str += fmt.Sprintf(
|
||||
"\t[%s]%s: [%s]%f\n",
|
||||
widget.settings.colors.to.name,
|
||||
toItem.name,
|
||||
widget.settings.colors.to.price,
|
||||
toItem.price,
|
||||
)
|
||||
}
|
||||
str += "\n"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user