|
|
|
@ -51,7 +51,7 @@ exports.WebServer = class {
|
|
|
|
|
filter: (req, res) => {
|
|
|
|
|
if (req.headers['x-no-compression'])
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
return compression.filter(req, res);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -81,7 +81,7 @@ exports.WebServer = class {
|
|
|
|
|
this.app.use((req, res, next) => {
|
|
|
|
|
if (req.session.user)
|
|
|
|
|
next();
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
res.render('login');
|
|
|
|
|
});
|
|
|
|
|
this.app.get('/', (req, res) => {
|
|
|
|
@ -89,7 +89,10 @@ exports.WebServer = class {
|
|
|
|
|
});
|
|
|
|
|
this.app.use('/graphql', graphqlHTTP({
|
|
|
|
|
schema: this.schema,
|
|
|
|
|
rootValue: this.root,
|
|
|
|
|
rootValue: Object.assign({
|
|
|
|
|
query: this.query,
|
|
|
|
|
mutation: this.mutation
|
|
|
|
|
}, this.query),
|
|
|
|
|
graphiql: config.webinterface.graphiql || false
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
@ -163,15 +166,15 @@ exports.WebServer = class {
|
|
|
|
|
new dblib.Column('token', sql.types.getVarchar(255), [sql.constraints.unique, sql.constraints.notNull]),
|
|
|
|
|
new dblib.Column('scope', sql.types.integer, [sql.constraints.notNull, sql.default(0)])
|
|
|
|
|
]));
|
|
|
|
|
this.root = {
|
|
|
|
|
this.query = {
|
|
|
|
|
client: {
|
|
|
|
|
guilds: async (args) => {
|
|
|
|
|
async guilds(args) {
|
|
|
|
|
let dcGuilds = objects.client.guilds.values();
|
|
|
|
|
if (args.id)
|
|
|
|
|
return [(await Promise.all(Array.from(dcGuilds)
|
|
|
|
|
.map(async (x) => new Guild(x, await objects.getGuildHandler(x)))))
|
|
|
|
|
.find(x => (x.id === args.id))];
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
try {
|
|
|
|
|
return await Promise.all(Array.from(dcGuilds)
|
|
|
|
|
.slice(args.offset, args.offset + args.first)
|
|
|
|
@ -182,22 +185,22 @@ exports.WebServer = class {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
guildCount: () => {
|
|
|
|
|
guildCount() {
|
|
|
|
|
return Array.from(objects.client.guilds.values()).length;
|
|
|
|
|
},
|
|
|
|
|
user: () => {
|
|
|
|
|
user() {
|
|
|
|
|
return new User(objects.client.user);
|
|
|
|
|
},
|
|
|
|
|
ping: () => {
|
|
|
|
|
ping() {
|
|
|
|
|
return objects.client.ping;
|
|
|
|
|
},
|
|
|
|
|
status: () => {
|
|
|
|
|
status() {
|
|
|
|
|
return objects.client.status;
|
|
|
|
|
},
|
|
|
|
|
uptime: () => {
|
|
|
|
|
uptime() {
|
|
|
|
|
return objects.client.uptime;
|
|
|
|
|
},
|
|
|
|
|
voiceConnectionCount: () => {
|
|
|
|
|
voiceConnectionCount() {
|
|
|
|
|
let dcGuilds = Array.from(objects.client.guilds.values());
|
|
|
|
|
return dcGuilds.filter((x) => {
|
|
|
|
|
let gh = objects.guildHandlers[x.id];
|
|
|
|
@ -206,7 +209,7 @@ exports.WebServer = class {
|
|
|
|
|
return gh.musicPlayer.playing;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}).length;
|
|
|
|
@ -214,12 +217,12 @@ exports.WebServer = class {
|
|
|
|
|
},
|
|
|
|
|
prefix: objects.prefix,
|
|
|
|
|
presences: objects.presences,
|
|
|
|
|
config: () => {
|
|
|
|
|
config() {
|
|
|
|
|
let newConfig = JSON.parse(JSON.stringify(config));
|
|
|
|
|
delete newConfig.api;
|
|
|
|
|
return JSON.stringify(newConfig, null, ' ');
|
|
|
|
|
},
|
|
|
|
|
logs: (args) => {
|
|
|
|
|
logs(args) {
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
let logEntries = [];
|
|
|
|
|
let lineReader = require('readline').createInterface({
|
|
|
|
@ -238,7 +241,7 @@ exports.WebServer = class {
|
|
|
|
|
|
|
|
|
|
if (args.first)
|
|
|
|
|
logEntries = logEntries.slice(args.offset, args.offset + args.first);
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
logEntries = logEntries.slice(logEntries.length - args.last);
|
|
|
|
|
|
|
|
|
|
resolve(logEntries);
|
|
|
|
@ -246,6 +249,19 @@ exports.WebServer = class {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.mutation = {
|
|
|
|
|
togglePause(args) {
|
|
|
|
|
if (args.guildId) {
|
|
|
|
|
let guildId = resolveId(args.guildId).replace('Guild', '');
|
|
|
|
|
let gh = objects.guildHandlers[guildId];
|
|
|
|
|
|
|
|
|
|
if (gh.musicPlayer.paused)
|
|
|
|
|
gh.musicPlayer.resume();
|
|
|
|
|
else
|
|
|
|
|
gh.musicPlayer.pause();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -255,13 +271,20 @@ exports.WebServer = class {
|
|
|
|
|
* @returns {*}
|
|
|
|
|
*/
|
|
|
|
|
function generateID(valArr) {
|
|
|
|
|
let b64 = Buffer.from(valArr.map(x => {
|
|
|
|
|
return Buffer.from(valArr.map(x => {
|
|
|
|
|
if (x)
|
|
|
|
|
return x.toString();
|
|
|
|
|
else
|
|
|
|
|
return 'null';
|
|
|
|
|
}).join('_')).toString('base64');
|
|
|
|
|
return md5(b64);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* resolves an id string
|
|
|
|
|
* @param id {String}
|
|
|
|
|
*/
|
|
|
|
|
function resolveId(id) {
|
|
|
|
|
return Buffer.from(id, 'base64');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -282,22 +305,6 @@ class MusicPlayer {
|
|
|
|
|
this.quality = musicPlayer.quality;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue(args) {
|
|
|
|
|
let queue = this.musicPlayer.queue.map((x) => {
|
|
|
|
|
return {
|
|
|
|
|
id: generateID(['Media', x.url]),
|
|
|
|
|
name: x.title,
|
|
|
|
|
url: x.url,
|
|
|
|
|
thumbnail: utils.YouTube.getVideoThumbnailUrlFromUrl(x.url)
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
if (args.id)
|
|
|
|
|
return [queue.find(x => (x.id === args.id))];
|
|
|
|
|
else
|
|
|
|
|
return queue.slice(args.offset, args.offset + args.first);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get playing() {
|
|
|
|
|
return this.musicPlayer.playing;
|
|
|
|
|
}
|
|
|
|
@ -307,7 +314,7 @@ class MusicPlayer {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get paused() {
|
|
|
|
|
return this.musicPlayer.disp? this.musicPlayer.disp.paused : false;
|
|
|
|
|
return this.musicPlayer.disp ? this.musicPlayer.disp.paused : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get queueCount() {
|
|
|
|
@ -339,6 +346,22 @@ class MusicPlayer {
|
|
|
|
|
get voiceChannel() {
|
|
|
|
|
return this.musicPlayer.voiceChannel.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue(args) {
|
|
|
|
|
let queue = this.musicPlayer.queue.map((x) => {
|
|
|
|
|
return {
|
|
|
|
|
id: generateID(['Media', x.url]),
|
|
|
|
|
name: x.title,
|
|
|
|
|
url: x.url,
|
|
|
|
|
thumbnail: utils.YouTube.getVideoThumbnailUrlFromUrl(x.url)
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
if (args.id)
|
|
|
|
|
return [queue.find(x => (x.id === args.id))];
|
|
|
|
|
else
|
|
|
|
|
return queue.slice(args.offset, args.offset + args.first);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -382,16 +405,16 @@ class Guild {
|
|
|
|
|
let result = await this.querySaved();
|
|
|
|
|
if (args.id)
|
|
|
|
|
return [result.find(x => (x.id === args.id))];
|
|
|
|
|
else if (args.name)
|
|
|
|
|
else if (args.name)
|
|
|
|
|
return [result.find(x => (x.name === args.name))];
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
return result.slice(args.offset, args.offset + args.first);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
roles(args) {
|
|
|
|
|
if (args.id)
|
|
|
|
|
return [this.prRoles.find(x => (x.id === args.id))];
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
return this.prRoles.slice(args.offset, args.offset + args.first);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -399,7 +422,7 @@ class Guild {
|
|
|
|
|
members(args) {
|
|
|
|
|
if (args.id)
|
|
|
|
|
return [this.prMembers.find(x => (x.id === args.id))];
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
return this.prMembers.slice(args.offset, args.offset + args.first);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -421,7 +444,7 @@ class Role {
|
|
|
|
|
members(args) {
|
|
|
|
|
if (args.id)
|
|
|
|
|
return [this.prMembers.find(x => (x.id === args.id))];
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
return this.prMembers.slice(args.offset, args.offset + args.first);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -444,7 +467,7 @@ class GuildMember {
|
|
|
|
|
roles(args) {
|
|
|
|
|
if (args.id)
|
|
|
|
|
return [this.prRoles.find(x => (x.id === args.id))];
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
return this.prRoles.slice(args.offset, args.offset + args.first);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -463,7 +486,7 @@ class User {
|
|
|
|
|
this.tag = discordUser.tag;
|
|
|
|
|
this.tag = discordUser.tag;
|
|
|
|
|
this.presence = {
|
|
|
|
|
game: discordUser.presence.game? discordUser.presence.game.name : null,
|
|
|
|
|
game: discordUser.presence.game ? discordUser.presence.game.name : null,
|
|
|
|
|
status: discordUser.presence.status
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|