Archived
1

/send_all feature for administrators

This commit is contained in:
2017-10-22 14:04:14 +04:00
parent 88c9853c77
commit 7975ea54c1
7 changed files with 95 additions and 4 deletions

View File

@@ -54,3 +54,16 @@ func (g *Getters) GetOrCreateChat(telegramUpdate *tgbotapi.Update) (dbmapping.Ch
return chatRaw, true
}
// GetAllPrivateChats returns all private chats
func (g *Getters) GetAllPrivateChats() ([]dbmapping.Chat, bool) {
privateChats := []dbmapping.Chat{}
err := c.Db.Select(&privateChats, "SELECT * FROM chats WHERE chat_type='private'")
if err != nil {
log.Println(err)
return privateChats, false
}
return privateChats, true
}

View File

@@ -15,8 +15,10 @@ type GettersInterface interface {
Init()
GetOrCreateChat(update *tgbotapi.Update) (dbmapping.Chat, bool)
GetChatByID(chatID int) (dbmapping.Chat, bool)
GetAllPrivateChats() ([]dbmapping.Chat, bool)
GetOrCreatePlayer(telegramID int) (dbmapping.Player, bool)
GetPlayerByID(playerID int) (dbmapping.Player, bool)
PlayerBetterThan(playerRaw *dbmapping.Player, powerLevel string) bool
GetProfile(playerID int) (dbmapping.Profile, bool)
GetPokememes() ([]dbmapping.PokememeFull, bool)
GetBestPokememes(playerID int) ([]dbmapping.PokememeFull, bool)

View File

@@ -50,3 +50,21 @@ func (g *Getters) GetOrCreatePlayer(telegramID int) (dbmapping.Player, bool) {
return playerRaw, true
}
// PlayerBetterThan return true, if profile is more or equal powerful than
// provided power level
func (g *Getters) PlayerBetterThan(playerRaw *dbmapping.Player, powerLevel string) bool {
var isBetter = false
switch playerRaw.Status {
case "owner":
isBetter = true
case "admin":
if powerLevel != "owner" {
isBetter = true
}
default:
isBetter = false
}
return isBetter
}