func for sending messages to user terminals
parent
8c7bf288c4
commit
860effb91c
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
import { promisify, inspect } from 'util';
|
import { promisify, inspect } from 'util';
|
||||||
import childProcess from 'child_process';
|
import childProcess from 'child_process';
|
||||||
|
@ -7,6 +8,7 @@ import uuid from 'uuid/v4';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { Client } from '..';
|
import { Client } from '..';
|
||||||
|
import { getUserByUid } from '../functions';
|
||||||
import { AccountUtil, Command, RichEmbed } from '.';
|
import { AccountUtil, Command, RichEmbed } from '.';
|
||||||
import { ModerationInterface, AccountInterface, Account } from '../models';
|
import { ModerationInterface, AccountInterface, Account } from '../models';
|
||||||
|
|
||||||
|
@ -52,6 +54,30 @@ export default class Util {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async sendMessageToUserTerminal(username: string, message: string): Promise<boolean> {
|
||||||
|
const ptsArray = await this.getPTS(username);
|
||||||
|
if (!ptsArray) return false;
|
||||||
|
for (const pts of ptsArray) {
|
||||||
|
const msg = `==SYSTEM NOTIFICATION | CLOUD SERVICES MANAGEMENT DAEMON==\n${new Date().toLocaleString('en-us')}\n\n${message}\n`;
|
||||||
|
await this.exec(`echo "${msg}" >> /dev/pts/${pts}`);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getPTS(username: string): Promise<number[] | undefined> {
|
||||||
|
const dir = await fs.promises.readdir('/dev/pts');
|
||||||
|
const returnArray: number[] = [];
|
||||||
|
for (const file of dir) {
|
||||||
|
const fileInformation = await fs.promises.stat(`/dev/pts/${file}`);
|
||||||
|
const user = await getUserByUid(this.client, fileInformation.uid);
|
||||||
|
if (user && user === username) {
|
||||||
|
returnArray.push(Number(file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (returnArray.length > 1) return undefined;
|
||||||
|
return returnArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a command
|
* Resolves a command
|
||||||
|
|
Loading…
Reference in New Issue