From 0eec26d4981cf3f9512fb13a0486b16b4da7692b Mon Sep 17 00:00:00 2001 From: Piero Date: Wed, 3 Apr 2019 11:43:45 -0400 Subject: [PATCH] fixes for reset and setchannel --- .gitignore | 2 ++ package-lock.json | 8 ++++++++ package.json | 3 ++- src/bot/commands/info.js | 2 +- src/db/interfaces/postgres/create.js | 2 ++ src/db/interfaces/postgres/update.js | 6 ++++++ test.js | 10 ---------- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 713d500..69f07f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules/ .env +src/miscellaneous/migratenicknames.js +test.js diff --git a/package-lock.json b/package-lock.json index 5d39e7d..2c870fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1727,6 +1727,14 @@ "signal-exit": "^3.0.2" } }, + "rethinkdbdash": { + "version": "2.3.31", + "resolved": "https://registry.npmjs.org/rethinkdbdash/-/rethinkdbdash-2.3.31.tgz", + "integrity": "sha512-6nXrKFjdg2Ug0YpdmPWSvyD/2EisHnFNt4FWZ74dcXGK48ievSv+cNFTmVv+KjLi6I9CCf6w4CKZ6yCYTfMfdQ==", + "requires": { + "bluebird": ">= 3.0.1" + } + }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", diff --git a/package.json b/package.json index 2fc586a..275d9c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loggerv3", - "version": "0.5.0", + "version": "3.0.5", "description": "Logger version 3, hopefully it was worth the wait!", "main": "index.js", "scripts": { @@ -30,6 +30,7 @@ "pg": "^7.8.0", "raven": "^2.6.4", "redis": "^2.8.0", + "rethinkdbdash": "^2.3.31", "standard": "^12.0.1", "superagent": "^4.0.0", "util": "^0.11.1" diff --git a/src/bot/commands/info.js b/src/bot/commands/info.js index 796e7e7..d0b49cb 100644 --- a/src/bot/commands/info.js +++ b/src/bot/commands/info.js @@ -21,7 +21,7 @@ module.exports = { 'fields': [ { 'name': 'Technical Details', - 'value': `${global.bot.user.username} is written in JavaScript utilizing the Node.js runtime. It uses the [eris](https://github.com/abalabahaha/eris) library to interact with the Discord API. RethinkDB and Redis are used.` + 'value': `${global.bot.user.username} is written in JavaScript utilizing the Node.js runtime. It uses the [eris](https://github.com/abalabahaha/eris) library to interact with the Discord API. PostgreSQL and Redis are used.` }, { 'name': 'The Author', diff --git a/src/db/interfaces/postgres/create.js b/src/db/interfaces/postgres/create.js index 6ae5267..3e8a753 100644 --- a/src/db/interfaces/postgres/create.js +++ b/src/db/interfaces/postgres/create.js @@ -1,5 +1,6 @@ const pool = require('../../clients/postgres') const aes = require('../../aes') +const cacheGuild = require('../../../bot/utils/cacheGuild') let arr = [] arr[0] = 'placeholder' arr = JSON.stringify(arr) @@ -35,6 +36,7 @@ async function createGuild (guild) { console.log(`Creating a guild document for guild ${guild.name} with ${guild.memberCount} members.`) try { await pool.query('INSERT INTO guilds (id, owner_id, ignored_channels, disabled_events, event_logs, log_bots) VALUES ($1, $2, $3, $4, $5, $6)', [guild.id, guild.ownerID, [], [], eventLogs, false]) // Regenerate the document if a user kicks and reinvites the bot. + await cacheGuild(guild.id) } catch (e) {} } diff --git a/src/db/interfaces/postgres/update.js b/src/db/interfaces/postgres/update.js index 4e8d8fc..c6629d5 100644 --- a/src/db/interfaces/postgres/update.js +++ b/src/db/interfaces/postgres/update.js @@ -2,6 +2,7 @@ const pool = require('../../clients/postgres') const getDoc = require('./read').getGuild const getMessageById = require('./read').getMessageById const getUser = require('./read').getUser +const cacheGuild = require('../../../bot/utils/cacheGuild') const aes = require('../../aes') const eventList = [ @@ -57,6 +58,7 @@ const eventLogs = { } async function clearEventLog (guildID) { + await cacheGuild(guildID) return await pool.query('UPDATE guilds SET event_logs=$1 WHERE id=$2', [eventLogs, guildID]) } @@ -68,6 +70,7 @@ async function clearEventByID (guildID, channelID) { eventLogs[event] = '' } }) + await cacheGuild(guildID) return await pool.query('UPDATE guilds SET event_logs=$1 WHERE id=$2', [eventLogs, guildID]) } @@ -76,6 +79,7 @@ async function setAllEventsOneId (guildID, channelID) { eventList.forEach(event => { doc.event_logs[event] = channelID }) + await cacheGuild(guildID) return await pool.query('UPDATE guilds SET event_logs=$1 WHERE id=$2', [doc.event_logs, guildID]) } @@ -84,6 +88,7 @@ async function setEventsLogId (guildID, channelID, events) { events.forEach(event => { doc.event_logs[event] = channelID }) + await cacheGuild(guildID) return await pool.query('UPDATE guilds SET event_logs=$1 WHERE id=$2', [doc.event_logs, guildID]) } @@ -97,6 +102,7 @@ async function disableEvent (guildID, event) { doc.disabled_events.push(event) } await pool.query('UPDATE guilds SET disabled_events=$1 WHERE id=$2', [doc.disabled_events, guildID]) + await cacheGuild(guildID) return disabled } diff --git a/test.js b/test.js index 979b8b4..e69de29 100644 --- a/test.js +++ b/test.js @@ -1,10 +0,0 @@ -const pool = require('./src/db/clients/postgres') -const getAllMessages = require('./src/db/interfaces/postgres/read').getAllMessages - -async function test () { - const messages = await getAllMessages() - const m = await messages[0] - console.log(new Date().getTime() - new Date(m.ts).getTime()) -} - -test()