:clown:
This commit is contained in:
parent
2517f4b5e6
commit
b28440fda6
File diff suppressed because one or more lines are too long
|
@ -23,6 +23,7 @@ import CssEditor from "../ui/cssEditor";
|
||||||
import CardList from "../ui/addonlist";
|
import CardList from "../ui/addonlist";
|
||||||
import V2C_PresenceSettings from "../ui/presenceSettings";
|
import V2C_PresenceSettings from "../ui/presenceSettings";
|
||||||
import CustomRichPresence from "./CustomRichPresence";
|
import CustomRichPresence from "./CustomRichPresence";
|
||||||
|
import V2C_AccountInfos from "../ui/AccountInfos";
|
||||||
|
|
||||||
export default new class V2_SettingsPanel {
|
export default new class V2_SettingsPanel {
|
||||||
|
|
||||||
|
@ -117,6 +118,10 @@ export default new class V2_SettingsPanel {
|
||||||
break
|
break
|
||||||
case "status":
|
case "status":
|
||||||
this.renderPresenceSettings()
|
this.renderPresenceSettings()
|
||||||
|
break
|
||||||
|
case "accountinfo":
|
||||||
|
this.renderAccountInfos()
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +287,7 @@ export default new class V2_SettingsPanel {
|
||||||
get PresenceComponent() {
|
get PresenceComponent() {
|
||||||
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true},
|
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true},
|
||||||
BDV2.react.createElement(V2C_PresenceSettings, {
|
BDV2.react.createElement(V2C_PresenceSettings, {
|
||||||
key: "lspannel",
|
key: "lppannel",
|
||||||
onChange: this.onChange,
|
onChange: this.onChange,
|
||||||
settings: this.PresenceSettings
|
settings: this.PresenceSettings
|
||||||
}),
|
}),
|
||||||
|
@ -290,6 +295,15 @@ export default new class V2_SettingsPanel {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get AccountInfosComponent() {
|
||||||
|
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true},
|
||||||
|
BDV2.react.createElement(V2C_AccountInfos, {
|
||||||
|
key: "lapannel"
|
||||||
|
}),
|
||||||
|
BDV2.react.createElement(Tools, {key: "tools"})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
get customCssComponent() {
|
get customCssComponent() {
|
||||||
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true},
|
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true},
|
||||||
BDV2.react.createElement(CssEditor, {key: "csseditor"}),
|
BDV2.react.createElement(CssEditor, {key: "csseditor"}),
|
||||||
|
@ -315,6 +329,12 @@ export default new class V2_SettingsPanel {
|
||||||
BDV2.reactDom.render(this.PresenceComponent, root);
|
BDV2.reactDom.render(this.PresenceComponent, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderAccountInfos() {
|
||||||
|
const root = this.root;
|
||||||
|
if (!root) return Utils.err("SettingsPanel", "FAILED TO LOCATE ROOT: .layer-3QrUeG .standardSidebarView-3F1I7i");
|
||||||
|
BDV2.reactDom.render(this.AccountInfosComponent, root);
|
||||||
|
}
|
||||||
|
|
||||||
renderCustomCssEditor() {
|
renderCustomCssEditor() {
|
||||||
const root = this.root;
|
const root = this.root;
|
||||||
if (!root) return Utils.err("SettingsPanel", "FAILED TO LOCATE ROOT: .layer-3QrUeG .standardSidebarView-3F1I7i");
|
if (!root) return Utils.err("SettingsPanel", "FAILED TO LOCATE ROOT: .layer-3QrUeG .standardSidebarView-3F1I7i");
|
||||||
|
|
|
@ -35,6 +35,9 @@ export default class V2_SettingsPanel_Sidebar {
|
||||||
}, {
|
}, {
|
||||||
text: "Message Logger",
|
text: "Message Logger",
|
||||||
id: "msglog"
|
id: "msglog"
|
||||||
|
}, {
|
||||||
|
text: "Account Info",
|
||||||
|
id: "accountinfo"
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
import BDV2 from "../modules/v2";
|
||||||
|
import V2C_SettingsTitle from "./settingsTitle";
|
||||||
|
import V2C_SettingsGroup from "./settingsGroup";
|
||||||
|
import dataStore from "../modules/dataStore";
|
||||||
|
import { defaultRPC, settingsRPC } from "../0globals";
|
||||||
|
import CustomRichPresence from "../modules/CustomRichPresence"
|
||||||
|
import Select from "./select";
|
||||||
|
import timestampRender from "./timestampRender"
|
||||||
|
import DOMTools from "../modules/domtools";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {typeof import("react")}
|
||||||
|
*/
|
||||||
|
const React = BDV2.React;
|
||||||
|
|
||||||
|
let contentModule = BDModules.get(e => e.contentColumn)[0]
|
||||||
|
let marginModule2 = BDModules.get(e => e.defaultMarginh5)[0]
|
||||||
|
let colorModule = BDModules.get(e => e.colorStandard)[0]
|
||||||
|
let sizeModule = BDModules.get(e => e.size32)[0]
|
||||||
|
const scrollbarModule1 = BDModules.get(e => e.scrollbarGhostHairline)[0]
|
||||||
|
const GuildModule = BDModules.get(e => e.default && e.default.getGuilds)[0].default
|
||||||
|
const relationShipModule = BDModules.get(e => e.default && e.default.getRelationships)[0].default
|
||||||
|
const sessionModule = BDModules.get(e => e.default && e.default.getSessions)[0].default
|
||||||
|
const userModule = BDModules.get(e => e.default && e.default.getCurrentUser)[0].default
|
||||||
|
|
||||||
|
export default class V2C_AccountInfos extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
|
||||||
|
return (<div className={contentModule.contentColumn+" "+contentModule.contentColumnDefault+" content-column default"}
|
||||||
|
style={{padding: "60px 40px 0px"}}>
|
||||||
|
<V2C_SettingsTitle text="Account Infos"/>
|
||||||
|
<div>
|
||||||
|
<h5 className={colorModule.colorStandard+" "+sizeModule.size14+" "+marginModule2.h5+" "+marginModule2.defaultMarginh5}>
|
||||||
|
Profile
|
||||||
|
</h5>
|
||||||
|
<CodeContent content={this.getProfileValue()} language="diff" />
|
||||||
|
<h5 className={colorModule.colorStandard+" "+sizeModule.size14+" "+marginModule2.h5+" "+marginModule2.defaultMarginh5}>
|
||||||
|
Statistics
|
||||||
|
</h5>
|
||||||
|
<CodeContent content={this.getStatistics()} language="diff" />
|
||||||
|
<h5 className={colorModule.colorStandard+" "+sizeModule.size14+" "+marginModule2.h5+" "+marginModule2.defaultMarginh5}>
|
||||||
|
Connected Sessions
|
||||||
|
</h5>
|
||||||
|
<CodeContent content={this.getSessionValue()} language="diff" />
|
||||||
|
</div>
|
||||||
|
<div className={BDModules.get(e => e.marginBottom20)[0].marginBottom20}></div>
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
|
|
||||||
|
getSessionValue(){
|
||||||
|
const sessionsRaw = sessionModule.getSessions()
|
||||||
|
const sessions = Object.keys(sessionsRaw).filter(e => e !== "all").map(e => sessionsRaw[e])
|
||||||
|
|
||||||
|
if(sessions.length === 0)return "- No session detected. Please try in a few seconds"
|
||||||
|
|
||||||
|
return sessions.map(e => {
|
||||||
|
return `+ id: ${e.sessionId}
|
||||||
|
+ os: ${e.clientInfo.os[0].toUpperCase()+e.clientInfo.os.slice(1)}
|
||||||
|
+ client: ${e.clientInfo.client}
|
||||||
|
+ status: ${e.status}
|
||||||
|
+ active: ${e.active ? "Yes" : "No"}
|
||||||
|
+ Activities: ${e.activities.length}`
|
||||||
|
}).join("\n"+"-".repeat(38)+"\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
getProfileValue(){
|
||||||
|
const user = userModule.getCurrentUser()
|
||||||
|
|
||||||
|
return `+ Username: ${user.username}
|
||||||
|
+ Discriminator: ${user.discriminator}
|
||||||
|
+ Tag: ${user.tag}
|
||||||
|
+ ID: ${user.id}
|
||||||
|
+ Avatar: ${user.avatar}
|
||||||
|
+ Avatar URL: https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.${user.avatar.startsWith("a_") ? "gif" : "png"}?size=4096
|
||||||
|
+ Email: ${user.email}
|
||||||
|
+ Flags: ${user.flags}
|
||||||
|
+ 2FA: ${user.mfaEnabled ? "Yes" : "No"}
|
||||||
|
+ Has Been On Mobile: ${user.mobile ? "Yes" : "No"}
|
||||||
|
+ Phone: ${user.phone || "None"}
|
||||||
|
+ Verified: ${user.verified}
|
||||||
|
+ Has Nitro: ${user.hasPremiumSubscription ? "Yes" : "No"}`
|
||||||
|
}
|
||||||
|
|
||||||
|
getStatistics(){
|
||||||
|
|
||||||
|
const guilds = Object.values(GuildModule.getGuilds())
|
||||||
|
const relations = Object.keys(relationShipModule.getRelationships())
|
||||||
|
const friends = relations.filter(e => relationShipModule.isFriend(e))
|
||||||
|
const blocked = relations.filter(e => relationShipModule.isBlocked(e))
|
||||||
|
|
||||||
|
return `+ Server Count: ${guilds.length} servers
|
||||||
|
+ Relations: ${relations.length} relations
|
||||||
|
+ Friends Count: ${friends.length} friends
|
||||||
|
- Blocked Users Count: ${blocked.length} blocked users`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const hightlightJS = BDModules.get(e => e.highlight)[0]
|
||||||
|
const messageModule1 = BDModules.get(e => e.markup)[0]
|
||||||
|
const messageModule2 = BDModules.get(e => e.messageContent)[0]
|
||||||
|
|
||||||
|
class CodeContent extends React.Component {
|
||||||
|
render(){
|
||||||
|
|
||||||
|
return (<div class={`${messageModule1.markup} ${messageModule2.messageContent}`}>
|
||||||
|
<pre>
|
||||||
|
<code class={`${scrollbarModule1.scrollbarGhostHairline} hljs`} dangerouslySetInnerHTML={{__html: hightlightJS.highlight(this.props.language, this.props.content).value}}>
|
||||||
|
|
||||||
|
</code>
|
||||||
|
</pre>
|
||||||
|
<div className={BDModules.get(e => e.marginBottom8)[0].marginBottom8}></div>
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,8 +5,11 @@ import { Snowflake, Channel } from "..";
|
||||||
import { channelsModule } from "../util/DiscordToModules";
|
import { channelsModule } from "../util/DiscordToModules";
|
||||||
import { createChannel } from "../util/util";
|
import { createChannel } from "../util/util";
|
||||||
|
|
||||||
|
let hasInit = false
|
||||||
export default class Client extends EventEmitter {
|
export default class Client extends EventEmitter {
|
||||||
constructor(){
|
constructor(){
|
||||||
|
if(hasInit)throw new DiscordJSError("Cannot initialized more than one client.")
|
||||||
|
hasInit = true
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +31,7 @@ export default class Client extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
get channels():Collection<Snowflake, Channel>{
|
get channels():Collection<Snowflake, Channel>{
|
||||||
const channels = Object.values(channelsModule.getChannels())
|
const channels = Object.values(channelsModule.getAllChannels())
|
||||||
return new Collection(channels.map(e => ([e.id, createChannel(e)])))
|
return new Collection(channels.map(e => ([e.id, createChannel(e)])))
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,25 @@
|
||||||
export default class BaseChannel {
|
import { DiscordChannel, channelsModule } from "../util/DiscordToModules";
|
||||||
constructor(){
|
import Client from "../client/client";
|
||||||
|
import BaseStructure from "./BaseStructure";
|
||||||
|
import Snowflake from "../util/Snowflake"
|
||||||
|
|
||||||
|
export default class BaseChannel extends BaseStructure {
|
||||||
|
id:string
|
||||||
|
deleted:boolean
|
||||||
|
constructor(channel:DiscordChannel){
|
||||||
|
super()
|
||||||
|
this.id = channel.id
|
||||||
|
this.deleted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get createdAt():Date{
|
||||||
|
return new Date(this.createdTimestamp)
|
||||||
|
}
|
||||||
|
get createdTimestamp(): number{
|
||||||
|
return Snowflake.deconstruct(this.id).timestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
delete() {
|
||||||
|
return channelsModule.delete(this.id);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
import Client from "../client/client";
|
||||||
|
|
||||||
|
export default class BaseStructure {
|
||||||
|
constructor(){}
|
||||||
|
|
||||||
|
get client():Client {
|
||||||
|
return window.DiscordJSClient
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
export class TextChannel extends TextBasedChannel, GuildChannel {
|
||||||
|
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ function requireModule(filter: (module:any) => boolean){
|
||||||
return module && module.default || module
|
return module && module.default || module
|
||||||
}
|
}
|
||||||
|
|
||||||
export const channelsModule:{
|
const channelsModuleInternal1:{
|
||||||
getChannel(id:Snowflake): DiscordChannel,
|
getChannel(id:Snowflake): DiscordChannel,
|
||||||
getChannels(): {
|
getChannels(): {
|
||||||
[k:string]: DiscordChannel
|
[k:string]: DiscordChannel
|
||||||
|
@ -30,6 +30,10 @@ export const channelsModule:{
|
||||||
},
|
},
|
||||||
getGDMsForRecipients(recipients: Snowflake[]):Set<Snowflake>
|
getGDMsForRecipients(recipients: Snowflake[]):Set<Snowflake>
|
||||||
} = requireModule(e => e.default && e.default.getChannels && e.default.getChannel)
|
} = requireModule(e => e.default && e.default.getChannels && e.default.getChannel)
|
||||||
|
export const channelsModule = {
|
||||||
|
getChannel: channelsModuleInternal1.getChannel,
|
||||||
|
getAllChannels: channelsModuleInternal1.getChannels
|
||||||
|
}
|
||||||
|
|
||||||
export interface DiscordChannel {
|
export interface DiscordChannel {
|
||||||
application_id?: Snowflake,
|
application_id?: Snowflake,
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
import Util = require('../util/util');
|
||||||
|
|
||||||
|
// Discord epoch (2015-01-01T00:00:00.000Z)
|
||||||
|
const EPOCH = 1420070400000;
|
||||||
|
let INCREMENT = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A container for useful snowflake-related methods.
|
||||||
|
*/
|
||||||
|
export default class SnowflakeUtil {
|
||||||
|
constructor() {
|
||||||
|
throw new Error(`The ${this.constructor.name} class may not be instantiated.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Twitter snowflake, except the epoch is 2015-01-01T00:00:00.000Z
|
||||||
|
* ```
|
||||||
|
* If we have a snowflake '266241948824764416' we can represent it as binary:
|
||||||
|
*
|
||||||
|
* 64 22 17 12 0
|
||||||
|
* 000000111011000111100001101001000101000000 00001 00000 000000000000
|
||||||
|
* number of ms since Discord epoch worker pid increment
|
||||||
|
* ```
|
||||||
|
* @typedef {string} Snowflake
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a Discord snowflake.
|
||||||
|
* <info>This hardcodes the worker ID as 1 and the process ID as 0.</info>
|
||||||
|
* @param {number|Date} [timestamp=Date.now()] Timestamp or date of the snowflake to generate
|
||||||
|
* @returns {Snowflake} The generated snowflake
|
||||||
|
*/
|
||||||
|
static generate(timestamp: number | Date = Date.now()): Snowflake {
|
||||||
|
if (timestamp instanceof Date) timestamp = timestamp.getTime();
|
||||||
|
if (typeof timestamp !== 'number' || isNaN(timestamp)) {
|
||||||
|
throw new TypeError(
|
||||||
|
`"timestamp" argument must be a number (received ${isNaN(timestamp) ? 'NaN' : typeof timestamp})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (INCREMENT >= 4095) INCREMENT = 0;
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
const BINARY = `${(timestamp - EPOCH).toString(2).padStart(42, '0')}0000100000${(INCREMENT++)
|
||||||
|
.toString(2)
|
||||||
|
.padStart(12, '0')}`;
|
||||||
|
return Util.binaryToID(BINARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A deconstructed snowflake.
|
||||||
|
* @typedef {Object} DeconstructedSnowflake
|
||||||
|
* @property {number} timestamp Timestamp the snowflake was created
|
||||||
|
* @property {Date} date Date the snowflake was created
|
||||||
|
* @property {number} workerID Worker ID in the snowflake
|
||||||
|
* @property {number} processID Process ID in the snowflake
|
||||||
|
* @property {number} increment Increment in the snowflake
|
||||||
|
* @property {string} binary Binary representation of the snowflake
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deconstructs a Discord snowflake.
|
||||||
|
* @param {Snowflake} snowflake Snowflake to deconstruct
|
||||||
|
* @returns {DeconstructedSnowflake} Deconstructed snowflake
|
||||||
|
*/
|
||||||
|
static deconstruct(snowflake: Snowflake): DeconstructedSnowflake {
|
||||||
|
const BINARY = Util.idToBinary(snowflake)
|
||||||
|
.toString()
|
||||||
|
.padStart(64, '0');
|
||||||
|
const res = {
|
||||||
|
timestamp: parseInt(BINARY.substring(0, 42), 2) + EPOCH,
|
||||||
|
workerID: parseInt(BINARY.substring(42, 47), 2),
|
||||||
|
processID: parseInt(BINARY.substring(47, 52), 2),
|
||||||
|
increment: parseInt(BINARY.substring(52, 64), 2),
|
||||||
|
binary: BINARY,
|
||||||
|
};
|
||||||
|
Object.defineProperty(res, 'date', {
|
||||||
|
get: function get() {
|
||||||
|
return new Date(this.timestamp);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
});
|
||||||
|
return res as DeconstructedSnowflake;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeconstructedSnowflake = {
|
||||||
|
timestamp: number,
|
||||||
|
workerID: number,
|
||||||
|
processID: number,
|
||||||
|
increment: number,
|
||||||
|
binary: string,
|
||||||
|
readonly date: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
type Snowflake = string
|
|
@ -1,5 +1,71 @@
|
||||||
import { DiscordChannel } from "./DiscordToModules"
|
import { DiscordChannel } from "./DiscordToModules"
|
||||||
|
import { Channel } from "..";
|
||||||
|
|
||||||
export function createChannel(channel:DiscordChannel){
|
export function createChannel(channel:DiscordChannel):Channel{
|
||||||
|
let constructor = channels[channel.type]
|
||||||
|
return new constructor(channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
const channels:(new(channel:DiscordChannel) => Channel)[] = [
|
||||||
|
TextChann
|
||||||
|
]
|
||||||
|
|
||||||
|
export function applyMixins(derivedCtor: any, baseCtors: any[]) {
|
||||||
|
baseCtors.forEach(baseCtor => {
|
||||||
|
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
|
||||||
|
if (name !== 'constructor') {
|
||||||
|
derivedCtor.prototype[name] = baseCtor.prototype[name];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms a snowflake from a decimal string to a bit string.
|
||||||
|
* @param {string} num Snowflake to be transformed
|
||||||
|
* @returns {string}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
export function idToBinary(num:string):string{
|
||||||
|
let bin = '';
|
||||||
|
let high = parseInt(num.slice(0, -10)) || 0;
|
||||||
|
let low = parseInt(num.slice(-10));
|
||||||
|
while (low > 0 || high > 0) {
|
||||||
|
bin = String(low & 1) + bin;
|
||||||
|
low = Math.floor(low / 2);
|
||||||
|
if (high > 0) {
|
||||||
|
low += 5000000000 * (high % 2);
|
||||||
|
high = Math.floor(high / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms a snowflake from a bit string to a decimal string.
|
||||||
|
* @param {string} num Bit string to be transformed
|
||||||
|
* @returns {string}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
export function binaryToID(num:string):string {
|
||||||
|
let dec = '';
|
||||||
|
|
||||||
|
while (num.length > 50) {
|
||||||
|
const high = parseInt(num.slice(0, -32), 2);
|
||||||
|
const low = parseInt((high % 10).toString(2) + num.slice(-32), 2);
|
||||||
|
|
||||||
|
dec = (low % 10).toString() + dec;
|
||||||
|
num = Math.floor(high / 10).toString(2) +
|
||||||
|
Math.floor(low / 10)
|
||||||
|
.toString(2)
|
||||||
|
.padStart(32, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
let num2 = parseInt(num, 2);
|
||||||
|
while (num2 > 0) {
|
||||||
|
dec = (num2 % 10).toString() + dec;
|
||||||
|
num2 = Math.floor(num2 / 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dec;
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue