Skip to content

Commit e5a3f81

Browse files
committed
sync works
1 parent d4db8ad commit e5a3f81

5 files changed

Lines changed: 42 additions & 24 deletions

File tree

source/database/pool/devs.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ const Pool = require('pg').Pool
22

33
global.pool = new Pool({
44
connectionString: process.env.DEVS_PG,
5-
connectionTimeoutMillis: 5000,
6-
idleTimeoutMillis: 10000,
7-
max: 10
85
})
96

10-
global.pool.on('drain', global.pool.end.bind(client));
7+
global.pool.on('drain', global.pool.end.bind(global.pool));
118

129
module.exports = global.pool

source/database/pool/prod.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ const Pool = require('pg').Pool
22

33
global.pool = new Pool({
44
connectionString: process.env.PROD_PG,
5-
connectionTimeoutMillis: 5000,
6-
idleTimeoutMillis: 10000,
7-
max: 10
85
})
96

10-
11-
global.pool.on('drain', global.pool.end.bind(client));
7+
global.pool.on('drain', global.pool.end.bind(global.pool));
128

139
module.exports = global.pool
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
module.exports = async ({ userId, userName, cmdBlacklist }) => {
2-
const query = {
3-
text: 'INSERT INTO enfinityUser(userId, userName, cmdBlacklist) VALUES ($1, $2, $3)',
4-
values: [userId, userName, cmdBlacklist]
5-
}
1+
module.exports = async ({ userId, globalName, displayName, cmdBlacklist }) => {
2+
const count = await global.pool.query({
3+
text: 'SELECT COUNT(*) FROM enfinityUser WHERE userId = $1',
4+
values: [userId]
5+
})
66

7-
await global.pool.query(query)
7+
if(count?.rows[0]?.count != 0) {
8+
console.log(`EnfinityUser: row found, updating: ${JSON.stringify(count.rows)}`)
9+
10+
await global.pool.query({
11+
text: 'UPDATE enfinityUser SET globalName = $1, cmd_blacklist = $2 WHERE userId = $3',
12+
values: [globalName, cmdBlacklist, userId]
13+
})
14+
15+
} else {
16+
const query = {
17+
text: 'INSERT INTO enfinityUser (userId, globalName, displayName, cmd_blacklist) VALUES ($1, $2, $3, $4)',
18+
values: [userId, globalName, displayName, cmdBlacklist]
19+
}
20+
21+
await global.pool.query(query)
22+
}
823
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
module.exports = async ({ userId }) => {
2-
await global.pool.query(`SELECT * FROM enfinityUser WHERE userId='${userId}'`)
2+
const res = await global.pool.query({
3+
text: 'SELECT * FROM enfinityUser WHERE userId = $1',
4+
values: [userId],
5+
})
6+
7+
if(res?.rows?.length == 0) {
8+
return null
9+
}
10+
11+
return res.rows[0]
312
}

source/enfinity/slash/Users/sync.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = {
1010
userId: enfinity.interaction.user.id
1111
})
1212

13-
if (!user) {
1413
await enfinity.interaction.reply({
1514
embeds: [
1615
new enfinity.Gateway.EmbedBuilder()
@@ -26,12 +25,13 @@ module.exports = {
2625
]
2726
})
2827

28+
if (!user) {
2929
await enfinity.db.enfinityUser
3030
.upsert({
3131
userId: `${enfinity.interaction.user.id}`,
3232
globalName: `${enfinity.interaction.user.globalName}`,
3333
displayName: `${enfinity.interaction.user.displayName}`,
34-
cmd_blacklist: false
34+
cmdBlacklist: false
3535
})
3636
.then(async () => {
3737
await enfinity.interaction.editReply({
@@ -88,7 +88,7 @@ module.exports = {
8888
})
8989
}, 8000)
9090
})
91-
} else if (user) {
91+
} else {
9292
await enfinity.interaction.editReply({
9393
embeds: [
9494
new enfinity.Gateway.EmbedBuilder()
@@ -106,12 +106,13 @@ module.exports = {
106106

107107
await enfinity.db.enfinityUser
108108
.upsert({
109-
userId: enfinity.interaction.user.id,
110-
globalName: enfinity.interaction.user.globalName,
111-
displayName: enfinity.interaction.user.displayName,
112-
cmd_blacklist: user.cmd_blacklist
109+
userId: `${enfinity.interaction.user.id}`,
110+
globalName: `${enfinity.interaction.user.globalName}`,
111+
displayName: `${enfinity.interaction.user.displayName}`,
112+
cmdBlacklist: false
113113
})
114-
.then(async () => {
114+
115+
.then(async () => {
115116
await enfinity.interaction.editReply({
116117
embeds: [
117118
new enfinity.Gateway.EmbedBuilder()

0 commit comments

Comments
 (0)