mrmBot-Matrix/commands/general/banner.js

45 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-01-18 19:05:39 +00:00
import Command from "../../classes/command.js";
2022-06-07 23:26:50 +00:00
const mentionRegex = /^<?[@#]?[&!]?(\d+)>?$/;
2022-01-18 19:05:39 +00:00
class BannerCommand extends Command {
async run() {
2022-06-07 23:26:50 +00:00
const member = this.specialArgs.member ?? this.args[0];
const self = await this.client.getRESTUser(this.author.id);
if (this.type === "classic" && this.message.mentions[0]) {
return this.message.mentions[0].dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!";
} else if (await this.ipc.fetchUser(member)) {
const user = await this.client.getRESTUser(member);
return user.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!";
} else if (mentionRegex.test(member)) {
const id = member.match(mentionRegex)[1];
if (id < 21154535154122752n) return "That's not a valid mention!";
2022-01-18 19:05:39 +00:00
try {
2022-06-07 23:26:50 +00:00
const user = await this.client.getRESTUser(id);
return user.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!";
2022-01-18 19:05:39 +00:00
} catch {
2022-06-07 23:26:50 +00:00
return self.dynamicBannerURL(null, 512) ?? "You don't have a banner!";
2022-01-18 19:05:39 +00:00
}
} else if (this.args.join(" ") !== "" && this.channel.guild) {
2022-06-07 23:26:50 +00:00
const searched = await this.channel.guild.searchMembers(this.args.join(" "));
if (searched.length === 0) return self.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!";
const user = await this.client.getRESTUser(searched[0].user.id);
return user.dynamicBannerURL(null, 512) ?? (self.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!");
2022-01-18 19:05:39 +00:00
} else {
2022-06-07 23:26:50 +00:00
return self.dynamicBannerURL(null, 512) ?? "You don't have a banner!";
2022-01-18 19:05:39 +00:00
}
}
static description = "Gets a user's banner";
static aliases = ["userbanner"];
static arguments = ["{mention/id}"];
2022-06-07 23:26:50 +00:00
static flags = [{
name: "member",
type: 6,
description: "The member to get the banner from",
required: false
}];
2022-01-18 19:05:39 +00:00
}
export default BannerCommand;