Skip to content

Commit

Permalink
Add command to show disk stats
Browse files Browse the repository at this point in the history
  • Loading branch information
out386 committed Oct 12, 2019
1 parent cc6aaf0 commit a0f5865
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bot_utils/event_regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export class EventRegex {
readonly commandsRegexNoName: regexps.RegExps;

constructor() {
var commands = ['^/start', '^/mirrorTar', '^/mirror', '^/mirrorStatus', '^/list', '^/getFolder', '^/cancelMirror', '^/cancelAll'];
var commands = ['^/start', '^/mirrorTar', '^/mirror', '^/mirrorStatus', '^/list', '^/getFolder', '^/cancelMirror', '^/cancelAll', '^/disk'];
var commandsNoName: string[] = [];
var commandAfter = ['$', ' (.+)', ' (.+)', '$', ' (.+)', '$', '$', '$'];
var commandAfter = ['$', ' (.+)', ' (.+)', '$', ' (.+)', '$', '$', '$', '$'];

if (constants.COMMANDS_USE_BOT_NAME && constants.COMMANDS_USE_BOT_NAME.ENABLED) {
commands.forEach((command, i) => {
Expand Down
2 changes: 2 additions & 0 deletions src/bot_utils/reg_exps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class RegExps {
readonly getFolder: RegExp;
readonly cancelMirror: RegExp;
readonly cancelAll: RegExp;
readonly disk: RegExp;

constructor(commands: string[]) {
this.start = new RegExp(commands[0], 'i');
Expand All @@ -17,5 +18,6 @@ export class RegExps {
this.getFolder = new RegExp(commands[5], 'i');
this.cancelMirror = new RegExp(commands[6], 'i');
this.cancelAll = new RegExp(commands[7], 'i');
this.disk = new RegExp(commands[8], 'i');
}
}
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import driveUtils = require('./drive/drive-utils.js');
import details = require('./dl_model/detail');
import filenameUtils = require('./download_tools/filename-utils');
import { EventRegex } from './bot_utils/event_regex';
import { exec } from 'child_process';

const eventRegex = new EventRegex();
const bot = new TelegramBot(constants.TOKEN, { polling: true });
Expand Down Expand Up @@ -55,6 +56,19 @@ setEventCallback(eventRegex.commandsRegex.mirror, eventRegex.commandsRegexNoName
}
});

setEventCallback(eventRegex.commandsRegex.disk, eventRegex.commandsRegexNoName.disk, (msg) => {
if (msgTools.isAuthorized(msg) < 0) {
msgTools.sendUnauthorizedMessage(bot, msg);
} else {
exec(`df --output="size,used,avail" -h "${constants.ARIA_DOWNLOAD_LOCATION_ROOT}" | tail -n1`,
(err, res) => {
var disk = res.trim().split(/\s+/);
msgTools.sendMessage(bot, msg, `Total space: ${disk[0]}B\nUsed: ${disk[1]}B\nAvailable: ${disk[2]}B`);
}
);
}
});

/**
* Start a new download operation. Make sure that this is triggered by an
* authorized user, because this function itself does not check for that.
Expand Down

0 comments on commit a0f5865

Please sign in to comment.