diff --git a/README.md b/README.md index 03b29481..314574cc 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,14 @@ With botway, you can focus on your bot's logic and don't worry about the infrastructure. and we will take care of the rest. -Botway uses [Railway][rw] to host your bot code and database. +Botway uses [Railway][rw] and [Render][rnd] to host your bot code and database. https://user-images.githubusercontent.com/64256993/175816610-70160d02-8324-4a50-ac4d-78e0993cd91d.mp4 ## Requirements - [**Railway Account**][rw] +- [**Render Account**][rnd] ## Installation ⬇ @@ -68,10 +69,14 @@ scoop install botway botway init ``` -- Authenticate with [**Railway**][rw] +- Authenticate with your favorite host service ```bash + # railway botway login railway + + # render + botway login render ``` - Open Botway TUI @@ -106,18 +111,18 @@ scoop install botway botway database ``` -- Deploy and upload project to [**Railway**][rw] from the current directory +- Deploy and upload project from the current directory ```bash # Under the project directory botway deploy ``` -- Run a local command using variables from the active environment +- Execute a local command using variables from the active environment ```bash # Under the project directory - botway run + botway exec ``` ## Roadmap @@ -129,13 +134,14 @@ scoop install botway - Up: **Move up** - Down: **Move down** - Tab: **Switch windows** -- Ctrl+O: **Open bot project at Railway** +- Ctrl+O: **Open bot project at Host Service** - Esc: **Reset** - Ctrl+Q: **Quit** ### Technologies Used in Botway - [**Railway API**][rw] +- [**Render Rest API**][rnd] - [**Charm**](https://charm.sh) - [**Cobra**](https://github.com/spf13/cobra) - [**Viper**](https://github.com/spf13/viper) @@ -147,7 +153,7 @@ scoop install botway Thanks to [**@charmbracelet**](https://github.com/charmbracelet) for their awesome TUI libraries 🏗. -Also thanks to [**@railwayapp**](https://github.com/railwayapp) for amazing cloud services ☁️. +Also thanks to [**@railwayapp**](https://github.com/railwayapp) and [**renderinc**](https://github.com/renderinc) for their amazing cloud and host services ☁️. ### License @@ -158,3 +164,4 @@ botway is licensed under the terms of [MIT](https://github.com/abdfnx/botway/blo [![Star History Chart](https://api.star-history.com/svg?repos=abdfnx/botway&type=Date)](https://star-history.com/#abdfnx/botway) [rw]: https://railway.app +[rnd]: https://render.com diff --git a/go.mod b/go.mod index 84e95687..b6ca618b 100644 --- a/go.mod +++ b/go.mod @@ -5,11 +5,11 @@ go 1.18 require ( github.com/AlecAivazis/survey/v2 v2.3.5 github.com/MakeNowJust/heredoc v1.0.0 - github.com/abdfnx/botwaygo v0.0.83 + github.com/abdfnx/botwaygo v0.0.9 github.com/abdfnx/looker v0.1.0 github.com/abdfnx/resto v0.1.6 github.com/abdfnx/tran v0.1.43 - github.com/botwayorg/gh v0.0.8 + github.com/botwayorg/gh v0.0.9 github.com/briandowns/spinner v1.19.0 github.com/charmbracelet/bubbles v0.13.0 github.com/charmbracelet/bubbletea v0.22.1 @@ -26,7 +26,7 @@ require ( github.com/spf13/viper v1.12.0 github.com/tidwall/gjson v1.14.3 github.com/tidwall/sjson v1.2.5 - golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 + golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 gopkg.in/yaml.v3 v3.0.1 ) @@ -73,7 +73,7 @@ require ( github.com/muesli/cancelreader v0.2.2 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pelletier/go-toml v1.9.5 // indirect - github.com/pelletier/go-toml/v2 v2.0.3 // indirect + github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -95,7 +95,7 @@ require ( github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 // indirect github.com/yuin/goldmark v1.4.13 // indirect github.com/yuin/goldmark-emoji v1.0.1 // indirect - golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c // indirect + golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index cdff428b..2f524748 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6 github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/abdfnx/botwaygo v0.0.83 h1:DZkQr1OmTWAQwylvgyITBmjFhHwdySAAWihNbGmYrXI= -github.com/abdfnx/botwaygo v0.0.83/go.mod h1:0HyyA0FxqRy94B++LOmg0w5wz7+7BMHVhzgPHhndimI= +github.com/abdfnx/botwaygo v0.0.9 h1:Y1ZZst9Y97CYUvGfVQy7xOAKVtUYjU9qcmGlmq3UCV8= +github.com/abdfnx/botwaygo v0.0.9/go.mod h1:cSnH5z3N9YTIYlzOXwglI+gChnRFSvtNDkWJ7KMoqso= github.com/abdfnx/looker v0.1.0 h1:tMN7E0wKIgbydAPPQ1RkppJ1bGHn+B+y9PZy7mwa+3U= github.com/abdfnx/looker v0.1.0/go.mod h1:QVfPHnredPBUg4R+MtEkZbMBbqrgtoaj0JHO3KYkvyE= github.com/abdfnx/resto v0.1.6 h1:yOM9O9bpMP4lb2ox0U7/gcFXO78P5eUZBxWuKrfdrFA= @@ -70,8 +70,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/botwayorg/gh v0.0.8 h1:szDJtlVxl2ZR0wIysi395tMEqQayI2LP9E3orDCX0go= -github.com/botwayorg/gh v0.0.8/go.mod h1:E3dTBPLt3L9wogY7e4QPHqUYHAbWrlNnumKgu9tcglA= +github.com/botwayorg/gh v0.0.9 h1:jHXglsDdAup+wNAhLvqeeXNILTR4DEL12gubyDcxEWs= +github.com/botwayorg/gh v0.0.9/go.mod h1:E3dTBPLt3L9wogY7e4QPHqUYHAbWrlNnumKgu9tcglA= github.com/botwayorg/git v0.0.0-20220813023031-a7a261511635 h1:AJLUr0Ef6avA5S2SXua7XG4yXI7vAjsZLBrZD5zCOk4= github.com/botwayorg/git v0.0.0-20220813023031-a7a261511635/go.mod h1:XdqqKSxdEZz88SByHfT4Vwpl/b9gQK9tjZ/FQuwrM0g= github.com/briandowns/spinner v1.11.1/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX3FScO+3/ZPQ= @@ -378,8 +378,8 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9 github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml/v2 v2.0.3 h1:h9JoA60e1dVEOpp0PFwJSmt1Htu057NUq9/bUwaO61s= -github.com/pelletier/go-toml/v2 v2.0.3/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= +github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg= +github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= @@ -589,8 +589,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c h1:JVAXQ10yGGVbSyoer5VILysz6YKjdNT2bsvlayjqhes= -golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY= +golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -670,8 +670,8 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 h1:Sx/u41w+OwrInGdEckYmEuU5gHoGSL4QbDz3S9s6j4U= -golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM= +golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 00000000..04015284 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,12 @@ +package config + +import ( + "github.com/abdfnx/botway/constants" + "github.com/tidwall/gjson" +) + +func Get(value string) string { + c := gjson.Get(string(constants.BotwayConfig), value) + + return c.String() +} diff --git a/internal/dashboard/bots.go b/internal/dashboard/bots.go index 0a1a6518..1a2a1fc2 100755 --- a/internal/dashboard/bots.go +++ b/internal/dashboard/bots.go @@ -25,6 +25,8 @@ func (b Bubble) botInfo(infoToGet string) string { if infoToGet == "token" { return gjson.Get(bot.String(), "bot_token").String() + } else if infoToGet == "name" { + return v } return gjson.Get(bot.String(), infoToGet).String() diff --git a/internal/dashboard/components/keymap/keymap.go b/internal/dashboard/components/keymap/keymap.go index ade10b5c..799593cf 100644 --- a/internal/dashboard/components/keymap/keymap.go +++ b/internal/dashboard/components/keymap/keymap.go @@ -3,17 +3,17 @@ package keymap import "github.com/charmbracelet/bubbles/key" type KeyMap struct { - Quit key.Binding - Down key.Binding - Up key.Binding - Left key.Binding - Right key.Binding - Esc key.Binding - SwapView key.Binding - OpenAtRailway key.Binding - PageDown key.Binding - PageUp key.Binding - New key.Binding + Quit key.Binding + Down key.Binding + Up key.Binding + Left key.Binding + Right key.Binding + Esc key.Binding + SwapView key.Binding + Open key.Binding + PageDown key.Binding + PageUp key.Binding + New key.Binding } func New() KeyMap { @@ -46,9 +46,9 @@ func New() KeyMap { key.WithKeys("tab"), key.WithHelp("tab", "select"), ), - OpenAtRailway: key.NewBinding( + Open: key.NewBinding( key.WithKeys("ctrl+o"), - key.WithHelp("ctrl+o", "Open bot project at Railway"), + key.WithHelp("ctrl+o", "Open bot project at Host Service"), ), PageDown: key.NewBinding( key.WithKeys("pgdown", " ", "f"), diff --git a/internal/dashboard/keyhandler.go b/internal/dashboard/keyhandler.go index 112a4da8..0b3e0f00 100644 --- a/internal/dashboard/keyhandler.go +++ b/internal/dashboard/keyhandler.go @@ -57,11 +57,17 @@ func (b *Bubble) handleKeys(msg tea.KeyMsg) tea.Cmd { b.switchActiveView(components.BotListView) } - // Open bot project at Railway - case key.Matches(msg, b.keyMap.OpenAtRailway): - bot_project_id := gjson.Get(string(constants.RailwayConfig), "projects."+strings.ToLower(b.botInfo("path"))+".project").String() + // Open bot project at Railway or Render + case key.Matches(msg, b.keyMap.Open): + if b.botInfo("host_service") == "railway.app" { + bot_project_id := gjson.Get(string(constants.RailwayConfig), "projects."+strings.ToLower(b.botInfo("path"))+".project").String() - OpenBrowser("https://railway.app/project/" + bot_project_id) + OpenBrowser("https://railway.app/project/" + bot_project_id) + } else if b.botInfo("host_service") == "render.com" { + bot_project_id := gjson.Get(string(constants.BotwayConfig), "render.projects."+b.botInfo("name")+".id").String() + + OpenBrowser("https://dashboard.render.com/web/" + bot_project_id) + } } return tea.Batch(cmds...) diff --git a/internal/dashboard/views.go b/internal/dashboard/views.go index d4d8a206..a4b3e536 100644 --- a/internal/dashboard/views.go +++ b/internal/dashboard/views.go @@ -7,6 +7,7 @@ import ( "path/filepath" "github.com/abdfnx/botway/constants" + "github.com/abdfnx/botway/internal/config" "github.com/abdfnx/botway/internal/dashboard/components/style" "github.com/abdfnx/botway/internal/dashboard/components/theme" "github.com/abdfnx/botway/internal/dashboard/icons" @@ -54,7 +55,6 @@ func (b Bubble) botListView() string { line := trunc(value.String(), b.bubbles.primaryPaginator.Width-2) - lang := gjson.Get(string(constants.BotwayConfig), "botway.bots."+v+".lang").String() if lang == "php" || lang == "crystal" { @@ -105,8 +105,6 @@ func (b Bubble) botInfoView() string { bType := drawKVColor("Bot Type", b.botInfo("type"), theme.AppTheme.Blue, b) - version := drawKV("Bot Version", bot_config.GetString("bot.version"), b) - lang := drawKVColor("Language", b.botInfo("lang"), theme.AppTheme.LightGray, b) bPath := trunc(b.botInfo("path"), (b.bubbles.secondaryViewport.Width*2/3)-3) @@ -131,7 +129,6 @@ func (b Bubble) botInfoView() string { return connectVert( styles(b).Render(""), bType, - version, "\n", lang, bPath, @@ -172,9 +169,8 @@ func (b Bubble) homeView() string { is_logged_in = drawKVColor("Is Logged In ?", "Yes", theme.AppTheme.Green, b) } - gh_username := drawKVColor("GitHub Username", "abdfnx", theme.AppTheme.LightGray, b) - docker_id := drawKVColor("Docker ID", "abdcodedoc", theme.AppTheme.Blue, b) - host := drawKV("Host", "abdfnx@railway.app", b) + gh_username := drawKVColor("GitHub Username", config.Get("github.username"), theme.AppTheme.LightGray, b) + docker_id := drawKVColor("Docker ID", config.Get("docker.id"), theme.AppTheme.Blue, b) total_bots := drawKV("Total Bots", fmt.Sprint(bots_count), b) style := lipgloss.NewStyle(). @@ -187,7 +183,6 @@ func (b Bubble) homeView() string { gh_username, docker_id, "\n", - host, is_logged_in, "\n", total_bots, @@ -199,7 +194,7 @@ func (b Bubble) helpView() string { b.drawHelpKV("up", "Move up"), b.drawHelpKV("down", "Move down"), b.drawHelpKV("tab", "Swap windows"), - b.drawHelpKV("ctrl+o", "Open bot project at Railway"), + b.drawHelpKV("ctrl+o", "Open bot project at Host Service"), b.drawHelpKV("esc", "Reset"), } diff --git a/internal/pipes/initx/init.go b/internal/pipes/initx/init.go index c2923421..83ae8c3b 100755 --- a/internal/pipes/initx/init.go +++ b/internal/pipes/initx/init.go @@ -28,6 +28,8 @@ func (m model) InitCmd() { viper.SetConfigType("json") viper.SetDefault("botway.bots", map[string]string{}) + viper.SetDefault("botway.settings.auto_sync", true) + viper.SetDefault("botway.settings.check_updates", true) viper.SetDefault("botway.bots_names", []string{}) viper.SetDefault("github.username", m.inputs[0].Value()) viper.SetDefault("docker.id", m.inputs[1].Value()) diff --git a/internal/pipes/new/config/add_bot_to_config.go b/internal/pipes/new/config/add_bot_to_config.go index 4de3bea6..2e808214 100755 --- a/internal/pipes/new/config/add_bot_to_config.go +++ b/internal/pipes/new/config/add_bot_to_config.go @@ -10,7 +10,7 @@ import ( "github.com/tidwall/sjson" ) -func AddBotToConfig(botName, botType, botPath, botLang string) { +func AddBotToConfig(botName, botType, botPath, botLang, hostService string) { homeDir, _ := dfs.GetHomeDirectory() botwayConfigPath := filepath.Join(homeDir, ".botway", "botway.json") botwayConfig, err := ioutil.ReadFile(botwayConfigPath) @@ -22,7 +22,8 @@ func AddBotToConfig(botName, botType, botPath, botLang string) { botTypeContent, _ := sjson.Set(string(botwayConfig), "botway.bots."+botName+".type", botType) botPathContent, _ := sjson.Set(botTypeContent, "botway.bots."+botName+".path", botPath) botLangContent, _ := sjson.Set(botPathContent, "botway.bots."+botName+".lang", botLang) - addBotToBotsNamesContent, _ := sjson.Set(botLangContent, "botway.bots_names.-1", botName) + botHostServiceContent, _ := sjson.Set(botLangContent, "botway.bots."+botName+".host_service", hostService) + addBotToBotsNamesContent, _ := sjson.Set(botHostServiceContent, "botway.bots_names.-1", botName) remove := os.Remove(botwayConfigPath) diff --git a/internal/pipes/new/create.go b/internal/pipes/new/create.go index 5b7336e8..a0f493c2 100644 --- a/internal/pipes/new/create.go +++ b/internal/pipes/new/create.go @@ -157,5 +157,5 @@ func NewBot(m model, l string, platform, lang int) { pwd = filepath.Join(pwd, opts.BotName) - config.AddBotToConfig(opts.BotName, BotType(m), pwd, BotLang(m)) + config.AddBotToConfig(opts.BotName, BotType(m), pwd, BotLang(m), HostService(m)) } diff --git a/packages/botwaygo b/packages/botwaygo index cb3bd549..63657ede 160000 --- a/packages/botwaygo +++ b/packages/botwaygo @@ -1 +1 @@ -Subproject commit cb3bd549542bb662d779c16f82fd2866fc2d1b51 +Subproject commit 63657edec3d20f2715c842b0b9864e6cf45cbf20