Archived
1

Pins to selected chats

Closes #6
This commit is contained in:
2017-11-26 08:31:56 +04:00
parent a6811f61fc
commit 8368a3c60b
7 changed files with 120 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ type ChatterInterface interface {
GetAllPrivateChats() ([]dbmapping.Chat, bool)
GetLeaguePrivateChats() ([]dbmapping.Chat, bool)
GetAllGroupChats() ([]dbmapping.Chat, bool)
GetGroupChatsByIDs(chatsIDs string) ([]dbmapping.Chat, bool)
UpdateChatTitle(chatRaw *dbmapping.Chat, newTitle string) (*dbmapping.Chat, bool)
UpdateChatTelegramID(update *tgbotapi.Update) (*dbmapping.Chat, bool)

View File

@@ -6,6 +6,8 @@ package chatter
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
"strconv"
"strings"
"time"
)
@@ -140,3 +142,34 @@ func (ct *Chatter) GetAllGroupChats() ([]dbmapping.Chat, bool) {
return groupChats, true
}
// GetGroupChatsByIDs returns group chats with selected IDs
func (ct *Chatter) GetGroupChatsByIDs(chatsIDs string) ([]dbmapping.Chat, bool) {
groupChats := []dbmapping.Chat{}
queryIDs := make([]int, 0)
queryIDsStr := strings.Split(chatsIDs, ",")
for i := range queryIDsStr {
id, _ := strconv.Atoi(queryIDsStr[i])
if id != 0 {
queryIDs = append(queryIDs, id)
}
}
finalQueryIDs := ""
for i := range queryIDs {
finalQueryIDs += strconv.Itoa(queryIDs[i])
if i < len(queryIDs)-1 {
finalQueryIDs += ","
}
}
c.Log.Debug("Chat query IDs: " + finalQueryIDs)
err := c.Db.Select(&groupChats, "SELECT * FROM chats WHERE chat_type IN ('group', 'supergroup') AND id IN ("+finalQueryIDs+")")
if err != nil {
c.Log.Error(err)
return groupChats, false
}
return groupChats, true
}