rebuilt files

This commit is contained in:
Amish Shah
2015-11-22 15:01:42 +00:00
parent cf33df18cf
commit 68b60c5464
27 changed files with 1023 additions and 1746 deletions

View File

@@ -1,87 +1,87 @@
/*
this bot is a permissions bot and is currently working
with the experimental additions. Some functions may
change in the future.
*/
var Discord = require("../../");
// Get the email and password
var AuthDetails = require("../auth.json");
var bot = new Discord.Client();
bot.on("ready", function () {
console.log("Ready to begin! Serving in " + bot.channels.length + " channels");
});
bot.on("disconnected", function () {
console.log("Disconnected!");
process.exit(1); //exit node.js with an error
});
bot.on("message", function (msg) {
if (msg.content === "skype") {
//stop the user from speaking in the channel:
bot.overwritePermissions(msg.channel, msg.sender, {
sendMessages: false
});
// send a barely funny message ;)
bot.reply(msg, "how dare you mention that!");
}
if (msg.content === "discord") {
// if the role doesn't exist, make it
bot.createRoleIfNotExists(msg.channel.server, {
name: "good people",
color: Discord.Colors.BLUE, // colour of blue
hoist: true // make a seperate category in the users list
}).then(addUserToList).catch(console.log);
function addUserToList(role, alreadyExists) {
console.log(arguments);
bot.addMemberToRole(msg.sender, role);
bot.reply(msg, "welcome to the good people! " + alreadyExists);
}
}
if (msg.content === "remove me") {
// remove the user from the good people list, if it exists
var found = false;
for (var role of msg.channel.server.roles) {
if (role.name === "good people") {
found = role;
break;
}
}
if (found) {
// if the role exists
if (msg.sender.hasRole(role)) {
// remove the member from the role
bot.removeMemberFromRole(msg.sender, role);
bot.reply(msg, "removed!")
} else {
bot.reply(msg, "you're not in the role!");
}
} else {
// role doesn't exist
bot.reply(msg, "the role doesn't even exist!");
}
}
});
/*
this bot is a permissions bot and is currently working
with the experimental additions. Some functions may
change in the future.
*/
var Discord = require("../../");
// Get the email and password
var AuthDetails = require("../auth.json");
var bot = new Discord.Client();
bot.on("ready", function () {
console.log("Ready to begin! Serving in " + bot.channels.length + " channels");
});
bot.on("disconnected", function () {
console.log("Disconnected!");
process.exit(1); //exit node.js with an error
});
bot.on("message", function (msg) {
if (msg.content === "skype") {
//stop the user from speaking in the channel:
bot.overwritePermissions(msg.channel, msg.sender, {
sendMessages: false
});
// send a barely funny message ;)
bot.reply(msg, "how dare you mention that!");
}
if (msg.content === "discord") {
// if the role doesn't exist, make it
bot.createRoleIfNotExists(msg.channel.server, {
name: "good people",
color: Discord.Colors.BLUE, // colour of blue
hoist: true // make a seperate category in the users list
}).then(addUserToList).catch(console.log);
function addUserToList(role, alreadyExists) {
console.log(arguments);
bot.addMemberToRole(msg.sender, role);
bot.reply(msg, "welcome to the good people! " + alreadyExists);
}
}
if (msg.content === "remove me") {
// remove the user from the good people list, if it exists
var found = false;
for (var role of msg.channel.server.roles) {
if (role.name === "good people") {
found = role;
break;
}
}
if (found) {
// if the role exists
if (msg.sender.hasRole(role)) {
// remove the member from the role
bot.removeMemberFromRole(msg.sender, role);
bot.reply(msg, "removed!")
} else {
bot.reply(msg, "you're not in the role!");
}
} else {
// role doesn't exist
bot.reply(msg, "the role doesn't even exist!");
}
}
});
bot.login(AuthDetails.email, AuthDetails.password);

View File

@@ -1,50 +1,50 @@
/* this bot will see if a user can send TTS messages */
var Discord = require("../../");
Discord.patchStrings();
var AuthDetails = require("../auth.json");
var bot = new Discord.Client();
bot.on("ready", () => {
console.log("Ready to begin!");
});
bot.on("message", (msg) => {
if(msg.content === "can I tts?"){
var user = msg.sender;
// get the evaluated permissions for a user in the channel they asked
var permissions = msg.channel.permissionsOf(user);
if(permissions.sendTTSMessages){
bot.reply(msg, "You " + "can".italic.bold + " send TTS messages.");
}else{
bot.reply(msg, "You " + "can't".italic.bold + " send TTS messages.");
}
}else if(msg.content === "what are my full permissions?"){
var user = msg.sender;
// get the serialised permissions of the user
var permissions = msg.channel.permissionsOf(user).serialise();
// if you want to stringify permissions, they need to be serialised first.
bot.reply(msg, JSON.stringify(permissions, null, 4).replace(/true/g, "**true**"));
}
/*
for a list of more permissions, go to
https://github.com/hydrabolt/discord.js/blob/master/src/EvaluatedPermissions.js
*/
})
/* this bot will see if a user can send TTS messages */
var Discord = require("../../");
Discord.patchStrings();
var AuthDetails = require("../auth.json");
var bot = new Discord.Client();
bot.on("ready", () => {
console.log("Ready to begin!");
});
bot.on("message", (msg) => {
if(msg.content === "can I tts?"){
var user = msg.sender;
// get the evaluated permissions for a user in the channel they asked
var permissions = msg.channel.permissionsOf(user);
if(permissions.sendTTSMessages){
bot.reply(msg, "You " + "can".italic.bold + " send TTS messages.");
}else{
bot.reply(msg, "You " + "can't".italic.bold + " send TTS messages.");
}
}else if(msg.content === "what are my full permissions?"){
var user = msg.sender;
// get the serialised permissions of the user
var permissions = msg.channel.permissionsOf(user).serialise();
// if you want to stringify permissions, they need to be serialised first.
bot.reply(msg, JSON.stringify(permissions, null, 4).replace(/true/g, "**true**"));
}
/*
for a list of more permissions, go to
https://github.com/hydrabolt/discord.js/blob/master/src/EvaluatedPermissions.js
*/
})
bot.login(AuthDetails.email, AuthDetails.password);

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,3 @@
"use strict";
exports.IDLE = 0;
exports.LOGGING_IN = 1;
exports.LOGGED_IN = 2;

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,7 @@
"use strict";
"use strict"
/* global Buffer */
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
;
var fs = require("fs");
var User = require("../../Structures/User.js"),
@@ -16,32 +15,17 @@ var User = require("../../Structures/User.js"),
Invite = require("../../Structures/Invite.js"),
Games = require("../../../ref/gameMap.js");
var Resolver = (function () {
function Resolver(internal) {
_classCallCheck(this, Resolver);
class Resolver {
constructor(internal) {
this.internal = internal;
}
Resolver.prototype.resolveGameID = function resolveGameID(resource) {
resolveGameID(resource) {
if (!isNaN(resource) && parseInt(resource) % 1 === 0) {
return resource;
} else if (typeof resource == "string" || resource instanceof String) {
for (var _iterator = Games, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var game = _ref;
for (var game of Games) {
if (game.name.toUpperCase() === resource.toUpperCase()) {
return game.id;
}
@@ -49,17 +33,17 @@ var Resolver = (function () {
}
return null;
};
}
Resolver.prototype.resolveToBase64 = function resolveToBase64(resource) {
resolveToBase64(resource) {
if (resource instanceof Buffer) {
resource = resource.toString("base64");
resource = "data:image/jpg;base64," + resource;
}
return resource;
};
}
Resolver.prototype.resolveInviteID = function resolveInviteID(resource) {
resolveInviteID(resource) {
if (resource instanceof Invite) {
return resource.id;
} else if (typeof resource == "string" || resource instanceof String) {
@@ -72,9 +56,9 @@ var Resolver = (function () {
}
}
return null;
};
}
Resolver.prototype.resolveServer = function resolveServer(resource) {
resolveServer(resource) {
if (resource instanceof Server) {
return resource;
} else if (resource instanceof ServerChannel) {
@@ -87,39 +71,26 @@ var Resolver = (function () {
}
}
return null;
};
}
Resolver.prototype.resolveFile = function resolveFile(resource) {
resolveFile(resource) {
if (typeof resource === "string" || resource instanceof String) {
return fs.createReadStream(resource);
} else {
return resource;
}
};
}
Resolver.prototype.resolveMentions = function resolveMentions(resource) {
resolveMentions(resource) {
// resource is a string
var _mentions = [];
for (var _iterator2 = resource.match(/<@[^>]*>/g) || [], _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var mention = _ref2;
for (var mention of resource.match(/<@[^>]*>/g) || []) {
_mentions.push(mention.substring(2, mention.length - 1));
}
return _mentions;
};
}
Resolver.prototype.resolveString = function resolveString(resource) {
resolveString(resource) {
// accepts Array, Channel, Server, User, Message, String and anything
// toString()-able
@@ -130,9 +101,9 @@ var Resolver = (function () {
}
return final.toString();
};
}
Resolver.prototype.resolveUser = function resolveUser(resource) {
resolveUser(resource) {
/*
accepts a Message, Channel, Server, String ID, User, PMChannel
*/
@@ -155,9 +126,9 @@ var Resolver = (function () {
}
return found;
};
}
Resolver.prototype.resolveMessage = function resolveMessage(resource) {
resolveMessage(resource) {
// accepts a Message, PMChannel & TextChannel
var found = null;
@@ -168,23 +139,23 @@ var Resolver = (function () {
}
return found;
};
}
Resolver.prototype.resolveVoiceChannel = function resolveVoiceChannel(resource) {
resolveVoiceChannel(resource) {
// resolveChannel will also work but this is more apt
if (resource instanceof VoiceChannel) {
return resource;
}
return null;
};
}
Resolver.prototype.resolveChannel = function resolveChannel(resource) {
resolveChannel(resource) {
/*
accepts a Message, Channel, Server, String ID, User
*/
var self = this;
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
var found = null;
if (resource instanceof Message) {
found = resource.channel;
@@ -197,20 +168,7 @@ var Resolver = (function () {
} else if (resource instanceof User) {
// see if a PM exists
var chatFound = false;
for (var _iterator3 = self.internal.private_channels, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref3;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var pmchat = _ref3;
for (var pmchat of self.internal.private_channels) {
if (pmchat.recipient.equals(resource)) {
chatFound = pmchat;
break;
@@ -221,19 +179,12 @@ var Resolver = (function () {
found = chatFound;
} else {
// PM does not exist :\
self.internal.startPM(resource).then(function (pmchannel) {
return resolve(pmchannel);
})["catch"](function (e) {
return reject(e);
});
self.internal.startPM(resource).then(pmchannel => resolve(pmchannel)).catch(e => reject(e));
return;
}
}
if (found) resolve(found);else reject(new Error("Didn't found anything"));
});
};
return Resolver;
})();
}
}
module.exports = Resolver;

View File

@@ -1,75 +1,35 @@
"use strict";
var API = "https://discordapp.com/api";
var Endpoints = {
// general endpoints
LOGIN: API + "/auth/login",
LOGOUT: API + "/auth/logout",
ME: API + "/users/@me",
GATEWAY: API + "/gateway",
USER_CHANNELS: function USER_CHANNELS(userID) {
return API + "/users/" + userID + "/channels";
},
AVATAR: function AVATAR(userID, avatar) {
return API + "/users/" + userID + "/avatars/" + avatar + ".jpg";
},
INVITE: function INVITE(id) {
return API + "/invite/" + id;
},
LOGIN: `${ API }/auth/login`,
LOGOUT: `${ API }/auth/logout`,
ME: `${ API }/users/@me`,
GATEWAY: `${ API }/gateway`,
USER_CHANNELS: userID => `${ API }/users/${ userID }/channels`,
AVATAR: (userID, avatar) => `${ API }/users/${ userID }/avatars/${ avatar }.jpg`,
INVITE: id => `${ API }/invite/${ id }`,
// servers
SERVERS: API + "/guilds",
SERVER: function SERVER(serverID) {
return Endpoints.SERVERS + "/" + serverID;
},
SERVER_ICON: function SERVER_ICON(serverID, hash) {
return Endpoints.SERVER(serverID) + "/icons/" + hash + ".jpg";
},
SERVER_PRUNE: function SERVER_PRUNE(serverID) {
return Endpoints.SERVER(serverID) + "/prune";
},
SERVER_EMBED: function SERVER_EMBED(serverID) {
return Endpoints.SERVER(serverID) + "/embed";
},
SERVER_INVITES: function SERVER_INVITES(serverID) {
return Endpoints.SERVER(serverID) + "/invites";
},
SERVER_ROLES: function SERVER_ROLES(serverID) {
return Endpoints.SERVER(serverID) + "/roles";
},
SERVER_BANS: function SERVER_BANS(serverID) {
return Endpoints.SERVER(serverID) + "/bans";
},
SERVER_INTEGRATIONS: function SERVER_INTEGRATIONS(serverID) {
return Endpoints.SERVER(serverID) + "/integrations";
},
SERVER_MEMBERS: function SERVER_MEMBERS(serverID) {
return Endpoints.SERVER(serverID) + "/members";
},
SERVER_CHANNELS: function SERVER_CHANNELS(serverID) {
return Endpoints.SERVER(serverID) + "/channels";
},
SERVERS: `${ API }/guilds`,
SERVER: serverID => `${ Endpoints.SERVERS }/${ serverID }`,
SERVER_ICON: (serverID, hash) => `${ Endpoints.SERVER(serverID) }/icons/${ hash }.jpg`,
SERVER_PRUNE: serverID => `${ Endpoints.SERVER(serverID) }/prune`,
SERVER_EMBED: serverID => `${ Endpoints.SERVER(serverID) }/embed`,
SERVER_INVITES: serverID => `${ Endpoints.SERVER(serverID) }/invites`,
SERVER_ROLES: serverID => `${ Endpoints.SERVER(serverID) }/roles`,
SERVER_BANS: serverID => `${ Endpoints.SERVER(serverID) }/bans`,
SERVER_INTEGRATIONS: serverID => `${ Endpoints.SERVER(serverID) }/integrations`,
SERVER_MEMBERS: serverID => `${ Endpoints.SERVER(serverID) }/members`,
SERVER_CHANNELS: serverID => `${ Endpoints.SERVER(serverID) }/channels`,
// channels
CHANNELS: API + "/channels",
CHANNEL: function CHANNEL(channelID) {
return Endpoints.CHANNELS + "/" + channelID;
},
CHANNEL_MESSAGES: function CHANNEL_MESSAGES(channelID) {
return Endpoints.CHANNEL(channelID) + "/messages";
},
CHANNEL_INVITES: function CHANNEL_INVITES(channelID) {
return Endpoints.CHANNEL(channelID) + "/invites";
},
CHANNEL_TYPING: function CHANNEL_TYPING(channelID) {
return Endpoints.CHANNEL(channelID) + "/typing";
},
CHANNEL_PERMISSIONS: function CHANNEL_PERMISSIONS(channelID) {
return Endpoints.CHANNEL(channelID) + "/permissions";
},
CHANNEL_MESSAGE: function CHANNEL_MESSAGE(channelID, messageID) {
return Endpoints.CHANNEL_MESSAGES(channelID) + "/" + messageID;
}
CHANNELS: `${ API }/channels`,
CHANNEL: channelID => `${ Endpoints.CHANNELS }/${ channelID }`,
CHANNEL_MESSAGES: channelID => `${ Endpoints.CHANNEL(channelID) }/messages`,
CHANNEL_INVITES: channelID => `${ Endpoints.CHANNEL(channelID) }/invites`,
CHANNEL_TYPING: channelID => `${ Endpoints.CHANNEL(channelID) }/typing`,
CHANNEL_PERMISSIONS: channelID => `${ Endpoints.CHANNEL(channelID) }/permissions`,
CHANNEL_MESSAGE: (channelID, messageID) => `${ Endpoints.CHANNEL_MESSAGES(channelID) }/${ messageID }`
};
var Permissions = {

View File

@@ -1,39 +1,26 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Equality = require("../Util/Equality.js");
var Cache = require("../Util/Cache.js");
var PermissionOverwrite = require("./PermissionOverwrite.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
var Channel = (function (_Equality) {
_inherits(Channel, _Equality);
class Channel extends Equality {
function Channel(data, client) {
_classCallCheck(this, Channel);
_Equality.call(this);
constructor(data, client) {
super();
this.id = data.id;
this.client = client;
}
Channel.prototype["delete"] = function _delete() {
get isPrivate() {
return !!this.server;
}
delete() {
return this.client.deleteChannel.apply(this.client, reg(this, arguments));
};
}
_createClass(Channel, [{
key: "isPrivate",
get: function get() {
return !!this.server;
}
}]);
return Channel;
})(Equality);
}
module.exports = Channel;

View File

@@ -1,22 +1,15 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Permissions = require("../Constants.js").Permissions;
var ChannelPermissions = (function () {
function ChannelPermissions(permissions) {
_classCallCheck(this, ChannelPermissions);
class ChannelPermissions {
constructor(permissions) {
this.permissions = permissions;
}
ChannelPermissions.prototype.serialise = function serialise(explicit) {
var _this = this;
serialise(explicit) {
var hp = function hp(perm) {
return _this.hasPermission(perm, explicit);
};
var hp = perm => this.hasPermission(perm, explicit);
return {
// general
@@ -43,16 +36,14 @@ var ChannelPermissions = (function () {
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
voiceUseVAD: hp(Permissions.voiceUseVAD)
};
};
}
ChannelPermissions.prototype.serialize = function serialize() {
serialize() {
// ;n;
return this.serialise();
};
ChannelPermissions.prototype.hasPermission = function hasPermission(perm) {
var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
}
hasPermission(perm, explicit = false) {
if (perm instanceof String || typeof perm === "string") {
perm = Permissions[perm];
}
@@ -67,9 +58,7 @@ var ChannelPermissions = (function () {
}
}
return !!(this.permissions & perm);
};
return ChannelPermissions;
})();
}
}
module.exports = ChannelPermissions;

View File

@@ -1,32 +1,26 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Server = require("./Server.js");
var ServerChannel = require("./ServerChannel.js");
var Invite = (function () {
function Invite(data, chan, client) {
_classCallCheck(this, Invite);
class Invite {
constructor(data, chan, client) {
this.maxAge = data.max_age;
this.code = data.code;
this.server = chan.server;
this.channel = chan;
this.revoked = data.revoked;
this.createdAt = Date.parse(data.created_at);
this.temporary = data.temporary;
this.uses = data.uses;
this.maxUses = data.uses;
this.inviter = client.internal.users.get("id", data.inviter.id);
this.xkcd = data.xkcdpass;
}
this.maxAge = data.max_age;
this.code = data.code;
this.server = chan.server;
this.channel = chan;
this.revoked = data.revoked;
this.createdAt = Date.parse(data.created_at);
this.temporary = data.temporary;
this.uses = data.uses;
this.maxUses = data.uses;
this.inviter = client.internal.users.get("id", data.inviter.id);
this.xkcd = data.xkcdpass;
}
Invite.prototype.toString = function toString() {
return "https://discord.gg/" + this.code;
};
return Invite;
})();
toString() {
return `https://discord.gg/${ this.code }`;
}
}
module.exports = Invite;

View File

@@ -1,25 +1,13 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Cache = require("../Util/Cache.js");
var User = require("./User.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
var Equality = require("../Util/Equality");
var Message = (function (_Equality) {
_inherits(Message, _Equality);
function Message(data, channel, client) {
var _this = this;
_classCallCheck(this, Message);
_Equality.call(this);
class Message extends Equality {
constructor(data, channel, client) {
super();
this.channel = channel;
this.client = client;
this.nonce = data.nonce;
@@ -37,51 +25,46 @@ var Message = (function (_Equality) {
this.content = data.content;
this.mentions = new Cache();
data.mentions.forEach(function (mention) {
data.mentions.forEach(mention => {
// this is .add and not .get because it allows the bot to cache
// users from messages from logs who may have left the server and were
// not previously cached.
if (mention instanceof User) _this.mentions.push(mention);else _this.mentions.add(client.internal.users.add(new User(mention, client)));
if (mention instanceof User) this.mentions.push(mention);else this.mentions.add(client.internal.users.add(new User(mention, client)));
});
}
Message.prototype.isMentioned = function isMentioned(user) {
isMentioned(user) {
user = this.client.internal.resolver.resolveUser(user);
if (user) {
return this.mentions.has("id", user.id);
} else {
return false;
}
};
}
Message.prototype.toString = function toString() {
toString() {
return this.content;
};
}
Message.prototype["delete"] = function _delete() {
delete() {
return this.client.deleteMessage.apply(this.client, reg(this, arguments));
};
}
Message.prototype.update = function update() {
update() {
return this.client.updateMessage.apply(this.client, reg(this, arguments));
};
}
Message.prototype.reply = function reply() {
reply() {
return this.client.reply.apply(this.client, reg(this, arguments));
};
}
Message.prototype.replyTTS = function replyTTS() {
replyTTS() {
return this.client.replyTTS.apply(this.client, reg(this, arguments));
};
}
_createClass(Message, [{
key: "sender",
get: function get() {
return this.author;
}
}]);
return Message;
})(Equality);
get sender() {
return this.author;
}
}
module.exports = Message;

View File

@@ -1,24 +1,14 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Channel = require("./Channel.js");
var User = require("./User.js");
var Equality = require("../Util/Equality.js");
var Cache = require("../Util/Cache.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
var PMChannel = (function (_Channel) {
_inherits(PMChannel, _Channel);
function PMChannel(data, client) {
_classCallCheck(this, PMChannel);
_Channel.call(this, data, client);
class PMChannel extends Channel {
constructor(data, client) {
super(data, client);
this.type = data.type || "text";
this.lastMessageId = data.last_message_id;
@@ -27,27 +17,21 @@ var PMChannel = (function (_Channel) {
}
/* warning! may return null */
get lastMessage() {
return this.messages.get("id", this.lastMessageID);
}
PMChannel.prototype.toString = function toString() {
toString() {
return this.recipient.toString();
};
}
PMChannel.prototype.sendMessage = function sendMessage() {
sendMessage() {
return this.client.sendMessage.apply(this.client, reg(this, arguments));
};
}
PMChannel.prototype.sendTTSMessage = function sendTTSMessage() {
sendTTSMessage() {
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
};
_createClass(PMChannel, [{
key: "lastMessage",
get: function get() {
return this.messages.get("id", this.lastMessageID);
}
}]);
return PMChannel;
})(Channel);
}
}
module.exports = PMChannel;

View File

@@ -1,15 +1,10 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Permissions = require("../Constants.js").Permissions;
var PermissionOverwrite = (function () {
function PermissionOverwrite(data) {
_classCallCheck(this, PermissionOverwrite);
class PermissionOverwrite {
constructor(data) {
this.id = data.id;
this.type = data.type; // member or role
this.deny = data.deny;
@@ -17,70 +12,59 @@ var PermissionOverwrite = (function () {
}
// returns an array of allowed permissions
get allowed() {
var allowed = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
// these permissions do not exist in overwrites.
continue;
}
PermissionOverwrite.prototype.setAllowed = function setAllowed(allowedArray) {
var _this = this;
if (!!(this.allow & Permissions[permName])) {
allowed.push(permName);
}
}
return allowed;
}
allowedArray.forEach(function (permission) {
// returns an array of denied permissions
get denied() {
var denied = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
// these permissions do not exist in overwrites.
continue;
}
if (!!(this.deny & Permissions[permName])) {
denied.push(permName);
}
}
return denied;
}
setAllowed(allowedArray) {
allowedArray.forEach(permission => {
if (permission instanceof String || typeof permission === "string") {
permission = Permissions[permission];
}
if (permission) {
_this.allow |= 1 << permission;
this.allow |= 1 << permission;
}
});
};
}
PermissionOverwrite.prototype.setDenied = function setDenied(deniedArray) {
var _this2 = this;
deniedArray.forEach(function (permission) {
setDenied(deniedArray) {
deniedArray.forEach(permission => {
if (permission instanceof String || typeof permission === "string") {
permission = Permissions[permission];
}
if (permission) {
_this2.deny |= 1 << permission;
this.deny |= 1 << permission;
}
});
};
}
_createClass(PermissionOverwrite, [{
key: "allowed",
get: function get() {
var allowed = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
// these permissions do not exist in overwrites.
continue;
}
if (!!(this.allow & Permissions[permName])) {
allowed.push(permName);
}
}
return allowed;
}
// returns an array of denied permissions
}, {
key: "denied",
get: function get() {
var denied = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
// these permissions do not exist in overwrites.
continue;
}
if (!!(this.deny & Permissions[permName])) {
denied.push(permName);
}
}
return denied;
}
}]);
return PermissionOverwrite;
})();
}
module.exports = PermissionOverwrite;

View File

@@ -1,7 +1,5 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Permissions = require("../Constants.js").Permissions;
/*
@@ -16,14 +14,10 @@ example data
color: 0 }
*/
var DefaultRole = [Permissions.createInstantInvite, Permissions.readMessages, Permissions.readMessageHistory, Permissions.sendMessages, Permissions.sendTTSMessages, Permissions.embedLinks, Permissions.attachFiles, Permissions.readMessageHistory, Permissions.mentionEveryone, Permissions.voiceConnect, Permissions.voiceSpeak, Permissions.voiceUseVAD].reduce(function (previous, current) {
return previous | current;
}, 0);
var Role = (function () {
function Role(data, server, client) {
_classCallCheck(this, Role);
const DefaultRole = [Permissions.createInstantInvite, Permissions.readMessages, Permissions.readMessageHistory, Permissions.sendMessages, Permissions.sendTTSMessages, Permissions.embedLinks, Permissions.attachFiles, Permissions.readMessageHistory, Permissions.mentionEveryone, Permissions.voiceConnect, Permissions.voiceSpeak, Permissions.voiceUseVAD].reduce((previous, current) => previous | current, 0);
class Role {
constructor(data, server, client) {
this.position = data.position || -1;
this.permissions = data.permissions || (data.name === "@everyone" ? DefaultRole : 0);
this.name = data.name || "@everyone";
@@ -35,12 +29,9 @@ var Role = (function () {
this.client = client;
}
Role.prototype.serialise = function serialise(explicit) {
var _this = this;
serialise(explicit) {
var hp = function hp(perm) {
return _this.hasPermission(perm, explicit);
};
var hp = perm => this.hasPermission(perm, explicit);
return {
// general
@@ -67,16 +58,14 @@ var Role = (function () {
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
voiceUseVAD: hp(Permissions.voiceUseVAD)
};
};
}
Role.prototype.serialize = function serialize() {
serialize() {
// ;n;
return this.serialise();
};
Role.prototype.hasPermission = function hasPermission(perm) {
var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
}
hasPermission(perm, explicit = false) {
if (perm instanceof String || typeof perm === "string") {
perm = Permissions[perm];
}
@@ -95,9 +84,9 @@ var Role = (function () {
// !!(36953089 & (1 << 21)) = voice speak allowed
return !!(this.permissions & perm);
};
}
Role.prototype.setPermission = function setPermission(permission, value) {
setPermission(permission, value) {
if (permission instanceof String || typeof permission === "string") {
permission = Permissions[permission];
}
@@ -109,31 +98,27 @@ var Role = (function () {
this.permissions &= ~permission;
}
}
};
}
Role.prototype.setPermissions = function setPermissions(obj) {
var _this2 = this;
obj.forEach(function (value, permission) {
setPermissions(obj) {
obj.forEach((value, permission) => {
if (permission instanceof String || typeof permission === "string") {
permission = Permissions[permission];
}
if (permission) {
// valid permission
_this2.setPermission(permission, value);
this.setPermission(permission, value);
}
});
};
}
Role.prototype.colorAsHex = function colorAsHex() {
colorAsHex() {
var val = this.color.toString();
while (val.length < 6) {
val = "0" + val;
}
return "#" + val;
};
return Role;
})();
}
}
module.exports = Role;

View File

@@ -1,11 +1,5 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Equality = require("../Util/Equality.js");
var Endpoints = require("../Constants.js").Endpoints;
var Cache = require("../Util/Cache.js");
@@ -16,15 +10,10 @@ var Role = require("./Role.js");
var strictKeys = ["region", "ownerID", "name", "id", "icon", "afkTimeout", "afkChannelID"];
var Server = (function (_Equality) {
_inherits(Server, _Equality);
class Server extends Equality {
constructor(data, client) {
function Server(data, client) {
var _this = this;
_classCallCheck(this, Server);
_Equality.call(this);
super();
var self = this;
this.client = client;
@@ -43,48 +32,33 @@ var Server = (function (_Equality) {
var self = this;
data.roles.forEach(function (dataRole) {
_this.roles.add(new Role(dataRole, _this, client));
data.roles.forEach(dataRole => {
this.roles.add(new Role(dataRole, this, client));
});
data.members.forEach(function (dataUser) {
_this.memberMap[dataUser.user.id] = {
roles: dataUser.roles.map(function (pid) {
return self.roles.get("id", pid);
}),
data.members.forEach(dataUser => {
this.memberMap[dataUser.user.id] = {
roles: dataUser.roles.map(pid => self.roles.get("id", pid)),
mute: dataUser.mute,
deaf: dataUser.deaf,
joinedAt: Date.parse(dataUser.joined_at)
};
var user = client.internal.users.add(new User(dataUser.user, client));
_this.members.add(user);
this.members.add(user);
});
data.channels.forEach(function (dataChannel) {
data.channels.forEach(dataChannel => {
if (dataChannel.type === "text") {
var channel = client.internal.channels.add(new TextChannel(dataChannel, client, _this));
_this.channels.add(channel);
var channel = client.internal.channels.add(new TextChannel(dataChannel, client, this));
this.channels.add(channel);
} else {
var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client, _this));
_this.channels.add(channel);
var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client, this));
this.channels.add(channel);
}
});
if (data.presences) {
for (var _iterator = data.presences, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var presence = _ref;
for (var presence of data.presences) {
var user = client.internal.users.get("id", presence.user.id);
if (user) {
user.status = presence.status;
@@ -94,39 +68,46 @@ var Server = (function (_Equality) {
}
}
Server.prototype.rolesOfUser = function rolesOfUser(user) {
rolesOfUser(user) {
user = this.client.internal.resolver.resolveUser(user);
if (user) {
return this.memberMap[user.id] ? this.memberMap[user.id].roles : [];
} else {
return null;
}
};
}
Server.prototype.rolesOf = function rolesOf(user) {
rolesOf(user) {
return this.rolesOfUser(user);
};
}
Server.prototype.toString = function toString() {
get iconURL() {
if (!this.icon) {
return null;
} else {
return Endpoints.SERVER_ICON(this.id, this.icon);
}
}
get afkChannel() {
return this.channels.get("id", this.afkChannelID);
}
get defaultChannel() {
return this.channels.get("id", this.id);
}
get owner() {
return this.members.get("id", this.ownerID);
}
toString() {
return this.name;
};
}
Server.prototype.equalsStrict = function equalsStrict(obj) {
equalsStrict(obj) {
if (obj instanceof Server) {
for (var _iterator2 = strictKeys, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var key = _ref2;
for (var key of strictKeys) {
if (obj[key] !== this[key]) {
return false;
}
@@ -135,35 +116,8 @@ var Server = (function (_Equality) {
return false;
}
return true;
};
}
_createClass(Server, [{
key: "iconURL",
get: function get() {
if (!this.icon) {
return null;
} else {
return Endpoints.SERVER_ICON(this.id, this.icon);
}
}
}, {
key: "afkChannel",
get: function get() {
return this.channels.get("id", this.afkChannelID);
}
}, {
key: "defaultChannel",
get: function get() {
return this.channels.get("id", this.id);
}
}, {
key: "owner",
get: function get() {
return this.members.get("id", this.ownerID);
}
}]);
return Server;
})(Equality);
}
module.exports = Server;

View File

@@ -1,35 +1,25 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Channel = require("./Channel.js");
var Cache = require("../Util/Cache.js");
var PermissionOverwrite = require("./PermissionOverwrite.js");
var ChannelPermissions = require("./ChannelPermissions.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
var ServerChannel = (function (_Channel) {
_inherits(ServerChannel, _Channel);
function ServerChannel(data, client, server) {
var _this = this;
_classCallCheck(this, ServerChannel);
_Channel.call(this, data, client);
class ServerChannel extends Channel {
constructor(data, client, server) {
super(data, client);
this.name = data.name;
this.type = data.type;
this.position = data.position;
this.permissionOverwrites = new Cache();
this.server = server;
data.permission_overwrites.forEach(function (permission) {
_this.permissionOverwrites.add(new PermissionOverwrite(permission));
data.permission_overwrites.forEach(permission => {
this.permissionOverwrites.add(new PermissionOverwrite(permission));
});
}
ServerChannel.prototype.permissionsOf = function permissionsOf(user) {
permissionsOf(user) {
user = this.client.internal.resolver.resolveUser(user);
if (user) {
if (this.server.owner.equals(user)) {
@@ -38,13 +28,11 @@ var ServerChannel = (function (_Channel) {
var everyoneRole = this.server.roles.get("name", "@everyone");
var userRoles = [everyoneRole].concat(this.server.rolesOf(user) || []);
var userRolesID = userRoles.map(function (v) {
return v.id;
});
var userRolesID = userRoles.map(v => v.id);
var roleOverwrites = [],
memberOverwrites = [];
this.permissionOverwrites.forEach(function (overwrite) {
this.permissionOverwrites.forEach(overwrite => {
if (overwrite.type === "member" && overwrite.id === user.id) {
memberOverwrites.push(overwrite);
} else if (overwrite.type === "role" && overwrite.id in userRolesID) {
@@ -54,37 +42,11 @@ var ServerChannel = (function (_Channel) {
var permissions = 0;
for (var _iterator = userRoles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var serverRole = _ref;
for (var serverRole of userRoles) {
permissions |= serverRole.permissions;
}
for (var _iterator2 = roleOverwrites.concat(memberOverwrites), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var overwrite = _ref2;
for (var overwrite of roleOverwrites.concat(memberOverwrites)) {
permissions = permissions & ~overwrite.deny;
permissions = permissions | overwrite.allow;
}
@@ -93,25 +55,23 @@ var ServerChannel = (function (_Channel) {
} else {
return null;
}
};
}
ServerChannel.prototype.permsOf = function permsOf(user) {
permsOf(user) {
return this.permissionsOf(user);
};
}
ServerChannel.prototype.mention = function mention() {
return "<#" + this.id + ">";
};
mention() {
return `<#${ this.id }>`;
}
ServerChannel.prototype.toString = function toString() {
toString() {
return this.mention();
};
}
ServerChannel.prototype.setName = function setName() {
setName() {
return this.client.setChannelName.apply(this.client, reg(this, arguments));
};
return ServerChannel;
})(Channel);
}
}
module.exports = ServerChannel;

View File

@@ -1,22 +1,12 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ServerChannel = require("./ServerChannel.js");
var Cache = require("../Util/Cache.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
var TextChannel = (function (_ServerChannel) {
_inherits(TextChannel, _ServerChannel);
function TextChannel(data, client, server) {
_classCallCheck(this, TextChannel);
_ServerChannel.call(this, data, client, server);
class TextChannel extends ServerChannel {
constructor(data, client, server) {
super(data, client, server);
this.topic = data.topic;
this.lastMessageID = data.last_message_id;
@@ -24,35 +14,29 @@ var TextChannel = (function (_ServerChannel) {
}
/* warning! may return null */
get lastMessage() {
return this.messages.get("id", this.lastMessageID);
}
TextChannel.prototype.setTopic = function setTopic() {
setTopic() {
return this.client.setTopic.apply(this.client, reg(this, arguments));
};
}
TextChannel.prototype.setNameAndTopic = function setNameAndTopic() {
setNameAndTopic() {
return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments));
};
}
TextChannel.prototype.update = function update() {
update() {
return this.client.updateChannel.apply(this.client, reg(this, arguments));
};
}
TextChannel.prototype.sendMessage = function sendMessage() {
sendMessage() {
return this.client.sendMessage.apply(this.client, reg(this, arguments));
};
}
TextChannel.prototype.sendTTSMessage = function sendTTSMessage() {
sendTTSMessage() {
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
};
_createClass(TextChannel, [{
key: "lastMessage",
get: function get() {
return this.messages.get("id", this.lastMessageID);
}
}]);
return TextChannel;
})(ServerChannel);
}
}
module.exports = TextChannel;

View File

@@ -1,21 +1,11 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Equality = require("../Util/Equality.js");
var Endpoints = require("../Constants.js").Endpoints;
var User = (function (_Equality) {
_inherits(User, _Equality);
function User(data, client) {
_classCallCheck(this, User);
_Equality.call(this);
class User extends Equality {
constructor(data, client) {
super();
this.client = client;
this.username = data.username;
this.discriminator = data.discriminator;
@@ -29,30 +19,25 @@ var User = (function (_Equality) {
};
}
User.prototype.mention = function mention() {
return "<@" + this.id + ">";
};
User.prototype.toString = function toString() {
return this.mention();
};
User.prototype.equalsStrict = function equalsStrict(obj) {
if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && this.gameID === obj.gameID;else return false;
};
_createClass(User, [{
key: "avatarURL",
get: function get() {
if (!this.avatar) {
return null;
} else {
return Endpoints.AVATAR(this.id, this.avatar);
}
get avatarURL() {
if (!this.avatar) {
return null;
} else {
return Endpoints.AVATAR(this.id, this.avatar);
}
}]);
}
return User;
})(Equality);
mention() {
return `<@${ this.id }>`;
}
toString() {
return this.mention();
}
equalsStrict(obj) {
if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && this.gameID === obj.gameID;else return false;
}
}
module.exports = User;

View File

@@ -1,21 +1,11 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ServerChannel = require("./ServerChannel.js");
var VoiceChannel = (function (_ServerChannel) {
_inherits(VoiceChannel, _ServerChannel);
function VoiceChannel(data, client, server) {
_classCallCheck(this, VoiceChannel);
_ServerChannel.call(this, data, client, server);
class VoiceChannel extends ServerChannel {
constructor(data, client, server) {
super(data, client, server);
}
return VoiceChannel;
})(ServerChannel);
}
module.exports = VoiceChannel;

View File

@@ -1,5 +1,3 @@
"use strict";
exports.reg = function (c, a) {
return [c].concat(Array.prototype.slice.call(a));
};

View File

@@ -1,61 +1,40 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Cache = (function (_Array) {
_inherits(Cache, _Array);
function Cache(discrim, limit) {
_classCallCheck(this, Cache);
_Array.call(this);
class Cache extends Array {
constructor(discrim, limit) {
super();
this.discrim = discrim || "id";
}
Cache.prototype.get = function get(key, value) {
get(key, value) {
var found = null;
this.forEach(function (val, index, array) {
this.forEach((val, index, array) => {
if (val.hasOwnProperty(key) && val[key] == value) {
found = val;
return;
}
});
return found;
};
}
Cache.prototype.has = function has(key, value) {
has(key, value) {
return !!this.get(key, value);
};
}
Cache.prototype.getAll = function getAll(key, value) {
getAll(key, value) {
var found = new Cache(this.discrim);
this.forEach(function (val, index, array) {
this.forEach((val, index, array) => {
if (val.hasOwnProperty(key) && val[key] == value) {
found.push(val);
return;
}
});
return found;
};
}
Cache.prototype.add = function add(data) {
add(data) {
var exit = false;
for (var _iterator = this, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var item = _ref;
for (var item of this) {
if (item[this.discrim] === data[this.discrim]) {
exit = item;
break;
@@ -70,9 +49,9 @@ var Cache = (function (_Array) {
this.push(data);
return data;
}
};
}
Cache.prototype.update = function update(old, data) {
update(old, data) {
var item = this.get(this.discrim, old[this.discrim]);
if (item) {
var index = this.indexOf(item);
@@ -81,13 +60,13 @@ var Cache = (function (_Array) {
} else {
return false;
}
};
}
Cache.prototype.random = function random() {
random() {
return this[Math.floor(Math.random() * this.length)];
};
}
Cache.prototype.remove = function remove(data) {
remove(data) {
var index = this.indexOf(data);
if (~index) {
this.splice(index, 1);
@@ -98,9 +77,7 @@ var Cache = (function (_Array) {
}
}
return false;
};
return Cache;
})(Array);
}
}
module.exports = Cache;

View File

@@ -9,37 +9,24 @@
Instead, use objectThatExtendsEquality.equals()
*/
"use strict";
class Equality {
constructor() {}
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Equality = (function () {
function Equality() {
_classCallCheck(this, Equality);
get eqDiscriminator() {
return "id";
}
Equality.prototype.equals = function equals(object) {
equals(object) {
if (object && object[this.eqDiscriminator] == this[this.eqDiscriminator]) {
return true;
}
return false;
};
}
Equality.prototype.equalsStrict = function equalsStrict(object) {
equalsStrict(object) {
// override per class type
return;
};
_createClass(Equality, [{
key: "eqDiscriminator",
get: function get() {
return "id";
}
}]);
return Equality;
})();
}
}
module.exports = Equality;

View File

@@ -1,7 +1,5 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var cpoc = require("child_process");
var opus;
@@ -12,41 +10,26 @@ try {
}
var VoicePacket = require("./VoicePacket.js");
var AudioEncoder = (function () {
function AudioEncoder() {
_classCallCheck(this, AudioEncoder);
class AudioEncoder {
constructor() {
if (opus) {
this.opus = new opus.OpusEncoder(48000, 1);
}
this.choice = false;
}
AudioEncoder.prototype.opusBuffer = function opusBuffer(buffer) {
opusBuffer(buffer) {
return this.opus.encode(buffer, 1920);
};
}
AudioEncoder.prototype.getCommand = function getCommand(force) {
getCommand(force) {
if (this.choice && force) return choice;
var choices = ["avconv", "ffmpeg"];
for (var _iterator = choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var choice = _ref;
for (var choice of choices) {
var p = cpoc.spawnSync(choice);
if (!p.error) {
this.choice = choice;
@@ -55,13 +38,11 @@ var AudioEncoder = (function () {
}
return "help";
};
AudioEncoder.prototype.encodeStream = function encodeStream(stream) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
}
encodeStream(stream, callback = function (err, buffer) {}) {
var self = this;
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
var enc = cpoc.spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
"-af", "volume=1", "pipe:1", "-i", "-"]);
@@ -90,13 +71,11 @@ var AudioEncoder = (function () {
reject("close");
});
});
};
AudioEncoder.prototype.encodeFile = function encodeFile(file) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
}
encodeFile(file, callback = function (err, buffer) {}) {
var self = this;
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
var enc = cpoc.spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
"-af", "volume=1", "pipe:1", "-i", file]);
@@ -121,9 +100,7 @@ var AudioEncoder = (function () {
reject("close");
});
});
};
return AudioEncoder;
})();
}
}
module.exports = AudioEncoder;

View File

@@ -1,22 +1,12 @@
"use strict";
"use strict"
// represents an intent of streaming music
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
;
var EventEmitter = require("events");
var StreamIntent = (function (_EventEmitter) {
_inherits(StreamIntent, _EventEmitter);
function StreamIntent() {
_classCallCheck(this, StreamIntent);
_EventEmitter.call(this);
class StreamIntent extends EventEmitter {
constructor() {
super();
}
return StreamIntent;
})(EventEmitter);
}
module.exports = StreamIntent;

View File

@@ -1,4 +1,4 @@
"use strict";
"use strict"
/*
Major credit to izy521 who is the creator of
https://github.com/izy521/discord.io,
@@ -7,10 +7,7 @@
been possible!
*/
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
;
var WebSocket = require("ws");
var dns = require("dns");
var udp = require("dgram");
@@ -20,13 +17,9 @@ var VoicePacket = require("./VoicePacket.js");
var StreamIntent = require("./StreamIntent.js");
var EventEmitter = require("events");
var VoiceConnection = (function (_EventEmitter) {
_inherits(VoiceConnection, _EventEmitter);
function VoiceConnection(channel, client, session, token, server, endpoint) {
_classCallCheck(this, VoiceConnection);
_EventEmitter.call(this);
class VoiceConnection extends EventEmitter {
constructor(channel, client, session, token, server, endpoint) {
super();
this.id = channel.id;
this.voiceChannel = channel;
this.client = client;
@@ -47,7 +40,7 @@ var VoiceConnection = (function (_EventEmitter) {
this.init();
}
VoiceConnection.prototype.destroy = function destroy() {
destroy() {
this.stopPlaying();
if (this.KAI) clearInterval(this.KAI);
this.vWS.close();
@@ -61,18 +54,18 @@ var VoiceConnection = (function (_EventEmitter) {
self_deaf: false
}
});
};
}
VoiceConnection.prototype.stopPlaying = function stopPlaying() {
stopPlaying() {
this.playing = false;
this.playingIntent = null;
if (this.instream) {
this.instream.end();
this.instream.destroy();
}
};
}
VoiceConnection.prototype.playStream = function playStream(stream) {
playStream(stream) {
var self = this;
@@ -123,7 +116,7 @@ var VoiceConnection = (function (_EventEmitter) {
sequence + 10 < 65535 ? sequence += 1 : sequence = 0;
time + 9600 < 4294967295 ? time += 960 : time = 0;
self.sendBuffer(buffer, sequence, time, function (e) {});
self.sendBuffer(buffer, sequence, time, e => {});
var nextTime = startTime + count * length;
@@ -141,9 +134,9 @@ var VoiceConnection = (function (_EventEmitter) {
send();
return retStream;
};
}
VoiceConnection.prototype.setSpeaking = function setSpeaking(value) {
setSpeaking(value) {
this.playing = value;
if (this.vWS.readyState === WebSocket.OPEN) this.vWS.send(JSON.stringify({
op: 5,
@@ -152,11 +145,9 @@ var VoiceConnection = (function (_EventEmitter) {
delay: 0
}
}));
};
VoiceConnection.prototype.sendPacket = function sendPacket(packet) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
}
sendPacket(packet, callback = function (err) {}) {
var self = this;
self.playing = true;
try {
@@ -166,9 +157,9 @@ var VoiceConnection = (function (_EventEmitter) {
callback(e);
return false;
}
};
}
VoiceConnection.prototype.sendBuffer = function sendBuffer(rawbuffer, sequence, timestamp, callback) {
sendBuffer(rawbuffer, sequence, timestamp, callback) {
var self = this;
self.playing = true;
try {
@@ -186,68 +177,54 @@ var VoiceConnection = (function (_EventEmitter) {
self.emit("error", e);
return false;
}
};
}
VoiceConnection.prototype.test = function test() {
this.playFile("C:/users/amish/desktop/audio.mp3").then(function (stream) {
stream.on("time", function (time) {
test() {
this.playFile("C:/users/amish/desktop/audio.mp3").then(stream => {
stream.on("time", time => {
console.log("Time", time);
});
});
};
VoiceConnection.prototype.playFile = function playFile(stream) {
var _this = this;
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
}
playFile(stream, callback = function (err, str) {}) {
var self = this;
return new Promise(function (resolve, reject) {
_this.encoder.encodeFile(stream)["catch"](error).then(function (data) {
return new Promise((resolve, reject) => {
this.encoder.encodeFile(stream).catch(error).then(data => {
self.streamProc = data.proc;
var intent = self.playStream(data.stream);
resolve(intent);
callback(null, intent);
});
function error() {
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
function error(e = true) {
reject(e);
callback(e);
}
});
};
VoiceConnection.prototype.playRawStream = function playRawStream(stream) {
var _this2 = this;
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
}
playRawStream(stream, callback = function (err, str) {}) {
var self = this;
return new Promise(function (resolve, reject) {
_this2.encoder.encodeStream(stream)["catch"](error).then(function (data) {
return new Promise((resolve, reject) => {
this.encoder.encodeStream(stream).catch(error).then(data => {
self.streamProc = data.proc;
self.instream = data.instream;
var intent = self.playStream(data.stream);
resolve(intent);
callback(null, intent);
});
function error() {
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
function error(e = true) {
reject(e);
callback(e);
}
});
};
VoiceConnection.prototype.init = function init() {
var _this3 = this;
}
init() {
var self = this;
dns.lookup(this.endpoint, function (err, address, family) {
dns.lookup(this.endpoint, (err, address, family) => {
self.endpoint = address;
var vWS = self.vWS = new WebSocket("wss://" + _this3.endpoint, null, { rejectUnauthorized: false });
var vWS = self.vWS = new WebSocket("wss://" + this.endpoint, null, { rejectUnauthorized: false });
var udpClient = self.udp = udp.createSocket("udp4");
var firstPacket = true;
@@ -280,7 +257,7 @@ var VoiceConnection = (function (_EventEmitter) {
}
});
vWS.on("open", function () {
vWS.on("open", () => {
vWS.send(JSON.stringify({
op: 0,
d: {
@@ -294,13 +271,13 @@ var VoiceConnection = (function (_EventEmitter) {
var KAI;
vWS.on("message", function (msg) {
vWS.on("message", msg => {
var data = JSON.parse(msg);
switch (data.op) {
case 2:
self.vWSData = data.d;
KAI = setInterval(function () {
KAI = setInterval(() => {
if (vWS && vWS.readyState === WebSocket.OPEN) vWS.send(JSON.stringify({
op: 3,
d: null
@@ -310,7 +287,7 @@ var VoiceConnection = (function (_EventEmitter) {
var udpPacket = new Buffer(70);
udpPacket.writeUIntBE(data.d.ssrc, 0, 4);
udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, function (err) {
udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, err => {
if (err) self.emit("error", err);
});
break;
@@ -324,9 +301,7 @@ var VoiceConnection = (function (_EventEmitter) {
}
});
});
};
return VoiceConnection;
})(EventEmitter);
}
}
module.exports = VoiceConnection;

View File

@@ -1,26 +1,25 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
class VoicePacket {
constructor(data, sequence, time, ssrc) {
var VoicePacket = function VoicePacket(data, sequence, time, ssrc) {
_classCallCheck(this, VoicePacket);
var audioBuffer = data,
returnBuffer = new Buffer(audioBuffer.length + 12);
var audioBuffer = data,
returnBuffer = new Buffer(audioBuffer.length + 12);
returnBuffer.fill(0);
returnBuffer[0] = 0x80;
returnBuffer[1] = 0x78;
returnBuffer.fill(0);
returnBuffer[0] = 0x80;
returnBuffer[1] = 0x78;
returnBuffer.writeUIntBE(sequence, 2, 2);
returnBuffer.writeUIntBE(time, 4, 4);
returnBuffer.writeUIntBE(ssrc, 8, 4);
returnBuffer.writeUIntBE(sequence, 2, 2);
returnBuffer.writeUIntBE(time, 4, 4);
returnBuffer.writeUIntBE(ssrc, 8, 4);
for (var i = 0; i < audioBuffer.length; i++) {
returnBuffer[i + 12] = audioBuffer[i];
}
for (var i = 0; i < audioBuffer.length; i++) {
returnBuffer[i + 12] = audioBuffer[i];
}
return returnBuffer;
};
return returnBuffer;
}
}
module.exports = VoicePacket;

View File

@@ -1,5 +1,3 @@
"use strict";
module.exports = {
Client: require("./Client/Client"),
Channel: require("./Structures/Channel"),