Archived
1

Bot administration functions for squads chats

Closes #11
Closes #15
This commit is contained in:
2017-11-26 06:48:13 +04:00
parent 130aabda81
commit fed4a52075
5 changed files with 196 additions and 2 deletions

View File

@@ -38,6 +38,19 @@ func (s *Squader) GetSquadByID(squadID int) (dbmapping.SquadChat, bool) {
return squadFull, true
}
// GetAvailableSquadChatsForUser returns squad chats which user can join
func (s *Squader) GetAvailableSquadChatsForUser(playerRaw *dbmapping.Player) ([]dbmapping.Chat, bool) {
groupChats := []dbmapping.Chat{}
err := c.Db.Select(&groupChats, c.Db.Rebind("SELECT ch.* FROM chats ch, squads s, squads_players sp WHERE (s.chat_id=ch.id OR s.flood_chat_id=ch.id) AND sp.player_id = ? AND s.id = sp.squad_id"), playerRaw.ID)
if err != nil {
c.Log.Error(err)
return groupChats, false
}
return groupChats, true
}
// GetAllSquadChats returns all main squad chats
func (s *Squader) GetAllSquadChats() ([]dbmapping.Chat, bool) {
groupChats := []dbmapping.Chat{}
@@ -51,6 +64,19 @@ func (s *Squader) GetAllSquadChats() ([]dbmapping.Chat, bool) {
return groupChats, true
}
// GetAllSquadFloodChats returns all flood squad chats
func (s *Squader) GetAllSquadFloodChats() ([]dbmapping.Chat, bool) {
groupChats := []dbmapping.Chat{}
err := c.Db.Select(&groupChats, "SELECT ch.* FROM chats ch, squads s WHERE s.flood_chat_id=ch.id")
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{}
@@ -78,3 +104,29 @@ func (s *Squader) GetUserRolesInSquads(playerRaw *dbmapping.Player) ([]dbmapping
return userRoles, true
}
// IsChatASquadEnabled checks group chat for restricting actions for squad
func (s *Squader) IsChatASquadEnabled(chatRaw *dbmapping.Chat) string {
mainChats, ok := s.GetAllSquadChats()
if !ok {
return "no"
}
floodChats, ok := s.GetAllSquadFloodChats()
if !ok {
return "no"
}
for i := range mainChats {
if *chatRaw == mainChats[i] {
return "main"
}
}
for i := range floodChats {
if *chatRaw == floodChats[i] {
return "flood"
}
}
return "no"
}