Archived
1

Some work on ordering. Special user behaviour

See #10
This commit is contained in:
2017-11-26 15:28:55 +04:00
parent 8368a3c60b
commit 53a99b0ff3
20 changed files with 466 additions and 16 deletions

View File

@@ -5,6 +5,8 @@ package squader
import (
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
"strconv"
"strings"
)
// GetSquadByID returns squad will all support information
@@ -77,6 +79,43 @@ func (s *Squader) GetAllSquadFloodChats() ([]dbmapping.Chat, bool) {
return groupChats, true
}
// GetSquadChatsBySquadsIDs returns main squad chats for given squads IDs
func (s *Squader) GetSquadChatsBySquadsIDs(squadsIDs string) ([]dbmapping.Chat, bool) {
groupChats := []dbmapping.Chat{}
squadsIDsArray := strings.Split(squadsIDs, ",")
if len(squadsIDsArray) < 1 {
return groupChats, false
}
sIDs := make([]int, 0)
for i := range squadsIDsArray {
sID, _ := strconv.Atoi(squadsIDsArray[i])
if sID != 0 {
sIDs = append(sIDs, sID)
}
}
if len(sIDs) < 1 {
return groupChats, false
}
queryLine := ""
for i := range sIDs {
queryLine += strconv.Itoa(sIDs[i])
if i < len(sIDs)-1 {
queryLine += ","
}
}
err := c.Db.Select(&groupChats, "SELECT ch.* FROM chats ch, squads s WHERE s.chat_id=ch.id AND s.id IN ("+queryLine+")")
if err != nil {
c.Log.Error(err)
return groupChats, false
}
return groupChats, true
}
// GetUserRolesInSquads lists all user roles
func (s *Squader) GetUserRolesInSquads(playerRaw *dbmapping.Player) ([]dbmapping.SquadPlayerFull, bool) {
userRoles := []dbmapping.SquadPlayerFull{}

View File

@@ -16,6 +16,7 @@ type SquaderInterface interface {
GetAllSquadFloodChats() ([]dbmapping.Chat, bool)
GetAvailableSquadChatsForUser(playerRaw *dbmapping.Player) ([]dbmapping.Chat, bool)
GetSquadByID(squadID int) (dbmapping.SquadChat, bool)
GetSquadChatsBySquadsIDs(squadsID string) ([]dbmapping.Chat, bool)
GetUserRolesInSquads(playerRaw *dbmapping.Player) ([]dbmapping.SquadPlayerFull, bool)
IsChatASquadEnabled(chatRaw *dbmapping.Chat) string