mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +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
|
||||
- **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
|
||||
|
||||
@@ -13,6 +13,8 @@ var Message = require("./message.js");
|
||||
var Invite = require("./invite.js");
|
||||
var PMChannel = require("./PMChannel.js");
|
||||
|
||||
var gameMap = require("../ref/gameMap.json");
|
||||
|
||||
//node modules
|
||||
var request = require("superagent");
|
||||
var WebSocket = require("ws");
|
||||
@@ -63,6 +65,9 @@ var Client = (function () {
|
||||
this.readyTime = null;
|
||||
this.checkingQueue = {};
|
||||
this.queue = {};
|
||||
|
||||
this.__idleTime = null;
|
||||
this.__gameId = null;
|
||||
}
|
||||
|
||||
_createClass(Client, [{
|
||||
@@ -1778,14 +1783,73 @@ var Client = (function () {
|
||||
|
||||
var idleTime = stat === "online" ? null : Date.now();
|
||||
|
||||
this.__idleTime = idleTime;
|
||||
|
||||
this.websocket.send(JSON.stringify({
|
||||
op: 3,
|
||||
d: {
|
||||
idle_since: idleTime,
|
||||
game_id: null
|
||||
idle_since: this.__idleTime,
|
||||
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",
|
||||
get: function get() {
|
||||
@@ -1822,27 +1886,27 @@ var Client = (function () {
|
||||
get: function get() {
|
||||
|
||||
var msgs = [];
|
||||
var _iteratorNormalCompletion16 = true;
|
||||
var _didIteratorError16 = false;
|
||||
var _iteratorError16 = undefined;
|
||||
var _iteratorNormalCompletion17 = true;
|
||||
var _didIteratorError17 = false;
|
||||
var _iteratorError17 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator16 = this.channelCache[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) {
|
||||
var channel = _step16.value;
|
||||
for (var _iterator17 = this.channelCache[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) {
|
||||
var channel = _step17.value;
|
||||
|
||||
msgs = msgs.concat(channel.messages);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError16 = true;
|
||||
_iteratorError16 = err;
|
||||
_didIteratorError17 = true;
|
||||
_iteratorError17 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion16 && _iterator16["return"]) {
|
||||
_iterator16["return"]();
|
||||
if (!_iteratorNormalCompletion17 && _iterator17["return"]) {
|
||||
_iterator17["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError16) {
|
||||
throw _iteratorError16;
|
||||
if (_didIteratorError17) {
|
||||
throw _iteratorError17;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@ var PMChannel = (function () {
|
||||
}, {
|
||||
key: "getMessage",
|
||||
value: function getMessage(key, value) {
|
||||
|
||||
if (this.messages.length > 1000) {
|
||||
this.messages.splice(0, 1);
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
@@ -142,6 +142,11 @@ var Server = (function () {
|
||||
value: function toString() {
|
||||
return this.name;
|
||||
}
|
||||
}, {
|
||||
key: "equals",
|
||||
value: function equals(object) {
|
||||
return object.id === this.id;
|
||||
}
|
||||
}, {
|
||||
key: "iconURL",
|
||||
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 PMChannel = require("./PMChannel.js");
|
||||
|
||||
var gameMap = require("../ref/gameMap.json");
|
||||
|
||||
//node modules
|
||||
var request = require("superagent");
|
||||
var WebSocket = require("ws");
|
||||
@@ -53,6 +55,9 @@ class Client {
|
||||
this.readyTime = null;
|
||||
this.checkingQueue = {};
|
||||
this.queue = {};
|
||||
|
||||
this.__idleTime = null;
|
||||
this.__gameId = null;
|
||||
}
|
||||
|
||||
get uptime() {
|
||||
@@ -1521,14 +1526,56 @@ class Client {
|
||||
|
||||
var idleTime = (stat === "online" ? null : Date.now());
|
||||
|
||||
this.__idleTime = idleTime;
|
||||
|
||||
this.websocket.send(JSON.stringify({
|
||||
op : 3,
|
||||
d : {
|
||||
idle_since : idleTime,
|
||||
game_id : null
|
||||
idle_since : this.__idleTime,
|
||||
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;
|
||||
@@ -4,6 +4,8 @@ var fs = require("fs");
|
||||
|
||||
var server, channel, message, sentMessage = false;
|
||||
|
||||
counter = 1;
|
||||
|
||||
mybot.on("message", function (message) {
|
||||
|
||||
console.log("Everyone mentioned? " + message.everyoneMentioned);
|
||||
@@ -19,16 +21,14 @@ mybot.on("message", function (message) {
|
||||
|
||||
var onlineUsers = 0;
|
||||
|
||||
mybot.startTyping(message.channel, 6000);
|
||||
counter++;
|
||||
|
||||
mybot.playingGame( "Minecraft" );
|
||||
|
||||
});
|
||||
|
||||
mybot.on("ready", function () {
|
||||
console.log("im ready");
|
||||
|
||||
for(var chann of mybot.channels){
|
||||
mybot.setTopic(chann, "THINGS");
|
||||
}
|
||||
});
|
||||
|
||||
mybot.on("debug", function(info){
|
||||
|
||||
Reference in New Issue
Block a user