2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-22 18:08:51 +00:00
2020-05-26 13:23:54 +02:00

52 lines
950 B
JavaScript

'use strict';
const Datastore = require('nedb-promise');
const Group = new Datastore({
autoload: true,
filename: 'data/Group.db',
});
Group.ensureIndex({
fieldName: 'id',
unique: true,
});
const addGroup = group =>
Group.update({ id: group.id }, group, { upsert: true });
const hideGroup = ({ id }) =>
Group.update({ id }, { $set: { link: '' } });
const updateGroup = group =>
Group.update({ id: group.id }, { $set: group });
const listGroups = (query = {}) =>
Group.find(query);
const listVisibleGroups = () =>
Group.find({ $not: { link: '' } });
const managesGroup = group =>
Group.findOne(group);
const migrateGroup = (oldId, newId) =>
Group.update(
{ id: oldId, type: 'group' },
{ $set: { id: newId, type: 'supergroup' } },
);
const removeGroup = ({ id }) =>
Group.remove({ id });
module.exports = {
addGroup,
hideGroup,
listGroups,
listVisibleGroups,
managesGroup,
migrateGroup,
removeGroup,
updateGroup,
};