feat: PGP public keys
parent
21f966ce2b
commit
55512b735a
|
@ -0,0 +1,28 @@
|
||||||
|
import { Message } from 'eris';
|
||||||
|
import { Client, Command, RichEmbed } from '../class';
|
||||||
|
|
||||||
|
import PGP_Upload from './pgp_upload';
|
||||||
|
import PGP_Remove from './pgp_remove';
|
||||||
|
|
||||||
|
export default class PGP extends Command {
|
||||||
|
constructor(client: Client) {
|
||||||
|
super(client);
|
||||||
|
this.name = 'pgp';
|
||||||
|
this.description = 'Uploads to or removes from your account an PGP public key.';
|
||||||
|
this.usage = `${this.client.config.prefix}${this.name}`;
|
||||||
|
this.permissions = 0;
|
||||||
|
this.guildOnly = true;
|
||||||
|
this.enabled = true;
|
||||||
|
this.subcmds = [PGP_Upload, PGP_Remove];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async run(message: Message) {
|
||||||
|
const profile = await this.client.db.Member.findOne({ userID: message.author.id });
|
||||||
|
const embed = new RichEmbed()
|
||||||
|
.setAuthor(`${message.author.username}#${message.author.discriminator}`, message.author.dynamicAvatarURL())
|
||||||
|
.setTitle('PGP Connections')
|
||||||
|
.setDescription(profile?.pgp ? 'A PGP public key is currently connected to your account.' : 'There are no PGP public keys connected to your account.')
|
||||||
|
.setTimestamp();
|
||||||
|
message.channel.createMessage({ embed });
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { Message } from 'eris';
|
||||||
|
import { Command, Client } from '../class';
|
||||||
|
|
||||||
|
export default class PGP_Remove extends Command {
|
||||||
|
constructor(client: Client) {
|
||||||
|
super(client);
|
||||||
|
this.name = 'remove';
|
||||||
|
this.aliases = ['rm', 'delete', 'del', 'unlink', 'disconnect'];
|
||||||
|
this.description = 'Removes a currently connected PGP public key from your account.';
|
||||||
|
this.usage = `${this.client.config.prefix}pgp ${this.name}`;
|
||||||
|
this.permissions = 0;
|
||||||
|
this.guildOnly = true;
|
||||||
|
this.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async run(message: Message) {
|
||||||
|
const profile = await this.client.db.Member.findOne({ userID: message.author.id });
|
||||||
|
if (!profile?.pgp) return this.error(message.channel, 'There are no PGP public keys connected to your account.');
|
||||||
|
await profile.updateOne({ $unset: { pgp: '' } });
|
||||||
|
this.success(message.channel, 'Unlinked PGP public key from your account.');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { Message } from 'eris';
|
||||||
|
import axios, { AxiosResponse } from 'axios';
|
||||||
|
import { Command, Client } from '../class';
|
||||||
|
|
||||||
|
export default class PGP_Upload extends Command {
|
||||||
|
constructor(client: Client) {
|
||||||
|
super(client);
|
||||||
|
this.name = 'upload';
|
||||||
|
this.aliases = ['add', 'link', 'connect'];
|
||||||
|
this.description = 'Uploads your PGP public key as a file to our database for authenticity and identity verification.';
|
||||||
|
this.usage = `${this.client.config.prefix}pgp ${this.name}`;
|
||||||
|
this.permissions = 0;
|
||||||
|
this.guildOnly = true;
|
||||||
|
this.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async run(message: Message) {
|
||||||
|
if (!message.attachments.length) return this.error(message.channel, 'Please upload your PGP public key as an attachment.');
|
||||||
|
if (!await this.client.db.Member.exists({ userID: message.author.id })) {
|
||||||
|
await this.client.db.Member.create({ userID: message.author.id });
|
||||||
|
}
|
||||||
|
const [pgpAttachment] = message.attachments;
|
||||||
|
const pgpReq: AxiosResponse<string> = await axios(pgpAttachment.proxy_url);
|
||||||
|
const pgp = pgpReq.data;
|
||||||
|
try {
|
||||||
|
await axios.post('https://certapi.libraryofcode.org/pgp', pgp);
|
||||||
|
} catch {
|
||||||
|
this.error(message.channel, 'Unable to parse your PGP public key.');
|
||||||
|
} finally {
|
||||||
|
await this.client.db.Member.updateOne({ userID: message.author.id }, { pgp });
|
||||||
|
this.success(message.channel, 'PGP public key successfully uploaded to your account.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ export default class X509 extends Command {
|
||||||
const embed = new RichEmbed()
|
const embed = new RichEmbed()
|
||||||
.setAuthor(`${message.author.username}#${message.author.discriminator}`, message.author.dynamicAvatarURL())
|
.setAuthor(`${message.author.username}#${message.author.discriminator}`, message.author.dynamicAvatarURL())
|
||||||
.setTitle('x509 Connections')
|
.setTitle('x509 Connections')
|
||||||
.setDescription(profile?.x509 ? 'An x509 certificate is currently connected to your account.' : 'There are no x509 certificates connected to your account')
|
.setDescription(profile?.x509 ? 'An x509 certificate is currently connected to your account.' : 'There are no x509 certificates connected to your account.')
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
message.channel.createMessage({ embed });
|
message.channel.createMessage({ embed });
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ export interface MemberInterface extends Document {
|
||||||
bio: string,
|
bio: string,
|
||||||
},
|
},
|
||||||
x509?: string,
|
x509?: string,
|
||||||
|
pgp?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const Member: Schema = new Schema({
|
const Member: Schema = new Schema({
|
||||||
|
@ -22,6 +23,7 @@ const Member: Schema = new Schema({
|
||||||
bio: String,
|
bio: String,
|
||||||
},
|
},
|
||||||
x509: String,
|
x509: String,
|
||||||
|
pgp: String,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default model<MemberInterface>('Member', Member);
|
export default model<MemberInterface>('Member', Member);
|
||||||
|
|
Loading…
Reference in New Issue