Skip to content

Commit

Permalink
(REWRITE): Now all code is more readable :P
Browse files Browse the repository at this point in the history
  • Loading branch information
iseizuu committed Oct 31, 2020
1 parent 03ed8fc commit 1a6aaad
Show file tree
Hide file tree
Showing 42 changed files with 2,420 additions and 2,398 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
},
"rules": {
"//": "The no-console rule is only for development purposes",
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": "error",
"comma-style": "error",
"curly": ["error", "multi-line", "consistent"],
"semi": ["error", "always"],
"indent": ["error", 4],
"quotes": ["error", "single"],
"space-before-function-paren": "off",
"no-console": "off",
"no-useless-escape": "off",
"no-inner-declarations": "off"
Expand Down
169 changes: 85 additions & 84 deletions commands/fun/friendship.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,90 +8,91 @@ registerFont(path.join(__dirname, '..', '..', 'assets', 'font', 'Pinky Cupid.otf


module.exports = class FriendshipCommand extends Command {
constructor(client) {
super(client, {
name: 'friendship',
aliases: ['friendship-meter', 'friends', 'friend', 'friendship-tester', 'friendship-test', 'fs'],
group: 'fun',
memberName: 'friendship',
description: 'Determines how good friends two users are.',
hidden: false,
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'first',
label: 'first user',
prompt: 'Who is the first friend?',
type: 'user'
},
{
key: 'second',
label: 'second user',
prompt: 'Who is the second friend?',
type: 'user',
default: msg => msg.author
}
]
});
}
constructor(client) {
super(client, {
name: 'friendship',
aliases: ['friendship-meter', 'friends', 'friend', 'friendship-tester', 'friendship-test', 'fs'],
group: 'fun',
memberName: 'friendship',
description: 'Determines how good friends two users are.',
hidden: false,
throttling: {
usages: 1,
duration: 10,
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'first',
label: 'first user',
prompt: 'Who is the first friend?',
type: 'user',
},
{
key: 'second',
label: 'second user',
prompt: 'Who is the second friend?',
type: 'user',
default: msg => msg.author,
},
],
});
}

async run(msg, { first, second }) {
if (first.id === second.id) return msg.reply('You should be good friends with yourself.');
const calculated = -Math.abs(Number.parseInt(BigInt(first.id) - BigInt(second.id), 10));
const random = MersenneTwister19937.seed(calculated);
const level = integer(0, 100)(random);
const firstAvatarURL = first.displayAvatarURL({ format: 'png', size: 512 });
const secondAvatarURL = second.displayAvatarURL({ format: 'png', size: 512 });
try {
const firstAvatarData = await request.get(firstAvatarURL);
const firstAvatar = await loadImage(firstAvatarData.body);
const secondAvatarData = await request.get(secondAvatarURL);
const secondAvatar = await loadImage(secondAvatarData.body);
const base = await loadImage('https://cdn.discordapp.com/attachments/688763072864976906/706512440690606181/friendship1.png');
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(firstAvatar, 70, 56, 400, 400);
ctx.drawImage(secondAvatar, 730, 56, 400, 400);
ctx.drawImage(base, 0, 0);
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillStyle = '#40e9ff';
ctx.font = '38px Pinky Cupid';
ctx.fillStyle = 'white';
ctx.fillText(first.username, 270, 448);
ctx.fillText(second.username, 930, 448);
ctx.font = '42px Pinky Cupid';
ctx.fillStyle = '#1ebefc';
ctx.fillText(`~${level}%~`, 600, 230);
ctx.fillText(this.calculateLevelText(level), 600, 296);
ctx.font = '90px Pinky Cupid';
ctx.fillText(level > 49 ? '😁' : '😣', 600, 100);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'friendship.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async run(msg, { first, second }) {
if (first.id === second.id) return msg.reply('You should be good friends with yourself.');
const calculated = -Math.abs(Number.parseInt(BigInt(first.id) - BigInt(second.id), 10));
const random = MersenneTwister19937.seed(calculated);
const level = integer(0, 100)(random);
const firstAvatarURL = first.displayAvatarURL({ format: 'png', size: 512 });
const secondAvatarURL = second.displayAvatarURL({ format: 'png', size: 512 });
try {
const firstAvatarData = await request.get(firstAvatarURL);
const firstAvatar = await loadImage(firstAvatarData.body);
const secondAvatarData = await request.get(secondAvatarURL);
const secondAvatar = await loadImage(secondAvatarData.body);
const base = await loadImage('https://cdn.discordapp.com/attachments/688763072864976906/706512440690606181/friendship1.png');
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(firstAvatar, 70, 56, 400, 400);
ctx.drawImage(secondAvatar, 730, 56, 400, 400);
ctx.drawImage(base, 0, 0);
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillStyle = '#40e9ff';
ctx.font = '38px Pinky Cupid';
ctx.fillStyle = 'white';
ctx.fillText(first.username, 270, 448);
ctx.fillText(second.username, 930, 448);
ctx.font = '42px Pinky Cupid';
ctx.fillStyle = '#1ebefc';
ctx.fillText(`~${level}%~`, 600, 230);
ctx.fillText(this.calculateLevelText(level), 600, 296);
ctx.font = '90px Pinky Cupid';
ctx.fillText(level > 49 ? '😁' : '😣', 600, 100);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'friendship.png' }] });
}
catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}

calculateLevelText(level) {
if (level === 0) return 'Abysmal';
if (level > 0 && level < 10) return 'Horrid';
if (level > 9 && level < 20) return 'Awful';
if (level > 19 && level < 30) return 'Very Bad';
if (level > 29 && level < 40) return 'Bad';
if (level > 39 && level < 50) return 'Poor';
if (level > 49 && level < 60) return 'Average';
if (level > 59 && level < 70) {
if (level === 69) return 'Nice';
return 'Fine';
}
if (level > 69 && level < 80) return 'Good';
if (level > 79 && level < 90) return 'Great';
if (level > 89 && level < 100) return 'Amazing';
if (level === 100) return 'Besties';
return '???';
}
calculateLevelText(level) {
if (level === 0) return 'Abysmal';
if (level > 0 && level < 10) return 'Horrid';
if (level > 9 && level < 20) return 'Awful';
if (level > 19 && level < 30) return 'Very Bad';
if (level > 29 && level < 40) return 'Bad';
if (level > 39 && level < 50) return 'Poor';
if (level > 49 && level < 60) return 'Average';
if (level > 59 && level < 70) {
if (level === 69) return 'Nice';
return 'Fine';
}
if (level > 69 && level < 80) return 'Good';
if (level > 79 && level < 90) return 'Great';
if (level > 89 && level < 100) return 'Amazing';
if (level === 100) return 'Besties';
return '???';
}
};
66 changes: 33 additions & 33 deletions commands/fun/meme.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@ const { list, formatNumber } = require('../../util/Util');
const subreddits = require('../../assets/json/meme');

module.exports = class MemeCommand extends SubredditCommand {
constructor(client) {
super(client, {
name: 'meme',
group: 'fun',
memberName: 'meme',
description: 'Responds with a random meme.',
details: `**Subreddits:** ${subreddits.join(', ')}`,
clientPermissions: ['ATTACH_FILES'],
postType: 'image',
hidden: false,
getIcon: true,
args: [
{
key: 'subreddit',
prompt: `What subreddit do you want to get memes from? Either ${list(subreddits, 'or')}.`,
type: 'string',
oneOf: subreddits,
default: () => subreddits[Math.floor(Math.random() * subreddits.length)],
parse: subreddit => subreddit.toLowerCase()
}
]
});
}
constructor(client) {
super(client, {
name: 'meme',
group: 'fun',
memberName: 'meme',
description: 'Responds with a random meme.',
details: `**Subreddits:** ${subreddits.join(', ')}`,
clientPermissions: ['ATTACH_FILES'],
postType: 'image',
hidden: false,
getIcon: true,
args: [
{
key: 'subreddit',
prompt: `What subreddit do you want to get memes from? Either ${list(subreddits, 'or')}.`,
type: 'string',
oneOf: subreddits,
default: () => subreddits[Math.floor(Math.random() * subreddits.length)],
parse: subreddit => subreddit.toLowerCase(),
},
],
});
}

generateText(post, subreddit, icon) {
return new MessageEmbed()
.setColor('#cce7e8')
.setAuthor(`r/${subreddit}`, icon, `https://www.reddit.com/r/${subreddit}/`)
.setTitle(post.title)
.setImage(post.post_hint === 'image' ? post.url : null)
.setURL(`https://www.reddit.com${post.permalink}`)
.setTimestamp(post.created_utc * 1000)
.setFooter(`⬆ ${formatNumber(post.ups)}`);
}
generateText(post, subreddit, icon) {
return new MessageEmbed()
.setColor('#cce7e8')
.setAuthor(`r/${subreddit}`, icon, `https://www.reddit.com/r/${subreddit}/`)
.setTitle(post.title)
.setImage(post.post_hint === 'image' ? post.url : null)
.setURL(`https://www.reddit.com${post.permalink}`)
.setTimestamp(post.created_utc * 1000)
.setFooter(`⬆ ${formatNumber(post.ups)}`);
}
};
103 changes: 52 additions & 51 deletions commands/fun/triggered.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,57 @@ const coord1 = [-25, -33, -42, -14];
const coord2 = [-25, -13, -34, -10];

module.exports = class TriggeredCommand extends Command {
constructor(client) {
super(client, {
name: 'triggered',
aliases: ['trigger'],
group: 'fun',
memberName: 'triggered',
description: 'Draws a user\'s avatar over the "Triggered" meme.',
hidden: false,
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'user',
prompt: 'Which user would you like to edit the avatar of?',
type: 'user',
default: msg => msg.author
}
]
});
}
constructor(client) {
super(client, {
name: 'triggered',
aliases: ['trigger'],
group: 'fun',
memberName: 'triggered',
description: 'Draws a user\'s avatar over the "Triggered" meme.',
hidden: false,
throttling: {
usages: 1,
duration: 10,
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'user',
prompt: 'Which user would you like to edit the avatar of?',
type: 'user',
default: msg => msg.author,
},
],
});
}

async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 2048 });
try {
const base = await loadImage('https://cdn.discordapp.com/attachments/688763072864976906/702119398638354482/triggered.png');
const { body } = await request.get(avatarURL);
const avatar = await loadImage(body);
const encoder = new GIFEncoder(base.width, base.width);
const canvas = createCanvas(base.width, base.width);
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, base.width, base.width);
const stream = encoder.createReadStream();
encoder.start();
encoder.setRepeat(0);
encoder.setDelay(50);
encoder.setQuality(200);
for (let i = 0; i < 4; i++) {
drawImageWithTint(ctx, avatar, 'red', coord1[i], coord2[i], 300, 300);
drawImageWithTint(ctx, base, coord1[i], coord2[i], 216, 290, 40, 50);
encoder.addFrame(ctx);
}
encoder.finish();
const buffer = await streamToArray(stream);
return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'triggered.gif' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async run(msg, { user }) {
const avatarURL = user.displayAvatarURL({ format: 'png', size: 2048 });
try {
const base = await loadImage('https://cdn.discordapp.com/attachments/688763072864976906/702119398638354482/triggered.png');
const { body } = await request.get(avatarURL);
const avatar = await loadImage(body);
const encoder = new GIFEncoder(base.width, base.width);
const canvas = createCanvas(base.width, base.width);
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, base.width, base.width);
const stream = encoder.createReadStream();
encoder.start();
encoder.setRepeat(0);
encoder.setDelay(50);
encoder.setQuality(200);
for (let i = 0; i < 4; i++) {
drawImageWithTint(ctx, avatar, 'red', coord1[i], coord2[i], 300, 300);
drawImageWithTint(ctx, base, coord1[i], coord2[i], 216, 290, 40, 50);
encoder.addFrame(ctx);
}
encoder.finish();
const buffer = await streamToArray(stream);
return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'triggered.gif' }] });
}
catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
Loading

0 comments on commit 1a6aaad

Please sign in to comment.