Skip to content

Commit

Permalink
3.0.1 bugfixes + profile colours
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon1320 committed Nov 8, 2018
1 parent 8564186 commit 6dff649
Show file tree
Hide file tree
Showing 11 changed files with 23,758 additions and 230 deletions.
4 changes: 4 additions & 0 deletions src/bot/commands/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ const xp = new Command({
}
}

leaderboard.sort((a, b) => {
return b.user.xp - a.user.xp;
});

const embed = new discord.RichEmbed();
embed.setAuthor("AWESOM-O // Xp - Guild Top 5", "https://cdn.discordapp.com/avatars/379370506933108746/a979694bf250f2293d929278328b707c.png");
embed.setColor(0xff594f);
Expand Down
17,411 changes: 17,304 additions & 107 deletions src/bot/commands/assets/fonts/fontAbout.fnt

Large diffs are not rendered by default.

Binary file modified src/bot/commands/assets/fonts/fontAbout.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6,355 changes: 6,248 additions & 107 deletions src/bot/commands/assets/fonts/fontName.fnt

Large diffs are not rendered by default.

Binary file modified src/bot/commands/assets/fonts/fontName.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions src/bot/commands/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,21 @@ const binding = new Command({

schemas.ScriptSchema
.find({
name, created_with: "script_bindings"
name,
created_with: "script_bindings"
})
.then(scripts => {
if (scripts.length === 0) {

return message.reply(`script '${name}' not found`);
}

scripts = scripts.filter(e => e.author_id === message.author.id);
if (scripts.length === 0) {

return message.reply(`script '${name}' does not belong to you`);
}

schemas.GuildSchema
.findOne({
discord_id: message.guild.id
Expand All @@ -218,7 +225,7 @@ const binding = new Command({
}
}

if (found = false) {
if (found === false) {

return message.reply(`script not found in current guild`);
}
Expand Down
177 changes: 169 additions & 8 deletions src/bot/commands/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,72 @@ const getLevelData = xp => {
};
}

const colourPrint = (src, font, x, y, str, colour, mix = "100") => {

const text = new jimp(textWidth(font, str), font.common.lineHeight);

text.print(font, 0, 0, str);
text.color([
{ apply: "mix", params: [colour, mix] }
]);

src.composite(text, x, y);
}

const colourText = (font, str, colour, mix = "100") => {

const text = new jimp(textWidth(font, str), font.common.lineHeight);

text.print(font, 0, 0, str);
text.color([
{ apply: "mix", params: [colour, mix] }
]);

return text;
}

const plainText = (font, str) => {

const text = new jimp(textWidth(font, str), font.common.lineHeight);

text.print(font, 0, 0, str);

return text;
}

const colourDistance = (c1, c2) => Math.sqrt(Math.pow(c1.r - c2.r, 2) + Math.pow(c1.g - c2.g, 2) + Math.pow(c1.b - c2.b, 2) + Math.pow(c1.a - c2.a, 2));

const magicRecolour = (src, targetColour, replaceColour, threshold) => {

src.scan(0, 0, src.bitmap.width, src.bitmap.height, (x, y, idx) => {

const thisColour = {

r: src.bitmap.data[idx + 0],
g: src.bitmap.data[idx + 1],
b: src.bitmap.data[idx + 2],
a: src.bitmap.data[idx + 3]
};

if (colourDistance(targetColour, thisColour) <= threshold) {

src.bitmap.data[idx + 0] = replaceColour.r;
src.bitmap.data[idx + 1] = replaceColour.g;
src.bitmap.data[idx + 2] = replaceColour.b;
src.bitmap.data[idx + 3] = replaceColour.a;
}
});
}

function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}

const levels = new Command({

name: "AWESOM-O Profiles",
Expand Down Expand Up @@ -128,6 +194,7 @@ const levels = new Command({
bio: "$bio",
trophies: "$trophies",
verified: "$verified",
colours: "$colours",
xp: "$xp"
}
},
Expand Down Expand Up @@ -155,6 +222,7 @@ const levels = new Command({
bio: "$arr.bio",
trophies: "$arr.trophies",
verified: "$arr.verified",
colours: "$arr.colours",
xp: "$arr.xp",
globalRank: "$globalRank",
globalTotal: "$globalTotal"
Expand All @@ -167,37 +235,102 @@ const levels = new Command({
return message.reply("this user does not have a profile");
}

// colours
const defaultColour = "#14b252";
const defaultNameColour = "#ffffff";

if (users[0].colours === undefined || users[0].colours === null) {

users[0].colours = {};
}

if (users[0].colours.progress === undefined || users[0].colours.progress === null) {

users[0].colours.progress = defaultColour;
}

if (users[0].colours.level === undefined || users[0].colours.level === null) {

users[0].colours.level = defaultColour;
}

if (users[0].colours.rank === undefined || users[0].colours.rank === null) {

users[0].colours.rank = defaultColour;
}

if (users[0].colours.name === undefined || users[0].colours.name === null) {

users[0].colours.name = defaultNameColour;
}

const colours = {};

for (let colour in users[0].colours) {

const rgb = hexToRgb(users[0].colours[colour]);

colours[colour] = {
hex: users[0].colours[colour],
rgb
};
}
//

const bg = new jimp(800, 750);

const banner = await jimp.read(users[0].banner);
let banner = await jimp.read(users[0].banner);
//let banner = await jimp.read("https://cdn.discordapp.com/attachments/449655476297138177/502508170019864586/tweekxcraig.png");
if (banner === undefined) {

banner = defaultBanner;
}

const prop = (banner.bitmap.width / banner.bitmap.height) * (bg.bitmap.width / bg.bitmap.height);
if (prop >= 1) {
const prop = banner.bitmap.width / banner.bitmap.height;
if (prop >= (bg.bitmap.width) / bg.bitmap.height) {

// change height
const heightDiff = bg.bitmap.height - banner.bitmap.height;
banner.resize(banner.bitmap.width + (heightDiff * prop), banner.bitmap.height + heightDiff);

banner.crop((banner.bitmap.width / 2) - bg.bitmap.width / 2, 0, bg.bitmap.width, bg.bitmap.height);
banner.blur(2);

bg.composite(banner, 0, 0);

/*
const heightDiff = bg.bitmap.height - banner.bitmap.height;
banner.resize((banner.bitmap.height + heightDiff) * prop, banner.bitmap.height + heightDiff);
banner.resize(banner.bitmap.height * prop, banner.bitmap.height + heightDiff);
// 750x750 (375 - 400, 0, 800, 750)
banner.crop((banner.bitmap.width / 2) - bg.bitmap.width / 2, 0, bg.bitmap.width, bg.bitmap.height);
banner.blur(2);
bg.composite(banner, 0, 0);
bg.composite(banner, 0, 0)
*/
} else {

// change width
const widthDiff = bg.bitmap.width - banner.bitmap.width;
banner.resize(banner.bitmap.width + widthDiff, banner.bitmap.height + (widthDiff * prop));

banner.crop((banner.bitmap.width / 2) - bg.bitmap.width / 2, 0, bg.bitmap.width, bg.bitmap.height);
banner.blur(2);

bg.composite(banner, 0, 0);

/*
const diffWidth = bg.bitmap.width - banner.bitmap.width;
banner.resize(banner.bitmap.width + diffWidth, (banner.bitmap.width + diffWidth) / prop);
banner.crop(0, (banner.bitmap.height / 2) - bg.bitmap.height / 2, bg.bitmap.width, bg.bitmap.height);
banner.blur(2);
bg.composite(banner, 0, 0);
*/
}

bg.composite(infoCardBase, 0, 0);
Expand All @@ -207,11 +340,14 @@ const levels = new Command({
// 398 148 723 187
const progress = new jimp(Math.floor(325 * levelData.progress), 39);
progress.opaque();
/*
progress.color([
{ apply: "red", params: [20] },
{ apply: "green", params: [178] },
{ apply: "blue", params: [82] }
]);
*/
magicRecolour(progress, { r: 0, g: 0, b: 0, a: 255 }, { r: colours.progress.rgb.r, g: colours.progress.rgb.g, b: colours.progress.rgb.b, a: 255 }, 160);

bg.composite(progress, 398, 148);

Expand All @@ -222,9 +358,34 @@ const levels = new Command({
avatar.resize(296, 296);
bg.composite(avatar, 16, 19);

printCenter(bg, fontLevel, 163, 35, `Level ${levelData.level}`, 800);
printCenter(bg, fontRank, 165, 195, `#${users[0].globalRank + 1}/${users[0].globalTotal}`, 800);
bg.print(fontName, 12, 316, searchUser.username);
//printCenter(bg, fontLevel, 163, 35, `Level ${levelData.level}`, 800);
const levelText = plainText(fontLevel, `Level ${levelData.level}`);
magicRecolour(levelText, { r: 20, g: 178, b: 82, a: 255 }, { r: colours.level.rgb.r, g: colours.level.rgb.g, b: colours.level.rgb.b, a: 255 }, 160);
bg.composite(levelText, (bg.bitmap.width / 2) - (levelText.bitmap.width / 2) + 173, 40);

//printCenter(bg, fontRank, 165, 195, `#${users[0].globalRank + 1}/${users[0].globalTotal}`, 800);
const rankText = plainText(fontRank, `#${users[0].globalRank + 1}/${users[0].globalTotal}`);
magicRecolour(rankText, { r: 20, g: 178, b: 82, a: 255 }, { r: colours.rank.rgb.r, g: colours.rank.rgb.g, b: colours.rank.rgb.b, a: 255 }, 160);
bg.composite(rankText, (bg.bitmap.width / 2) - (rankText.bitmap.width / 2) + 165, 200);

/* temp
const nameRecolour = new jimp(textWidth(fontName, searchUser.username), 84);
nameRecolour.print(fontName, 0, 0, searchUser.username);
nameRecolour.color([
{ apply: "mix", params: ["#ff594f", 100] }
]);
bg.composite(nameRecolour, 12, 316);
*/

//colourPrint(bg, fontName, 15, 321, searchUser.username, "#000000");

const shadowText = plainText(fontName, searchUser.username);
magicRecolour(shadowText, { r: 255, g: 255, b: 255, a: 255 }, { a: 0, g: 0, b: 0, a: 160 }, 256);
bg.composite(shadowText, 15, 321);

colourPrint(bg, fontName, 12, 316, searchUser.username, colours.name.hex);

//bg.print(fontName, 12, 316, searchUser.username);

if (users[0].verified === true) {

Expand All @@ -246,7 +407,7 @@ const levels = new Command({
changed = true;
}

bg.print(fontAbout, 24, 472, changed === true ? `${modifiedAbout}...` : modifiedAbout, 360);
bg.print(fontAbout, 24, 472, changed === true ? `${modifiedAbout}...` : modifiedAbout, 290);

// trophies
const userTrophies = [];
Expand Down
10 changes: 9 additions & 1 deletion src/bot/commands/libs/jimp_print.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ const textWidth = (font, str) => {
let width = 0;

for (let i = 0; i < str.length; i++) {
width += font.chars[str[i]].xoffset + font.chars[str[i]].xadvance;

if (font.chars[str[i]] === undefined) {

width += 0;

} else {

width += font.chars[str[i]].xoffset + font.chars[str[i]].xadvance;
}
}

return width;
Expand Down
4 changes: 4 additions & 0 deletions src/bot/commands/shits.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ const shits = new Command({
}
}

leaderboard.sort((a, b) => {
return b.user.shits - a.user.shits;
});

const embed = new discord.RichEmbed();
embed.setAuthor("AWESOM-O // Shits - Guild Top 5", "https://cdn.discordapp.com/avatars/379370506933108746/a979694bf250f2293d929278328b707c.png");
embed.setColor(0xff594f);
Expand Down
11 changes: 11 additions & 0 deletions src/db/schemas/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ const moduleSchema = new Schema({
_id: false
});

const colourSchema = new Schema({

progress: { type: String, default: "#42f4e5" },
level: { type: String, default: "#42f4e5" },
rank: { type: String, default: "#42f4e5" },
name: { type: String, default: "#42f4e5" }
}, {
_id: false
});

const UserSchema = new Schema({

// Id generated by mongo, this is here so I remember it exists.
Expand All @@ -33,6 +43,7 @@ const UserSchema = new Schema({
bio: { type: String, default: "This person is very mysterious." },
socials: [ socialSchema ],
modules: [ moduleSchema ],
colours: colourSchema,

admin: { type: Boolean, default: false },
verified: { type: Boolean, default: false },
Expand Down
5 changes: 0 additions & 5 deletions src/utils/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const textWidth = (font, str) => {

for (let i = 0; i < str.length; i++) {

if (font.chars[str[i]] === undefined) {

str[i] = "*";
}

width += font.chars[str[i]].xoffset + font.chars[str[i]].xadvance;
}

Expand Down

0 comments on commit 6dff649

Please sign in to comment.