Skip to content

Commit

Permalink
update default path to be in user home page
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed May 9, 2024
1 parent b27622d commit 64e78bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ var rootCmd = &cobra.Command{
}

if db == "" {
defaultPath, err := os.Getwd()
defaultPath, err := os.UserHomeDir()
if err != nil {
log.Fatal().Err(err).Send()
}
db = filepath.Join(defaultPath, "db")
db = filepath.Join(defaultPath, ".statusbot")
}

bot, err := internal.NewBot(token, time, timezone, db)
Expand Down
13 changes: 2 additions & 11 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,11 @@ func (db *DB) Save() error {
return err
}

err = os.WriteFile(db.path, file, 0777)
if err != nil {
return err
}

return nil
return os.WriteFile(db.path, file, 0777)
}

func (db *DB) Get(key int64) ChatInfo {
val, ok := db.chatsIDs[key]
if !ok {
return ChatInfo{}
}
return val
return db.chatsIDs[key]
}

func (db *DB) Update(key int64, value ChatInfo) {
Expand Down

0 comments on commit 64e78bb

Please sign in to comment.