Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
format botway.json, add botway-c-config.json generator
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Aug 4, 2022
1 parent 916f3ba commit a73a33e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 20 deletions.
36 changes: 16 additions & 20 deletions botway.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
{
"version": "0.1.8",
"architecture": {
"32bit": {
"url": "https://github.com/abdfnx/botway/releases/download/v0.1.8/botway_windows_v0.1.8_386.zip",
"bin": [
"bin/botway.exe"
],
"hash": "1a4ecf64c5b6b6f07b35a7d6db4b82d92d11351e9ac872e43f2c46307494b39f"
},
"64bit": {
"url": "https://github.com/abdfnx/botway/releases/download/v0.1.8/botway_windows_v0.1.8_amd64.zip",
"bin": [
"bin/botway.exe"
],
"hash": "882bd7c26b369fc980f18e256c46a69ff58633c1a015edb27d9dd24573511884"
}
"version": "0.1.8",
"architecture": {
"32bit": {
"url": "https://github.com/abdfnx/botway/releases/download/v0.1.8/botway_windows_v0.1.8_386.zip",
"bin": ["bin/botway.exe"],
"hash": "1a4ecf64c5b6b6f07b35a7d6db4b82d92d11351e9ac872e43f2c46307494b39f"
},
"homepage": "https://botway.web.app",
"license": "MIT",
"description": "🤖 Generate, build, handle and deploy your own bot with your favorite language, for Discord, or Telegram, or Slack"
}
"64bit": {
"url": "https://github.com/abdfnx/botway/releases/download/v0.1.8/botway_windows_v0.1.8_amd64.zip",
"bin": ["bin/botway.exe"],
"hash": "882bd7c26b369fc980f18e256c46a69ff58633c1a015edb27d9dd24573511884"
}
},
"homepage": "https://botway.web.app",
"license": "MIT",
"description": "🤖 Generate, build, handle and deploy your own bot with your favorite language, for Discord, or Telegram, or Slack"
}
4 changes: 4 additions & 0 deletions internal/pipes/token/discord/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/abdfnx/botway/constants"
token_shared "github.com/abdfnx/botway/internal/pipes/token"
"github.com/abdfnx/botway/tools"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/tidwall/sjson"
Expand Down Expand Up @@ -45,6 +46,9 @@ func (m model) AddToken() {

fmt.Print(constants.SUCCESS_BACKGROUND.Render("SUCCESS"))
fmt.Println(constants.SUCCESS_FOREGROUND.Render(" " + m.botName + " Discord tokens're added successfully"))

tools.GenerateCConfig(m.inputs[0].Value())

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") + " 📁")
}

Expand Down
52 changes: 52 additions & 0 deletions tools/generate-c-config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package tools

import (
"errors"
"fmt"
"log"
"os"

"github.com/abdfnx/botway/constants"
"github.com/spf13/viper"
)

func GenerateCConfig(token string) {
viper.AddConfigPath(constants.BotwayDirPath())
viper.SetConfigName("botway-c-config")
viper.SetConfigType("json")

viper.SetDefault("logging.level", "trace")
viper.SetDefault("logging.filename", "bot.log")
viper.SetDefault("logging.quiet", false)
viper.SetDefault("logging.overwrite", true)
viper.SetDefault("logging.use_color", true)
viper.SetDefault("logging.http.enable", true)
viper.SetDefault("logging.http.filename", "http.log")
viper.SetDefault("logging.disable_modules", []string{"WEBSOCKETS", "USER_AGENT"})
viper.SetDefault("discord.token", token)
viper.SetDefault("discord.default_prefix.enable", true)

if err := viper.SafeWriteConfig(); err != nil {
if os.IsNotExist(err) {
err = viper.WriteConfig()

if err != nil {
log.Fatal(err)
}
}
}

if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
log.Fatal(err)
}
}

if _, err := os.Stat(constants.BotwayConfigFile); err == nil {
fmt.Print(constants.SUCCESS_BACKGROUND.Render("SUCCESS"))
fmt.Println(constants.SUCCESS_FOREGROUND.Render(" Botway C Config Initialization Successful"))
} else if errors.Is(err, os.ErrNotExist) {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" Botway C Config Initialization Failed, try again"))
}
}

0 comments on commit a73a33e

Please sign in to comment.