Skip to content

Commit

Permalink
try badge
Browse files Browse the repository at this point in the history
  • Loading branch information
LarmuseauNiels committed Apr 26, 2023
1 parent 50e8f43 commit 42aa042
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Binary file added achievementIcons/achievement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions islander/AchievementsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,17 @@ export class AchievementsModule {
console.log(guildMember);

const rank = new Rank()
.setUsername(guildMember.username)
.setAvatar(guildMember.avatarURL())
.setCurrentXP(this.getCurrentLevelXp(member.XP))
.setRequiredXP(this.getRequiredXp(this.getLevel(member.XP)))
.setRank(1, "RANK", false)
.setLevel(this.getLevel(member.XP), "LEVEL", true)
.setStatus("online")
.setProgressBar(["#FF0000", "#FF0000"], "GRADIENT")
.setUsername(guildMember.username);
.setCustomStatusColor("#00FF00")
.setProgressBar(["#00FF00", "#00FF00"], "COLOR")
.setBackground("COLOR", "#2b2f35")
.setOverlay("#2b2f35", 0.4)
.setProgressBarTrack("#2b2f35");

const data = await rank.build();
return new AttachmentBuilder(data, {
Expand Down
24 changes: 21 additions & 3 deletions islander/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const abbrev = (num) => {
var size = Math.pow(10, (i + 1) * 3);
if (size <= num) {
num = Math.round((num * decPlaces) / size) / decPlaces;
if (num == 1000 && i < abbrev.length - 1) {
if (num === 1000 && i < abbrev.length - 1) {
num = 1;
i++;
}
Expand Down Expand Up @@ -147,8 +147,7 @@ const Util = class Util {
return (arr + txt).slice(-length);
};

const finalHex = `#${pad(r)}${pad(g)}${pad(b)}`;
return finalHex;
return `#${pad(r)}${pad(g)}${pad(b)}`;
}

/**
Expand Down Expand Up @@ -358,6 +357,11 @@ export default class Rank {
data: 0,
color: "#FFFFFF",
},
achievementToRender: [
{
imagePath: "achievementIcons/achievement.png",
},
],
};

// Load default fonts
Expand Down Expand Up @@ -417,6 +421,11 @@ export default class Rank {
return this;
}

setAchievements(achievements = []) {
this.data.achievementToRender = achievements;
return this;
}

/**
* Set discriminator
* param {string|number} discriminator User discriminator
Expand Down Expand Up @@ -773,6 +782,15 @@ export default class Rank {
: // @ts-ignore
await Util.renderEmoji(ctx, name, 257 + 18.5, 82);

let achievementXlocation = 264;
//draw achievements
for (const achievement of this.data.achievementToRender) {
//const index = this.data.achievementsToRender.indexOf(achievement);
let badge = await Canvas.loadImage(achievement.imagePath);
ctx.drawImage(badge, achievementXlocation, 164, 64, 64);
achievementXlocation += 64;
}

// draw discriminator
/*
if (!this.data.discriminator.discrim)
Expand Down

0 comments on commit 42aa042

Please sign in to comment.