+
Skip to content

test: refactor #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ node_modules
.git
.vscode

test/auth.json
test/config.json
test/db.sqlite
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
"typescript": "^3.4.2"
},
"scripts": {
"test": "npm run lint",
"lint": "eslint ./src && tslint ./src/index.d.ts"
"test": "node test/bot.js",
"test:nodb": "node test/bot.js --no-db",
"lint": "eslint ./test ./src && tslint ./src/index.d.ts"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion test/bot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const TestClient = require('./struct/TestClient');
const client = new TestClient();

const { token } = require('./auth.json');
const { token } = require('./config.json');
client.start(token);

process.on('unhandledRejection', err => console.error(err)); // eslint-disable-line no-console
6 changes: 2 additions & 4 deletions test/commands/args.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable no-console */

const { Command } = require('../..');
const util = require('util');
const { inspect } = require('util');

class ArgsCommand extends Command {
constructor() {
Expand Down Expand Up @@ -48,7 +46,7 @@ class ArgsCommand extends Command {
}

exec(message, args) {
message.channel.send(util.inspect(args, { depth: 1 }), { code: 'js' });
return message.util.send(inspect(args, { depth: 1 }), { code: 'js' });
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/commands/ayy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AyyCommand extends Command {
}

exec(message) {
return message.reply('lmao');
return message.util.reply('lmao');
}
}

Expand Down
12 changes: 6 additions & 6 deletions test/commands/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class EmbedCommand extends Command {
});
}

exec(message, args) {
if (args.emptyContent) {
return message.util.send(null, { embed: { description: args.phrase } });
exec(message, { emptyContent, emptyEmbed, phrase }) {
if (emptyContent) {
return message.util.send({ embed: { description: phrase } });
}

if (args.emptyEmbed) {
return message.util.send(args.phrase, { embed: null });
if (emptyEmbed) {
return message.util.send(phrase);
}

return message.util.send(args.phrase, { embed: { description: args.phrase } });
return message.util.send(phrase, { embed: { description: phrase } });
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/commands/eval.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Command } = require('../..');
const util = require('util');
const { inspect } = require('util');

class EvalCommand extends Command {
constructor() {
Expand Down Expand Up @@ -30,7 +30,7 @@ class EvalCommand extends Command {

const print = (...a) => { // eslint-disable-line no-unused-vars
const cleaned = a.map(obj => {
if (typeof o !== 'string') obj = util.inspect(obj, { depth: 1 });
if (typeof o !== 'string') obj = inspect(obj, { depth: 1 });
return obj.replace(tokenRegex, '[TOKEN]');
});

Expand All @@ -57,7 +57,7 @@ class EvalCommand extends Command {
let output = eval(code);
if (output && typeof output.then === 'function') output = await output;

if (typeof output !== 'string') output = util.inspect(output, { depth: 0 });
if (typeof output !== 'string') output = inspect(output, { depth: 0 });
output = `${logs.join('\n')}\n${logs.length && output === 'undefined' ? '' : output}`;
output = output.replace(tokenRegex, '[TOKEN]');

Expand All @@ -78,7 +78,7 @@ class EvalCommand extends Command {

return sent;
} catch (err) {
console.error(err); // eslint-disable-line no-console
console.error('Eval command error:', err); // eslint-disable-line no-console
let error = err;

error = error.toString();
Expand Down
6 changes: 3 additions & 3 deletions test/commands/f.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */

const { Command, Flag } = require('../..');
const util = require('util');
const { inspect } = require('util');

class FCommand extends Command {
constructor() {
Expand All @@ -18,7 +18,7 @@ class FCommand extends Command {
return phrase;
},
default: (msg, value) => {
console.log('failed', value);
console.log('f command: failed', value);
return 1;
}
}
Expand All @@ -27,7 +27,7 @@ class FCommand extends Command {
}

exec(message, args) {
message.channel.send(util.inspect(args, { depth: 1 }), { code: 'js' });
return message.util.send(inspect(args, { depth: 1 }), { code: 'js' });
}
}

Expand Down
7 changes: 2 additions & 5 deletions test/commands/generate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* eslint-disable no-console */

const { Command, Flag } = require('../..');
const util = require('util');

class GenerateCommand extends Command {
constructor() {
Expand All @@ -23,8 +20,8 @@ class GenerateCommand extends Command {
return { x };
}

exec(message, args) {
message.channel.send(util.inspect(args, { depth: 1 }), { code: 'js' });
exec(message, { x }) {
return message.util.send(`X -> ${x}`);
}
}

Expand Down
4 changes: 1 addition & 3 deletions test/commands/lock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */

const { Command } = require('../..');
const sleep = require('util').promisify(setTimeout);

Expand All @@ -12,7 +10,7 @@ class LockCommand extends Command {
}

exec(message) {
return [0, 1, 2, 3, 4].reduce((promise, num) => promise.then(() => sleep(1000)).then(() => message.util.send(num)), Promise.resolve());
return [0, 1, 2, 3, 4].reduce((promise, num) => promise.then(() => sleep(1000)).then(() => message.util.send(num.toString())), Promise.resolve());
}
}

Expand Down
7 changes: 3 additions & 4 deletions test/commands/p.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-console */

const { Command } = require('../..');
const util = require('util');

class PCommand extends Command {
constructor() {
Expand All @@ -25,11 +24,11 @@ class PCommand extends Command {
}

before() {
console.log(1);
console.log('p command: before');
}

exec(message, args) {
message.channel.send(util.inspect(args, { depth: 1 }), { code: 'js' });
exec(message, { integer }) {
return message.util.send(`integer -> ${integer}`);
}
}

Expand Down
2 changes: 0 additions & 2 deletions test/commands/q.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */

const { Command } = require('../..');

class QCommand extends Command {
Expand Down
8 changes: 3 additions & 5 deletions test/commands/separate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable no-console */

const { Command } = require('../..');
const util = require('util');
const { inspect } = require('util');

class SeparateCommand extends Command {
constructor() {
Expand All @@ -21,8 +19,8 @@ class SeparateCommand extends Command {
});
}

exec(message, args) {
message.channel.send(util.inspect(args, { depth: 1 }), { code: 'js' });
exec(message, { integers }) {
return message.util.send(inspect(integers, { depth: 1 }), { code: 'js' });
}
}

Expand Down
6 changes: 2 additions & 4 deletions test/commands/sub.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable no-console */

const { Command } = require('../../src');
const util = require('util');
const { inspect } = require('util');

class SubCommand extends Command {
constructor() {
Expand All @@ -15,7 +13,7 @@ class SubCommand extends Command {
}

exec(message, args) {
message.channel.send(util.inspect(args, { depth: 1 }), { code: 'js' });
return message.util.send(inspect(args, { depth: 1 }), { code: 'js' });
}
}

Expand Down
7 changes: 2 additions & 5 deletions test/commands/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* eslint-disable no-console */

const { Argument: { compose, range, union }, Command } = require('../..');
const util = require('util');

class TestCommand extends Command {
constructor() {
Expand All @@ -19,8 +16,8 @@ class TestCommand extends Command {
});
}

exec(message, args) {
message.channel.send(util.inspect(args, { depth: 1 }), { code: 'js' });
exec(message, { x }) {
return message.util.send(`x -> ${x}`);
}
}

Expand Down
7 changes: 2 additions & 5 deletions test/commands/test2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* eslint-disable no-console */

const { Argument: { compose, range, union }, Command } = require('../..');
const util = require('util');

class Test2Command extends Command {
constructor() {
Expand All @@ -19,8 +16,8 @@ class Test2Command extends Command {
});
}

exec(message, args) {
message.channel.send(util.inspect(args, { depth: 1 }), { code: 'js' });
exec(message, { y }) {
return message.util.send(`y -> ${y}`);
}
}

Expand Down
6 changes: 2 additions & 4 deletions test/commands/unordered.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable no-console */

const { Command } = require('../..');
const util = require('util');
const { inspect } = require('util');

class UnorderedCommand extends Command {
constructor() {
Expand All @@ -23,7 +21,7 @@ class UnorderedCommand extends Command {
}

exec(message, args) {
message.channel.send(util.inspect(args, { depth: 1 }), { code: 'js' });
return message.util.send(inspect(args, { depth: 1 }), { code: 'js' });
}
}

Expand Down
Empty file added test/inhibitors/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion test/listeners/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MessageListener extends Listener {
}

exec(msg) {
console.log(msg.content);
console.log('message:', msg.content);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */

const { Listener } = require('../..');
const { Listener } = require('../../');

class InvalidMessageListener extends Listener {
constructor() {
Expand All @@ -12,7 +12,7 @@ class InvalidMessageListener extends Listener {
}

exec(msg) {
console.log(msg.util.parsed);
console.log('messageInvalid: msg.util.parsed:', msg.util.parsed);
}
}

Expand Down
27 changes: 16 additions & 11 deletions test/struct/TestClient.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
const { AkairoClient, CommandHandler, InhibitorHandler, ListenerHandler, SQLiteProvider } = require('../../src/index');
const sqlite = require('sqlite');
const { owner } = require('../config.json');

let sqlite;

const useDb = !process.argv.includes('--no-db');
if (useDb) sqlite = require('sqlite');

class TestClient extends AkairoClient {
constructor() {
super({
ownerID: '123992700587343872'
});
super({ ownerID: owner });

this.commandHandler = new CommandHandler(this, {
directory: './test/commands/',
ignoreCooldownID: ['132266422679240704'],
ignoreCooldownID: owner,
aliasReplacement: /-/g,
prefix: '!!',
allowMention: true,
commandUtil: true,
commandUtilLifetime: 10000,
commandUtilSweepInterval: 10000,
commandUtilLifetime: 30000,
commandUtilSweepInterval: 30000,
storeMessages: true,
handleEdits: true,
argumentDefaults: {
Expand All @@ -41,9 +44,11 @@ class TestClient extends AkairoClient {
directory: './test/listeners/'
});

const db = sqlite.open('./test/db.sqlite')
.then(d => d.run('CREATE TABLE IF NOT EXISTS guilds (id TEXT NOT NULL UNIQUE, settings TEXT)').then(() => d));
this.settings = new SQLiteProvider(db, 'guilds', { dataColumn: 'settings' });
if (useDb) {
const db = sqlite.open('./test/db.sqlite')
.then(d => d.run('CREATE TABLE IF NOT EXISTS guilds (id TEXT NOT NULL UNIQUE, settings TEXT)').then(() => d));
this.settings = new SQLiteProvider(db, 'guilds', { dataColumn: 'settings' });
}

this.setup();
}
Expand Down Expand Up @@ -72,7 +77,7 @@ class TestClient extends AkairoClient {
}

async start(token) {
await this.settings.init();
if (useDb) await this.settings.init();
await this.login(token);
console.log('Ready!'); // eslint-disable-line no-console
}
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载