guild create functions
This commit is contained in:
parent
5ffce3ff95
commit
432caf5276
2 changed files with 24 additions and 0 deletions
|
@ -17,6 +17,7 @@ module.exports = class {
|
||||||
const data = {};
|
const data = {};
|
||||||
|
|
||||||
data.user = await this.client.db.getUser(message.author.id);
|
data.user = await this.client.db.getUser(message.author.id);
|
||||||
|
if (!data.user) data.user = await this.client.db.createUser(message.author.id);
|
||||||
|
|
||||||
// Prefix cache
|
// Prefix cache
|
||||||
if (this.client.prefixCache.has(message.author.id)) {
|
if (this.client.prefixCache.has(message.author.id)) {
|
||||||
|
@ -29,7 +30,11 @@ module.exports = class {
|
||||||
|
|
||||||
if (message.guild) {
|
if (message.guild) {
|
||||||
data.guild = await this.client.db.getGuild(message.guild.id);
|
data.guild = await this.client.db.getGuild(message.guild.id);
|
||||||
|
if (!data.guild) data.guild = await this.client.db.createGuild(message.guild.id);
|
||||||
|
|
||||||
// data.member = await this.client.db.getMember(message.guild.id, message.author.id);
|
// data.member = await this.client.db.getMember(message.guild.id, message.author.id);
|
||||||
|
// if (!data.member) data.member = await this.client.db.createMember(message.guild.id, message.author.id)
|
||||||
|
|
||||||
if (this.client.prefixCache.has(message.guild.id)) {
|
if (this.client.prefixCache.has(message.guild.id)) {
|
||||||
guildPrefix = this.client.prefixCache.get(message.guild.id);
|
guildPrefix = this.client.prefixCache.get(message.guild.id);
|
||||||
prefixes.push(guildPrefix);
|
prefixes.push(guildPrefix);
|
||||||
|
|
|
@ -105,16 +105,35 @@ class Database {
|
||||||
async deleteGuild (id) {
|
async deleteGuild (id) {
|
||||||
await this.pool.query('DELETE FROM guilds WHERE guild_id = $1;', [id]);
|
await this.pool.query('DELETE FROM guilds WHERE guild_id = $1;', [id]);
|
||||||
await this.pool.query('DELETE FROM members WHERE member_id LIKE $1;', [`${id}%`]);
|
await this.pool.query('DELETE FROM members WHERE member_id LIKE $1;', [`${id}%`]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteMember (guild_id, user_id) {
|
async deleteMember (guild_id, user_id) {
|
||||||
const key = guild_id + ':' + user_id;
|
const key = guild_id + ':' + user_id;
|
||||||
await this.pool.query('DELETE FROM members WHERE member_id = $1;', [key]);
|
await this.pool.query('DELETE FROM members WHERE member_id = $1;', [key]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteUser (id) {
|
async deleteUser (id) {
|
||||||
await this.pool.query('DELETE FROM users WHERE user_id = $1;', [id]);
|
await this.pool.query('DELETE FROM users WHERE user_id = $1;', [id]);
|
||||||
await this.pool.query('DELETE FROM members WHERE member_id LIKE $1;', [`${id}%`]);
|
await this.pool.query('DELETE FROM members WHERE member_id LIKE $1;', [`${id}%`]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async createGuild (id) {
|
||||||
|
const res = await this.pool.query('INSERT INTO guilds (guild_id) VALUES ($1) RETURNING *;', [id]);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
async createMember (guild_id, user_id) {
|
||||||
|
const key = guild_id + ':' + user_id;
|
||||||
|
const res = await this.pool.query('INSERT INTO members (member_id) VALUES ($1) RETURNING *;', [key]);
|
||||||
|
return res.rows[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
async createUser (id) {
|
||||||
|
const res = await this.pool.query('INSERT INTO users (user_id) VALUES ($1) RETURNING *;', [id]);
|
||||||
|
return res.rows[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue