Skip to content

Commit

Permalink
update slack and telegram templates, start building guilds.json
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed May 11, 2022
1 parent 219046b commit 9f0db10
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docker/full.dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM frolvlad/alpine-glibc:alpine-3.14_glibc-2.33

### variables ###
ENV PKGS="zip unzip git curl npm rust libsodium ffmpeg cargo build-base build-dependencies abuild binutils opus autoconf automake libtool m4 youtube-dl binutils-doc gcc-doc python3-dev neofetch zsh sudo make lsof wget gcc asciidoctor ca-certificates bash-completion htop jq less llvm nano vim ruby-full ruby-dev libffi-dev"
ENV PKGS="zip unzip git curl npm rust libsodium ffmpeg cargo build-base abuild binutils opus autoconf automake libtool m4 youtube-dl binutils-doc gcc-doc python3-dev neofetch zsh sudo make lsof wget gcc asciidoctor ca-certificates bash-completion htop jq less llvm nano vim ruby-full ruby-dev libffi-dev"
ENV ZSHRC=".zshrc"

### install packages ###
Expand Down
50 changes: 44 additions & 6 deletions internal/pipes/initx/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ import (
"github.com/gookit/config/v2"
"github.com/gookit/config/v2/yaml"
"github.com/spf13/viper"
"github.com/tidwall/gjson"
)

func GetBotName() string {
botwayConfigPath := filepath.Join(".botway.yaml")
var (
c = config.New(".")
)

c := config.New(".")
func GetBotName() string {
c.AddDriver(yaml.Driver)
c.LoadFiles(botwayConfigPath)
c.LoadFiles(".botway.yaml")

return c.String("bot.name")
}

func GetBotType() string {
c.AddDriver(yaml.Driver)
c.LoadFiles(".botway.yaml")

return c.String("bot.type")
}

func DockerInit() {
err := dfs.CreateDirectory(filepath.Join(constants.HomeDir, ".botway"))

Expand All @@ -34,8 +43,37 @@ func DockerInit() {
viper.SetConfigName("botway")
viper.SetConfigType("json")

viper.SetDefault("botway.bots." + GetBotName() + ".discord_token", os.Getenv("DISCORD_TOKEN"))
viper.SetDefault("botway.bots." + GetBotName() + ".discord_client_id", os.Getenv("DISCORD_CLIENT_ID"))
t := GetBotType()
bot_token := ""
app_token := ""
cid := ""

if t == "discord" {
bot_token = "DISCORD_TOKEN"
app_token = "DISCORD_CLIENT_ID"
cid = "bot_app_id"
} else if t == "slack" {
bot_token = "SLACK_TOKEN"
app_token = "SLACK_APP_TOKEN"
cid = "bot_app_token"
} else if t == "telegram" {
bot_token = "TELEGRAM_TOKEN"
}

viper.SetDefault("botway.bots." + GetBotName() + ".bot_token", os.Getenv(bot_token))

if t != "telegram" {
viper.SetDefault("botway.bots." + GetBotName() + "." + cid, os.Getenv(app_token))
}

if t == "discord" {
// viper.Set("botway.bots." + GetBotName() + ".guilds." + m.inputs[1].Value() + ".server_id", m.inputs[2].Value())
guilds := gjson.Get(string(constants.BotConfig), "guilds.#")

for x := 0; x < int(guilds.Int()); x++ {

}
}

if err := viper.SafeWriteConfig(); err != nil {
if os.IsNotExist(err) {
Expand Down
8 changes: 8 additions & 0 deletions internal/pipes/new/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ func buildBot(msg tea.Msg, m model, botName string) (tea.Model, tea.Cmd) {
viper.SetDefault("docker.cmds.build", "docker build -t " + dockerImage + " .")
viper.SetDefault("docker.cmds.run", "docker run -it " + dockerImage)

if m.PlatformChoice == 0 {
guildsFile := os.WriteFile(filepath.Join(opts.BotName, "guilds.json"), []byte("{}"), 0644)

if guildsFile != nil {
panic(guildsFile)
}
}

if err := viper.SafeWriteConfig(); err != nil {
if os.IsNotExist(err) {
err = viper.WriteConfig()
Expand Down
23 changes: 23 additions & 0 deletions internal/pipes/token/discord/guilds/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"

"github.com/abdfnx/botway/constants"
Expand Down Expand Up @@ -47,6 +48,28 @@ func (m model) AddGuildId() {
panic(newBotwayConfig)
}

bot_path := gjson.Get(string(botwayConfig), "botway.bots." + m.inputs[0].Value() + ".path").String()
guildsPath := filepath.Join(bot_path, "guilds.json")
guildsFile, err := ioutil.ReadFile(guildsPath)

if err != nil {
panic(err)
}

addGuild, _ := sjson.Set(string(guildsFile), "guilds.-1", m.inputs[1].Value())

removeOldGuilds := os.Remove(guildsPath)

if removeOldGuilds != nil {
panic(removeOldGuilds)
}

newGuilds := os.WriteFile(guildsPath, []byte(addGuild), 0644)

if newGuilds != nil {
panic(newGuilds)
}

fmt.Print(constants.SUCCESS_BACKGROUND.Render("SUCCESS"))
fmt.Println(constants.SUCCESS_FOREGROUND.Render(" " + m.inputs[1].Value() + " server id is added successfully"))
fmt.Println(constants.SUCCESS_FOREGROUND.Render("You can add more server ids by running the same command again"))
Expand Down
2 changes: 1 addition & 1 deletion internal/pipes/token/discord/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (m model) AddToken() {

fmt.Print(constants.SUCCESS_BACKGROUND.Render("SUCCESS"))
fmt.Println(constants.SUCCESS_FOREGROUND.Render(" " + m.botName + " Discord tokens're added successfully"))
fmt.Println(constants.SUCCESS_FOREGROUND.Render("You can add the guild ids of your discord server via the command") + token_shared.BoldStyle.Render(" " + "botway tokens add-guilds"))
fmt.Println(constants.SUCCESS_FOREGROUND.Render("You can add the guild ids of your discord server via the command") + token_shared.BoldStyle.Render(" " + "botway tokens add-guilds") + " 馃搧")
// fmt.Println("Your Secret key -> " + token_shared.BoldStyle.Render(token_shared.UserSecret) + " Keep it in a safe place")
}

Expand Down
2 changes: 1 addition & 1 deletion templates/slack/go/assets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${SLACK_BOT_NAME}
RUN botway init --docker
RUN go mod tidy
RUN go build src/main.go -o ${SLACK_BOT_NAME}

Expand Down
2 changes: 1 addition & 1 deletion templates/slack/nodejs/assets/npm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${SLACK_BOT_NAME}
RUN botway init --docker
RUN npm i --production

EXPOSE 8000
Expand Down
2 changes: 1 addition & 1 deletion templates/slack/nodejs/assets/pnpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${SLACK_BOT_NAME}
RUN botway init --docker
RUN curl -fsSL https://get.pnpm.io/install.sh | PNPM_VERSION=7.0.0 sh -

RUN pnpm fetch --prod
Expand Down
2 changes: 1 addition & 1 deletion templates/slack/nodejs/assets/yarn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${SLACK_BOT_NAME}
RUN botway init --docker
RUN yarn

EXPOSE 8000
Expand Down
2 changes: 1 addition & 1 deletion templates/slack/python/assets/pip/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY . .
RUN apk update && \
apk add --no-cache --virtual build-dependencies build-base gcc abuild binutils python3-dev libffi-dev git

RUN botway init --docker --name ${SLACK_BOT_NAME}
RUN botway init --docker
RUN pip3 install -r requirements.txt

# Add packages you want
Expand Down
2 changes: 1 addition & 1 deletion templates/slack/python/assets/pipenv/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY . .
RUN apk update && \
apk add --no-cache --virtual build-dependencies build-base gcc abuild binutils binutils-doc gcc-doc python3-dev libffi-dev git

RUN botway init --docker --name ${SLACK_BOT_NAME}
RUN botway init --docker
RUN curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
RUN pipenv sync --system

Expand Down
2 changes: 1 addition & 1 deletion templates/slack/ruby/assets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN gem update --system
RUN gem install bundler
RUN bundle install
Expand Down
2 changes: 1 addition & 1 deletion templates/telegram/go/assets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN go mod tidy
RUN go build src/main.go -o ${TELEGRAM_BOT_NAME}

Expand Down
2 changes: 1 addition & 1 deletion templates/telegram/nodejs/assets/npm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN npm i --production

EXPOSE 8000
Expand Down
2 changes: 1 addition & 1 deletion templates/telegram/nodejs/assets/pnpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN curl -fsSL https://get.pnpm.io/install.sh | PNPM_VERSION=7.0.0 sh -

RUN pnpm fetch --prod
Expand Down
2 changes: 1 addition & 1 deletion templates/telegram/nodejs/assets/yarn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN yarn

EXPOSE 8000
Expand Down
2 changes: 1 addition & 1 deletion templates/telegram/python/assets/pip/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COPY . .
RUN apk update && \
apk add --no-cache --virtual build-dependencies build-base gcc abuild binutils binutils-doc gcc-doc python3-dev libffi-dev git

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN pip3 install -r requirements.txt

# Add packages you want
Expand Down
2 changes: 1 addition & 1 deletion templates/telegram/python/assets/pipenv/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
RUN pipenv sync --system

Expand Down
2 changes: 1 addition & 1 deletion templates/telegram/ruby/assets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN gem update --system
RUN gem install bundler
RUN bundle install
Expand Down
2 changes: 1 addition & 1 deletion templates/telegram/rust/assets/cargo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN cargo build --release
RUN cp ./target/release/${TELEGRAM_BOT_NAME} .

Expand Down
2 changes: 1 addition & 1 deletion templates/telegram/rust/assets/fleet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apk update && \
# Add packages you want
# RUN apk add PACKAGE_NAME

RUN botway init --docker --name ${TELEGRAM_BOT_NAME}
RUN botway init --docker
RUN curl -L get.fleet.rs | sh
RUN fleet build --release
RUN cp ./target/release/${TELEGRAM_BOT_NAME} .
Expand Down

0 comments on commit 9f0db10

Please sign in to comment.