Skip to content

Commit

Permalink
now botway supports twitch bots, update client packages
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Sep 27, 2022
1 parent 539d5e5 commit 73d31cf
Show file tree
Hide file tree
Showing 26 changed files with 440 additions and 158 deletions.
5 changes: 5 additions & 0 deletions cmd/app/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/abdfnx/botway/internal/pipes/token/discord/guilds"
slack_token "github.com/abdfnx/botway/internal/pipes/token/slack"
telegram_token "github.com/abdfnx/botway/internal/pipes/token/telegram"
twitch_token "github.com/abdfnx/botway/internal/pipes/token/twitch"
"github.com/spf13/cobra"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
Expand All @@ -36,6 +37,7 @@ func TokenSetCMD() *cobra.Command {
Discord: false,
Slack: false,
Telegram: false,
Twitch: false,
}

cmd := &cobra.Command{
Expand All @@ -50,6 +52,8 @@ func TokenSetCMD() *cobra.Command {
slack_token.BotwaySlackTokenSetup(args[0])
} else if opts.Telegram {
telegram_token.BotwayTelegramTokenSetup(args[0])
} else if opts.Twitch {
twitch_token.BotwayTwitchTokenSetup(args[0])
} else {
fmt.Println("Bot Type is not found")
}
Expand All @@ -62,6 +66,7 @@ func TokenSetCMD() *cobra.Command {
cmd.Flags().BoolVarP(&opts.Discord, "discord", "d", false, "For discord bot tokens")
cmd.Flags().BoolVarP(&opts.Slack, "slack", "s", false, "For slack bot tokens")
cmd.Flags().BoolVarP(&opts.Telegram, "telegram", "t", false, "For telegram bot tokens")
cmd.Flags().BoolVarP(&opts.Twitch, "twitch", "w", false, "For twitch bot tokens")

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/botway/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var opts = options.RootOptions{
}

func Execute(f *factory.Factory, version string, buildDate string) *cobra.Command {
const desc = `🤖 Generate, build, handle and deploy your own bot with your favorite language, for Discord, or Telegram, or Slack`
const desc = `🤖 Generate, build, handle and deploy your own bot with your favorite language, for Discord, or Telegram, or Slack, or even Twitch`

// Root command
var rootCmd = &cobra.Command{
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module github.com/abdfnx/botway

go 1.18
go 1.19

require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/MakeNowJust/heredoc v1.0.0
github.com/abdfnx/botwaygo v0.1.1
github.com/abdfnx/botwaygo v0.1.2
github.com/abdfnx/looker v0.1.0
github.com/abdfnx/resto v0.1.6
github.com/abdfnx/tran v0.1.43
github.com/botwayorg/get-latest v0.1.4
github.com/botwayorg/gh v0.0.9
github.com/botwayorg/git v0.0.0-20220813023031-a7a261511635
github.com/botwayorg/railway-api v0.0.5
github.com/botwayorg/templates v0.0.2
github.com/botwayorg/templates v0.0.4
github.com/briandowns/spinner v1.19.0
github.com/charmbracelet/bubbles v0.14.0
github.com/charmbracelet/bubbletea v0.22.1
Expand All @@ -29,7 +29,7 @@ require (
github.com/spf13/viper v1.13.0
github.com/tidwall/gjson v1.14.3
github.com/tidwall/sjson v1.2.5
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25
golang.org/x/term v0.0.0-20220919170432-7a66f970e087
)

Expand Down Expand Up @@ -61,7 +61,7 @@ require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/itchyny/gojq v0.12.9 // indirect
github.com/itchyny/timefmt-go v0.1.4 // indirect
github.com/jedib0t/go-pretty/v6 v6.3.8 // indirect
github.com/jedib0t/go-pretty/v6 v6.3.9 // indirect
github.com/joho/godotenv v1.4.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
Expand Down Expand Up @@ -96,9 +96,9 @@ require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 // indirect
github.com/yuin/goldmark v1.4.15 // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect
golang.org/x/net v0.0.0-20220926192436-02166a98028e // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
41 changes: 12 additions & 29 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/dashboard/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (b Bubble) homeView() string {
PaddingLeft(2)

return connectVert(
style.Render("\n🤖 Generate, build, handle and deploy your own bot with your\nfavorite language, for Discord, or Telegram, or Slack.\n\n"),
style.Render("\n🤖 Generate, build, handle and deploy your own bot with your\nfavorite language, for Discord, or Telegram, or Slack, or even Twitch\n\n"),
gh_username,
docker_id,
"\n",
Expand Down
1 change: 1 addition & 0 deletions internal/options/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type TokenAddOptions struct {
Discord bool
Slack bool
Telegram bool
Twitch bool
}

type LoginOptions struct {
Expand Down
33 changes: 21 additions & 12 deletions internal/pipes/initx/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,41 @@ func DockerInit() {
viper.SetConfigType("json")

botType := botwaygo.GetBotInfo("bot.type")
bot_token := ""
app_token := ""
signing_secret := "SLACK_SIGNING_SECRET"
field1 := ""
field2 := ""
field3 := ""
cid := ""
secret_value := ""

if botType == "discord" {
bot_token = "DISCORD_TOKEN"
app_token = "DISCORD_CLIENT_ID"
field1 = "DISCORD_TOKEN"
field2 = "DISCORD_CLIENT_ID"
cid = "bot_app_id"
} else if botType == "slack" {
bot_token = "SLACK_TOKEN"
app_token = "SLACK_APP_TOKEN"
field1 = "SLACK_TOKEN"
field2 = "SLACK_APP_TOKEN"
field3 = "SLACK_SIGNING_SECRET"
cid = "bot_app_token"
secret_value = "signing_secret"
} else if botType == "telegram" {
bot_token = "TELEGRAM_TOKEN"
field1 = "TELEGRAM_TOKEN"
} else if botType == "twitch" {
field1 = "TWITCH_OAUTH_TOKEN"
field2 = "TWITCH_CLIENT_ID"
field3 = "TWITCH_CLIENT_SECRET"
cid = "bot_client_id"
secret_value = "bot_client_secret"
}

viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+".bot_token", os.Getenv(bot_token))
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+".bot_token", os.Getenv(field1))
viper.SetDefault("botway.bots_names", []string{botwaygo.GetBotInfo("bot.name")})

if botType != "telegram" {
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+"."+cid, os.Getenv(app_token))
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+"."+cid, os.Getenv(field2))
}

if botType == "slack" {
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+".signing_secret", os.Getenv(signing_secret))
if botType == "slack" || botType == "twitch" {
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+"."+secret_value, os.Getenv(field3))
}

if botType == "discord" {
Expand Down
34 changes: 23 additions & 11 deletions internal/pipes/new/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func updatePlatforms(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
switch msg.String() {
case "j", "down":
m.PlatformChoice += 1
if m.PlatformChoice > 2 {
m.PlatformChoice = 2
if m.PlatformChoice > 3 {
m.PlatformChoice = 3
}

case "k", "up":
Expand Down Expand Up @@ -67,14 +67,18 @@ func updateLangs(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
if m.LangChoice > 2 {
m.LangChoice = 2
}
} else {
if m.PlatformChoice == 0 {
if m.LangChoice > 15 {
m.LangChoice = 15
}
} else if m.PlatformChoice == 3 {
if m.LangChoice > 5 {
m.LangChoice = 5
} else {
if m.LangChoice > 14 {
m.LangChoice = 14
if m.PlatformChoice == 0 {
if m.LangChoice > 15 {
m.LangChoice = 15
}
} else {
if m.LangChoice > 14 {
m.LangChoice = 14
}
}
}
}
Expand Down Expand Up @@ -154,9 +158,17 @@ func buildBot(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
} else if m.LangChoice == 2 || m.LangChoice == 3 || m.LangChoice == 6 {
l = "Node"
} else if m.LangChoice == 4 {
l = "Ruby"
if m.PlatformChoice == 3 {
l = "Node"
} else {
l = "Ruby"
}
} else if m.LangChoice == 5 {
l = "Rust"
if m.PlatformChoice == 3 {
l = "Java"
} else {
l = "Rust"
}
} else if m.LangChoice == 7 {
l = "C#"
} else if m.LangChoice == 8 {
Expand Down
1 change: 1 addition & 0 deletions internal/pipes/new/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func NewBot(m model, l string, platform, lang int) {
DiscordHandler(m)
TelegramHandler(m)
SlackHandler(m)
TwitchHandler(m)
} else {
dockerFile := os.WriteFile(filepath.Join(opts.BotName, "Dockerfile"), []byte(DockerfileContent(opts.BotName, HostServiceName(m))), 0644)

Expand Down
35 changes: 29 additions & 6 deletions internal/pipes/new/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ func BotType(m model) string {
return "telegram"
} else if m.PlatformChoice == 2 {
return "slack"
} else if m.PlatformChoice == 3 {
return "twitch"
}

return "# You need to specify a platform (discord, telegram, slack)"
return "# You need to specify a platform (discord, telegram, slack, twitch)"
}

var blankLangMessage = "# You need to specify a language (python, go, nodejs, nodejs (typescript) ruby, rust, deno, csharp, dart, php, kotlin, java, crystal, c++, nim, c)"
Expand All @@ -74,9 +76,17 @@ func BotLang(m model) string {
} else if m.LangChoice == 3 {
return "typescript"
} else if m.LangChoice == 4 {
return "ruby"
if m.PlatformChoice == 3 {
return "deno"
} else {
return "ruby"
}
} else if m.LangChoice == 5 {
return "rust"
if m.PlatformChoice == 3 {
return "java"
} else {
return "rust"
}
} else if m.LangChoice == 6 {
return "deno"
} else if m.LangChoice == 7 {
Expand Down Expand Up @@ -108,6 +118,7 @@ func BotLang(m model) string {

func BotStartCmd(m model) string {
nodeCmd := BotPM(m) + " src/main."
denoCmd := "deno run --allow-all main.ts"

if m.LangChoice == 0 && m.PMChoice == 0 {
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -138,11 +149,23 @@ func BotStartCmd(m model) string {
} else if m.LangChoice == 3 {
return nodeCmd + ".js"
} else if m.LangChoice == 4 {
return "bundle exec ruby src/main.rb"
if m.PlatformChoice == 3 {
return denoCmd
} else {
return "bundle exec ruby src/main.rb"
}
} else if m.LangChoice == 5 {
return "cargo run src/main.rs"
if m.PlatformChoice == 3 {
if runtime.GOOS == "windows" {
return `.\gradlew.bat run`
} else {
return "./gradlew run"
}
} else {
return "cargo run src/main.rs"
}
} else if m.LangChoice == 6 {
return "deno run --allow-all main.ts"
return denoCmd
} else if m.LangChoice == 7 {
return "dotnet run"
} else if m.LangChoice == 8 {
Expand Down
35 changes: 35 additions & 0 deletions internal/pipes/new/twitch-handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package new

import "github.com/botwayorg/templates"

func TwitchHandler(m model) {
if m.PlatformChoice == 3 && m.LangChoice == 0 && m.PMChoice == 0 {
templates.PythonTemplate(opts.BotName, "twitch", "pip", HostServiceName(m))
} else if m.PlatformChoice == 3 && m.LangChoice == 0 && m.PMChoice == 1 {
templates.PythonTemplate(opts.BotName, "twitch", "pipenv", HostServiceName(m))
} else if m.PlatformChoice == 3 && m.LangChoice == 0 && m.PMChoice == 2 {
templates.PythonTemplate(opts.BotName, "twitch", "poetry", HostServiceName(m))
} else if m.PlatformChoice == 3 && m.LangChoice == 1 {
templates.GoTemplate(opts.BotName, "twitch", HostServiceName(m))
} else if m.PlatformChoice == 3 && m.LangChoice == 2 && m.PMChoice == 0 {
templates.NodejsTemplate(opts.BotName, "npm", "twitch", HostServiceName(m), false)
} else if m.PlatformChoice == 3 && m.LangChoice == 2 && m.PMChoice == 1 {
templates.NodejsTemplate(opts.BotName, "yarn", "twitch", HostServiceName(m), false)
} else if m.PlatformChoice == 3 && m.LangChoice == 2 && m.PMChoice == 2 {
templates.NodejsTemplate(opts.BotName, "pnpm", "twitch", HostServiceName(m), false)
} else if m.PlatformChoice == 3 && m.LangChoice == 2 && m.PMChoice == 3 {
templates.NodejsTemplate(opts.BotName, "bun", "twitch", HostServiceName(m), false)
} else if m.PlatformChoice == 3 && m.LangChoice == 3 && m.PMChoice == 0 {
templates.NodejsTemplate(opts.BotName, "npm", "twitch", HostServiceName(m), true)
} else if m.PlatformChoice == 3 && m.LangChoice == 3 && m.PMChoice == 1 {
templates.NodejsTemplate(opts.BotName, "yarn", "twitch", HostServiceName(m), true)
} else if m.PlatformChoice == 3 && m.LangChoice == 3 && m.PMChoice == 2 {
templates.NodejsTemplate(opts.BotName, "pnpm", "twitch", HostServiceName(m), true)
} else if m.PlatformChoice == 3 && m.LangChoice == 3 && m.PMChoice == 3 {
templates.NodejsTemplate(opts.BotName, "bun", "twitch", HostServiceName(m), true)
} else if m.PlatformChoice == 3 && m.LangChoice == 4 {
templates.DenoTemplate(opts.BotName, "twitch", HostServiceName(m))
} else if m.PlatformChoice == 3 && m.LangChoice == 5 {
templates.JavaTemplate(opts.BotName, "twitch", HostServiceName(m))
}
}
Loading

0 comments on commit 73d31cf

Please sign in to comment.