202 lines
7.6 KiB
JavaScript
202 lines
7.6 KiB
JavaScript
"use strict";
|
|
exports.__esModule = true;
|
|
var tslib_1 = require("tslib");
|
|
var readline = require("readline");
|
|
var discord_js_1 = require("discord.js");
|
|
var fs_1 = require("fs");
|
|
var path = require("path");
|
|
var settings = JSON.parse((0, fs_1.readFileSync)(path.resolve('./settings.json')).toString());
|
|
var rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
function exitNicely() {
|
|
client.destroy();
|
|
rl.close();
|
|
process.exit();
|
|
}
|
|
var DiscordLocation = (function () {
|
|
function DiscordLocation(prompt, parent) {
|
|
this.prompt = '';
|
|
this.exitListener = function () { };
|
|
if (parent)
|
|
prompt = parent.prompt + "/" + prompt;
|
|
if (prompt)
|
|
this.prompt = prompt;
|
|
this.parent = parent;
|
|
this.runPrompt();
|
|
}
|
|
DiscordLocation.prototype.runPrompt = function () {
|
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
var answer;
|
|
var _this = this;
|
|
return (0, tslib_1.__generator)(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0: return [4, new Promise(function (p) { return rl.question(_this.prompt + "> ", p); })];
|
|
case 1:
|
|
answer = _a.sent();
|
|
this.handleRepl(answer, function () { return _this.runPrompt(); });
|
|
return [2];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
DiscordLocation.prototype.handleRepl = function (rawArgs, done) {
|
|
var _this = this;
|
|
var argsArr = rawArgs.split(' '), cmd = argsArr.shift() || '', args = argsArr.join(' ');
|
|
switch (cmd) {
|
|
case 'exit':
|
|
this.exit();
|
|
break;
|
|
default:
|
|
this.runCommand(cmd, args, done)["catch"](function (e) {
|
|
console.error(e);
|
|
_this.runPrompt();
|
|
});
|
|
}
|
|
};
|
|
DiscordLocation.prototype.onExit = function (listener) {
|
|
this.exitListener = listener;
|
|
};
|
|
DiscordLocation.prototype.exit = function () {
|
|
this.exitListener();
|
|
};
|
|
DiscordLocation.prototype.runCommand = function (cmd, args, done) {
|
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { return (0, tslib_1.__generator)(this, function (_a) {
|
|
return [2];
|
|
}); });
|
|
};
|
|
return DiscordLocation;
|
|
}());
|
|
var ClientLocation = (function (_super) {
|
|
(0, tslib_1.__extends)(ClientLocation, _super);
|
|
function ClientLocation(client) {
|
|
var _a;
|
|
var _this = _super.call(this, (_a = client.user) === null || _a === void 0 ? void 0 : _a.username, null) || this;
|
|
_this.client = client;
|
|
return _this;
|
|
}
|
|
ClientLocation.prototype.runCommand = function (cmd, args, done) {
|
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
var _a, g, gloc;
|
|
return (0, tslib_1.__generator)(this, function (_b) {
|
|
switch (_b.label) {
|
|
case 0:
|
|
_a = cmd;
|
|
switch (_a) {
|
|
case 'ls': return [3, 1];
|
|
case 'dir': return [3, 1];
|
|
case 'guilds': return [3, 1];
|
|
case 'join': return [3, 2];
|
|
}
|
|
return [3, 4];
|
|
case 1:
|
|
this.client.guilds.cache.forEach(function (g) {
|
|
console.log(g.id + ": " + ((g === null || g === void 0 ? void 0 : g.name) || 'ERROR'));
|
|
});
|
|
done();
|
|
return [3, 5];
|
|
case 2: return [4, this.client.guilds.fetch(args)];
|
|
case 3:
|
|
g = _b.sent();
|
|
gloc = new GuildLocation(this, g);
|
|
gloc.onExit(done);
|
|
return [3, 5];
|
|
case 4:
|
|
console.log(cmd + " is invalid");
|
|
done();
|
|
_b.label = 5;
|
|
case 5: return [2];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
return ClientLocation;
|
|
}(DiscordLocation));
|
|
var GuildLocation = (function (_super) {
|
|
(0, tslib_1.__extends)(GuildLocation, _super);
|
|
function GuildLocation(parent, guild) {
|
|
var _this = _super.call(this, guild.name, parent) || this;
|
|
_this.guild = guild;
|
|
return _this;
|
|
}
|
|
GuildLocation.prototype.runCommand = function (cmd, args, done) {
|
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
var _a, c, gloc;
|
|
return (0, tslib_1.__generator)(this, function (_b) {
|
|
switch (_b.label) {
|
|
case 0:
|
|
_a = cmd;
|
|
switch (_a) {
|
|
case 'ls': return [3, 1];
|
|
case 'dir': return [3, 1];
|
|
case 'channels': return [3, 1];
|
|
case 'join': return [3, 2];
|
|
}
|
|
return [3, 4];
|
|
case 1:
|
|
this.guild.channels.cache.forEach(function (c) {
|
|
console.log(c.id + ": " + ((c === null || c === void 0 ? void 0 : c.name) || 'ERROR'));
|
|
});
|
|
done();
|
|
return [3, 5];
|
|
case 2: return [4, this.guild.channels.fetch(args)];
|
|
case 3:
|
|
c = _b.sent();
|
|
gloc = new TextChannelLocation(this, c);
|
|
gloc.onExit(done);
|
|
return [3, 5];
|
|
case 4:
|
|
console.log(cmd + " is invalid");
|
|
done();
|
|
_b.label = 5;
|
|
case 5: return [2];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
return GuildLocation;
|
|
}(DiscordLocation));
|
|
var TextChannelLocation = (function (_super) {
|
|
(0, tslib_1.__extends)(TextChannelLocation, _super);
|
|
function TextChannelLocation(parent, channel) {
|
|
var _this = _super.call(this, "" + channel.name, parent) || this;
|
|
_this.channel = channel;
|
|
return _this;
|
|
}
|
|
TextChannelLocation.prototype.runCommand = function (cmd, args, done) {
|
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
var _a;
|
|
return (0, tslib_1.__generator)(this, function (_b) {
|
|
switch (_b.label) {
|
|
case 0:
|
|
_a = cmd;
|
|
switch (_a) {
|
|
case 'say': return [3, 1];
|
|
}
|
|
return [3, 3];
|
|
case 1: return [4, this.channel.send(args)];
|
|
case 2:
|
|
_b.sent();
|
|
done();
|
|
return [3, 4];
|
|
case 3:
|
|
console.log(cmd + " is invalid");
|
|
done();
|
|
_b.label = 4;
|
|
case 4: return [2];
|
|
}
|
|
});
|
|
});
|
|
};
|
|
return TextChannelLocation;
|
|
}(DiscordLocation));
|
|
var client = new discord_js_1.Client({ intents: discord_js_1.Intents.FLAGS.GUILDS });
|
|
client.login(settings.token);
|
|
client.on('ready', function () {
|
|
var clientRepl = new ClientLocation(client);
|
|
clientRepl.onExit(function () {
|
|
exitNicely();
|
|
});
|
|
});
|
|
//# sourceMappingURL=index.js.map
|