lampdiscordbot/commands.js
Lamp 6f369ee441 :sGrimace:
also allow removing role icon
2022-01-13 19:28:15 -08:00

175 lines
4.5 KiB
JavaScript

var client = require("./client");
var config = require("./config");
var Discord = require("discord.js");
var BaseCommandInteraction = require("discord.js/src/structures/BaseCommandInteraction.js")
var commands = module.exports = [
{
name: "say",
description: "test command",
options: [
{
name: "text",
description: "text to say",
type: 3, // string
required: true
}
],
exec: i => {
i.reply(i.options.getString("text") || "bruh");
}
},
{
name: "owo",
description: "random owo",
options: [
{
name: "length",
description: "length of owo",
type: 4, // integer
required: false
}
],
exec: i => {
let owo = Math.round(Math.random()) ? 'O' : 'o';
let n = Math.min(i.options.getInteger("length") || 9, 1998);
for (let i = 0; i < n; i++) owo += ['o','w','O','W'][Math.floor(Math.random() * 4)];
owo += owo = Math.round(Math.random()) ? 'O' : 'o';
i.reply(owo);
}
},
{
name: "archive",
description: "Delete a channel without actually deleting it",
options: [
{
name: "channel",
description: "channel",
type: "CHANNEL",
required: true
}
],
defaultPermission: false,
permissions: [
{
id: config.admin_role,
type: "ROLE",
permission: true
}
],
exec: async i => {
let channel = i.options.getChannel("channel");
await channel.setParent(config.archive_category);
await channel.lockPermissions();
await i.reply({content: channel.toString()});
}
},
{
name: "avatar",
description: "View a user's original avatar (and save permanently as attachment)",
options: [
{
name: "user",
description: "can i not leave some obvious descriptions blank?",
type: "USER"
}
],
exec: async i => {
var user = i.options.getUser("user") || i.user;
var au = user.avatarURL({size:4096, dynamic: true});
var an = au.split('/').pop(); an = an.substring(0, an.indexOf('?'));
i.reply({files: [{attachment: au, name: an}], embeds: [{
title: `Avatar for ${user.tag}`,
url: au,
image: {url: `attachment://${an}`},
color: (await require('./colors').getColorRoleFor(user.id)).color
}]});
}
},
{
name: "steal",
description: "Copy an emoji to this server",
options: [
{
name: "emoji",
description: "The emoji to steal",
type: "STRING",
required: true
},
{
name: "name",
description: "Optional rename of stolen emoji",
type: "STRING",
required: false
}
],
exec: async i => {
await i.deferReply();
try {
var input = i.options.getString("emoji") || (await i.channel.messages.fetch(i.targetId))?.content;
var emoji = Discord.Util.parseEmoji(input);
if (!emoji.id || !emoji.name) return void await i.editReply({content: `Invalid emoji input: ${input}`});
var url = client.rest.cdn.Emoji(emoji.id, emoji.animated ? 'gif' : 'png');
var emoji2 = await i.guild.emojis.create(url, i.options.getString("name") || emoji.name);
await i.editReply({content: emoji2.toString()});
} catch (error) {
await i.editReply({content: error.message});
}
}
},
{
name: "Steal Emoji",
type: "MESSAGE",
exec: i => commands.find(x => x.name == "steal").exec(i)
},
{
name: "setbanner",
description: "Set the server banner image",
options: [
{
name: "url",
description: "HTTP(S) URL to an image",
type: "STRING"
}
],
exec: async i => {
var url = i.options.getString("url");
try {
if (!url) {
await i.guild.setBanner(null);
await i.reply("cleared the server banner");
} else {
if (/^https?:\/\//i.test(url)) {
await i.guild.setBanner(url);
await i.reply(url);
} else {
await i.reply("http image url only!");
}
}
} catch (error) {
await i.reply(error.message);
}
}
}
];
client.on("interactionCreate", interaction => {
if (interaction instanceof BaseCommandInteraction)
commands.find(x => x.name == interaction.commandName)?.exec?.(interaction);
});
client.once("ready", async () => {
let global_commands = commands.filter(x => x.global);
let guild_commands = commands.filter(x => !x.global);
let guild = client.guilds.resolve(config.guild);
await guild.commands.set(guild_commands);
await guild.commands.permissions.set({
fullPermissions: guild_commands.map(local_command => {
let discord_command = guild.commands.cache.find(discord_command => local_command.name == discord_command.name);
return {
id: discord_command.id,
permissions: local_command.permissions || []
}
})
});
await client.application.commands.set(global_commands);
});