mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-09-03 07:35:17 +00:00
added error handling for db methods
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
const { logError } = require('../utils/log');
|
||||||
|
|
||||||
const Datastore = require('nedb-promise');
|
const Datastore = require('nedb-promise');
|
||||||
|
|
||||||
const Admin = new Datastore({
|
const Admin = new Datastore({
|
||||||
@@ -16,13 +19,15 @@ const admin = user =>
|
|||||||
Admin.insert({
|
Admin.insert({
|
||||||
first_name: user.first_name,
|
first_name: user.first_name,
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
});
|
})
|
||||||
|
.catch(logError(process.env.DEBUG));
|
||||||
|
|
||||||
const allAdmins = () =>
|
const allAdmins = () =>
|
||||||
Admin.find({});
|
Admin.find({});
|
||||||
|
|
||||||
const unadmin = user =>
|
const unadmin = user =>
|
||||||
Admin.remove({ user_id: user.id });
|
Admin.remove({ user_id: user.id })
|
||||||
|
.catch(logError(process.env.DEBUG));
|
||||||
|
|
||||||
const isAdmin = user =>
|
const isAdmin = user =>
|
||||||
Admin.findOne({ user_id: user.id });
|
Admin.findOne({ user_id: user.id });
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
const { logError } = require('../utils/log');
|
||||||
|
|
||||||
const Datastore = require('nedb-promise');
|
const Datastore = require('nedb-promise');
|
||||||
|
|
||||||
const Ban = new Datastore({
|
const Ban = new Datastore({
|
||||||
@@ -13,10 +16,12 @@ Ban.ensureIndex({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const ban = (user, reason) =>
|
const ban = (user, reason) =>
|
||||||
Ban.insert({ reason, user_id: user.id });
|
Ban.insert({ reason, user_id: user.id })
|
||||||
|
.catch(logError(process.env.DEBUG));
|
||||||
|
|
||||||
const unban = user =>
|
const unban = user =>
|
||||||
Ban.remove({ user_id: user.id });
|
Ban.remove({ user_id: user.id })
|
||||||
|
.catch(logError(process.env.DEBUG));
|
||||||
|
|
||||||
const isBanned = user =>
|
const isBanned = user =>
|
||||||
Ban.findOne({ user_id: user.id }).then(bannedUser =>
|
Ban.findOne({ user_id: user.id }).then(bannedUser =>
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
const { logError } = require('../utils/log');
|
||||||
|
|
||||||
const Datastore = require('nedb-promise');
|
const Datastore = require('nedb-promise');
|
||||||
|
|
||||||
const groups = new Datastore({
|
const groups = new Datastore({
|
||||||
@@ -13,7 +16,8 @@ groups.ensureIndex({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const addGroup = group =>
|
const addGroup = group =>
|
||||||
groups.insert(group);
|
groups.insert(group)
|
||||||
|
.catch(logError(process.env.DEBUG));
|
||||||
|
|
||||||
const listGroups = () =>
|
const listGroups = () =>
|
||||||
groups.find({});
|
groups.find({});
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
const { logError } = require('../utils/log');
|
||||||
|
|
||||||
const Datastore = require('nedb-promise');
|
const Datastore = require('nedb-promise');
|
||||||
|
|
||||||
const User = new Datastore({
|
const User = new Datastore({
|
||||||
@@ -13,7 +16,8 @@ User.ensureIndex({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const addUser = ({ id, first_name = '', last_name = '', username = '' }) =>
|
const addUser = ({ id, first_name = '', last_name = '', username = '' }) =>
|
||||||
User.insert({ first_name, id, last_name, username });
|
User.insert({ first_name, id, last_name, username })
|
||||||
|
.catch(logError(process.env.DEBUG));
|
||||||
|
|
||||||
const isUser = ({ id }) =>
|
const isUser = ({ id }) =>
|
||||||
User.findOne({ id });
|
User.findOne({ id });
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
const { logError } = require('../utils/log');
|
||||||
|
|
||||||
const Datastore = require('nedb-promise');
|
const Datastore = require('nedb-promise');
|
||||||
|
|
||||||
const Warn = new Datastore({
|
const Warn = new Datastore({
|
||||||
@@ -21,7 +24,8 @@ const warn = (user, reason) =>
|
|||||||
Warn.update(
|
Warn.update(
|
||||||
{ user_id: loadedUser.user_id },
|
{ user_id: loadedUser.user_id },
|
||||||
{ $push: { reasons: reason } })
|
{ $push: { reasons: reason } })
|
||||||
.then(() => loadedUser.reasons.length + 1));
|
.then(() => loadedUser.reasons.length + 1))
|
||||||
|
.catch(logError(process.env.DEBUG));
|
||||||
|
|
||||||
const unwarn = user =>
|
const unwarn = user =>
|
||||||
Warn.findOne({ user_id: user.id })
|
Warn.findOne({ user_id: user.id })
|
||||||
@@ -30,15 +34,16 @@ const unwarn = user =>
|
|||||||
lastWarn && Warn.update(
|
lastWarn && Warn.update(
|
||||||
{ user_id: user.id },
|
{ user_id: user.id },
|
||||||
{ $pop: { reasons: 1 } })
|
{ $pop: { reasons: 1 } })
|
||||||
.then(() => lastWarn));
|
.then(() => lastWarn))
|
||||||
|
.catch(logError(process.env.DEBUG));
|
||||||
|
|
||||||
const nowarns = user =>
|
const nowarns = user =>
|
||||||
Warn.findOne({ user_id: user.id })
|
Warn.findOne({ user_id: user.id })
|
||||||
.then(isUser => isUser && Warn.update(
|
.then(isUser => isUser && Warn.update(
|
||||||
{ user_id: user.id },
|
{ user_id: user.id },
|
||||||
{ $set: { reasons: [] } })
|
{ $set: { reasons: [] } })
|
||||||
.then(updatedUser => updatedUser)
|
.then(updatedUser => updatedUser))
|
||||||
);
|
.catch(logError(process.env.DEBUG));
|
||||||
|
|
||||||
const getWarns = user =>
|
const getWarns = user =>
|
||||||
Warn.findOne({ user_id: user.id })
|
Warn.findOne({ user_id: user.id })
|
||||||
|
Reference in New Issue
Block a user