Skip to content

Commit

Permalink
feat: support GHP
Browse files Browse the repository at this point in the history
  • Loading branch information
HunteRoi committed May 1, 2022
1 parent 18f9068 commit 213b4dc
Show file tree
Hide file tree
Showing 18 changed files with 473 additions and 448 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ghp-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: GitHub Packages Registry

on:
workflow_dispatch:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: https://npm.pkg.github.com
- run: yarn install
- run: yarn build
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GHP_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Publish
name: NPM Registry

on:
workflow_dispatch:
release:
types: [created]

jobs:
build:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -13,6 +16,7 @@ jobs:
registry-url: https://registry.npmjs.org/
scope: '@hunteroi'
- run: yarn install
- run: yarn build
- run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": true
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ If you need examples, take a look at [`SendGridService`](/src/services/SendGridS
```ts
manager.on(VerificationManagerEvents.codeCreate, (code) => {});
manager.on(
VerificationManagerEvents.codeVerify,
(user, userid, code, isVerified) => {}
VerificationManagerEvents.codeVerify,
(user, userid, code, isVerified) => {}
);
manager.on(VerificationManagerEvents.userCreate, (user) => {});
manager.on(VerificationManagerEvents.userAwait, (user) => {});
Expand Down
144 changes: 72 additions & 72 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,114 +4,114 @@ const synchronizeSlashCommands = require('discord-sync-commands');
const { join } = require('path');

const {
VerificationManager,
VerificationManagerEvents,
JSONDatabaseService,
SendGridService,
VerificationManager,
VerificationManagerEvents,
JSONDatabaseService,
SendGridService,
} = require('../lib');

const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.GUILD_MESSAGES,
],
partials: [Constants.PartialTypes.MESSAGE],
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.GUILD_MESSAGES,
],
partials: [Constants.PartialTypes.MESSAGE],
});
synchronizeSlashCommands(
client,
[
new SlashCommandBuilder()
.setName('code')
.setDescription('Generates a code and then sends it to the given email')
.addStringOption((option) =>
option
.setName('email')
.setDescription('The email to which the code is sent')
.setRequired(true)
),
new SlashCommandBuilder()
.setName('verify')
.setDescription(
'Verifies the provided code and grants access to the rest of the server'
)
.addStringOption((option) =>
option
.setName('code')
.setDescription('The code sent by email')
.setRequired(true)
),
],
{ guild: 'GUILD_ID' }
client,
[
new SlashCommandBuilder()
.setName('code')
.setDescription('Generates a code and then sends it to the given email')
.addStringOption((option) =>
option
.setName('email')
.setDescription('The email to which the code is sent')
.setRequired(true)
),
new SlashCommandBuilder()
.setName('verify')
.setDescription(
'Verifies the provided code and grants access to the rest of the server'
)
.addStringOption((option) =>
option
.setName('code')
.setDescription('The code sent by email')
.setRequired(true)
),
],
{ guild: 'GUILD_ID' }
);

const db = new JSONDatabaseService(join(__dirname, 'db.json'));
db.init();

const sgMail = new SendGridService({
apiKey: 'SENDGRID_API_KEY',
mailData: {
from: 'EMAIL',
templateId: 'SENDGRID_TEMPLATE_ID',
},
apiKey: 'SENDGRID_API_KEY',
mailData: {
from: 'EMAIL',
templateId: 'SENDGRID_TEMPLATE_ID',
},
});

const manager = new VerificationManager(client, db, sgMail);

client.once('ready', () => {
console.log('Connected!');
console.log('Connected!');
});

client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
await interaction.deferReply({ ephemeral: true });
if (interaction.isCommand()) {
await interaction.deferReply({ ephemeral: true });

let feedback = 'Unknown command!';
switch (interaction.commandName) {
case 'code':
feedback = await manager.sendCode(
interaction.user.id,
interaction.options.getString('email', true) // !! PLEASE ADD CHECKS TO VALIDATE THE FIELD
);
break;
let feedback = 'Unknown command!';
switch (interaction.commandName) {
case 'code':
feedback = await manager.sendCode(
interaction.user.id,
interaction.options.getString('email', true) // !! PLEASE ADD CHECKS TO VALIDATE THE FIELD
);
break;

case 'verify':
feedback = await manager.verifyCode(
interaction.user.id,
interaction.options.getString('code', true)
);
break;
case 'verify':
feedback = await manager.verifyCode(
interaction.user.id,
interaction.options.getString('code', true)
);
break;

// you can also add other commands such as one to change the data field for users who mistyped it in the first place
}
// you can also add other commands such as one to change the data field for users who mistyped it in the first place
}

await interaction.editReply(feedback);
}
await interaction.editReply(feedback);
}
});

manager.on(VerificationManagerEvents.codeCreate, (code) => {
console.log('A code has just been created!', code);
console.log('A code has just been created!', code);
});
manager.on(
VerificationManagerEvents.codeVerify,
(user, userid, code, isVerified) =>
console.log(
`A user (${userid}) has ${
isVerified ? 'successfully verified' : 'unsuccessfully tried to verify'
} the code ${code}.`
)
VerificationManagerEvents.codeVerify,
(user, userid, code, isVerified) =>
console.log(
`A user (${userid}) has ${
isVerified ? 'successfully verified' : 'unsuccessfully tried to verify'
} the code ${code}.`
)
);
manager.on(VerificationManagerEvents.userCreate, (user) =>
console.log('A user has just been created!')
console.log('A user has just been created!')
);
manager.on(VerificationManagerEvents.userAwait, (user) =>
console.log('A user is waiting to verify their code!')
console.log('A user is waiting to verify their code!')
);
manager.on(VerificationManagerEvents.senderCall, () =>
console.log('Sender API called!')
console.log('Sender API called!')
);
manager.on(VerificationManagerEvents.storingSystemCall, () =>
console.log('Storing system called!')
console.log('Storing system called!')
);

client.login('TOKEN');
97 changes: 46 additions & 51 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,48 @@
{
"name": "@hunteroi/discord-verification",
"version": "1.0.1",
"description": "A framework to integrate a verification system with your Discord guild built with DiscordJS",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\" --tab-width 4",
"lint": "tslint -p tsconfig.json",
"prepare": "yarn run build",
"example": "yarn run build & node ./example/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hunteroi/discord-verification.git"
},
"keywords": [
"verification",
"discordjs",
"authentication"
],
"author": "HunteRoi <[email protected]> (https://tinaeldevresse.eu/)",
"funding": "https://github.com/sponsors/hunteroi",
"engines": {
"node": ">=16.6.0"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/hunteroi/discord-verification/issues"
},
"homepage": "https://github.com/hunteroi/discord-verification#readme",
"dependencies": {
"@sendgrid/mail": "^7.6.0",
"discord.js": "^13.2.0"
},
"devDependencies": {
"@types/node": "^16.11.1",
"@types/node-json-db": "^0.9.3",
"@types/sqlite3": "^3.1.7",
"discord-sync-commands": "^0.3.0",
"node-json-db": "^1.4.1",
"tslint": "^6.1.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.4.4"
},
"directories": {
"lib": "lib"
},
"files": [
"lib/**/*"
]
"name": "@hunteroi/discord-verification",
"version": "1.0.2",
"description": "A framework to integrate a verification system with your Discord guild built with DiscordJS",
"main": "lib/index.js",
"scripts": {
"build": "tsc",
"format": "npx prettier --write \"src/**/*.ts\" \"src/**/*.js\" \"example/**/*.ts\" \"example/**/*.js\"",
"lint": "tslint -p tsconfig.json",
"example": "yarn run build & node ./example/index.js"
},
"repository": "git//github.com/hunteroi/discord-verification.git",
"keywords": [
"verification",
"discordjs",
"authentication"
],
"author": "HunteRoi <[email protected]> (https://tinaeldevresse.eu/)",
"funding": "https://github.com/sponsors/hunteroi",
"engines": {
"node": ">=16.6.0"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/hunteroi/discord-verification/issues"
},
"homepage": "https://github.com/hunteroi/discord-verification#readme",
"dependencies": {
"@sendgrid/mail": "^7.6.0",
"discord.js": "^13.2.0"
},
"devDependencies": {
"@types/node": "^16.11.1",
"@types/node-json-db": "^0.9.3",
"@types/sqlite3": "^3.1.7",
"discord-sync-commands": "^0.3.0",
"node-json-db": "^1.4.1",
"tslint": "^6.1.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.4.4"
},
"directories": {
"lib": "lib"
},
"files": [
"lib/**/*"
]
}
Loading

0 comments on commit 213b4dc

Please sign in to comment.