2018-05-17 18:35:53 +03:00
|
|
|
package main
|
|
|
|
|
2018-05-24 18:08:48 +03:00
|
|
|
func getConnection(uid string) *Connection {
|
2018-05-17 18:35:53 +03:00
|
|
|
var connection Connection
|
|
|
|
orm.DB.First(&connection, "client_id = ?", uid)
|
|
|
|
|
2018-05-24 18:08:48 +03:00
|
|
|
return &connection
|
2018-05-17 18:35:53 +03:00
|
|
|
}
|
|
|
|
|
2018-05-24 18:08:48 +03:00
|
|
|
func getConnectionByURL(urlCrm string) *Connection {
|
2018-05-17 18:35:53 +03:00
|
|
|
var connection Connection
|
|
|
|
orm.DB.First(&connection, "api_url = ?", urlCrm)
|
|
|
|
|
2018-05-24 18:08:48 +03:00
|
|
|
return &connection
|
2018-05-17 18:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Connection) setConnectionActivity() error {
|
|
|
|
return orm.DB.Model(c).Where("client_id = ?", c.ClientID).Update("Active", c.Active).Error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Connection) createConnection() error {
|
|
|
|
return orm.DB.Create(c).Error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Connection) saveConnection() error {
|
|
|
|
return orm.DB.Model(c).Where("client_id = ?", c.ClientID).Update(c).Error
|
|
|
|
}
|
|
|
|
|
2018-05-28 18:16:13 +03:00
|
|
|
func (c *Connection) createBot(b Bot) error {
|
|
|
|
return orm.DB.Model(c).Association("Bots").Append(&b).Error
|
|
|
|
}
|
|
|
|
|
2018-05-24 18:08:48 +03:00
|
|
|
func getBotByToken(token string) *Bot {
|
2018-05-17 18:35:53 +03:00
|
|
|
var bot Bot
|
|
|
|
orm.DB.First(&bot, "token = ?", token)
|
|
|
|
|
2018-05-24 18:08:48 +03:00
|
|
|
return &bot
|
2018-05-17 18:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Bot) setBotActivity() error {
|
|
|
|
return orm.DB.Model(b).Where("token = ?", b.Token).Update("Active", !b.Active).Error
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBotChannelByToken(token string) uint64 {
|
|
|
|
var b Bot
|
|
|
|
orm.DB.First(&b, "token = ?", token)
|
|
|
|
|
|
|
|
return b.Channel
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Bots) getBotsByClientID(uid string) error {
|
2018-05-28 18:16:13 +03:00
|
|
|
var c Connection
|
|
|
|
return orm.DB.First(&c, "client_id = ?", uid).Association("Bots").Find(b).Error
|
|
|
|
}
|
|
|
|
|
|
|
|
func getConnectionById(id int) *Connection {
|
|
|
|
var connection Connection
|
|
|
|
orm.DB.First(&connection, "id = ?", id)
|
|
|
|
|
|
|
|
return &connection
|
2018-05-17 18:35:53 +03:00
|
|
|
}
|