This commit is contained in:
Flummi 2019-08-19 14:17:35 +00:00
parent 8233560a3f
commit d6a737931a
7 changed files with 53 additions and 31 deletions

View File

@ -9,13 +9,17 @@ export const getLevel = (network, user) => {
return "user has to be an object!"; return "user has to be an object!";
if (!user.account || !user.prefix) if (!user.account || !user.prefix)
return ret; return ret;
for(let admin of config.admins) {
if (admin.account === user.account.toLowerCase() && admin.network === network.toLowerCase()) { let admin;
ret = { if(admin = config.admins.filter(a =>
level: admin.level, a.account === user.account.toLowerCase() &&
verified: user.prefix.toLowerCase() === admin.prefix a.network === network.toLowerCase()
}; )[0]) {
} ret = {
}; level: admin.level,
verified: user.prefix.toLowerCase() === admin.prefix
};
}
return ret; return ret;
}; };

10
src/inc/events/error.mjs Normal file
View File

@ -0,0 +1,10 @@
export default async bot => {
return [{
name: "error",
listener: "error",
f: e => {
console.log(e);
}
}];
};

10
src/inc/events/info.mjs Normal file
View File

@ -0,0 +1,10 @@
export default async bot => {
return [{
name: "info",
listener: "info",
f: e => {
console.log(e);
}
}];
};

View File

@ -1,11 +1,9 @@
import logger from "../log"; import logger from "../log";
import { cfg } from "../cfg";
import { getLevel } from "../../inc/admin"; import { getLevel } from "../../inc/admin";
const parseArgs = (msg) => { const parseArgs = msg => {
let args = msg.trim().split(" "); let args = msg.trim().split(" ")
let cmd = args.shift(); , cmd = args.shift();
return { return {
cmd: cmd.replace(/^(\.|\/|\!)/, ""), cmd: cmd.replace(/^(\.|\/|\!)/, ""),
args: args args: args
@ -17,7 +15,9 @@ export default async bot => {
return [{ return [{
name: "message", name: "message",
listener: "message", listener: "message",
f: e => { f: (a, e = { ...a, ...parseArgs(a.message) }) => {
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
const trigger = [...bot._trigger.entries()].filter(t => const trigger = [...bot._trigger.entries()].filter(t =>
t[1].call.exec(e.message) && t[1].call.exec(e.message) &&
t[1].clients.includes(e.type) && t[1].clients.includes(e.type) &&
@ -28,7 +28,6 @@ export default async bot => {
trigger.forEach(async t => { trigger.forEach(async t => {
try { try {
e = { ...e, ...parseArgs(e.message) };
await t[1].f(e); await t[1].f(e);
console.log(`triggered > ${t[0]}`); console.log(`triggered > ${t[0]}`);
} }
@ -37,8 +36,6 @@ export default async bot => {
logger.error(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${error.toString ? error : JSON.stringify(error)}`); logger.error(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${error.toString ? error : JSON.stringify(error)}`);
} }
}); });
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
} }
}]; }];

View File

@ -15,6 +15,14 @@ let context = vm.createContext({
export default async bot => { export default async bot => {
return [{ return [{
name: "level",
call: /^!level (.*)/i,
active: true,
f: e => {
const user = e.message.trim().substring(7);
e.reply( JSON.stringify(getLevel(e.network, e.self.user.geti(user) || {})) );
}
}, {
name: "sandbox_debug", name: "sandbox_debug",
call: /^\!debug (.*)/i, call: /^\!debug (.*)/i,
active: true, active: true,

View File

@ -8,13 +8,9 @@ export default async bot => {
name: "kernel", name: "kernel",
call: /^(\.|\/)kernel/i, call: /^(\.|\/)kernel/i,
set: "nxy", set: "nxy",
f: e => { f: async e => {
fetch(feed) const res = await (await fetch(feed)).json();
.then(res => res.json()) e.reply(res.releases.map(entry => `[b]${entry.version}[/b] (${entry.moniker}${entry.iseol ? `, [i]EOL[/i]` : ""})`).join(", "));
.then(content => {
const releases = content.releases;
e.reply(releases.map(entry => `[b]${entry.version}[/b] (${entry.moniker}${entry.iseol ? `, [i]EOL[/i]` : ""})`).join(", "));
}).catch(err => console.log(err));
} }
}]; }];
}; };

View File

@ -11,13 +11,10 @@ export default async bot => {
text: "get random track from Flummi's soundcloud favorites", text: "get random track from Flummi's soundcloud favorites",
usage: "[b].scrnd[/b]" usage: "[b].scrnd[/b]"
}, },
f: e => { f: async e => {
fetch(`http://api.soundcloud.com/users/${cfg.main.soundcloud.val.user}/favorites?client_id=${cfg.main.soundcloud.val.clientid}`) const res = await (await fetch(`http://api.soundcloud.com/users/${cfg.main.soundcloud.val.user}/favorites?client_id=${cfg.main.soundcloud.val.clientid}`)).json();
.then(res => res.json()) const track = res[~~((Math.random() * res.length) + 1)];
.then(res => { e.reply(`${track.permalink_url}\n[b]${track.title}[/b] - length [b]${track.duration}[/b] - [b]${track.user.username}[/b] on [b]${track.created_at}[/b]`);
const track = res[~~((Math.random() * res.length) + 1)];
e.reply(`${track.permalink_url}\n[b]${track.title}[/b] - length [b]${track.duration}[/b] - [b]${track.user.username}[/b] on [b]${track.created_at}[/b]`);
}).catch(err => console.log(err));
} }
}]; }];
}; };