Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const MongoClient = require('mongodb').MongoClient;
- const configService = require('./server-config-service');
- function randint(max) {
- return Math.round(Math.random() * max);
- }
- function randomstring() {
- const letters = 'ABCDEFHIJKLMNOPQRSTUVWXYZ';
- let result = '';
- for (let i = 0; i < 10; i++) {
- let index = randint(letters.length - 1);
- result += letters[index];
- }
- return result;
- }
- let mongoClient;
- async function start() {
- mongoClient = await MongoClient.connect('mongodb://localhost:27017', { useNewUrlParser: true });
- const db = mongoClient.db('my-cool-bot-db');
- await configService.initialize(db.collection('server-configs'));
- console.log(`Channel Id For Server A Before Set: ${await configService.get('A', 'channel-id')}`);
- console.log(`Channel Id For Server B Before Set: ${await configService.get('B', 'channel-id')}`);
- await configService.set('A', 'channel-id', randomstring());
- await configService.set('B', 'channel-id', randomstring());
- console.log(`Channel Id For Server A Before Set: ${await configService.get('A', 'channel-id')}`);
- console.log(`Channel Id For Server B Before Set: ${await configService.get('B', 'channel-id')}`);
- }
- start().then(() => {
- mongoClient.close().catch(err => {
- console.log('Error closing database: ' + err);
- });
- }).catch(err => {
- console.log('Error running demo: ' + err);
- mongoClient.close().catch(err => {
- console.log('Error closing database: ' + err);
- });
- });
Add Comment
Please, Sign In to add comment