mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 18:55:28 +00:00
add /avatar and /nick
This commit is contained in:
parent
a06c3547fb
commit
7a7ffcc805
64
bot/src/bot/commands/avatar.ts
Normal file
64
bot/src/bot/commands/avatar.ts
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import { Member } from "@janderedev/revolt.js/dist/maps/Members";
|
||||||
|
import axios from "axios";
|
||||||
|
import CommandCategory from "../../struct/commands/CommandCategory";
|
||||||
|
import SimpleCommand from "../../struct/commands/SimpleCommand";
|
||||||
|
import MessageCommandContext from "../../struct/MessageCommandContext";
|
||||||
|
import { hasPerm, isModerator, NO_MANAGER_MSG, parseUser } from "../util";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'avatar',
|
||||||
|
aliases: [ 'pfp' ],
|
||||||
|
description: 'Get or clear someone\'s avatar',
|
||||||
|
category: CommandCategory.Moderation,
|
||||||
|
run: async (message: MessageCommandContext, args: string[]) => {
|
||||||
|
try {
|
||||||
|
const targetStr = args.shift();
|
||||||
|
if (!targetStr) return message.reply('No target user specified.');
|
||||||
|
const targetUser = await parseUser(targetStr);
|
||||||
|
if (!targetUser) return message.reply('Couldn\'t find the specified user.');
|
||||||
|
const target = await message.channel?.server?.fetchMember(targetUser);
|
||||||
|
if (!target) return message.reply('The target is not part of this server.');
|
||||||
|
|
||||||
|
if (args[0]?.toLowerCase() == 'reset'
|
||||||
|
|| args[0]?.toLowerCase() == 'clear') {
|
||||||
|
// Clear server avatar
|
||||||
|
if (!message.member) return;
|
||||||
|
if (!hasPerm(message.member, 'RemoveAvatars')
|
||||||
|
&& !await isModerator(message)) return message.reply(NO_MANAGER_MSG);
|
||||||
|
|
||||||
|
if (!target.avatar) {
|
||||||
|
await message.reply(`\`@${targetUser.username}\` does not currently have an avatar set for this server.`);
|
||||||
|
} else {
|
||||||
|
await clearAvatar(target);
|
||||||
|
await message.reply(`\`@${targetUser.username}\`'s server avatar has been cleared.`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Print server and global avatar
|
||||||
|
|
||||||
|
await message.reply(
|
||||||
|
`### \`@${targetUser.username}\`'s avatar\n` +
|
||||||
|
(targetUser.avatar ? `[\\[Global\\]](<${targetUser.generateAvatarURL()}>)` : '[No global avatar]') +
|
||||||
|
' | ' +
|
||||||
|
(target.avatar ? `[\\[Server\\]](<${target.generateAvatarURL()}>)` : '[No server avatar]')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.error('' + e);
|
||||||
|
message.reply('Something went wrong: ' + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as SimpleCommand;
|
||||||
|
|
||||||
|
async function clearAvatar(member: Member) {
|
||||||
|
await axios.patch(
|
||||||
|
`${member.client.apiURL}/servers/${member.server!._id}/members/${member._id.user}`,
|
||||||
|
{
|
||||||
|
remove: "Avatar",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'x-bot-token': process.env['BOT_TOKEN']!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
58
bot/src/bot/commands/nick.ts
Normal file
58
bot/src/bot/commands/nick.ts
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
import { Member } from "@janderedev/revolt.js/dist/maps/Members";
|
||||||
|
import axios from "axios";
|
||||||
|
import CommandCategory from "../../struct/commands/CommandCategory";
|
||||||
|
import SimpleCommand from "../../struct/commands/SimpleCommand";
|
||||||
|
import MessageCommandContext from "../../struct/MessageCommandContext";
|
||||||
|
import { hasPerm, isModerator, NO_MANAGER_MSG, parseUser } from "../util";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'nick',
|
||||||
|
aliases: [ 'setnick' ],
|
||||||
|
description: 'Set or clear someone\'s nickname',
|
||||||
|
category: CommandCategory.Moderation,
|
||||||
|
run: async (message: MessageCommandContext, args: string[]) => {
|
||||||
|
try {
|
||||||
|
if (!message.member) return;
|
||||||
|
if (!hasPerm(message.member, 'ManageNicknames')
|
||||||
|
&& !await isModerator(message)) return message.reply(NO_MANAGER_MSG);
|
||||||
|
|
||||||
|
const targetStr = args.shift();
|
||||||
|
if (!targetStr) return message.reply('No target user specified.');
|
||||||
|
const targetUser = await parseUser(targetStr);
|
||||||
|
if (!targetUser) return message.reply('Couldn\'t find the specified user.');
|
||||||
|
const target = await message.channel?.server?.fetchMember(targetUser);
|
||||||
|
if (!target) return message.reply('The target is not part of this server.');
|
||||||
|
|
||||||
|
const newName = args.join(' ');
|
||||||
|
|
||||||
|
if (!newName) {
|
||||||
|
// Reset name
|
||||||
|
await setNick(target, null);
|
||||||
|
await message.reply(`Nickname of \`@${targetUser.username}\` has been cleared.`);
|
||||||
|
} else {
|
||||||
|
// Set new name
|
||||||
|
await setNick(target, newName);
|
||||||
|
await message.reply(`Nickname of \`@${targetUser.username}\` has been changed to `
|
||||||
|
+ `"${newName.replace(/`/g, '\\`')}".`);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.error('' + e);
|
||||||
|
message.reply('Something went wrong: ' + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as SimpleCommand;
|
||||||
|
|
||||||
|
async function setNick(member: Member, newName: string|null) {
|
||||||
|
await axios.patch(
|
||||||
|
`${member.client.apiURL}/servers/${member.server!._id}/members/${member._id.user}`,
|
||||||
|
{
|
||||||
|
nickname: newName || undefined,
|
||||||
|
remove: !newName ? "Nickname" : undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'x-bot-token': process.env['BOT_TOKEN']!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue