Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thedmdim committed May 16, 2024
1 parent 72fcbff commit 8ea9756
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions cmd/tele/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"errors"
"fmt"
"log"
"os"
Expand All @@ -16,12 +15,6 @@ import (
"zombiezen.com/go/sqlite/sqlitex"
)

type Session struct {
MessageID int
Text string
Year int
}

const YouTubeFounded = 2006

const DefaultYear = 2006
Expand All @@ -46,16 +39,18 @@ func main() {
for u := range echotron.PollingUpdates(token) {

visitor := strconv.FormatInt(u.ChatID(), 10)


if u.Message != nil && u.Message.Text == "/start" {

conn := db.Get(context.Background())
sc := &handlers.SearchCriteria{
YearsFrom: strconv.Itoa(DefaultYear),
YearsTo: strconv.Itoa(DefaultYear),
}
conn := db.Get(context.Background())
video, err := handlers.TakeFirstUnseen(conn, visitor, sc)
db.Put(conn)

if err != nil {
log.Println("cannot take video:", err)
continue
Expand All @@ -75,10 +70,13 @@ func main() {
continue
}

conn = db.Get(context.Background())
err = handlers.RememberSeen(conn, visitor, video.ID)
db.Put(conn)
if err != nil {
log.Println("cannot remember seen: ", err)
}
continue
}

if u.CallbackQuery != nil && strings.HasPrefix(u.CallbackQuery.Data, "/random") {
Expand All @@ -89,11 +87,12 @@ func main() {
continue
}

conn := db.Get(context.Background())

sc := &handlers.SearchCriteria{
YearsFrom: strconv.Itoa(year),
YearsTo: strconv.Itoa(year),
}
conn := db.Get(context.Background())
video, err := handlers.TakeFirstUnseen(conn, visitor, sc)
db.Put(conn)
if err != nil {
Expand Down Expand Up @@ -121,11 +120,13 @@ func main() {
continue
}

conn = db.Get(context.Background())
err = handlers.RememberSeen(conn, visitor, video.ID)
db.Put(conn)
if err != nil {
log.Println("cannot remember seen: ", err)
}

continue
}


Expand All @@ -148,14 +149,12 @@ func main() {
fmt.Println("cannot set year:", err)
continue
}

continue
}

}
}

var ErrNoSession = errors.New("no session found")

func GetKeyboard(year int) echotron.InlineKeyboardMarkup {

firstRow := make([]echotron.InlineKeyboardButton, 0, 3)
Expand Down

0 comments on commit 8ea9756

Please sign in to comment.