Skip to content

Commit 5a84980

Browse files
committed
refactor(version): move version variable to a dedicated util package
feat(cli): persist auto-buy and pending offer/payment settings across logins feat(bot): persist auto-buy and pending offer/payment settings across logins refactor(cli): remove "Keluar" (Exit) option from menus to simplify navigation style(bot): update login message to "Proses login..." for clarity style(cli): update login message to "Proses login..." for clarity feat(cli): display application version in the title
1 parent 86f4dc1 commit 5a84980

6 files changed

Lines changed: 37 additions & 11 deletions

File tree

bot/login.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (h *Handler) handlePhoneInput(b *gotgbot.Bot, ctx *ext.Context, userID int6
2121
return replyErr
2222
}
2323

24-
_, _ = ctx.EffectiveMessage.Reply(b, fmt.Sprintf("📱 Login: +%s\n\n🔄 Membuka browser...", full), nil)
24+
_, _ = ctx.EffectiveMessage.Reply(b, fmt.Sprintf("📱 Login: +%s\n\n🔄 Proses login...", full), nil)
2525

2626
otpChan := make(chan string, 1)
2727
h.otpChansMu.Lock()
@@ -57,6 +57,15 @@ func (h *Handler) handlePhoneInput(b *gotgbot.Bot, ctx *ext.Context, userID int6
5757
return replyErr
5858
}
5959

60+
existing := h.sessions.Get(userID)
61+
if existing != nil {
62+
session.AutoBuyInterval = existing.AutoBuyInterval
63+
session.AutoBuyPackage = existing.AutoBuyPackage
64+
session.AutoBuyPayment = existing.AutoBuyPayment
65+
session.AutoBuyActive = existing.AutoBuyActive
66+
session.PendingOfferID = existing.PendingOfferID
67+
session.PendingPayment = existing.PendingPayment
68+
}
6069
h.sessions.Set(userID, session)
6170

6271
profile, profileErr := h.api.GetFullProfile(context.Background(), session)

cli/menus.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ func (m tuiModel) selectMenu(selected string) (tea.Model, tea.Cmd) {
7979
m.message = "✓ Sudah logout."
8080
m.cursor = 0
8181
return m, nil
82-
case "Keluar":
83-
return m, tea.Quit
8482
}
8583
return m, nil
8684
}
@@ -97,7 +95,7 @@ func (m tuiModel) updateLogin(msg tea.Msg) (tea.Model, tea.Cmd) {
9795
}
9896
m.loginPhone = local
9997
m.screen = screenLoading
100-
m.loading = "Membuka browser untuk login..."
98+
m.loading = "Proses login..."
10199
return m, m.doLogin(local)
102100
}
103101
}
@@ -385,9 +383,9 @@ func (m tuiModel) updateSchedulePayment(msg tea.Msg) (tea.Model, tea.Cmd) {
385383

386384
func (m tuiModel) getMenuItems() []string {
387385
if m.loggedInUser != nil {
388-
return []string{"Cek Profil", "Cek Kuota", "Beli Paket", "Schedule Auto-Buy", "Logout", "Keluar"}
386+
return []string{"Cek Profil", "Cek Kuota", "Beli Paket", "Schedule Auto-Buy", "Logout"}
389387
}
390-
return []string{"Login", "Keluar"}
388+
return []string{"Login"}
391389
}
392390

393391
func (m tuiModel) viewMenu() string {

cli/update.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ func (m tuiModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6363
if m.loggedInID == 0 {
6464
m.loggedInID = 1
6565
}
66+
67+
existing := m.sessions.Get(m.loggedInID)
68+
if existing != nil {
69+
msg.session.AutoBuyInterval = existing.AutoBuyInterval
70+
msg.session.AutoBuyPackage = existing.AutoBuyPackage
71+
msg.session.AutoBuyPayment = existing.AutoBuyPayment
72+
msg.session.AutoBuyActive = existing.AutoBuyActive
73+
msg.session.PendingOfferID = existing.PendingOfferID
74+
msg.session.PendingPayment = existing.PendingPayment
75+
}
76+
6677
m.sessions.Set(m.loggedInID, msg.session)
6778
m.loggedInUser = msg.session
6879
m.screen = screenMenu

cli/views.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/makiuchi-d/gozxing"
1414
"github.com/makiuchi-d/gozxing/qrcode"
1515
qrterminal "github.com/mdp/qrterminal/v3"
16+
"telkomsel-bot/util"
1617
)
1718

1819
var (
@@ -55,7 +56,7 @@ var (
5556
func (m tuiModel) View() string {
5657
var b strings.Builder
5758

58-
b.WriteString(titleStyle.Render("Telbot"))
59+
b.WriteString(titleStyle.Render("Telbot", util.GetVersion()))
5960
b.WriteString("\n")
6061

6162
switch m.screen {

main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import (
1515
"telkomsel-bot/config"
1616
"telkomsel-bot/mcp"
1717
"telkomsel-bot/model"
18+
"telkomsel-bot/util"
1819
)
1920

20-
var version = "dev"
21-
2221
func main() {
2322
log.SetFlags(log.LstdFlags | log.Lshortfile)
2423

@@ -37,7 +36,7 @@ func main() {
3736
case "--mcp":
3837
mcp.Run()
3938
case "--version", "-v":
40-
fmt.Printf("telbot %s\n", version)
39+
fmt.Printf("telbot %s\n", util.GetVersion())
4140
case "--help", "-h":
4241
printHelp()
4342
default:
@@ -49,7 +48,7 @@ func main() {
4948

5049
func printHelp() {
5150
fmt.Println("╔══════════════════════════════════╗")
52-
fmt.Printf("║ Telbot %-17s║\n", version)
51+
fmt.Printf("║ Telbot %-17s║\n", util.GetVersion())
5352
fmt.Println("╚══════════════════════════════════╝")
5453
fmt.Println()
5554
fmt.Println("Usage:")

util/version.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package util
2+
3+
var version = "dev"
4+
5+
func GetVersion() string {
6+
return version
7+
}
8+

0 commit comments

Comments
 (0)