tweak tags cmd, try and fail to fix natives

This commit is contained in:
murm 2023-03-17 01:00:59 -04:00
parent 776e4908ba
commit b4c5885435
3 changed files with 30 additions and 29 deletions

View File

@ -8,7 +8,6 @@ class TagsCommand extends Command {
// todo: attempt to not make this file the worst thing that human eyes have ever seen // todo: attempt to not make this file the worst thing that human eyes have ever seen
async run() { async run() {
this.success = false; this.success = false;
if (!this.guild) return "This command only works in servers!";
const cmd = this.type === "classic" ? (this.args[0] ?? "").toLowerCase() : this.optionsArray[0].name; const cmd = this.type === "classic" ? (this.args[0] ?? "").toLowerCase() : this.optionsArray[0].name;
if (!cmd || !cmd.trim()) return "You need to provide the name of the tag you want to view!"; if (!cmd || !cmd.trim()) return "You need to provide the name of the tag you want to view!";
const tagName = this.type === "classic" ? this.args.slice(1)[0] : (this.optionsArray[0].options[0] ?? {}).value; const tagName = this.type === "classic" ? this.args.slice(1)[0] : (this.optionsArray[0].options[0] ?? {}).value;
@ -16,7 +15,7 @@ class TagsCommand extends Command {
if (cmd === "create" || cmd === "add") { if (cmd === "create" || cmd === "add") {
if (!tagName || !tagName.trim()) return "You need to provide the name of the tag you want to add!"; if (!tagName || !tagName.trim()) return "You need to provide the name of the tag you want to add!";
if (blacklist.includes(tagName)) return "You can't make a tag with that name!"; if (blacklist.includes(tagName)) return "You can't make a tag with that name!";
const getResult = await database.getTag(this.guild.id, tagName); const getResult = await database.getTag(this.channel, tagName);
if (getResult) return "This tag already exists!"; if (getResult) return "This tag already exists!";
const result = await database.setTag(tagName, { content: this.type === "classic" ? this.args.slice(2).join(" ") : this.optionsArray[0].options[1].value, author: this.member.id }, this.guild); const result = await database.setTag(tagName, { content: this.type === "classic" ? this.args.slice(2).join(" ") : this.optionsArray[0].options[1].value, author: this.member.id }, this.guild);
this.success = true; this.success = true;
@ -24,25 +23,25 @@ class TagsCommand extends Command {
return `The tag \`${tagName}\` has been added!`; return `The tag \`${tagName}\` has been added!`;
} else if (cmd === "delete" || cmd === "remove") { } else if (cmd === "delete" || cmd === "remove") {
if (!tagName || !tagName.trim()) return "You need to provide the name of the tag you want to delete!"; if (!tagName || !tagName.trim()) return "You need to provide the name of the tag you want to delete!";
const getResult = await database.getTag(this.guild.id, tagName); const getResult = await database.getTag(this.channel, tagName);
if (!getResult) return "This tag doesn't exist!"; if (!getResult) return "This tag doesn't exist!";
const owners = process.env.OWNER.split(","); const owners = process.env.OWNER.split(",");
if (getResult.author !== this.author && !this.member.permissions.has("MANAGE_MESSAGES") && !owners.includes(this.author)) return "You don't own this tag!"; if (getResult.author !== this.author && !owners.includes(this.author)) return "You don't own this tag!";
await database.removeTag(tagName, this.guild); await database.removeTag(tagName, this.guild);
this.success = true; this.success = true;
return `The tag \`${tagName}\` has been deleted!`; return `The tag \`${tagName}\` has been deleted!`;
} else if (cmd === "edit") { } else if (cmd === "edit") {
if (!tagName || !tagName.trim()) return "You need to provide the name of the tag you want to edit!"; if (!tagName || !tagName.trim()) return "You need to provide the name of the tag you want to edit!";
const getResult = await database.getTag(this.guild.id, tagName); const getResult = await database.getTag(this.channel, tagName);
if (!getResult) return "This tag doesn't exist!"; if (!getResult) return "This tag doesn't exist!";
const owners = process.env.OWNER.split(","); const owners = process.env.OWNER.split(",");
if (getResult.author !== this.author && !this.member.permissions.has("MANAGE_MESSAGES") && !owners.includes(this.author)) return "You don't own this tag!"; if (getResult.author !== this.author && !owners.includes(this.author)) return "You don't own this tag!";
await database.editTag(tagName, { content: this.type === "classic" ? this.args.slice(2).join(" ") : this.optionsArray[0].options[1].value, author: this.member.id }, this.guild); await database.editTag(tagName, { content: this.type === "classic" ? this.args.slice(2).join(" ") : this.optionsArray[0].options[1].value, author: this.member.id }, this.guild);
this.success = true; this.success = true;
return `The tag \`${tagName}\` has been edited!`; return `The tag \`${tagName}\` has been edited!`;
} else if (cmd === "own" || cmd === "owner") { } else if (cmd === "own" || cmd === "owner") {
if (!tagName || !tagName.trim()) return "You need to provide the name of the tag you want to check the owner of!"; if (!tagName || !tagName.trim()) return "You need to provide the name of the tag you want to check the owner of!";
const getResult = await database.getTag(this.guild.id, tagName); const getResult = await database.getTag(this.channel, tagName);
if (!getResult) return "This tag doesn't exist!"; if (!getResult) return "This tag doesn't exist!";
const user = this.client.users.get(getResult.author); const user = this.client.users.get(getResult.author);
this.success = true; this.success = true;
@ -58,39 +57,41 @@ class TagsCommand extends Command {
} }
} else if (cmd === "list") { } else if (cmd === "list") {
if (!this.channel.permissionsOf(this.client.user.id.toString()).has("EMBED_LINKS")) return "I don't have the `Embed Links` permission!"; if (!this.channel.permissionsOf(this.client.user.id.toString()).has("EMBED_LINKS")) return "I don't have the `Embed Links` permission!";
const tagList = await database.getTags(this.guild.id); const tagList = await database.getTags(this.channel);
const embeds = []; const embeds = [];
const groups = Object.keys(tagList).map((item, index) => { const groups = Object.keys(tagList).map((item, index) => {
return index % 15 === 0 ? Object.keys(tagList).slice(index, index + 15) : null; return index % 15 === 0 ? Object.keys(tagList).slice(index, index + 15) : null;
}).filter((item) => { }).filter((item) => {
return item; return item;
}); });
for (const [i, value] of groups.entries()) { let output = JSON.stringify(groups.entries());
embeds.push({ // for (const [i, value] of groups.entries()) {
embeds: [{ // // embeds.push({
title: "Tag List", // // embeds: [{
color: 16711680, // // title: "Tag List",
footer: { // // color: 16711680,
text: `Page ${i + 1} of ${groups.length}` // // footer: {
}, // // text: `Page ${i + 1} of ${groups.length}`
description: value.join("\n"), // // },
author: { // // description: value.join("\n"),
name: this.author.username, // // author: {
iconURL: this.author.avatarURL() // // name: this.author.username,
} // // iconURL: this.author.avatarURL()
}] // // }
}); // // }]
} // // });
// }
if (embeds.length === 0) return "I couldn't find any tags!"; if (embeds.length === 0) return "I couldn't find any tags!";
this.success = true; this.success = true;
return paginator(this.client, { type: this.type, message: this.message, interaction: this.interaction, channel: this.channel, author: this.author }, embeds); return output;
// return paginator(this.client, { type: this.type, message: this.message, interaction: this.interaction, channel: this.channel, author: this.author }, embeds);
} else { } else {
let getResult; let getResult;
if (cmd === "random") { if (cmd === "random") {
const tagList = await database.getTags(this.guild.id); const tagList = await database.getTags(this.channel);
getResult = tagList[random(Object.keys(tagList))]; getResult = tagList[random(Object.keys(tagList))];
} else { } else {
getResult = await database.getTag(this.guild.id, this.type === "classic" ? cmd : tagName); getResult = await database.getTag(this.channel, this.type === "classic" ? cmd : tagName);
} }
if (!getResult) return "This tag doesn't exist!"; if (!getResult) return "This tag doesn't exist!";
this.success = true; this.success = true;

View File

@ -7,7 +7,7 @@ using namespace vips;
char *Explode(string type, string *outType, char *BufferData, char *Explode(string type, string *outType, char *BufferData,
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
bool implode = GetArgument<bool>(Arguments, "implode"); bool implode = GetArgumentWithFallback<bool>(Arguments, "implode", false);
string basePath = GetArgument<string>(Arguments, "basePath"); string basePath = GetArgument<string>(Arguments, "basePath");
VOption *options = VImage::option(); VOption *options = VImage::option();

View File

@ -7,7 +7,7 @@ using namespace vips;
char *Reddit(string type, string *outType, char *BufferData, char *Reddit(string type, string *outType, char *BufferData,
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
string text = GetArgument<string>(Arguments, "text"); string text = GetArgumentWithFallback<string>(Arguments, "text", "");
string basePath = GetArgument<string>(Arguments, "basePath"); string basePath = GetArgument<string>(Arguments, "basePath");
VOption *options = VImage::option()->set("access", "sequential"); VOption *options = VImage::option()->set("access", "sequential");