mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
added setPlaying and now working on docs
This commit is contained in:
@@ -399,6 +399,13 @@ Gets a PMChannel_ that matches the specified criteria. E.g:
|
|||||||
- **key** - a `String` that is the key
|
- **key** - a `String` that is the key
|
||||||
- **value** - a `String` that is the value
|
- **value** - a `String` that is the value
|
||||||
|
|
||||||
|
setPlayingGame(id)
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Sets the client as playing the specified game name/id.
|
||||||
|
|
||||||
|
- **id** - Either a `Number` or a `String`. If it's a Number, it's assumed that you are using the Discord Game ID
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
Event Management
|
Event Management
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ var Message = require("./message.js");
|
|||||||
var Invite = require("./invite.js");
|
var Invite = require("./invite.js");
|
||||||
var PMChannel = require("./PMChannel.js");
|
var PMChannel = require("./PMChannel.js");
|
||||||
|
|
||||||
|
var gameMap = require("../ref/gameMap.json");
|
||||||
|
|
||||||
//node modules
|
//node modules
|
||||||
var request = require("superagent");
|
var request = require("superagent");
|
||||||
var WebSocket = require("ws");
|
var WebSocket = require("ws");
|
||||||
@@ -63,6 +65,9 @@ var Client = (function () {
|
|||||||
this.readyTime = null;
|
this.readyTime = null;
|
||||||
this.checkingQueue = {};
|
this.checkingQueue = {};
|
||||||
this.queue = {};
|
this.queue = {};
|
||||||
|
|
||||||
|
this.__idleTime = null;
|
||||||
|
this.__gameId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(Client, [{
|
_createClass(Client, [{
|
||||||
@@ -1778,14 +1783,73 @@ var Client = (function () {
|
|||||||
|
|
||||||
var idleTime = stat === "online" ? null : Date.now();
|
var idleTime = stat === "online" ? null : Date.now();
|
||||||
|
|
||||||
|
this.__idleTime = idleTime;
|
||||||
|
|
||||||
this.websocket.send(JSON.stringify({
|
this.websocket.send(JSON.stringify({
|
||||||
op: 3,
|
op: 3,
|
||||||
d: {
|
d: {
|
||||||
idle_since: idleTime,
|
idle_since: this.__idleTime,
|
||||||
game_id: null
|
game_id: this.__gameId
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
key: "setPlayingGame",
|
||||||
|
value: function setPlayingGame(id) {
|
||||||
|
|
||||||
|
if (id instanceof String || typeof id === "string") {
|
||||||
|
|
||||||
|
// working on names
|
||||||
|
var gid = id.trim().toUpperCase();
|
||||||
|
|
||||||
|
id = null;
|
||||||
|
|
||||||
|
var _iteratorNormalCompletion16 = true;
|
||||||
|
var _didIteratorError16 = false;
|
||||||
|
var _iteratorError16 = undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (var _iterator16 = gameMap[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) {
|
||||||
|
var game = _step16.value;
|
||||||
|
|
||||||
|
if (game.name.trim().toUpperCase() === gid) {
|
||||||
|
|
||||||
|
id = game.id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
_didIteratorError16 = true;
|
||||||
|
_iteratorError16 = err;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (!_iteratorNormalCompletion16 && _iterator16["return"]) {
|
||||||
|
_iterator16["return"]();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (_didIteratorError16) {
|
||||||
|
throw _iteratorError16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.__gameId = id;
|
||||||
|
|
||||||
|
this.websocket.send(JSON.stringify({
|
||||||
|
op: 3,
|
||||||
|
d: {
|
||||||
|
idle_since: this.__idleTime,
|
||||||
|
game_id: this.__gameId
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: "playingGame",
|
||||||
|
value: function playingGame(id) {
|
||||||
|
|
||||||
|
this.setPlayingGame(id);
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "uptime",
|
key: "uptime",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
@@ -1822,27 +1886,27 @@ var Client = (function () {
|
|||||||
get: function get() {
|
get: function get() {
|
||||||
|
|
||||||
var msgs = [];
|
var msgs = [];
|
||||||
var _iteratorNormalCompletion16 = true;
|
var _iteratorNormalCompletion17 = true;
|
||||||
var _didIteratorError16 = false;
|
var _didIteratorError17 = false;
|
||||||
var _iteratorError16 = undefined;
|
var _iteratorError17 = undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (var _iterator16 = this.channelCache[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) {
|
for (var _iterator17 = this.channelCache[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) {
|
||||||
var channel = _step16.value;
|
var channel = _step17.value;
|
||||||
|
|
||||||
msgs = msgs.concat(channel.messages);
|
msgs = msgs.concat(channel.messages);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError16 = true;
|
_didIteratorError17 = true;
|
||||||
_iteratorError16 = err;
|
_iteratorError17 = err;
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (!_iteratorNormalCompletion16 && _iterator16["return"]) {
|
if (!_iteratorNormalCompletion17 && _iterator17["return"]) {
|
||||||
_iterator16["return"]();
|
_iterator17["return"]();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (_didIteratorError16) {
|
if (_didIteratorError17) {
|
||||||
throw _iteratorError16;
|
throw _iteratorError17;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ var PMChannel = (function () {
|
|||||||
}, {
|
}, {
|
||||||
key: "getMessage",
|
key: "getMessage",
|
||||||
value: function getMessage(key, value) {
|
value: function getMessage(key, value) {
|
||||||
|
|
||||||
|
if (this.messages.length > 1000) {
|
||||||
|
this.messages.splice(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
var _iteratorNormalCompletion = true;
|
var _iteratorNormalCompletion = true;
|
||||||
var _didIteratorError = false;
|
var _didIteratorError = false;
|
||||||
var _iteratorError = undefined;
|
var _iteratorError = undefined;
|
||||||
|
|||||||
@@ -142,6 +142,11 @@ var Server = (function () {
|
|||||||
value: function toString() {
|
value: function toString() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
key: "equals",
|
||||||
|
value: function equals(object) {
|
||||||
|
return object.id === this.id;
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "iconURL",
|
key: "iconURL",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
|
|||||||
1
ref/gameMap.json
Normal file
1
ref/gameMap.json
Normal file
File diff suppressed because one or more lines are too long
@@ -7,6 +7,8 @@ var Message = require("./message.js");
|
|||||||
var Invite = require("./invite.js");
|
var Invite = require("./invite.js");
|
||||||
var PMChannel = require("./PMChannel.js");
|
var PMChannel = require("./PMChannel.js");
|
||||||
|
|
||||||
|
var gameMap = require("../ref/gameMap.json");
|
||||||
|
|
||||||
//node modules
|
//node modules
|
||||||
var request = require("superagent");
|
var request = require("superagent");
|
||||||
var WebSocket = require("ws");
|
var WebSocket = require("ws");
|
||||||
@@ -53,6 +55,9 @@ class Client {
|
|||||||
this.readyTime = null;
|
this.readyTime = null;
|
||||||
this.checkingQueue = {};
|
this.checkingQueue = {};
|
||||||
this.queue = {};
|
this.queue = {};
|
||||||
|
|
||||||
|
this.__idleTime = null;
|
||||||
|
this.__gameId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get uptime() {
|
get uptime() {
|
||||||
@@ -1521,14 +1526,56 @@ class Client {
|
|||||||
|
|
||||||
var idleTime = (stat === "online" ? null : Date.now());
|
var idleTime = (stat === "online" ? null : Date.now());
|
||||||
|
|
||||||
|
this.__idleTime = idleTime;
|
||||||
|
|
||||||
this.websocket.send(JSON.stringify({
|
this.websocket.send(JSON.stringify({
|
||||||
op : 3,
|
op : 3,
|
||||||
d : {
|
d : {
|
||||||
idle_since : idleTime,
|
idle_since : this.__idleTime,
|
||||||
game_id : null
|
game_id : this.__gameId
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPlayingGame(id){
|
||||||
|
|
||||||
|
if( id instanceof String || typeof id === `string` ){
|
||||||
|
|
||||||
|
// working on names
|
||||||
|
var gid = id.trim().toUpperCase();
|
||||||
|
|
||||||
|
id = null;
|
||||||
|
|
||||||
|
for( var game of gameMap ){
|
||||||
|
|
||||||
|
if(game.name.trim().toUpperCase() === gid){
|
||||||
|
|
||||||
|
id = game.id;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.__gameId = id;
|
||||||
|
|
||||||
|
this.websocket.send(JSON.stringify({
|
||||||
|
op : 3,
|
||||||
|
d : {
|
||||||
|
idle_since : this.__idleTime,
|
||||||
|
game_id : this.__gameId
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
playingGame(id){
|
||||||
|
|
||||||
|
this.setPlayingGame(id);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Client;
|
module.exports = Client;
|
||||||
@@ -4,6 +4,8 @@ var fs = require("fs");
|
|||||||
|
|
||||||
var server, channel, message, sentMessage = false;
|
var server, channel, message, sentMessage = false;
|
||||||
|
|
||||||
|
counter = 1;
|
||||||
|
|
||||||
mybot.on("message", function (message) {
|
mybot.on("message", function (message) {
|
||||||
|
|
||||||
console.log("Everyone mentioned? " + message.everyoneMentioned);
|
console.log("Everyone mentioned? " + message.everyoneMentioned);
|
||||||
@@ -19,16 +21,14 @@ mybot.on("message", function (message) {
|
|||||||
|
|
||||||
var onlineUsers = 0;
|
var onlineUsers = 0;
|
||||||
|
|
||||||
mybot.startTyping(message.channel, 6000);
|
counter++;
|
||||||
|
|
||||||
|
mybot.playingGame( "Minecraft" );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mybot.on("ready", function () {
|
mybot.on("ready", function () {
|
||||||
console.log("im ready");
|
console.log("im ready");
|
||||||
|
|
||||||
for(var chann of mybot.channels){
|
|
||||||
mybot.setTopic(chann, "THINGS");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mybot.on("debug", function(info){
|
mybot.on("debug", function(info){
|
||||||
|
|||||||
Reference in New Issue
Block a user