Skip to content

Commit

Permalink
Rpg changes (#708)
Browse files Browse the repository at this point in the history
* many changes

Added /message
Added roleAudits for donor colours in onboarding
Added typing status to /say

* Team Mindset Roles BETA

It works, but is kinda slow sometimes, probably some inefficient looping

* Update tents to use new voice category

Tents are now in their own category

* I forgot 2 roles

I am silly

* Important Fixes

Make AFK channel immune to deletion
Make TTS role count as donor for donor colours

* Add "Busy" role to TTS mindsets

* Update futon ID

Silly bot keeps deleting it

* Change how deleting tents works

Changed from checking explicit IDs to not delete to simply checking if a voice channel includes a tent emoji or not

* Add bot typing status to announcements

* Fix TTS access to donor colours

* Make typing status 3 seconds

* Small fixes / updates

Add 'busy' role to TTS mindsets
Make tripbot typing 3 seconds instead of 1.5
Add typing to announcements
Change how tent deletion works
Update IDs in env

* Merge and lint

* Update tents permission overwrites

* belly button linting

* Bug in knex

* Add /voice radio

First pass, needs work and add function of changing the tent name to signify the bot is being borrowed

* Add /voice bitrate

Allows editing of bitrate

* Lint that shit

* One more lint

* Finish up

* Possible /voice radio fix

No way to test in dev. Incorporated what was originally a separate function (checking if there is already a radio bot in the channel before moving a new one in), into the same part of the code that checks if the radio is available and pulls it in

* Make "user" entry for /timezone and /birthday required to speed up command entry

* Trivia, small fixes

Re-enabled Trivia
Stopped Verified role from being removed during tripsit session (stops welcome messages)
Added code for /voice add (disabled)
Removed /voice radio (just way too buggy)
Small edit to welcome message

* Undo required

* Linting

* Fixing actions

* New donator system

Becoming a patron sub now also gives the "Premium Member" role. This new role is what activates all the donator benefits. Supporter role now only acts as a cosmetic with as a hoisted role with gem icon.

Premium Member is permanent for Patreon or Kofi donations. Booster is unchanged and all donator perks for boosters is removed once they stop boosting.

* Update env.config.ts

* Add kofi link

* Ignore donor roles in tripsit mode

To prevent duplicate donation announcement messages

* Update d.donate and a few minor things

* Add premium role add

* Add 4 new backgrounds, remove multipliers

* Add premium and legacy icon to /profile and /levels

* Oops

* Better implementation

* Better implementation v2

* Update background URLs

* lint that belly button

* Commit of shame

* Incredible new icon slot system + medal colours

Future proof icon system, and added gold, silver and bronze colouring to top ranks in /levels

* [EXPERIMENTAL] Donation trigger system

Can differentiate between all types of donations and act accordingly.

* Making /levels actually modular

* Remove debug

* VoiceXP in levels fix & Basic code for flairs (inactive)

* Make total rank use actual total, not just text total

* /profile Pixel peep positioning fix

* Made /profile icons more intuitive

* Rooni needs to lint =P

* Update env.config with trigger role

* Fix for voice xp bar appearing even if level 0

* Big triptown backgrounds update + level icon fixes

A wonderful day

* Add link to background images to view easier

* Even more backgrounds

* Add Unequip and Sell options to rpgHome, and better button logic

* Linting =P

* Revert "Merge branch 'main' into hipperooni-branch"

This reverts commit 0c9adb1, reversing
changes made to e9e0716.

* WIP: TripTown additions

Purchasable fonts
Made the "preview" button image the default image for items
Added a discount system for boosters and donators
Added a inventory limit to prevent inaccessible items due to string menu limits

* One more sync

* One more sync

* Update imageGet to getAsset

* Final rpg edits for rpg update

Added spaces to item names
Removed "Page" wording in market for improved readability

---------

Co-authored-by: Hipperooni <[email protected]>
  • Loading branch information
LunaUrsa and Hipperooni authored Nov 17, 2023
1 parent b154369 commit 0641609
Show file tree
Hide file tree
Showing 6 changed files with 573 additions and 177 deletions.
6 changes: 3 additions & 3 deletions src/discord/commands/global/d.mushroom_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SlashCommand } from '../../@types/commandDef';
import { embedTemplate } from '../../utils/embedTemplate';
// import mushroomInfo from '../../../global/commands/g.mushroomInfo';
import commandContext from '../../utils/context';
import { imageGet } from '../../utils/imageGet';
import getAsset from '../../utils/getAsset';

const F = f(__filename);

Expand All @@ -28,7 +28,7 @@ async function mushroomPageOneEmbed() {
For more information check out [the source](${source}) and [this article](${article}).`)
.setImage('attachment://mushroomInfoA.png')],
files: [new AttachmentBuilder(await imageGet('mushroomInfoA'))],
files: [new AttachmentBuilder(await getAsset('mushroomInfoA'))],

components: [new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
Expand All @@ -48,7 +48,7 @@ async function mushroomPageTwoEmbed() {
For more information check out [the source](${source}) and [this article](${article}).`)
.setImage('attachment://mushroomInfoB.png')],
files: [new AttachmentBuilder(await imageGet('mushroomInfoB'))],
files: [new AttachmentBuilder(await getAsset('mushroomInfoB'))],

components: [new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
Expand Down
44 changes: 23 additions & 21 deletions src/discord/commands/guild/d.levels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ import { levels } from '../../../global/commands/g.levels';
import { profile, ProfileData } from '../../../global/commands/g.profile';
import { getPersonaInfo } from '../../../global/commands/g.rpg';
import { inventoryGet } from '../../../global/utils/knex';
import { imageGet } from '../../utils/imageGet';
import getAsset from '../../utils/getAsset';
import commandContext from '../../utils/context';
import { numFormatter, numFormatterVoice } from './d.profile';
import { Personas } from '../../../global/@types/database';
// import { expForNextLevel, getTotalLevel } from '../../../global/utils/experience';
// import { inventoryGet } from '../../../global/utils/knex';
// import { imageGet } from '../../utils/imageGet';

// import { getTotalLevel } from '../../../global/utils/experience';

const F = f(__filename);

Expand Down Expand Up @@ -240,16 +235,16 @@ export const dLevels: SlashCommand = {
// Get the levels of the user
await levels(target.id),
// Load Images
await Canvas.loadImage(await imageGet('cardLevelIcons')),
await Canvas.loadImage(await getAsset('cardLevelIcons')),
await Canvas.loadImage(target.user.displayAvatarURL({ extension: 'jpg' })),
await Canvas.loadImage(await imageGet('teamtripsitIcon')),
await Canvas.loadImage(await imageGet('premiumIcon')),
await Canvas.loadImage(await imageGet('boosterIcon')),
await Canvas.loadImage(await imageGet('legacyIcon')),
await Canvas.loadImage(await imageGet('voiceBar')),
await Canvas.loadImage(await imageGet('tripsitterBar')),
await Canvas.loadImage(await imageGet('developerBar')),
await Canvas.loadImage(await imageGet('teamtripsitBar')),
await Canvas.loadImage(await getAsset('teamtripsitIcon')),
await Canvas.loadImage(await getAsset('premiumIcon')),
await Canvas.loadImage(await getAsset('boosterIcon')),
await Canvas.loadImage(await getAsset('legacyIcon')),
await Canvas.loadImage(await getAsset('voiceBar')),
await Canvas.loadImage(await getAsset('tripsitterBar')),
await Canvas.loadImage(await getAsset('developerBar')),
await Canvas.loadImage(await getAsset('teamtripsitBar')),
]);

const profileData = values[1].status === 'fulfilled' ? values[1].value : {} as ProfileData;
Expand Down Expand Up @@ -516,16 +511,17 @@ export const dLevels: SlashCommand = {
// Purchased Background
// Check get fresh persona data
// log.debug(F, `personaData home (Change) ${JSON.stringify(personaData, null, 2)}`);

let userFont = 'futura';
if (personaData) {
// Get the existing inventory data
const inventoryData = await inventoryGet(personaData.id);
// log.debug(F, `Persona home inventory (change): ${JSON.stringify(inventoryData, null, 2)}`);

const equippedBackground = inventoryData.find(item => item.equipped === true && item.effect === 'background');
const equippedFont = inventoryData.find(item => item.equipped === true && item.effect === 'font');
// log.debug(F, `equippedBackground: ${JSON.stringify(equippedBackground, null, 2)} `);
if (equippedBackground) {
const imagePath = await imageGet(equippedBackground.value);
const imagePath = await getAsset(equippedBackground.value);
const Background = await Canvas.loadImage(imagePath);
context.save();
context.globalCompositeOperation = 'lighter';
Expand All @@ -537,6 +533,10 @@ export const dLevels: SlashCommand = {
context.drawImage(Background, 0, 0);
context.restore();
}
if (equippedFont) {
await getAsset(equippedFont.value);
userFont = equippedFont.value;
}
}

// Overly complicated avatar clip
Expand Down Expand Up @@ -608,14 +608,16 @@ export const dLevels: SlashCommand = {
const usernameContext = canvas.getContext('2d');
do {
fontSize -= 2;
usernameContext.font = `${fontSize}px futura`;
usernameContext.font = `${fontSize}px ${userFont}`;
} while (usernameContext.measureText(text).width > 530);
return usernameContext.font;
};

// Username Text
// Temporary code for user flairs
const filteredDisplayName = target.displayName.replace(/[^A-Za-z0-9]/g, '');
context.fillStyle = textColor;
context.font = `40px ${userFont}`;
context.textAlign = 'left';
const flair = null;
let usernameHeight = 76;
Expand All @@ -630,8 +632,8 @@ export const dLevels: SlashCommand = {
context.textBaseline = 'bottom';
}
fontSize = 40;
context.font = applyUsername(canvasObj, `${target.displayName}`);
context.fillText(`${target.displayName}`, 146, usernameHeight);
context.font = applyUsername(canvasObj, `${filteredDisplayName}`);
context.fillText(`${filteredDisplayName}`, 146, usernameHeight);

// Progress Bars Draw
context.fillStyle = barColor;
Expand Down Expand Up @@ -813,7 +815,7 @@ export const dLevels: SlashCommand = {
} else if (levelData.ALL.TOTAL.level >= 100) {
LevelImagePath = 'badgeVip10';
}
const LevelImage = await Canvas.loadImage(await imageGet(LevelImagePath));
const LevelImage = await Canvas.loadImage(await getAsset(LevelImagePath));
context.drawImage(LevelImage, 97, 181, 58, 58);

// Process The Entire Card and Send it to Discord
Expand Down
86 changes: 55 additions & 31 deletions src/discord/commands/guild/d.profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import commandContext from '../../utils/context';
import { expForNextLevel, getTotalLevel } from '../../../global/utils/experience';
import { getPersonaInfo } from '../../../global/commands/g.rpg';
import { inventoryGet } from '../../../global/utils/knex';
import { imageGet } from '../../utils/imageGet';
import getAsset from '../../utils/getAsset';
import { Personas } from '../../../global/@types/database';

// ??? TO BE MOVED TO A DEDICATED FILE, OR IMAGEGET.TS ???
// Load external fonts from web

const F = f(__filename);

Canvas.GlobalFonts.registerFromPath(
Expand All @@ -32,17 +35,6 @@ export function numFormatter(num:number):string {
return num.toFixed(0);
}

// Username Text Resize to fit
export function applyUsername(canvas:Canvas.Canvas, text:string) {
const usernameContext = canvas.getContext('2d');
let fontSize = 40;
do {
fontSize -= 2;
usernameContext.font = `${fontSize}px futura`;
} while (usernameContext.measureText(text).width > 530); // LARGER LENGTH LIMIT WHILE CAMP ICON ISN'T ENABLED (DEFAULT IS 380)
return usernameContext.font;
}

// Number Formatter Voice
export function numFormatterVoice(num:number):string {
if (num > 999 && num < 1000000) {
Expand Down Expand Up @@ -211,17 +203,17 @@ export const dProfile: SlashCommand = {
// Check get fresh persona data
await getPersonaInfo(target.user.id),
// Load Icon Images
await Canvas.loadImage(await imageGet('cardIcons')),
await Canvas.loadImage(await getAsset('cardIcons')),
// Get the status icon
// await Canvas.loadImage(await imageGet(`icon_${target.presence?.status ?? 'offline'}`)),
// Get the avatar image
await Canvas.loadImage(target.user.displayAvatarURL({ extension: 'jpg' })),
// Get the birthday card overlay
await Canvas.loadImage(await imageGet('cardBirthday')),
await Canvas.loadImage(await imageGet('teamtripsitIcon')),
await Canvas.loadImage(await imageGet('premiumIcon')),
await Canvas.loadImage(await imageGet('boosterIcon')),
await Canvas.loadImage(await imageGet('legacyIcon')),
await Canvas.loadImage(await getAsset('cardBirthday')),
await Canvas.loadImage(await getAsset('teamtripsitIcon')),
await Canvas.loadImage(await getAsset('premiumIcon')),
await Canvas.loadImage(await getAsset('boosterIcon')),
await Canvas.loadImage(await getAsset('legacyIcon')),
]);

const profileData = values[0].status === 'fulfilled' ? values[0].value : {} as ProfileData;
Expand Down Expand Up @@ -338,16 +330,17 @@ export const dProfile: SlashCommand = {
// WIP: Purchased Background

// log.debug(F, `personaData home (Change) ${JSON.stringify(personaData, null, 2)}`);

let userFont = 'futura';
if (personaData) {
// Get the existing inventory data
const inventoryData = await inventoryGet(personaData.id);
// log.debug(F, `Persona home inventory (change): ${JSON.stringify(inventoryData, null, 2)}`);

const equippedBackground = inventoryData.find(item => item.equipped === true && item.effect === 'background');
const equippedFont = inventoryData.find(item => item.equipped === true && item.effect === 'font');
// log.debug(F, `equippedBackground: ${JSON.stringify(equippedBackground, null, 2)} `);
if (equippedBackground) {
const imagePath = await imageGet(equippedBackground.value);
const imagePath = await getAsset(equippedBackground.value);
const Background = await Canvas.loadImage(imagePath);
context.save();
context.globalCompositeOperation = 'lighter';
Expand All @@ -359,6 +352,10 @@ export const dProfile: SlashCommand = {
context.drawImage(Background, 0, 0);
context.restore();
}
if (equippedFont) {
await getAsset(equippedFont.value);
userFont = equippedFont.value;
}
}

context.drawImage(Icons, 0, 0);
Expand Down Expand Up @@ -445,11 +442,24 @@ export const dProfile: SlashCommand = {
// WIP: Check to see if a user has bought a title in the shop
// If so, move Username Text up so the title can fit underneath

// Username Text Resize to fit
let fontSize = 40;
const applyUsername = (canvas:Canvas.Canvas, text:string) => {
const usernameContext = canvas.getContext('2d');
do {
fontSize -= 2;
usernameContext.font = `${fontSize}px ${userFont}`;
} while (usernameContext.measureText(text).width > 530);
return usernameContext.font;
};

// Username Text
context.font = applyUsername(canvasObj, `${target.displayName}`);
const filteredDisplayName = target.displayName.replace(/[^A-Za-z0-9]/g, '');
context.font = `40px ${userFont}`;
context.fillStyle = textColor;
context.textBaseline = 'middle';
context.fillText(`${target.displayName}`, 146, 76);
context.font = applyUsername(canvasObj, `${filteredDisplayName}`);
context.fillText(`${filteredDisplayName}`, 146, 76);

// User Timezone
context.font = '25px futura';
Expand Down Expand Up @@ -538,7 +548,7 @@ export const dProfile: SlashCommand = {
LevelImagePath = 'badgeVip10';
}
// log.debug(F, `LevelImagePath: ${LevelImagePath}`);
const LevelImage = await Canvas.loadImage(await imageGet(LevelImagePath));
const LevelImage = await Canvas.loadImage(await getAsset(LevelImagePath));
context.drawImage(LevelImage, 758, 57);

// Level Bar Circle BG
Expand Down Expand Up @@ -595,7 +605,7 @@ export const dProfile: SlashCommand = {
},
};

export async function getProfilePreview(target: GuildMember, imagePath: string, option: string): Promise<Buffer> {
export async function getProfilePreview(target: GuildMember, option: string, imagePath?: string, fontName?: string): Promise<Buffer> {
const values = await Promise.allSettled([

// Get the target's profile data from the database
Expand All @@ -604,15 +614,14 @@ export async function getProfilePreview(target: GuildMember, imagePath: string,
// await getPersonaInfo(target.user.id),
// Load Icon Images

await Canvas.loadImage(await imageGet('cardIcons')),
await Canvas.loadImage(await getAsset('cardIcons')),
// Get the status icon
// await Canvas.loadImage(await imageGet(`icon_${target.presence?.status ?? 'offline'}`)),
// Get the avatar image
await Canvas.loadImage(target.user.displayAvatarURL({ extension: 'jpg' })),
// Get the birthday card overlay
// await Canvas.loadImage(await imageGet('cardBirthday')),
]);

// const profileData = values[0].status === 'fulfilled' ? values[0].value : {} as ProfileData;
// const [personaData] = values[1].status === 'fulfilled' ? values[1].value : [];
const Icons = values[0].status === 'fulfilled' ? values[0].value : {} as Canvas.Image;
Expand Down Expand Up @@ -668,7 +677,7 @@ export async function getProfilePreview(target: GuildMember, imagePath: string,

// const equippedBackground = inventoryData.find(item => item.equipped === true && item.effect === 'background');

if (option === 'background') {
if (option === 'background' && imagePath) {
const Background = await Canvas.loadImage(imagePath.toString());
context.save();
context.globalCompositeOperation = 'lighter';
Expand Down Expand Up @@ -705,19 +714,34 @@ export async function getProfilePreview(target: GuildMember, imagePath: string,

// WIP: Check to see if a user has bought a title in the shop
// If so, move Username Text up so the title can fit underneath

let userFont = 'futura';
if (option === 'font' && fontName) {
await getAsset(fontName);
userFont = fontName;
}
const filteredDisplayName = target.displayName.replace(/[^A-Za-z0-9]/g, '');
// Username Text
context.font = applyUsername(canvasObj, `${target.displayName}`);
let fontSize = 40;
// eslint-disable-next-line sonarjs/no-identical-functions
const applyUsername = (canvas:Canvas.Canvas, text:string) => {
const usernameContext = canvas.getContext('2d');
do {
fontSize -= 2;
usernameContext.font = `${fontSize}px ${userFont}`;
} while (usernameContext.measureText(text).width > 530);
return usernameContext.font;
};
context.font = applyUsername(canvasObj, `${filteredDisplayName}`);
context.fillStyle = textColor;
if (option === 'profileTitle') {
context.textBaseline = 'bottom';
context.fillText(`${target.displayName}`, 146, 76);
context.fillText(`${filteredDisplayName}`, 146, 76);
context.font = '30px futura';
context.textBaseline = 'top';
context.fillText('Your Custom Title Here', 146, 86);
} else {
context.textBaseline = 'middle';
context.fillText(`${target.displayName}`, 146, 76);
context.fillText(`${filteredDisplayName}`, 146, 76);
}

/* User Timezone
Expand Down
Loading

0 comments on commit 0641609

Please sign in to comment.