2021-12-23 22:36:13 -05:00
|
|
|
import axios, { AxiosResponse } from 'axios';
|
2023-02-11 23:49:24 -05:00
|
|
|
import { Command, Client, CmdContext } from '../class';
|
2021-12-23 22:36:13 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-02-11 23:49:24 -05:00
|
|
|
public async run(ctx: CmdContext) {
|
|
|
|
if (!ctx.message.attachments.length) return this.error(ctx.message.channel, 'Please upload your PGP public key as an attachment.');
|
|
|
|
if (!await this.client.db.mongo.Member.exists({ userID: ctx.message.author.id })) {
|
|
|
|
await this.client.db.mongo.Member.create({ userID: ctx.message.author.id });
|
2021-12-23 22:36:13 -05:00
|
|
|
}
|
2023-02-11 23:49:24 -05:00
|
|
|
const [pgpAttachment] = ctx.message.attachments;
|
2021-12-23 22:36:13 -05:00
|
|
|
const pgpReq: AxiosResponse<string> = await axios(pgpAttachment.url);
|
|
|
|
const pgp = pgpReq.data;
|
|
|
|
try {
|
|
|
|
await axios.post('https://certapi.libraryofcode.org/pgp', pgp);
|
|
|
|
} catch {
|
2023-02-11 23:49:24 -05:00
|
|
|
return this.error(ctx.message.channel, 'Unable to parse your PGP public key.');
|
2021-12-23 22:36:13 -05:00
|
|
|
}
|
2023-02-11 23:49:24 -05:00
|
|
|
await this.client.db.mongo.Member.updateOne({ userID: ctx.message.author.id }, { pgp });
|
|
|
|
this.success(ctx.message.channel, 'PGP public key successfully uploaded to your account.');
|
2021-12-23 22:36:13 -05:00
|
|
|
}
|
|
|
|
}
|