add pre group one bot setting
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// LineBot -
|
||||
type LineBot struct {
|
||||
ID string `db:"id" cc:"id"`
|
||||
Name string `db:"name" cc:"name"`
|
||||
AccessToken string `db:"access_token" cc:"access_token"`
|
||||
Secret string `db:"secret" cc:"secret"`
|
||||
Ctime time.Time `db:"ctime" cc:"ctime"`
|
||||
Mtime time.Time `db:"mtime" cc:"mtime"`
|
||||
}
|
||||
|
||||
// GetBotInfo -
|
||||
func GetBotInfo(id string) (bot *LineBot, err error) {
|
||||
if len(id) == 0 {
|
||||
return nil, errors.New("id is emptu")
|
||||
}
|
||||
|
||||
query := `select
|
||||
"id", "name", "access_token", "secret", "ctime", "mtime"
|
||||
from public."line_bot"
|
||||
where
|
||||
"id" = $1`
|
||||
bot = &LineBot{}
|
||||
err = x.Get(bot, query, id)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
+23
-6
@@ -2,17 +2,19 @@ package model
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// LineGroup - struct
|
||||
type LineGroup struct {
|
||||
ID string `db:"id" cc:"id"`
|
||||
Name string `db:"name" cc:"name"`
|
||||
Notify bool `db:"notify" cc:"notify"`
|
||||
Owner string `db:"owner" cc:"owner"`
|
||||
Ctime time.Time `db:"ctime" cc:"ctime"`
|
||||
Mtime time.Time `db:"mtime" cc:"ctime"`
|
||||
ID string `db:"id" cc:"id"`
|
||||
Name string `db:"name" cc:"name"`
|
||||
Notify bool `db:"notify" cc:"notify"`
|
||||
Owner string `db:"owner" cc:"owner"`
|
||||
Ctime time.Time `db:"ctime" cc:"ctime"`
|
||||
Mtime time.Time `db:"mtime" cc:"ctime"`
|
||||
BotID sql.NullString `db:"bot_id" cc:"bot_id"`
|
||||
}
|
||||
|
||||
// CheckGroup -
|
||||
@@ -75,3 +77,18 @@ func (p *LineGroup) DeleteGroup() (err error) {
|
||||
_, err = x.Exec(`delete from "public"."line_group" where "id" = $1`, p.ID)
|
||||
return
|
||||
}
|
||||
|
||||
// GetBot - get group binding bot
|
||||
func (p *LineGroup) GetBot() (bot *LineBot, err error) {
|
||||
id, err := p.BotID.Value()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var botid string
|
||||
var ok bool
|
||||
if botid, ok = id.(string); !ok {
|
||||
return nil, errors.New("botid get fail")
|
||||
}
|
||||
bot, err = GetBotInfo(botid)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user