From: Javier Sancho Date: Wed, 8 Nov 2017 16:29:50 +0000 (+0100) Subject: Managing sessions functionality X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=287bb6b379833a10a1eca80a5fbe52422e345c76;p=midgaard_bot.git Managing sessions functionality --- 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 +}