Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Null committed Jul 26, 2020
1 parent 6539548 commit d067f71
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
18 changes: 18 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["@axonteam", "plugin:@typescript-eslint/recommended"],
"rules": {
"consistent-return": "warn",
"new-cap": "warn",
"@typescript-eslint/no-explicit-any": "off",
"linebreak-style": "off",
"builtinGlobals": 0,
"no-shadow": "off",
"@typescript-eslint/ban-ts-comment": "off",
"camelcase": "off"
},
"env": {
"node": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
},
"devDependencies": {
"@axonteam/eslint-config": "^2.1.1",
"@typescript-eslint/eslint-plugin": "^3.7.0",
"@typescript-eslint/parser": "^3.7.0",
"eslint": "^5.16.0",
"typescript": "^3.5.2"
}
Expand Down
17 changes: 12 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import PresenceClient, {Activity} from './structures/PresenceClient.js';
import PresenceClient, { Activity } from './structures/PresenceClient.js';
import { existsSync } from 'fs';
import { EventEmitter } from 'events';
const ee = new EventEmitter();
console.log('Initiating...');

let type = <string> 'js';

if (!existsSync('./config.js') ) type = 'json';
if (!existsSync('./config.js') ) {
type = 'json';
}
if (!existsSync('./config.json') && type === 'json') {
ee.emit('exit');
throw Error('Config file not found. Exiting.');
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require(`../config.${type}`);
let conf = config;

Expand All @@ -24,15 +27,19 @@ let prevtype = <string> type;
function updateConfig(): Promise<Activity | void | null> {
let ntype = <string> 'js';

if (!existsSync('./config.js') ) ntype = 'json';
if (!existsSync('./config.js') ) {
ntype = 'json';
}
if (!existsSync('./config.json') && ntype === 'json') {
ee.emit('exit');
throw Error('Config file not found. Exiting');
}
delete require.cache[require.resolve(`../config.${prevtype}`)];
delete require.cache[require.resolve(`../config.${prevtype}`)]; // eslint-disable-next-line @typescript-eslint/no-var-requires
const file = require(`../config.${ntype}`);

if (file.noUpdate || file === conf) return Promise.resolve();
if (file.noUpdate || file === conf) {
return Promise.resolve();
}

conf = file;
prevtype = ntype;
Expand Down
20 changes: 12 additions & 8 deletions src/structures/PresenceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ class PResenceClient extends EventEmitter {
// @ts-ignore
if (arrays.includes(key) ) {
// @ts-ignore
if (!Array.isArray(nConf[key] ) && typeof nConf[key] === 'string') conf[key] = Array(nConf[key] ); // @ts-ignore
else if (Array.isArray(nConf[key] ) && typeof nConf[key] === 'string') delete conf[key];
if (!Array.isArray(nConf[key] ) && typeof nConf[key] === 'string') { // @ts-ignore
conf[key] = Array(nConf[key] ); // @ts-ignore
} else if (Array.isArray(nConf[key] ) && typeof nConf[key] === 'string') { // @ts-ignore
delete conf[key];
}
} else if (key === 'timestamp' && ![
true,
false,
Expand All @@ -100,8 +103,7 @@ class PResenceClient extends EventEmitter {
].includes(nConf[key] ) ) {
delete conf[key];
} else if (key === 'partySize') { // @ts-ignore

if (isNaN(nConf[key] ) && isNaN(Number(nConf[key]) ) ) {
if (isNaN(nConf[key] ) && isNaN(Number(nConf[key] ) ) ) {
delete conf[key];
delete conf.partyMax;
} else if (!nConf.partyMax) {
Expand Down Expand Up @@ -146,10 +148,10 @@ class PResenceClient extends EventEmitter {
largeImageText: 'large_text',
smallImageText: 'small_text',
smallImageKey: 'small_image',
}
};

for (const key in conf) { // @ts-ignore
if (actMap[key]) {
if (actMap[key] ) {
// @ts-ignore
activity[key] = Array.isArray(conf[key] ) ? this.genRandom(conf[key] ) : conf[key]; // @ts-ignore
} else if (Array.isArray(conf[key] ) ) { // @ts-ignore
Expand All @@ -171,7 +173,9 @@ class PResenceClient extends EventEmitter {
}

public genRandom(array: any[] | string): any {
if (!Array.isArray(array) ) array = Array(array);
if (!Array.isArray(array) ) {
array = Array(array);
}
const item = array[Math.floor(Math.random() * array.length)];

return item;
Expand All @@ -196,4 +200,4 @@ class PResenceClient extends EventEmitter {
}
}

export default PResenceClient;
export default PResenceClient;

0 comments on commit d067f71

Please sign in to comment.