Skip to content

Commit

Permalink
refactor NewBot
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Nov 12, 2023
1 parent cc1b285 commit ebfed7b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Execute() {

func init() {
cobra.OnInitialize()
rootCmd.Flags().StringP("bot token", "b", "", "Enter a valid telegram bot token")
rootCmd.Flags().StringP("bot-token", "b", "", "Enter a valid telegram bot token")
rootCmd.Flags().StringP("time", "t", "17:00", "Enter a valid time")
rootCmd.Flags().StringP("timezone", "z", "Africa/Cairo", "Enter a valid timezone")
}
5 changes: 3 additions & 2 deletions internal/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Bot struct {
}

// NewBot creates new bot with a valid bot api and communication channels
func NewBot(token string, t string, timezone string) (Bot, error) {
func NewBot(token string, inputTime string, timezone string) (Bot, error) {
bot := Bot{}

botAPI, err := tgbotapi.NewBotAPI(token)
Expand All @@ -33,7 +33,8 @@ func NewBot(token string, t string, timezone string) (Bot, error) {
return bot, err
}

parsedTime, err := time.ParseInLocation("02 Jan 06 15:04", time.Now().Format("02 Jan 06 ")+t, loc)
inputTime = time.Now().Format("02 Jan 06 ") + inputTime
parsedTime, err := time.ParseInLocation("02 Jan 06 15:04", inputTime, loc)
if err != nil {
return bot, err
}
Expand Down

0 comments on commit ebfed7b

Please sign in to comment.