Skip to content

Commit

Permalink
kram
Browse files Browse the repository at this point in the history
  • Loading branch information
kubegu committed Aug 13, 2023
1 parent fc11def commit 43c9927
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 23 additions & 8 deletions bot/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import (
"strconv"
"strings"

"github.com/gunni1/leipzig-library-game-stock-api/domain"
libClient "github.com/gunni1/leipzig-library-game-stock-api/library-le"
tele "gopkg.in/telebot.v3"
)

type BotCommand struct {
Prefix string
Description string
}

// Listet alle Videospiele einer bestimmten Platform die aktuell in einer Zweigstelle Ausleihbar sind.
func ListBranchPlattformCommand(ctx tele.Context) error {
client := libClient.Client{}
Expand All @@ -19,22 +25,31 @@ func ListBranchPlattformCommand(ctx tele.Context) error {

games := client.FindAvailabelGames(branchCode, platform)
//TODO: func zum Umwandeln der Games-Liste in den Ergebnistext. Berücksichtigen, wenn Ergebniss leer ist!
var replyBuilder strings.Builder
//replyBuilder.WriteString(fmt.Sprintf("Spiele für %s in %s:\n", platform, libClient.BranchCodes[branchCode]))
for _, game := range games {
replyBuilder.WriteString(game.Title)
replyBuilder.WriteString("\n")

}
return ctx.Send(replyBuilder.String())
//replyBuilder.WriteString(fmt.Sprintf("Spiele für %s in %s:\n", platform, libClient.BranchCodes[branchCode]))
reply := formatReply(games)
return ctx.Send(reply)
}

func WelcomeCommand(ctx tele.Context) error {
var replyBuilder strings.Builder

replyBuilder.WriteString("Hi")
return ctx.Send(replyBuilder.String())
}

// Erzeugt eine formatierte Ausgabe einer Liste von Titeln oder eine entsprechene Rückgabe bei leerer Liste.
func formatReply(games []domain.Game) string {
if len(games) == 0 {
return "Es wurden keine ausleihbaren Titel gefunden."
}
var replyBuilder strings.Builder
for _, game := range games {
replyBuilder.WriteString(game.Title)
replyBuilder.WriteString("\n")
}
return replyBuilder.String()
}

// Holt aus den Command-Args die Platform und die Zweigstelle, oder liefert einen Fehlertext.
func parsePlatformAndBranch(args []string) (string, int, error) {
if len(args) < 2 {
Expand Down
2 changes: 2 additions & 0 deletions cmd/bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func main() {
return
}

//welcomeCommand := command.BotCommand{Prefix: "/start", Description: "Zeigt die Liste aller Bot-Funktionen an."}

bot.Handle("/start", command.WelcomeCommand)
bot.Handle("/list", command.ListBranchPlattformCommand)

Expand Down

0 comments on commit 43c9927

Please sign in to comment.