Skip to content

Commit

Permalink
Added more application commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBThai committed Nov 3, 2024
1 parent f82bf6b commit f7f2a2a
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 239 deletions.
13 changes: 13 additions & 0 deletions src/commands/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const adminCommands = {};
const aliasToCommand = {};
const mcommands = {};
const commandGroups = {};
const appCommandNameToCommand = {};

class Command {
constructor(main) {
Expand Down Expand Up @@ -144,6 +145,10 @@ class Command {
this.main.bot.users.update(rawUser, this.main.bot);
}
}

messageUserInteractionToCommand(interaction) {
return appCommandNameToCommand[interaction.name];
}
}

async function executeCommand(main, p) {
Expand Down Expand Up @@ -214,6 +219,13 @@ function initCommands() {
six: command.six,
group: command.group,
};

command.appCommands?.forEach((appCommand) => {
// Message or User commands
if (appCommand.type === 3 || appCommand.type === 2) {
appCommandNameToCommand[appCommand.name] = name;
}
});
};

let addAdminCommand = function (command) {
Expand Down Expand Up @@ -256,6 +268,7 @@ function initParam(msg, command, args, main, context) {
let param = {
msg: msg,
options: msg.options || {},
interaction: msg.interaction,
args: args,
context: context,
command: command,
Expand Down
26 changes: 25 additions & 1 deletion src/commands/commandList/memegen/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const CommandInterface = require('../../CommandInterface.js');

const commandGroups = require('../../../utils/commandGroups.js');
const request = require('request');
const rocketEmoji = '🚀';

Expand All @@ -25,13 +26,36 @@ module.exports = new CommandInterface({

group: ['memegeneration'],

appCommands: [
commandGroups.addOption('eject', ['gen'], {
'name': 'eject',
'description': 'Eject the user into space',
'type': 1,
'options': [
{
'name': 'user',
'description': 'The user to use',
'type': 6,
'required': true,
},
],
}),
{
'type': 2,
'name': 'Eject to space',
'dm_permission': true,
'integration_types': [0, 1],
'contexts': [0, 1, 2],
},
],

cooldown: 30000,
half: 100,
six: 500,
bot: true,

execute: async function (p) {
let user = p.getMention(p.args[0]);
let user = p.options.user || p.getMention(p.args[0]);
if (!user) {
p.errorMsg(', you must tag a user!', 5000);
p.setCooldown(5);
Expand Down
9 changes: 9 additions & 0 deletions src/commands/commandList/memegen/emergency.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const CommandInterface = require('../../CommandInterface.js');

const commandGroups = require('../../../utils/commandGroups.js');
const request = require('request');
const Vibrant = require('node-vibrant');
const rocketEmoji = '🚀';
Expand All @@ -26,6 +27,14 @@ module.exports = new CommandInterface({

group: ['memegeneration'],

appCommands: [
commandGroups.addOption('emergency', ['gen'], {
'name': 'emergency',
'description': 'Call an emergency meeting',
'type': 1,
}),
],

cooldown: 30000,
half: 100,
six: 500,
Expand Down
16 changes: 11 additions & 5 deletions src/commands/commandList/memegen/headpat.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,18 @@ module.exports = new CommandInterface({
'name': 'user',
'description': "Generate a headpat emoji with a user's avatar",
'type': 1,
'required': false,
'options': [
{
'name': 'user',
'description': 'The user to use',
'type': 6,
'required': false,
},
],
},
{
'name': 'emoji',
'description': 'Generate a headpat emoji with an emoji',
'type': 1,
'required': false,
'options': [
{
'name': 'emoji',
Expand All @@ -61,6 +58,13 @@ module.exports = new CommandInterface({
},
],
}),
{
'type': 2,
'name': 'Headpat',
'dm_permission': true,
'integration_types': [0, 1],
'contexts': [0, 1, 2],
},
],

cooldown: 30000,
Expand Down Expand Up @@ -120,11 +124,13 @@ async function display(p, url, name) {
collector.on('collect', async (component, user, ack) => {
try {
if (await emojiAdder.addEmoji(user.id)) {
(content.embed = createEmbed(p, url, name, emojiName, emojiAdder)), ack(content);
content.embed = createEmbed(p, url, name, emojiName, emojiAdder);
ack(content);
}
} catch (err) {
if (!emojiAdder.successCount) {
(content.embed = createEmbed(p, url, name, emojiName, emojiAdder)), ack(content);
content.embed = createEmbed(p, url, name, emojiName, emojiAdder);
ack(content);
}
}
});
Expand Down
3 changes: 0 additions & 3 deletions src/commands/commandList/memegen/waddle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,18 @@ module.exports = new CommandInterface({
'name': 'user',
'description': "Generate a waddle emoji with a user's avatar",
'type': 1,
'required': false,
'options': [
{
'name': 'user',
'description': 'The user to use',
'type': 6,
'required': false,
},
],
},
{
'name': 'emoji',
'description': 'Generate a waddle emoji with an emoji',
'type': 1,
'required': false,
'options': [
{
'name': 'emoji',
Expand Down
66 changes: 34 additions & 32 deletions src/commands/commandList/social/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,20 @@ module.exports = new CommandInterface({
six: 500,

execute: async function (p) {
/* Look at previous message */
if (
p.args.length == 0 ||
(p.args[0] &&
(p.args[0].toLowerCase() == 'prev' ||
p.args[0].toLowerCase() == 'previous' ||
p.args[0].toLowerCase() == 'p'))
) {
// Special case for message interaction
if (this.interaction && this.options.message) {
const emojis = parseEmojis([this.options.message]);
await display(p, emojis);

/* Look at previous message */
} else if (!p.args.length || ['prev', 'previous', 'p'].includes(p.args[0]?.toLowerCase())) {
let msgs = await p.global.getChannelMessages(p.msg.channel, 10);
if (!msgs) {
p.errorMsg(', There are no emojis! >:c', 3000);
return;
}
let emojis = '';
for (let i in msgs) {
const msg = msgs[i];
emojis += msg.content;
emojis += JSON.stringify(msg.embeds);
if (msg.reactions) {
for (let name in msg.reactions) {
const emoji = msg.reactions[name];
emojis += `<${emoji.animated ? 'a' : ''}:${name}>`;
}
}
if (msg.stickerItems?.length) {
msg.stickerItems.forEach((sticker) => {
emojis += `<s:${sticker.name}:${sticker.id}>`;
});
}
}

emojis = parseIDs(emojis);
if (emojis.length == 0)
p.errorMsg(', There are no emojis! I can only look at the previous 10 messages! >:c', 3000);
else await display(p, emojis);
const emojis = parseEmojis(msgs);
await display(p, emojis);

// Set emoji steal guild
} else if (['setguild', 'setserver', 'set', 'setsteal'].includes(p.args[0].toLowerCase())) {
Expand All @@ -90,12 +69,32 @@ module.exports = new CommandInterface({
} else {
let text = p.args.join(' ');
let emojis = parseIDs(text);
if (emojis.length == 0) p.errorMsg(', There are no emojis! >:c', 3000);
else await display(p, emojis);
await display(p, emojis);
}
},
});

function parseEmojis(msgs) {
let emojis = '';
msgs.forEach((msg) => {
emojis += msg.content;
emojis += JSON.stringify(msg.embeds);
if (msg.reactions) {
for (let name in msg.reactions) {
const emoji = msg.reactions[name];
emojis += `<${emoji.animated ? 'a' : ''}:${name}>`;
}
}
if (msg.stickerItems?.length) {
msg.stickerItems.forEach((sticker) => {
emojis += `<s:${sticker.name}:${sticker.id}>`;
});
}
});

return parseIDs(emojis);
}

function parseIDs(text) {
let emojis = [];

Expand Down Expand Up @@ -130,6 +129,9 @@ function parseIDs(text) {
}

async function display(p, emojis) {
if (emojis.length == 0) {
return p.errorMsg(', There are no emojis! >:c', 3000);
}
const emojiAdders = [];
const createEmbed = (currentPage, maxPage) => {
const emoji = emojis[currentPage];
Expand Down
43 changes: 39 additions & 4 deletions src/commands/commandList/social/level.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,39 @@ module.exports = new CommandInterface({

group: ['social'],

appCommands: [
{
'name': 'level',
'type': 1,
'description': 'Display your level',
'integration_types': [0, 1],
'contexts': [0, 1, 2],
'options': [
{
'type': 3,
'name': 'type',
'description': 'Either server or global level',
'choices': [
{
'name': 'Server',
'value': 'server',
},
{
'name': 'Global',
'value': 'global',
},
],
},
],
},
],

cooldown: 15000,
half: 100,
six: 500,

execute: async function (p) {
let perms = p.msg.member.permissions;
let perms = p.msg.member?.permissions;
if (p.args.length >= 1 && ['disable', 'disabletext', 'dt'].includes(p.args[0].toLowerCase())) {
if (perms.has('manageChannels')) {
let sql = `INSERT INTO guild_setting (id,levelup) VALUES (${p.msg.channel.guild.id},1) ON DUPLICATE KEY UPDATE levelup = 1;`;
Expand Down Expand Up @@ -58,8 +85,16 @@ module.exports = new CommandInterface({
} else {
//try{
let opt = {};
if (p.args[0] == 's' || p.args[0] == 'server' || p.args[0] == 'g' || p.args[0] == 'guild') {
opt.guild = true;
if (
this.options.type === 'server' ||
p.args[0] == 's' ||
p.args[0] == 'server' ||
p.args[0] == 'g' ||
p.args[0] == 'guild'
) {
if (this.msg.channel.guild) {
opt.guild = true;
}
}
let uuid = await levelUtil.display(p, p.msg.author, opt);

Expand All @@ -71,7 +106,7 @@ module.exports = new CommandInterface({
let url = `${process.env.GEN_HOST}/level/${uuid}.png`;
let data = await p.DataResolver.urlToBuffer(url);
await p.send('', null, { file: data, name: 'level.png' });
if (!opt.guild) await levelRewards.distributeRewards(p.msg);
if (!opt.guild && this.msg.channel?.guild) await levelRewards.distributeRewards(p.msg);
/*
}catch(e){
console.error(e);
Expand Down
37 changes: 33 additions & 4 deletions src/commands/commandList/social/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,43 @@ module.exports = new CommandInterface({

group: ['social'],

appCommands: [
{
'name': 'profile',
'type': 1,
'description': 'Display your profile',
'options': [
{
'type': 6,
'name': 'user',
'description': "Display a user's profile",
},
],
'integration_types': [0, 1],
'contexts': [0, 1, 2],
},
{
'type': 2,
'name': 'Display profile',
'dm_permission': true,
'integration_types': [0, 1],
'contexts': [0, 1, 2],
},
],

cooldown: 3000,

execute: async function (p) {
if (p.args.length <= 0) {
if (!p.options.user && p.args.length <= 0) {
await profileUtil.displayProfile(p, p.msg.author);
} else if (p.global.isUser(p.args[0]) || p.global.isInt(p.args[0])) {
let user = p.args[0].match(/[0-9]+/)[0];
user = await p.fetch.getUser(user);
} else if (p.options.user || p.global.isUser(p.args[0]) || p.global.isInt(p.args[0])) {
let user;
if (p.options.user) {
user = p.options.user;
} else {
user = p.args[0].match(/[0-9]+/)[0];
user = await p.fetch.getUser(user);
}
if (!user) p.errorMsg(", I couldn't find that user!", 3000);
else {
let sql = `SELECT private FROM user INNER JOIN user_profile ON user.uid = user_profile.uid WHERE id = ${user.id};`;
Expand Down
Loading

0 comments on commit f7f2a2a

Please sign in to comment.