new format args

This commit is contained in:
jane 2021-05-26 20:18:11 -04:00
parent 0e827d1c85
commit 1e30598bc4
4 changed files with 212 additions and 218 deletions

4
bot.js
View file

@ -24,6 +24,10 @@ global.ctx = {
set_ctx: (key, value) => { set_ctx: (key, value) => {
global.ctx[key] = value; global.ctx[key] = value;
}, },
lights: {
port: cfg.lights_port,
addr: cfg.lights_address
}
}; };
const log = new Logger(filename(import.meta.url), global.ctx.log_level); const log = new Logger(filename(import.meta.url), global.ctx.log_level);
const parse = new CommandParser(global.ctx, cfg.prefix || undefined); const parse = new CommandParser(global.ctx, cfg.prefix || undefined);

View file

@ -31,17 +31,26 @@ const available_targets = {
class Instruction { class Instruction {
constructor(name, targets, args) { constructor(name, targets, args) {
let valid_targets = []; let valid_targets = [];
targets.forEach((t) => { let matched_args = [];
targets.forEach((t, i) => {
if (t instanceof Target) { if (t instanceof Target) {
let match = Object.keys(available_targets).find((key) => available_targets[key].channel === t.channel); let match = Object.keys(available_targets).find((key) => available_targets[key].channel === t.channel);
if (match) { if (match) {
valid_targets.push(t); if (args[i]) {
matched_args.push({
...t,
arg: args[i]
})
}
else {
matched_args.push(t);
}
} }
} }
}); });
this.name = name; this.name = name;
this.targets = valid_targets; this.targets = valid_targets;
this.args = args; this.args = matched_args;
} }
name; name;
targets; targets;

View file

@ -16,7 +16,10 @@ export default function req(data, callback, errorCallback) {
} }
let client = new net.Socket(); let client = new net.Socket();
client.connect(port, hostname, () => {
let c_port = global.ctx.lights.port || port;
let c_addr = global.ctx.lights.addr || hostname;
client.connect(c_port, c_addr, () => {
client.write(string_data); client.write(string_data);
client.destroy(); client.destroy();
callback('success.'); callback('success.');

View file

@ -1,7 +1,6 @@
dependencies: dependencies:
eris: 0.14.0 eris: 0.14.0
socket.engine: 1.0.0 lockfileVersion: 5.2
lockfileVersion: 5.1
packages: packages:
/eris/0.14.0: /eris/0.14.0:
dependencies: dependencies:
@ -14,31 +13,11 @@ packages:
tweetnacl: 1.0.3 tweetnacl: 1.0.3
resolution: resolution:
integrity: sha512-/W6X0SFR2swtA9oc4ga5Wh1TQcZtPgbUaDDdwYc67fvFUAtwC+V1xzWUZq2yDeJnTfB8Uot9SJWA8Lthe2sDtQ== integrity: sha512-/W6X0SFR2swtA9oc4ga5Wh1TQcZtPgbUaDDdwYc67fvFUAtwC+V1xzWUZq2yDeJnTfB8Uot9SJWA8Lthe2sDtQ==
/fs/0.0.1-security:
dev: false
resolution:
integrity: sha1-invTcYa23d84E/I4WLV+yq9eQdQ=
/ip/1.1.5:
dev: false
resolution:
integrity: sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=
/net/1.0.2:
dev: false
resolution:
integrity: sha1-0XV+yaf7I3HYPPR1XOPifhCCk4g=
/opusscript/0.0.7: /opusscript/0.0.7:
dev: false dev: false
optional: true optional: true
resolution: resolution:
integrity: sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg== integrity: sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==
/socket.engine/1.0.0:
dependencies:
fs: 0.0.1-security
ip: 1.1.5
net: 1.0.2
dev: false
resolution:
integrity: sha512-vwc9JVBNe33686TBl9T3Ro53FaF09z11NVnrf0HIlYUOIDaZ1OFA1J1O6igU57qhP3NyUv4a+kZtgMm6SnziaQ==
/tweetnacl/1.0.3: /tweetnacl/1.0.3:
dev: false dev: false
optional: true optional: true
@ -60,4 +39,3 @@ packages:
integrity: sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA== integrity: sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==
specifiers: specifiers:
eris: ^0.14.0 eris: ^0.14.0
socket.engine: ^1.0.0