Skip to content

Commit

Permalink
Ability to install the bot onto users
Browse files Browse the repository at this point in the history
Also added support for a couple of image gen in slash commands
Fixed some slash command errors
  • Loading branch information
ChristopherBThai committed Nov 3, 2024
1 parent 0e4e6f7 commit f82bf6b
Show file tree
Hide file tree
Showing 20 changed files with 534 additions and 140 deletions.
3 changes: 3 additions & 0 deletions secret/env
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
BOT_TOKEN=BOT_TOKEN_GOES_HERE

CLIENT_ID=OAuth2 Client ID (Used for registerAppCommands)
CLIENT_SECRET=OAuth2 Client Secret (Used for registerAppCommands)

MYSQL_HOST=localhost
MYSQL_USER=user
MYSQL_PASS=password
Expand Down
14 changes: 11 additions & 3 deletions src/commands/commandList/battle/ab.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,25 @@ module.exports = new CommandInterface({

/* Get opponent name */
let sender = result[0][0].sender;
sender = await p.fetch.getMember(p.msg.channel.guild.id, sender);
if (p.msg.channel.guild) {
sender = await p.fetch.getMember(p.msg.channel.guild.id, sender);
} else {
sender = await p.fetch.getUser(sender);
}
if (!sender) {
p.errorMsg(', I could not find your opponent!', 3000);
return;
}
if (!p.msg.channel.guild) {
// Can't seem to edit message after interaction in DMs
flags.instant = true;
}

const settingOverride = {
friendlyBattle: true,
display: flags.display ? flags.display : 'image',
speed: flags.log ? 'instant' : 'short',
instant: flags.log ? true : false,
speed: flags.instant || flags.log ? 'instant' : 'short',
instant: flags.instant || flags.log ? true : false,
title: this.getName(author) + ' vs ' + this.getName(sender),
showLogs: flags.link ? 'link' : flags.log ? true : false,
};
Expand Down
17 changes: 17 additions & 0 deletions src/commands/commandList/battle/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ module.exports = new CommandInterface({

group: ['animals'],

appCommands: [
{
'name': 'battle',
'type': 1,
'description': 'Fight with your team of animals!',
'options': [
{
'type': 6,
'name': 'user',
'description': 'Fight a friend.',
},
],
'integration_types': [0, 1],
'contexts': [0, 1, 2],
},
],

cooldown: 15000,
half: 80,
six: 500,
Expand Down
17 changes: 17 additions & 0 deletions src/commands/commandList/battle/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ module.exports = new CommandInterface({

group: ['animals'],

appCommands: [
{
'name': 'crate',
'type': 1,
'description': 'Open a weapon crate',
'options': [
{
'type': 4,
'name': 'count',
'description': 'Number of weapon crates',
},
],
'integration_types': [0, 1],
'contexts': [0, 1, 2],
},
],

cooldown: 30000,
half: 100,
six: 500,
Expand Down
95 changes: 65 additions & 30 deletions src/commands/commandList/memegen/headpat.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');

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

group: ['memegeneration'],

appCommands: [
commandGroups.addOption('headpat', ['gen'], {
'name': 'headpat',
'description': 'Generate a headpat emoji',
'type': 2,
'options': [
{
'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',
'description': 'The emoji to use',
'type': 3,
'required': true,
},
],
},
],
}),
],

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

execute: async function (p) {
let user = p.getMention(p.args[0]);
let user = p.getMention(p.args[0]) || p.options.user;
let link;
let name;
if (user) {
link = user.dynamicAvatarURL('png', 128);
name = user.username;
} else if (!user && !p.args.length) {
link = p.msg.author.dynamicAvatarURL('png', 128);
name = p.getName();
} else if (!user && p.global.isEmoji(p.args[0])) {
link = p.args[0].match(/:[0-9]+>/gi)[0];
} else if (p.global.isEmoji(p.args[0] || p.options.emoji)) {
const emoji = p.args[0] || p.options.emoji;
link = emoji.match(/:[0-9]+>/gi)[0];
link = `https://cdn.discordapp.com/emojis/${link.slice(1, link.length - 1)}.png`;
name = p.args[0].match(/:[\w]+:/gi)[0];
name = emoji.match(/:[\w]+:/gi)[0];
name = name.slice(1, name.length - 1);
} else if (!p.args.length) {
link = p.msg.author.dynamicAvatarURL('png', 128);
name = p.getName();
} else {
p.errorMsg(', invalid arguments! Please tag a user or add an emoji!', 3000);
p.setCooldown(5);
Expand All @@ -65,41 +105,36 @@ module.exports = new CommandInterface({
async function display(p, url, name) {
const emojiName = `${name.replace(/[^\w]/gi, '')}_pat`;
let embed = createEmbed(p, url, name, emojiName);
let msg = await p.send({ embed });

// Check if user set stealing
let sql = `SELECT emoji_steal.guild FROM emoji_steal INNER JOIN user ON emoji_steal.uid = user.uid WHERE id = ${p.msg.author.id};`;
await p.query(sql);
let canSteal = (await p.query(sql))[0]?.guild;

// Add reactions
if (canSteal) await msg.addReaction(p.config.emoji.steal);
const components = await p.global.getStealButton(p, true);
const content = {
embed,
components,
};
let msg = await p.send(content);

// Create reaction collector
let filter = (emoji, userId) => emoji.name == p.config.emoji.steal && userId != p.client.user.id;
const collector = p.reactionCollector.create(msg, filter, { idle: 120000 });
// Create interaction collector
let filter = (componentName) => componentName === 'steal';
let collector = p.interactionCollector.create(msg, filter, { idle: 120000 });
const emojiAdder = new p.EmojiAdder(p, { name: emojiName, url });

collector.on('collect', async function (emoji, userId) {
collector.on('collect', async (component, user, ack) => {
try {
if (await emojiAdder.addEmoji(userId)) {
await msg.edit({
embed: createEmbed(p, url, name, emojiName, emojiAdder),
});
if (await emojiAdder.addEmoji(user.id)) {
(content.embed = createEmbed(p, url, name, emojiName, emojiAdder)), ack(content);
}
} catch (err) {
if (!emojiAdder.successCount) {
await msg.edit({
embed: createEmbed(p, url, name, emojiName, emojiAdder),
});
(content.embed = createEmbed(p, url, name, emojiName, emojiAdder)), ack(content);
}
}
});

collector.on('end', async function (_collected) {
const embed = createEmbed(p, url, name, emojiName, emojiAdder);
embed.color = 6381923;
await msg.edit({ content: 'This message is now inactive', embed });
content.embed = createEmbed(p, url, name, emojiName, emojiAdder);
content.embed.color = 6381923;
content.content = 'This message is now inactive';
content.components[0].components[0].disabled = true;
await msg.edit(content);
});
}

Expand Down
97 changes: 66 additions & 31 deletions src/commands/commandList/memegen/waddle.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* Copyright (C) 2024 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

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

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

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

group: ['memegeneration'],

appCommands: [
commandGroups.addOption('waddle', ['gen'], {
'name': 'waddle',
'description': 'Generate a waddle emoji',
'type': 2,
'options': [
{
'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',
'description': 'The emoji to use',
'type': 3,
'required': true,
},
],
},
],
}),
],

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

execute: async function (p) {
let user = p.getMention(p.args[0]);
let user = p.getMention(p.args[0]) || p.options.user;
let link;
let name;
if (user) {
link = user.dynamicAvatarURL('png', 128);
name = user.username;
} else if (!user && !p.args.length) {
link = p.msg.author.dynamicAvatarURL('png', 128);
name = p.getName();
} else if (!user && p.global.isEmoji(p.args[0])) {
link = p.args[0].match(/:[0-9]+>/gi)[0];
} else if (p.global.isEmoji(p.args[0] || p.options.emoji)) {
const emoji = p.args[0] || p.options.emoji;
link = emoji.match(/:[0-9]+>/gi)[0];
link = `https://cdn.discordapp.com/emojis/${link.slice(1, link.length - 1)}.png`;
name = p.args[0].match(/:[\w]+:/gi)[0];
name = emoji.match(/:[\w]+:/gi)[0];
name = name.slice(1, name.length - 1);
} else if (!p.args.length) {
link = p.msg.author.dynamicAvatarURL('png', 128);
name = p.getName();
} else {
p.errorMsg(', invalid arguments! Please tag a user or add an emoji!', 3000);
p.setCooldown(5);
Expand All @@ -65,41 +105,36 @@ module.exports = new CommandInterface({
async function display(p, url, name) {
const emojiName = `${name.replace(/[^\w]/gi, '')}_waddle`;
let embed = createEmbed(p, url, name, emojiName);
let msg = await p.send({ embed });

// Check if user set stealing
let sql = `SELECT emoji_steal.guild FROM emoji_steal INNER JOIN user ON emoji_steal.uid = user.uid WHERE id = ${p.msg.author.id};`;
await p.query(sql);
let canSteal = (await p.query(sql))[0]?.guild;

// Add reactions
if (canSteal) await msg.addReaction(p.config.emoji.steal);
const components = await p.global.getStealButton(p, true);
const content = {
embed,
components,
};
let msg = await p.send(content);

// Create reaction collector
let filter = (emoji, userId) => emoji.name == p.config.emoji.steal && userId != p.client.user.id;
const collector = p.reactionCollector.create(msg, filter, { idle: 120000 });
// Create interaction collector
let filter = (componentName) => componentName === 'steal';
let collector = p.interactionCollector.create(msg, filter, { idle: 120000 });
const emojiAdder = new p.EmojiAdder(p, { name: emojiName, url });

collector.on('collect', async function (emoji, userId) {
collector.on('collect', async (component, user, ack) => {
try {
if (await emojiAdder.addEmoji(userId)) {
await msg.edit({
embed: createEmbed(p, url, name, emojiName, emojiAdder),
});
if (await emojiAdder.addEmoji(user.id)) {
(content.embed = createEmbed(p, url, name, emojiName, emojiAdder)), ack(content);
}
} catch (err) {
if (!emojiAdder.successCount) {
await msg.edit({
embed: createEmbed(p, url, name, emojiName, emojiAdder),
});
(content.embed = createEmbed(p, url, name, emojiName, emojiAdder)), ack(content);
}
}
});

collector.on('end', async function (_collected) {
const embed = createEmbed(p, url, name, emojiName, emojiAdder);
embed.color = 6381923;
await msg.edit({ content: 'This message is now inactive', embed });
content.embed = createEmbed(p, url, name, emojiName, emojiAdder);
content.embed.color = 6381923;
content.content = 'This message is now inactive';
content.components[0].components[0].disabled = true;
await msg.edit(content);
});
}

Expand Down
Loading

0 comments on commit f82bf6b

Please sign in to comment.