@evolvejs/core
Version:
An advanced Discord API wrapper with TS and JS support
73 lines (72 loc) • 2.99 kB
JavaScript
"use strict";
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable no-mixed-spaces-and-tabs */
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Message = void 0;
const __1 = require("../..");
const util_1 = require("util");
class Message {
constructor(data, client) {
this.mentions = [];
Object.defineProperty(this, "client", {
value: client,
writable: false,
enumerable: false,
});
Object.defineProperty(this, "data", {
value: data,
enumerable: false,
writable: false,
});
if (!this.data)
return;
if (this.data.mentions)
for (const it of this.data.mentions) {
this.mentions.push(new __1.User(it));
}
this.channelId = data.channel_id;
this.guildId = data.guild_id;
if (this.data.guild_id)
this.client.rest.endpoint(__1.Endpoints.GUILD).get(this.data.guild_id);
this.sentAt = this.data.sent_at;
this.id = this.data.id;
this.pinned = this.data.pinned;
this.rolementions = this.data.mention_roles;
this.mentionEveryone = this.data.mention_everyone;
if (this.data.member)
this.member = new __1.GuildMember(this.data.member);
this.author = new __1.User(this.data.author);
if (this.member)
this.member.user = this.author;
this.editedTimestamp = this.data.edited_timestamp;
this.attachments = this.data.attachments;
this.content = this.data.content;
return this;
}
delete(time = 0) {
return __awaiter(this, void 0, void 0, function* () {
yield util_1.promisify(setTimeout)(time);
return yield this.client.rest
.endpoint(__1.Endpoints.CHANNEL_MESSAGE(this.channelId))
.delete(this.id);
});
}
edit(content, time = 0) {
return __awaiter(this, void 0, void 0, function* () {
yield util_1.promisify(setTimeout)(time);
return yield this.client.rest
.endpoint(__1.Endpoints.CHANNEL_MESSAGE(this.channelId))
.patch({ content }, this.id);
});
}
}
exports.Message = Message;