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!";
if (!user.account || !user.prefix)
return ret;
for(let admin of config.admins) {
if (admin.account === user.account.toLowerCase() && admin.network === network.toLowerCase()) {
ret = {
level: admin.level,
verified: user.prefix.toLowerCase() === admin.prefix
};
}
};
let admin;
if(admin = config.admins.filter(a =>
a.account === user.account.toLowerCase() &&
a.network === network.toLowerCase()
)[0]) {
ret = {
level: admin.level,
verified: user.prefix.toLowerCase() === admin.prefix
};
}
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 { cfg } from "../cfg";
import { getLevel } from "../../inc/admin";
const parseArgs = (msg) => {
let args = msg.trim().split(" ");
let cmd = args.shift();
const parseArgs = msg => {
let args = msg.trim().split(" ")
, cmd = args.shift();
return {
cmd: cmd.replace(/^(\.|\/|\!)/, ""),
args: args
@ -17,7 +15,9 @@ export default async bot => {
return [{
name: "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 =>
t[1].call.exec(e.message) &&
t[1].clients.includes(e.type) &&
@ -28,7 +28,6 @@ export default async bot => {
trigger.forEach(async t => {
try {
e = { ...e, ...parseArgs(e.message) };
await t[1].f(e);
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.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
}
}];

View File

@ -15,6 +15,14 @@ let context = vm.createContext({
export default async bot => {
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",
call: /^\!debug (.*)/i,
active: true,

View File

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

View File

@ -11,13 +11,10 @@ export default async bot => {
text: "get random track from Flummi's soundcloud favorites",
usage: "[b].scrnd[/b]"
},
f: e => {
fetch(`http://api.soundcloud.com/users/${cfg.main.soundcloud.val.user}/favorites?client_id=${cfg.main.soundcloud.val.clientid}`)
.then(res => res.json())
.then(res => {
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));
f: async e => {
const res = await (await fetch(`http://api.soundcloud.com/users/${cfg.main.soundcloud.val.user}/favorites?client_id=${cfg.main.soundcloud.val.clientid}`)).json();
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]`);
}
}];
};