refactor: move constants to new package
This commit is contained in:
parent
e4c2088363
commit
afaa155b51
6 changed files with 21 additions and 14 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/atotto/clipboard"
|
||||
"github.com/ayn2op/discordo/config"
|
||||
"github.com/ayn2op/discordo/internal/constants"
|
||||
"github.com/diamondburned/arikawa/v3/api"
|
||||
"github.com/diamondburned/arikawa/v3/discord"
|
||||
"github.com/diamondburned/arikawa/v3/utils/json/option"
|
||||
|
|
@ -112,7 +113,7 @@ func (mi *MessageInput) launchEditorAction() {
|
|||
e = os.Getenv("EDITOR")
|
||||
}
|
||||
|
||||
f, err := os.CreateTemp("", config.Name+"-*.md")
|
||||
f, err := os.CreateTemp("", constants.TmpFilePattern)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ package run
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
|
||||
"github.com/ayn2op/discordo/config"
|
||||
"github.com/ayn2op/discordo/internal/constants"
|
||||
"github.com/diamondburned/arikawa/v3/api"
|
||||
"github.com/diamondburned/arikawa/v3/gateway"
|
||||
"github.com/diamondburned/arikawa/v3/state"
|
||||
|
|
@ -15,10 +14,10 @@ import (
|
|||
)
|
||||
|
||||
func init() {
|
||||
api.UserAgent = fmt.Sprintf("%s/0.1 (https://github.com/diamondburned/arikawa, v3)", config.Name)
|
||||
api.UserAgent = constants.UserAgent
|
||||
gateway.DefaultIdentity = gateway.IdentifyProperties{
|
||||
OS: runtime.GOOS,
|
||||
Browser: config.Name,
|
||||
Browser: constants.Name,
|
||||
Device: "",
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ayn2op/discordo/internal/constants"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const Name = "discordo"
|
||||
|
||||
var Current = defConfig()
|
||||
|
||||
type Config struct {
|
||||
|
|
@ -71,10 +70,10 @@ func Load(path string) error {
|
|||
|
||||
func DefaultPath() string {
|
||||
path, _ := os.UserConfigDir()
|
||||
return filepath.Join(path, Name, "config.yml")
|
||||
return filepath.Join(path, constants.Name, "config.yml")
|
||||
}
|
||||
|
||||
func DefaultLogPath() string {
|
||||
path, _ := os.UserCacheDir()
|
||||
return filepath.Join(path, Name, "logs.txt")
|
||||
return filepath.Join(path, constants.Name, "logs.txt")
|
||||
}
|
||||
|
|
|
|||
7
internal/constants/constants.go
Normal file
7
internal/constants/constants.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package constants
|
||||
|
||||
const Name = "discordo"
|
||||
|
||||
const UserAgent = Name + "/0.1 (https://github.com/diamondburned/arikawa, v3)"
|
||||
|
||||
const TmpFilePattern = Name + "_*.md"
|
||||
4
main.go
4
main.go
|
|
@ -5,12 +5,12 @@ import (
|
|||
"log"
|
||||
|
||||
"github.com/ayn2op/discordo/cmd/run"
|
||||
"github.com/ayn2op/discordo/config"
|
||||
"github.com/ayn2op/discordo/internal/constants"
|
||||
"github.com/zalando/go-keyring"
|
||||
)
|
||||
|
||||
func main() {
|
||||
t, _ := keyring.Get(config.Name, "token")
|
||||
t, _ := keyring.Get(constants.Name, "token")
|
||||
token := flag.String("token", t, "The authentication token.")
|
||||
flag.Parse()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
|
||||
"github.com/ayn2op/discordo/config"
|
||||
"github.com/ayn2op/discordo/internal/constants"
|
||||
"github.com/diamondburned/arikawa/v3/api"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
|
|
@ -20,7 +21,7 @@ func NewLoginForm() *LoginForm {
|
|||
lf := &LoginForm{
|
||||
Form: tview.NewForm(),
|
||||
Token: make(chan string, 1),
|
||||
Error: make(chan error, 0),
|
||||
Error: make(chan error),
|
||||
}
|
||||
|
||||
lf.AddInputField("Email", "", 0, nil, nil)
|
||||
|
|
@ -72,13 +73,13 @@ func (lf *LoginForm) onLoginButtonSelected() {
|
|||
}
|
||||
|
||||
if lr.Token == "" {
|
||||
lf.Error <- errors.New("Token is missing")
|
||||
lf.Error <- errors.New("token is missing")
|
||||
return
|
||||
}
|
||||
|
||||
rememberMe := lf.GetFormItem(3).(*tview.Checkbox).IsChecked()
|
||||
if rememberMe {
|
||||
go keyring.Set(config.Name, "token", lr.Token)
|
||||
go keyring.Set(constants.Name, "token", lr.Token)
|
||||
}
|
||||
|
||||
lf.Token <- lr.Token
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue