community-relations/src/commands/pgp_upload.ts

35 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-07-02 19:42:50 -04:00
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.');
}
}
}