Skip to content

Commit

Permalink
Merge branch 'master' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
IRONM00N committed Dec 9, 2024
2 parents 77a9f8a + 1e312bf commit 58b84a5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 37 deletions.
6 changes: 2 additions & 4 deletions lib/arguments/tinyColor.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { BotArgumentTypeCaster } from '#lib';
import assert from 'node:assert/strict';
import tinycolorModule from 'tinycolor2';
assert(tinycolorModule);
import { TinyColor } from '@ctrl/tinycolor';

export const tinyColor: BotArgumentTypeCaster<string | null> = (_message, phrase) => {
// if the phase is a number it converts it to hex incase it could be representing a color in decimal
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const newPhase = isNaN(phrase as any) ? phrase : `#${Number(phrase).toString(16)}`;
return tinycolorModule(newPhase).isValid() ? newPhase : null;
return new TinyColor(newPhase).isValid ? newPhase : null;
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"gif-to-apng": "^0.1.2"
},
"dependencies": {
"@ctrl/tinycolor": "^4.1.0",
"@discordjs/builders": "^1.9.0",
"@discordjs/rest": "^2.4.0",
"@ironm00n/nbt-ts": "^1.4.1",
Expand Down Expand Up @@ -92,7 +93,6 @@
"rimraf": "^6.0.1",
"rollup": "^4.28.0",
"sequelize": "6.37.5",
"tinycolor2": "^1.6.0",
"typescript": "^5.7.2",
"vm2": "^3.9.19"
},
Expand All @@ -107,7 +107,6 @@
"@types/node-fetch": "^2.6.12",
"@types/numeral": "^2.0.5",
"@types/pg": "^8.11.10",
"@types/tinycolor2": "^1.4.6",
"@types/validator": "^13.12.2",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/dev/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class TestCommand extends BotCommand {
const _avatar = message.author.avatarURL() ?? undefined;
const author = { name: 'This is a author', iconURL: _avatar };
const footer = { text: 'This is a footer', iconURL: _avatar };
const fields = Array(25)
const fields = Array(21)
.fill(0)
.map((_, i) => ({ name: `Field ${i}`, value: 'Field Value' }));
const o = { description, author, footer, fields, time: Date.now() };
Expand All @@ -149,8 +149,8 @@ export default class TestCommand extends BotCommand {
for (let a = 1; a <= 5; a++) {
const row = new ActionRowBuilder<ButtonBuilder>();
for (let b = 1; b <= 5; b++) {
const id = (a + 5 * (b - 1)).toString();
const button = new ButtonBuilder({ style: ButtonStyle.Secondary, customId: id, label: id });
const id = `${a + 5 * (b - 1)}`;
const button = new ButtonBuilder({ style: ButtonStyle.Secondary, customId: `test;button;${id}`, label: id });
row.addComponents(button);
}
ButtonRows.push(row);
Expand Down
15 changes: 7 additions & 8 deletions src/commands/info/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import {
type CommandMessage,
type SlashMessage
} from '#lib';
import { TinyColor } from '@ctrl/tinycolor';
import canvas from '@napi-rs/canvas';
import { ApplicationCommandOptionType, EmbedBuilder, Role } from 'discord.js';
import assert from 'node:assert/strict';
import tinycolor from 'tinycolor2';
assert(tinycolor);

export default class ColorCommand extends BotCommand {
public constructor() {
Expand Down Expand Up @@ -55,10 +53,10 @@ export default class ColorCommand extends BotCommand {

const color =
typeof _color === 'string'
? tinycolor(_color)
? new TinyColor(_color)
: _color instanceof Role
? tinycolor(_color.hexColor)
: tinycolor(_color.displayHexColor);
? new TinyColor(_color.hexColor)
: new TinyColor(_color.displayHexColor);

if (_color instanceof Role && _color.hexColor === '#000000') {
return await message.util.reply({
Expand All @@ -72,7 +70,8 @@ export default class ColorCommand extends BotCommand {
{ name: '» Hexadecimal', value: color.toHexString() },
{ name: '» Decimal', value: `${colorToDecimal(color)}` },
{ name: '» HSL', value: color.toHslString() },
{ name: '» RGB', value: color.toRgbString() }
{ name: '» RGB', value: color.toRgbString() },
{ name: '» CMYK (approx)', value: color.toCmykString() }
)
.setColor(parseInt(color.toHex(), 16))
.setThumbnail('attachment://color.png');
Expand All @@ -94,6 +93,6 @@ export default class ColorCommand extends BotCommand {
}
}

export function colorToDecimal(color: tinycolor.Instance): number {
export function colorToDecimal(color: TinyColor): number {
return parseInt(color.toHex(), 16);
}
4 changes: 2 additions & 2 deletions src/commands/moulberry-bush/neuRepo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BotCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib';
import { formattingInfo, type RawNeuItem } from '#lib/utils/Minecraft.js';
import { TinyColor } from '@ctrl/tinycolor';
import canvas from '@napi-rs/canvas';
import { ApplicationCommandOptionType, AttachmentBuilder, AutocompleteInteraction, type CacheType } from 'discord.js';
import { join } from 'node:path';
import tinycolor from 'tinycolor2';

export default class NeuRepoCommand extends BotCommand {
public static items: { name: string; id: string }[] = [];
Expand Down Expand Up @@ -77,7 +77,7 @@ export default class NeuRepoCommand extends BotCommand {

ctx.globalAlpha = 0.78;

const borderColorStart = parseInt(new tinycolor(this.getPrimaryColour(item.displayname)).toHex(), 16);
const borderColorStart = parseInt(new TinyColor(this.getPrimaryColour(item.displayname)).toHex(), 16);
const borderColorEnd = ((borderColorStart & 0xfefefe) >> 1) | (borderColorStart & 0xff000000);

const borderColorStartStr = `#${borderColorStart.toString(16)}`;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/specialized/colorRole.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Arg, BotCommand, emojis, type ArgType, type CommandMessage } from '#lib';
import { TinyColor } from '@ctrl/tinycolor';
import type { AkairoMessage, ArgumentGeneratorReturn } from '@tanzanite/discord-akairo';
import { ApplicationCommandOptionType, Message, Role } from 'discord.js';
import assert from 'node:assert/strict';
import tinycolor from 'tinycolor2';
import { colorToDecimal } from '../info/color.js';

type Msg = CommandMessage<true> | AkairoMessage<'cached'>;
Expand Down Expand Up @@ -165,7 +165,7 @@ export default class ColorRoleCommand extends BotCommand {
}

async #useColorRole(message: Msg, inputColor: ArgType<'tinyColor'>) {
const color = tinycolor(inputColor);
const color = new TinyColor(inputColor);
const hex = color.toHexString();
const decimal = colorToDecimal(color);

Expand Down
24 changes: 8 additions & 16 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 58b84a5

Please sign in to comment.