Skip to content

Commit

Permalink
Add user blacklisting, update build process, add auto-build
Browse files Browse the repository at this point in the history
Postinstall script will build the lib so it can be installed directly from github. Also, as a result of updating the build process, I properly have types provided automatically via the compilation
  • Loading branch information
zajrik committed Mar 10, 2017
1 parent add6017 commit 3ede619
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
45 changes: 11 additions & 34 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
var gulp = require('gulp');
var ts = require('gulp-typescript');
var del = require('del');
const gulp = require('gulp');
const ts = require('gulp-typescript');
const del = require('del');

const project = ts.createProject('tsconfig.json');

gulp.task('default', () =>
{
del.sync(['./bin/**/*.*']);

gulp.src('./src/**/*.ts')
.pipe(ts({
noImplicitAny: true,
outDir: 'bin',
target: 'ES6',
module: 'commonjs',
moduleResolution: 'node'
}))
.pipe(gulp.dest('bin/'));
gulp.src('./src/config.json')
.pipe(project())
.pipe(gulp.dest('bin/'));
});

gulp.task('package', (done) =>
{
gulp.src('src/**/*ts')
.pipe(ts({
noImplicitAny: true,
outDir: 'bin',
target: 'ES6',
module: 'commonjs',
moduleResolution: 'node'
}))
.pipe(gulp.dest('pkg/yamdbf-addon-dm-manager/bin'));
gulp.src('src/**/*.json')
.pipe(gulp.dest('pkg/yamdbf-addon-dm-manager/bin'));
gulp.src(['package.json', '*.md'])
.pipe(gulp.dest('pkg/yamdbf-addon-dm-manager'));
done();
});
gulp.src('./src/**/*.js')
.pipe(gulp.dest('bin/'));

gulp.task('clean-package', (done) =>
{
del.sync(['pkg/yamdbf-addon-dm-manager/bin/**', '!pkg/yamdbf-addon-dm-manager/bin']);
done();
gulp.src('./src/**/*.json')
.pipe(gulp.dest('bin/'));
});
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"version": "0.1.3",
"description": "YAMDBF addon for viewing and replying to DMs sent to your discord bot",
"main": "bin/index.js",
"typings": "bin/index.d.ts",
"scripts": {
"postinstall": "postinstall-build \"npm run build -s\"",
"build": "gulp",
"lint": "tslint './src/**/*.ts'",
"package": "gulp clean-package && gulp package"
},
Expand All @@ -25,14 +28,15 @@
"homepage": "https://github.com/zajrik/yamdbf-addon-dm-manager#readme",
"dependencies": {
"discord.js": "^11.0.0",
"yamdbf": "^2.6.0"
"yamdbf": "^2.6.0",
"postinstall-build": "^2.1.3"
},
"devDependencies": {
"@types/node": "^6.0.46",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-typescript": "^3.1.0",
"tslint": "^3.15.1",
"typescript": "^2.1.4"
"typescript": "^2.2.1"
}
}
27 changes: 26 additions & 1 deletion src/DMManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LocalStorage } from 'yamdbf';
import { Client, Message, Guild, User, TextChannel, DMChannel, Collection, RichEmbed } from 'discord.js';
import { normalize } from './Util';

export default class DMManager
export class DMManager
{
private client: Client;
private _guild: Guild;
Expand Down Expand Up @@ -36,6 +36,30 @@ export default class DMManager
});
}

/**
* Add a user to the DMManager blacklist
*/
public blacklist(user: User): void
{
this.storage.setItem(`blacklist/${user.id}`, true);
}

/**
* Remove a user from the DMManager blacklist
*/
public whitelist(user: User): void
{
this.storage.removeItem(`blacklist/${user.id}`);
}

/**
* Return whether or not a user is blacklisted from the DMManager
*/
private isBlacklisted(user: User): boolean
{
return this.storage.exists(`blacklist/${user.id}`);
}

private get guild(): string { return this._guild.id; }

/**
Expand Down Expand Up @@ -112,6 +136,7 @@ export default class DMManager
*/
private async handleMessage(message: Message): Promise<void>
{
if (this.isBlacklisted(message.author)) return;
if (message.embeds[0] && message.channel.type !== 'dm') return;
if (message.channel.type !== 'dm' && message.guild.id !== this.guild) return;
if (message.guild && message.channel.id === message.guild.id) return;
Expand Down
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import _DMManager from './DMManager';

export const DMManager = _DMManager; // tslint:disable-line
export default DMManager;
export { DMManager } from './DMManager';
20 changes: 12 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es7"
]
},
"compilerOptions": {
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",
"lib": [
"es7"
],
"declaration": true,
"sourceMap": true,
"removeComments": false
},
"exclude": [
"node_modules",
"bower_components",
Expand All @@ -17,4 +21,4 @@
"pkg",
"examples"
]
}
}

0 comments on commit 3ede619

Please sign in to comment.