From 287bb6b379833a10a1eca80a5fbe52422e345c76 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Wed, 8 Nov 2017 17:29:50 +0100 Subject: [PATCH] Managing sessions functionality --- sessions.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sessions.go b/sessions.go index dad67ab..a0ff861 100644 --- a/sessions.go +++ b/sessions.go @@ -8,3 +8,23 @@ type Session struct { Chat *tgbotapi.Chat Msgbox chan tgbotapi.Message } + +var sessions map[int64]*Session + +func initSessions() { + sessions = make(map[int64]*Session) +} + +func getSession(chat *tgbotapi.Chat) *Session { + session, ok := sessions[chat.ID] + if !ok { + session = newSession(chat) + } + return session +} + +func newSession(chat *tgbotapi.Chat) *Session { + session := Session{chat, make(chan tgbotapi.Message)} + sessions[chat.ID] = &session + return &session +} -- 2.39.5