pinbot/utils.js

35 lines
769 B
JavaScript
Raw Normal View History

2021-04-10 05:12:10 +00:00
import path from 'path';
import { platform } from 'process';
import { Constants } from 'eris';
2021-04-05 20:53:19 +00:00
export function filename(url) {
2021-04-10 05:12:10 +00:00
const __filename = new URL(url).pathname;
return path.basename(__filename, '.js');
2021-04-05 20:53:19 +00:00
}
export function dirname(url) {
2021-04-10 05:12:10 +00:00
const __filename = new URL(url).pathname;
const __dirname = path.dirname(__filename);
return platform == 'win32' ? __dirname.slice(1) : __dirname;
}
export function getPerms(perms) {
const result = [];
for (const key in Constants.Permissions) {
if (Constants.Permissions[key].toString() & perms) {
result.push(key);
}
}
return result;
}
export function hasPerms(perms, test) {
let testPerms = getPerms(test);
for (const tp of testPerms) {
if (!perms.has(tp)) {
return false;
}
}
return true;
}