mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Suppor string game updates and better setStatus logic
This commit is contained in:
@@ -28,13 +28,13 @@ exports.toDec = function (data) {
|
|||||||
var hextest = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i;
|
var hextest = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i;
|
||||||
|
|
||||||
var num;
|
var num;
|
||||||
|
|
||||||
if(!data)
|
if(!data)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (hextest.test(data)) {
|
if (hextest.test(data)) {
|
||||||
// it's a hex number with a # in front
|
// it's a hex number with a # in front
|
||||||
|
|
||||||
// there's a bug in discord as of 28/10/15, where any
|
// there's a bug in discord as of 28/10/15, where any
|
||||||
// hex colors beginning with a 0 do not render properly.
|
// hex colors beginning with a 0 do not render properly.
|
||||||
// this is a temporary fix, and it does mean that you won't
|
// this is a temporary fix, and it does mean that you won't
|
||||||
@@ -44,7 +44,7 @@ exports.toDec = function (data) {
|
|||||||
tdata[1] = 1;
|
tdata[1] = 1;
|
||||||
data = tdata.join("");
|
data = tdata.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
num = parseInt(data.substr(1), 16).toString(10);
|
num = parseInt(data.substr(1), 16).toString(10);
|
||||||
} else if (hextest.test("#" + data)) {
|
} else if (hextest.test("#" + data)) {
|
||||||
// it's a hex number with no # in front
|
// it's a hex number with no # in front
|
||||||
@@ -57,14 +57,14 @@ exports.toDec = function (data) {
|
|||||||
} else {
|
} else {
|
||||||
num = data.toString(10);
|
num = data.toString(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseInt(num);
|
return parseInt(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.toHex = function (data) {
|
exports.toHex = function (data) {
|
||||||
|
|
||||||
var text = data.toString(16);
|
var text = data.toString(16);
|
||||||
|
|
||||||
while(text.length < 6){
|
while(text.length < 6){
|
||||||
text = "0" + text;
|
text = "0" + text;
|
||||||
}
|
}
|
||||||
|
|||||||
5687
ref/gameMap.js
5687
ref/gameMap.js
File diff suppressed because it is too large
Load Diff
@@ -824,31 +824,33 @@ export default class InternalClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//def setStatus
|
//def setStatus
|
||||||
setStatus(idleStatus, gameID) {
|
setStatus(idleStatus, game) {
|
||||||
|
|
||||||
this.idleStatus = idleStatus || this.idleStatus || null;
|
if(idleStatus === "online" || idleStatus === "here" || idleStatus === "available"){
|
||||||
if(idleStatus){
|
this.idleStatus = null;
|
||||||
if(idleStatus === "online" || idleStatus === "here" || idleStatus === "available"){
|
|
||||||
this.idleStatus = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.gameID = this.resolver.resolveGameID(gameID) || this.gameID || null;
|
else if (this.idleStatus === "idle" || this.idleStatus === "away") {
|
||||||
|
packet.d.idle_since = Date.now();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.idleStatus = this.idleStatus || null; //undefineds
|
||||||
|
}
|
||||||
|
|
||||||
|
this.game = game === null ? null : game || this.game;
|
||||||
|
|
||||||
var packet = {
|
var packet = {
|
||||||
op: 3,
|
op: 3,
|
||||||
d: {
|
d: {
|
||||||
idle_since: this.idleStatus,
|
idle_since: this.idleStatus,
|
||||||
game_id: this.gameID
|
game: {
|
||||||
|
name: this.game
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.idleStatus === "idle" || this.idleStatus === "away") {
|
|
||||||
packet.d.idle_since = Date.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sendWS(packet);
|
this.sendWS(packet);
|
||||||
|
|
||||||
return Promise.resolve();//why?
|
return Promise.resolve();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,28 +12,12 @@ import PMChannel from "../../Structures/PMChannel";
|
|||||||
import Server from "../../Structures/Server";
|
import Server from "../../Structures/Server";
|
||||||
import Message from "../../Structures/Message";
|
import Message from "../../Structures/Message";
|
||||||
import Invite from "../../Structures/Invite";
|
import Invite from "../../Structures/Invite";
|
||||||
import Games from "../../../ref/gameMap";
|
|
||||||
|
|
||||||
export default class Resolver {
|
export default class Resolver {
|
||||||
constructor(internal) {
|
constructor(internal) {
|
||||||
this.internal = internal;
|
this.internal = internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveGameID(resource) {
|
|
||||||
if (!isNaN(resource) && parseInt(resource) % 1 === 0) {
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
if (typeof resource === "string" || resource instanceof String) {
|
|
||||||
var gameName = resource.toLowerCase();
|
|
||||||
var found = Games.find(game => game.name.toLowerCase() === gameName);
|
|
||||||
if(found) {
|
|
||||||
return found.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
resolveToBase64(resource) {
|
resolveToBase64(resource) {
|
||||||
if (resource instanceof Buffer) {
|
if (resource instanceof Buffer) {
|
||||||
resource = resource.toString("base64");
|
resource = resource.toString("base64");
|
||||||
|
|||||||
Reference in New Issue
Block a user