Store global name and webhook status for puppets
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
const (
|
||||
puppetSelect = "SELECT id, name, name_set, avatar, avatar_url, avatar_set," +
|
||||
" contact_info_set, username, discriminator, is_bot, custom_mxid, access_token, next_batch" +
|
||||
" contact_info_set, global_name, username, discriminator, is_bot, is_webhook, custom_mxid, access_token, next_batch" +
|
||||
" FROM puppet "
|
||||
)
|
||||
|
||||
@@ -75,9 +75,11 @@ type Puppet struct {
|
||||
|
||||
ContactInfoSet bool
|
||||
|
||||
GlobalName string
|
||||
Username string
|
||||
Discriminator string
|
||||
IsBot bool
|
||||
IsWebhook bool
|
||||
|
||||
CustomMXID id.UserID
|
||||
AccessToken string
|
||||
@@ -89,7 +91,7 @@ func (p *Puppet) Scan(row dbutil.Scannable) *Puppet {
|
||||
var customMXID, accessToken, nextBatch sql.NullString
|
||||
|
||||
err := row.Scan(&p.ID, &p.Name, &p.NameSet, &p.Avatar, &avatarURL, &p.AvatarSet, &p.ContactInfoSet,
|
||||
&p.Username, &p.Discriminator, &p.IsBot, &customMXID, &accessToken, &nextBatch)
|
||||
&p.GlobalName, &p.Username, &p.Discriminator, &p.IsBot, &p.IsWebhook, &customMXID, &accessToken, &nextBatch)
|
||||
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
@@ -110,11 +112,16 @@ func (p *Puppet) Scan(row dbutil.Scannable) *Puppet {
|
||||
|
||||
func (p *Puppet) Insert() {
|
||||
query := `
|
||||
INSERT INTO puppet (id, name, name_set, avatar, avatar_url, avatar_set, contact_info_set, username, discriminator, is_bot, custom_mxid, access_token, next_batch)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
||||
INSERT INTO puppet (
|
||||
id, name, name_set, avatar, avatar_url, avatar_set, contact_info_set,
|
||||
global_name, username, discriminator, is_bot, is_webhook,
|
||||
custom_mxid, access_token, next_batch
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
|
||||
`
|
||||
_, err := p.db.Exec(query, p.ID, p.Name, p.NameSet, p.Avatar, p.AvatarURL.String(), p.AvatarSet, p.ContactInfoSet,
|
||||
p.Username, p.Discriminator, p.IsBot, strPtr(p.CustomMXID), strPtr(p.AccessToken), strPtr(p.NextBatch))
|
||||
p.GlobalName, p.Username, p.Discriminator, p.IsBot, p.IsWebhook,
|
||||
strPtr(p.CustomMXID), strPtr(p.AccessToken), strPtr(p.NextBatch))
|
||||
|
||||
if err != nil {
|
||||
p.log.Warnfln("Failed to insert %s: %v", p.ID, err)
|
||||
@@ -125,12 +132,17 @@ func (p *Puppet) Insert() {
|
||||
func (p *Puppet) Update() {
|
||||
query := `
|
||||
UPDATE puppet SET name=$1, name_set=$2, avatar=$3, avatar_url=$4, avatar_set=$5, contact_info_set=$6,
|
||||
username=$7, discriminator=$8, is_bot=$9, custom_mxid=$10, access_token=$11, next_batch=$12
|
||||
global_name=$7, username=$8, discriminator=$9, is_bot=$10, is_webhook=$11,
|
||||
custom_mxid=$12, access_token=$13, next_batch=$14
|
||||
WHERE id=$13
|
||||
`
|
||||
_, err := p.db.Exec(query, p.Name, p.NameSet, p.Avatar, p.AvatarURL.String(), p.AvatarSet, p.ContactInfoSet,
|
||||
p.Username, p.Discriminator, p.IsBot, strPtr(p.CustomMXID), strPtr(p.AccessToken), strPtr(p.NextBatch),
|
||||
p.ID)
|
||||
_, err := p.db.Exec(
|
||||
query,
|
||||
p.Name, p.NameSet, p.Avatar, p.AvatarURL.String(), p.AvatarSet, p.ContactInfoSet,
|
||||
p.GlobalName, p.Username, p.Discriminator, p.IsBot, p.IsWebhook,
|
||||
strPtr(p.CustomMXID), strPtr(p.AccessToken), strPtr(p.NextBatch),
|
||||
p.ID,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
p.log.Warnfln("Failed to update %s: %v", p.ID, err)
|
||||
|
||||
Reference in New Issue
Block a user