From 7cec4037ead3287c1d88db4274824b21d9d57d51 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 14 Jul 2022 09:01:43 -0400 Subject: messing around with repo stuff --- src/lib/common/util/Minecraft.ts | 303 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 src/lib/common/util/Minecraft.ts (limited to 'src/lib') diff --git a/src/lib/common/util/Minecraft.ts b/src/lib/common/util/Minecraft.ts new file mode 100644 index 0000000..fbacbf0 --- /dev/null +++ b/src/lib/common/util/Minecraft.ts @@ -0,0 +1,303 @@ +import { Byte, Int, parse } from '@ironm00n/nbt-ts'; +import { BitField } from 'discord.js'; +import fs from 'fs/promises'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +export enum FormattingCodes { + Black = '§0', + DarkBlue = '§1', + DarkGreen = '§2', + DarkAqua = '§3', + DarkRed = '§4', + DarkPurple = '§5', + Gold = '§6', + Gray = '§7', + DarkGray = '§8', + Blue = '§9', + Green = '§a', + Aqua = '§b', + Red = '§c', + LightPurple = '§d', + Yellow = '§e', + White = '§f', + + Obfuscated = '§k', + Bold = '§l', + Strikethrough = '§m', + Underline = '§n', + Italic = '§o', + Reset = '§r' +} + +// https://minecraft.fandom.com/wiki/Formatting_codes +export const formattingInfo = { + [FormattingCodes.Black]: { foreground: '#000000', background: '#000000', ansi: '\u001b[0;30m' }, + [FormattingCodes.DarkBlue]: { foreground: '#0000AA', background: '#00002A', ansi: '\u001b[0;34m' }, + [FormattingCodes.DarkGreen]: { foreground: '#00AA00', background: '#002A00', ansi: '\u001b[0;32m' }, + [FormattingCodes.DarkAqua]: { foreground: '#00AAAA', background: '#002A2A', ansi: '\u001b[0;36m' }, + [FormattingCodes.DarkRed]: { foreground: '#AA0000', background: '#2A0000', ansi: '\u001b[0;31m' }, + [FormattingCodes.DarkPurple]: { foreground: '#AA00AA', background: '#2A002A', ansi: '\u001b[0;35m' }, + [FormattingCodes.Gold]: { foreground: '#FFAA00', background: '#2A2A00', ansi: '\u001b[0;33m' }, + [FormattingCodes.Gray]: { foreground: '#AAAAAA', background: '#2A2A2A', ansi: '\u001b[0;37m' }, + [FormattingCodes.DarkGray]: { foreground: '#555555', background: '#151515', ansi: '\u001b[0;90m' }, + [FormattingCodes.Blue]: { foreground: '#5555FF', background: '#15153F', ansi: '\u001b[0;94m' }, + [FormattingCodes.Green]: { foreground: '#55FF55', background: '#153F15', ansi: '\u001b[0;92m' }, + [FormattingCodes.Aqua]: { foreground: '#55FFFF', background: '#153F3F', ansi: '\u001b[0;96m' }, + [FormattingCodes.Red]: { foreground: '#FF5555', background: '#3F1515', ansi: '\u001b[0;91m' }, + [FormattingCodes.LightPurple]: { foreground: '#FF55FF', background: '#3F153F', ansi: '\u001b[0;95m' }, + [FormattingCodes.Yellow]: { foreground: '#FFFF55', background: '#3F3F15', ansi: '\u001b[0;93m' }, + [FormattingCodes.White]: { foreground: '#FFFFFF', background: '#3F3F3F', ansi: '\u001b[0;97m' }, + + [FormattingCodes.Obfuscated]: { ansi: '\u001b[8m' }, + [FormattingCodes.Bold]: { ansi: '\u001b[1m' }, + [FormattingCodes.Strikethrough]: { ansi: '\u001b[9m' }, + [FormattingCodes.Underline]: { ansi: '\u001b[4m' }, + [FormattingCodes.Italic]: { ansi: '\u001b[3m' }, + [FormattingCodes.Reset]: { ansi: '\u001b[0m' } +} as const; + +export type McItemId = Lowercase; +export type SbItemId = Uppercase; +export type MojangJson = string; +export type SbRecipeItem = `${SbItemId}:${number}` | ''; +export type SbRecipe = { + [Location in `${'A' | 'B' | 'C'}${1 | 2 | 3}`]: SbRecipeItem; +}; +export type InfoType = 'WIKI_URL' | ''; + +type Slayer = `${'WOLF' | 'BLAZE' | 'EMAN'}_${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`; + +export interface RawNeuItem { + itemid: McItemId; + displayname: string; + nbttag: MojangJson; + damage: number; + lore: string[]; + recipe?: SbRecipe; + internalname: SbItemId; + modver: string; + infoType: InfoType; + info?: string[]; + crafttext: string; + vanilla?: boolean; + useneucraft?: boolean; + slayer_req?: Slayer; + clickcommand?: string; + x?: number; + y?: number; + z?: number; + island?: string; + recipes?: { type: string; cost: any[]; result: SbItemId }[]; + /** @deprecated */ + parent?: SbItemId; + noseal?: boolean; +} + +export enum HideFlagsBits { + Enchantments = 1, + AttributeModifiers = 2, + Unbreakable = 4, + CanDestroy = 8, + CanPlaceOn = 16, + /** + * potion effects, shield pattern info, "StoredEnchantments", written book + * "generation" and "author", "Explosion", "Fireworks", and map tooltips + */ + OtherInformation = 32, + Dyed = 64 +} + +export type HideFlagsString = keyof typeof HideFlagsBits; + +export class HideFlags extends BitField { + public static override Flags = HideFlagsBits; +} + +export const formattingCode = new RegExp( + `§[${Object.values(FormattingCodes) + .filter((v) => v.startsWith('§')) + .map((v) => v.substring(1)) + .join('')}]` +); + +export function removeMCFormatting(str: string) { + return str.replaceAll(formattingCode, ''); +} + +const repo = path.join(__dirname, '..', '..', '..', '..', '..', 'neu-item-repo-dangerous'); +const itemPath = path.join(repo, 'items'); +const items = await fs.readdir(itemPath); + +// for (let i = 0; i < 5; i++) { +for (const path_ of items) { + // const randomItem = items[Math.floor(Math.random() * items.length)]; + // console.log(randomItem); + const item = (await import(path.join(itemPath, /* randomItem */ path_), { assert: { type: 'json' } })).default as RawNeuItem; + if (item.displayname.includes('(Monster)') || item.displayname.includes('(NPC)')) continue; + /* console.log(path_); + console.dir(item, { depth: Infinity }); */ + + /* console.log('==========='); */ + const nbt = /* fn( */ parse(item.nbttag /* .replaceAll(/([0-9]{1,3}:)(["{])/g, '$2'), { useMaps: true } */) as any; /*); */ + console.dir(nbt, { depth: Infinity }); + console.log('==========='); + // console.dir((nbt.(item.nbttag))); + + /* // eslint-disable-next-line no-inner-declarations + function fn(map: TagMap) { + const ret = {} as any; + map.forEach((val, key) => { + function fn2(val: any): any { + if (val instanceof Map) return fn(val); + else if (Array.isArray(val)) return val.map((v) => fn2(v)); + else return val.valueOf(); + } + ret[key] = fn2(val); + }); + return ret; + } */ + + /* if (nbt?.display && nbt.display.Name !== item.displayname) + console.log(`${path_} display name mismatch: ${mcToAnsi(nbt.display.Name)} != ${mcToAnsi(item.displayname)}`); + + if (nbt?.ExtraAttributes && nbt?.ExtraAttributes.id !== item.internalname) + console.log(`${path_} internal name mismatch: ${mcToAnsi(nbt?.ExtraAttributes.id)} != ${mcToAnsi(item.internalname)}`); */ + + /* console.log('==========='); + + console.log(mcToAnsi(item.displayname)); + console.log(item.lore.map((l) => mcToAnsi(l)).join('\n')); */ + + /* const keys = [ + 'itemid', + 'displayname', + 'nbttag', + 'damage', + 'lore', + 'recipe', + 'internalname', + 'modver', + 'infoType', + 'info', + 'crafttext', + 'vanilla', + 'useneucraft', + 'slayer_req', + 'clickcommand', + 'x', + 'y', + 'z', + 'island', + 'recipes', + 'parent', + 'noseal' + ]; + + Object.keys(item).forEach((k) => { + if (!keys.includes(k)) throw new Error(`Unknown key: ${k}`); + }); + + if ( + 'slayer_req' in item && + !new Array(10).flatMap((_, i) => ['WOLF', 'BLAZE', 'EMAN'].map((e) => e + (i + 1)).includes(item.slayer_req!)) + ) + throw new Error(`Unknown slayer req: ${item.slayer_req!}`); */ + + /* console.log('=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-'); */ +} + +interface NbtTag { + overrideMeta?: Byte; + Unbreakable?: Int; + ench?: string[]; + HideFlags?: HideFlags; + SkullOwner?: SkullOwner; + display?: NbtTagDisplay; + ExtraAttributes?: ExtraAttributes; +} + +interface SkullOwner { + Id?: string; + Properties?: { + textures?: { Value?: string }[]; + }; +} + +interface NbtTagDisplay { + Lore?: string[]; + Name?: string; +} + +type RuneId = string; + +interface ExtraAttributes { + originTag?: Origin; + id?: string; + generator_tier?: Int; + boss_tier?: Int; + enchantments?: { hardened_mana?: Int }; + dungeon_item_level?: Int; + runes?: { [key: RuneId]: Int }; +} + +type Origin = 'SHOP_PURCHASE'; + +class NeuItem { + public itemId: string; + public nbtTag: NbtTag; + + public constructor(raw: RawNeuItem) { + this.itemId = raw.itemid; + this.nbtTag = parse(raw.nbttag); + } + + public get lore(): string { + return ''; + } + + private pet() {} +} + +function mcToAnsi(str: string) { + for (const format in formattingInfo) { + str = str.replaceAll(format, formattingInfo[format as keyof typeof formattingInfo].ansi); + } + return `${str}\u001b[0m`; +} + +const neuConstantsPath = path.join(repo, 'constants'); +const neuPetsPath = path.join(neuConstantsPath, 'pets.json'); +const neuPets = await import(neuPetsPath, { assert: { type: 'json' } }); + +// console.dir(await nbt.parse(buffer)); +/* console.dir( + await nbt.parse( + Buffer.from( + '{overrideMeta:1b,HideFlags:254,SkullOwner:{Id:"4173bc61-9e2f-3c84-8d31-4517e64062ab",Properties:{textures:[0:{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjNhYWY3YjFhNzc4OTQ5Njk2Y2I5OWQ0ZjA0YWQxYWE1MThjZWVlMjU2YzcyZTVlZDY1YmZhNWMyZDg4ZDllIn19fQ=="}]}},display:{Lore:[0:"§8Combat Pet",1:"",2:"§7Intelligence: §a{INTELLIGENCE}",3:"§7Strength: §a{STRENGTH}",4:"",5:"§6Rekindle",6:"§7§7Before death, become §eimmune",7:"§e§7and gain §c{0} §c❁ Strength",8:"§c§7for §a{1} §7seconds",9:"§83 minutes cooldown",10:"",11:"§6Fourth Flare",12:"§7§7On 4th melee strike, §6ignite",13:"§6§7mobs, dealing §c{4}x §7your",14:"§7§9☠ Crit Damage §7each second",15:"§7for §a{5} §7seconds",16:"",17:"§7§eRight-click to add this pet to",18:"§eyour pet menu!",19:"",20:"§5§lEPIC"],Name:"§f§f§7[Lvl {LVL}] §5Phoenix"},ExtraAttributes:{petInfo:"{\\"type\\":\\"PHOENIX\\",\\"active\\":false,\\"exp\\":0.0,\\"tier\\":\\"EPIC\\",\\"hideInfo\\":false}",id:"PHOENIX;3"},AttributeModifiers:[]}', + 'utf8' + ) + ) +); */ + +// import _ from 'lodash'; + +// const str = +// '{overrideMeta:1b,HideFlags:254,SkullOwner:{Id:"4173bc61-9e2f-3c84-8d31-4517e64062ab",Properties:{textures:[0:{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjNhYWY3YjFhNzc4OTQ5Njk2Y2I5OWQ0ZjA0YWQxYWE1MThjZWVlMjU2YzcyZTVlZDY1YmZhNWMyZDg4ZDllIn19fQ=="}]}},display:{Lore:[0:"§8Combat Pet",1:"",2:"§7Intelligence: §a{INTELLIGENCE}",3:"§7Strength: §a{STRENGTH}",4:"",5:"§6Rekindle",6:"§7§7Before death, become §eimmune",7:"§e§7and gain §c{0} §c❁ Strength",8:"§c§7for §a{1} §7seconds",9:"§83 minutes cooldown",10:"",11:"§6Fourth Flare",12:"§7§7On 4th melee strike, §6ignite",13:"§6§7mobs, dealing §c{4}x §7your",14:"§7§9☠ Crit Damage §7each second",15:"§7for §a{5} §7seconds",16:"",17:"§7§eRight-click to add this pet to",18:"§eyour pet menu!",19:"",20:"§5§lEPIC"],Name:"§f§f§7[Lvl {LVL}] §5Phoenix"},ExtraAttributes:{petInfo:"{\\"type\\":\\"PHOENIX\\",\\"active\\":false,\\"exp\\":0.0,\\"tier\\":\\"EPIC\\",\\"hideInfo\\":false}",id:"PHOENIX;3"},AttributeModifiers:[]}'.replaceAll( +// /([0-9]{1,3}:)(["{])/g, +// '$2' +// ); + +// console.log(str); + +// console.dir( +// _.chunk( +// str.split('').map((v, i) => [i, v]), +// 10 +// ).map((v) => [v[0][0], v.map((v) => v[1]).join('')]), +// { maxArrayLength: Infinity, compact: 100 } +// ); + +// console.dir(parse(str)); -- cgit From 7bdeccaeb4976a997d0d483481b29000795a92a9 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 14 Jul 2022 11:17:52 -0400 Subject: this is very boring --- src/lib/common/util/Minecraft.ts | 140 +++++++++++++++++++++++---------------- 1 file changed, 84 insertions(+), 56 deletions(-) (limited to 'src/lib') diff --git a/src/lib/common/util/Minecraft.ts b/src/lib/common/util/Minecraft.ts index fbacbf0..b4b013f 100644 --- a/src/lib/common/util/Minecraft.ts +++ b/src/lib/common/util/Minecraft.ts @@ -136,29 +136,28 @@ for (const path_ of items) { // const randomItem = items[Math.floor(Math.random() * items.length)]; // console.log(randomItem); const item = (await import(path.join(itemPath, /* randomItem */ path_), { assert: { type: 'json' } })).default as RawNeuItem; - if (item.displayname.includes('(Monster)') || item.displayname.includes('(NPC)')) continue; + if (/.*?((_MONSTER)|(_NPC)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$/.test(item.internalname)) continue; + if (!/.*?;[0-5]$/.test(item.internalname)) continue; /* console.log(path_); console.dir(item, { depth: Infinity }); */ /* console.log('==========='); */ - const nbt = /* fn( */ parse(item.nbttag /* .replaceAll(/([0-9]{1,3}:)(["{])/g, '$2'), { useMaps: true } */) as any; /*); */ + const nbt = parse(item.nbttag) as NbtTag; + + if (nbt?.SkullOwner?.Properties?.textures?.[0]?.Value) { + nbt.SkullOwner.Properties.textures[0].Value = parse( + Buffer.from(nbt.SkullOwner.Properties.textures[0].Value, 'base64').toString('utf-8') + ) as string; + } + + if (nbt.ExtraAttributes?.petInfo) { + nbt.ExtraAttributes.petInfo = JSON.parse(nbt.ExtraAttributes.petInfo as any as string); + } + + // delete nbt.display?.Lore; + console.dir(nbt, { depth: Infinity }); console.log('==========='); - // console.dir((nbt.(item.nbttag))); - - /* // eslint-disable-next-line no-inner-declarations - function fn(map: TagMap) { - const ret = {} as any; - map.forEach((val, key) => { - function fn2(val: any): any { - if (val instanceof Map) return fn(val); - else if (Array.isArray(val)) return val.map((v) => fn2(v)); - else return val.valueOf(); - } - ret[key] = fn2(val); - }); - return ret; - } */ /* if (nbt?.display && nbt.display.Name !== item.displayname) console.log(`${path_} display name mismatch: ${mcToAnsi(nbt.display.Name)} != ${mcToAnsi(item.displayname)}`); @@ -228,6 +227,7 @@ interface SkullOwner { interface NbtTagDisplay { Lore?: string[]; + color?: Int; Name?: string; } @@ -241,24 +241,86 @@ interface ExtraAttributes { enchantments?: { hardened_mana?: Int }; dungeon_item_level?: Int; runes?: { [key: RuneId]: Int }; + petInfo?: PetInfo; +} + +interface PetInfo { + type: 'ZOMBIE'; + active: boolean; + exp: number; + tier: 'COMMON' | 'UNCOMMON' | 'RARE' | 'EPIC' | 'LEGENDARY'; + hideInfo: boolean; + candyUsed: number; } type Origin = 'SHOP_PURCHASE'; +const neuConstantsPath = path.join(repo, 'constants'); +const neuPetsPath = path.join(neuConstantsPath, 'pets.json'); +const neuPets = (await import(neuPetsPath, { assert: { type: 'json' } })) as PetsConstants; +const neuPetNumsPath = path.join(neuConstantsPath, 'petnums.json'); +const neuPetNums = (await import(neuPetNumsPath, { assert: { type: 'json' } })) as PetNums; + +interface PetsConstants { + pet_rarity_offset: Record; + pet_levels: number[]; + custom_pet_leveling: Record; + pet_types: Record; +} + +interface PetNums { + [key: string]: { + [key: string]: { + '1': { + otherNums: number[]; + statNums: Record; + }; + '100': { + otherNums: number[]; + statNums: Record; + }; + 'stats_levelling_curve'?: `${number};${number};${number}`; + }; + }; +} + class NeuItem { - public itemId: string; + public itemId: McItemId; + public displayName: string; public nbtTag: NbtTag; + public internalName: SbItemId; + public lore: string[]; public constructor(raw: RawNeuItem) { this.itemId = raw.itemid; this.nbtTag = parse(raw.nbttag); - } + this.displayName = raw.displayname; + this.internalName = raw.internalname; + this.lore = raw.lore; - public get lore(): string { - return ''; + this.petLoreReplacements(); } - private pet() {} + private petLoreReplacements(level = -1) { + if (/.*?;[0-5]$/.test(this.internalName) && this.displayName.includes('LVL')) { + const maxLevel = neuPets?.custom_pet_leveling?.[this.internalName]?.max_level ?? 100; + this.displayName = this.displayName.replace('LVL', `1➡${maxLevel}`); + + const nums = neuPetNums[this.internalName]; + if (!nums) throw new Error(`Pet (${this.internalName}) has no pet nums.`); + + const teir = ['COMMON', 'UNCOMMON', 'RARE', 'EPIC', 'LEGENDARY', 'MYTHIC'][+this.internalName.at(-1)!]; + const petInfoTier = nums[teir]; + if (!petInfoTier) throw new Error(`Pet (${this.internalName}) has no pet nums for ${teir} rarity.`); + + const curve = petInfoTier?.stats_levelling_curve?.split(';'); + + const minStatsLevel = parseInt(curve?.[0] ?? '0'); + const maxStatsLevel = parseInt(curve?.[0] ?? '100'); + + const lore = ''; + } + } } function mcToAnsi(str: string) { @@ -267,37 +329,3 @@ function mcToAnsi(str: string) { } return `${str}\u001b[0m`; } - -const neuConstantsPath = path.join(repo, 'constants'); -const neuPetsPath = path.join(neuConstantsPath, 'pets.json'); -const neuPets = await import(neuPetsPath, { assert: { type: 'json' } }); - -// console.dir(await nbt.parse(buffer)); -/* console.dir( - await nbt.parse( - Buffer.from( - '{overrideMeta:1b,HideFlags:254,SkullOwner:{Id:"4173bc61-9e2f-3c84-8d31-4517e64062ab",Properties:{textures:[0:{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjNhYWY3YjFhNzc4OTQ5Njk2Y2I5OWQ0ZjA0YWQxYWE1MThjZWVlMjU2YzcyZTVlZDY1YmZhNWMyZDg4ZDllIn19fQ=="}]}},display:{Lore:[0:"§8Combat Pet",1:"",2:"§7Intelligence: §a{INTELLIGENCE}",3:"§7Strength: §a{STRENGTH}",4:"",5:"§6Rekindle",6:"§7§7Before death, become §eimmune",7:"§e§7and gain §c{0} §c❁ Strength",8:"§c§7for §a{1} §7seconds",9:"§83 minutes cooldown",10:"",11:"§6Fourth Flare",12:"§7§7On 4th melee strike, §6ignite",13:"§6§7mobs, dealing §c{4}x §7your",14:"§7§9☠ Crit Damage §7each second",15:"§7for §a{5} §7seconds",16:"",17:"§7§eRight-click to add this pet to",18:"§eyour pet menu!",19:"",20:"§5§lEPIC"],Name:"§f§f§7[Lvl {LVL}] §5Phoenix"},ExtraAttributes:{petInfo:"{\\"type\\":\\"PHOENIX\\",\\"active\\":false,\\"exp\\":0.0,\\"tier\\":\\"EPIC\\",\\"hideInfo\\":false}",id:"PHOENIX;3"},AttributeModifiers:[]}', - 'utf8' - ) - ) -); */ - -// import _ from 'lodash'; - -// const str = -// '{overrideMeta:1b,HideFlags:254,SkullOwner:{Id:"4173bc61-9e2f-3c84-8d31-4517e64062ab",Properties:{textures:[0:{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjNhYWY3YjFhNzc4OTQ5Njk2Y2I5OWQ0ZjA0YWQxYWE1MThjZWVlMjU2YzcyZTVlZDY1YmZhNWMyZDg4ZDllIn19fQ=="}]}},display:{Lore:[0:"§8Combat Pet",1:"",2:"§7Intelligence: §a{INTELLIGENCE}",3:"§7Strength: §a{STRENGTH}",4:"",5:"§6Rekindle",6:"§7§7Before death, become §eimmune",7:"§e§7and gain §c{0} §c❁ Strength",8:"§c§7for §a{1} §7seconds",9:"§83 minutes cooldown",10:"",11:"§6Fourth Flare",12:"§7§7On 4th melee strike, §6ignite",13:"§6§7mobs, dealing §c{4}x §7your",14:"§7§9☠ Crit Damage §7each second",15:"§7for §a{5} §7seconds",16:"",17:"§7§eRight-click to add this pet to",18:"§eyour pet menu!",19:"",20:"§5§lEPIC"],Name:"§f§f§7[Lvl {LVL}] §5Phoenix"},ExtraAttributes:{petInfo:"{\\"type\\":\\"PHOENIX\\",\\"active\\":false,\\"exp\\":0.0,\\"tier\\":\\"EPIC\\",\\"hideInfo\\":false}",id:"PHOENIX;3"},AttributeModifiers:[]}'.replaceAll( -// /([0-9]{1,3}:)(["{])/g, -// '$2' -// ); - -// console.log(str); - -// console.dir( -// _.chunk( -// str.split('').map((v, i) => [i, v]), -// 10 -// ).map((v) => [v[0][0], v.map((v) => v[1]).join('')]), -// { maxArrayLength: Infinity, compact: 100 } -// ); - -// console.dir(parse(str)); -- cgit From e4206aaa9211e792660b4015551519d633409355 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 5 Aug 2022 20:10:42 -0400 Subject: random stuff --- src/lib/utils/BushLogger.ts | 58 +++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) (limited to 'src/lib') diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts index 5c98760..995dd82 100644 --- a/src/lib/utils/BushLogger.ts +++ b/src/lib/utils/BushLogger.ts @@ -1,6 +1,7 @@ import chalk from 'chalk'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Client, EmbedBuilder, escapeMarkdown, PartialTextBasedChannelFields, type Message } from 'discord.js'; +import { Client, EmbedBuilder, escapeMarkdown, Formatters, PartialTextBasedChannelFields, type Message } from 'discord.js'; +import { stripVTControlCharacters as stripColor } from 'node:util'; import repl, { REPLServer, REPL_MODE_STRICT } from 'repl'; import { WriteStream } from 'tty'; import { type SendMessageType } from '../extensions/discord-akairo/BushClient.js'; @@ -72,16 +73,16 @@ function parseFormatting( discordFormat = false ): string | typeof content { if (typeof content !== 'string') return content; - const newContent: Array = content.split(/<<|>>/); - const tempParsedArray: Array = []; - newContent.forEach((value, index) => { - if (index % 2 !== 0) { - tempParsedArray.push(discordFormat ? `**${escapeMarkdown(value)}**` : color ? chalk[color](value) : value); - } else { - tempParsedArray.push(discordFormat ? escapeMarkdown(value) : value); - } - }); - return tempParsedArray.join(''); + return content + .split(/<<|>>/) + .map((value, index) => { + if (discordFormat) { + return index % 2 === 0 ? escapeMarkdown(value) : Formatters.bold(escapeMarkdown(value)); + } else { + return index % 2 === 0 || !color ? value : chalk[color](value); + } + }) + .join(''); } /** @@ -98,34 +99,25 @@ function inspectContent(content: any, depth = 2, colors = true): string { return content; } -/** - * Strips ANSI color codes from a string. - * @param text The string to strip color codes from. - * @returns A string without ANSI color codes. - */ -function stripColor(text: string): string { - return text.replace( - // eslint-disable-next-line no-control-regex - /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, - '' - ); -} - /** * Generates a formatted timestamp for logging. * @returns The formatted timestamp. */ function getTimeStamp(): string { const now = new Date(); - const hours = now.getHours(); - const minute = now.getMinutes(); - let hour = hours; - let amOrPm: 'AM' | 'PM' = 'AM'; - if (hour > 12) { - amOrPm = 'PM'; - hour = hour - 12; - } - return `${hour >= 10 ? hour : `0${hour}`}:${minute >= 10 ? minute : `0${minute}`} ${amOrPm}`; + const minute = pad(now.getMinutes()); + const hour = pad(now.getHours() % 12); + const meridiem = now.getHours() > 12 ? 'PM' : 'AM'; + const year = now.getFullYear().toString().slice(2).padStart(2, '0'); + const date = `${pad(now.getMonth() + 1)}/${pad(now.getDay())}/${year}`; + return `${date} ${hour}:${minute} ${meridiem}`; +} + +/** + * Pad a two-digit number. + */ +function pad(num: number) { + return num.toString().padStart(2, '0'); } /** -- cgit From 2ec1de170091178263e53ecfce744c7a0710a409 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 5 Aug 2022 20:11:45 -0400 Subject: wip tooltip rendering --- src/lib/common/util/Minecraft.ts | 234 ++++++++++++++++++---------------- src/lib/common/util/Minecraft_Test.ts | 86 +++++++++++++ 2 files changed, 212 insertions(+), 108 deletions(-) create mode 100644 src/lib/common/util/Minecraft_Test.ts (limited to 'src/lib') diff --git a/src/lib/common/util/Minecraft.ts b/src/lib/common/util/Minecraft.ts index b4b013f..a12ebf2 100644 --- a/src/lib/common/util/Minecraft.ts +++ b/src/lib/common/util/Minecraft.ts @@ -1,6 +1,5 @@ import { Byte, Int, parse } from '@ironm00n/nbt-ts'; import { BitField } from 'discord.js'; -import fs from 'fs/promises'; import path from 'path'; import { fileURLToPath } from 'url'; @@ -34,22 +33,118 @@ export enum FormattingCodes { // https://minecraft.fandom.com/wiki/Formatting_codes export const formattingInfo = { - [FormattingCodes.Black]: { foreground: '#000000', background: '#000000', ansi: '\u001b[0;30m' }, - [FormattingCodes.DarkBlue]: { foreground: '#0000AA', background: '#00002A', ansi: '\u001b[0;34m' }, - [FormattingCodes.DarkGreen]: { foreground: '#00AA00', background: '#002A00', ansi: '\u001b[0;32m' }, - [FormattingCodes.DarkAqua]: { foreground: '#00AAAA', background: '#002A2A', ansi: '\u001b[0;36m' }, - [FormattingCodes.DarkRed]: { foreground: '#AA0000', background: '#2A0000', ansi: '\u001b[0;31m' }, - [FormattingCodes.DarkPurple]: { foreground: '#AA00AA', background: '#2A002A', ansi: '\u001b[0;35m' }, - [FormattingCodes.Gold]: { foreground: '#FFAA00', background: '#2A2A00', ansi: '\u001b[0;33m' }, - [FormattingCodes.Gray]: { foreground: '#AAAAAA', background: '#2A2A2A', ansi: '\u001b[0;37m' }, - [FormattingCodes.DarkGray]: { foreground: '#555555', background: '#151515', ansi: '\u001b[0;90m' }, - [FormattingCodes.Blue]: { foreground: '#5555FF', background: '#15153F', ansi: '\u001b[0;94m' }, - [FormattingCodes.Green]: { foreground: '#55FF55', background: '#153F15', ansi: '\u001b[0;92m' }, - [FormattingCodes.Aqua]: { foreground: '#55FFFF', background: '#153F3F', ansi: '\u001b[0;96m' }, - [FormattingCodes.Red]: { foreground: '#FF5555', background: '#3F1515', ansi: '\u001b[0;91m' }, - [FormattingCodes.LightPurple]: { foreground: '#FF55FF', background: '#3F153F', ansi: '\u001b[0;95m' }, - [FormattingCodes.Yellow]: { foreground: '#FFFF55', background: '#3F3F15', ansi: '\u001b[0;93m' }, - [FormattingCodes.White]: { foreground: '#FFFFFF', background: '#3F3F3F', ansi: '\u001b[0;97m' }, + [FormattingCodes.Black]: { + foreground: 'rgb(0, 0, 0)', + foregroundDarker: 'rgb(0, 0, 0)', + background: 'rgb(0, 0, 0)', + backgroundDarker: 'rgb(0, 0, 0)', + ansi: '\u001b[0;30m' + }, + [FormattingCodes.DarkBlue]: { + foreground: 'rgb(0, 0, 170)', + foregroundDarker: 'rgb(0, 0, 118)', + background: 'rgb(0, 0, 42)', + backgroundDarker: 'rgb(0, 0, 29)', + ansi: '\u001b[0;34m' + }, + [FormattingCodes.DarkGreen]: { + foreground: 'rgb(0, 170, 0)', + foregroundDarker: 'rgb(0, 118, 0)', + background: 'rgb(0, 42, 0)', + backgroundDarker: 'rgb(0, 29, 0)', + ansi: '\u001b[0;32m' + }, + [FormattingCodes.DarkAqua]: { + foreground: 'rgb(0, 170, 170)', + foregroundDarker: 'rgb(0, 118, 118)', + background: 'rgb(0, 42, 42)', + backgroundDarker: 'rgb(0, 29, 29)', + ansi: '\u001b[0;36m' + }, + [FormattingCodes.DarkRed]: { + foreground: 'rgb(170, 0, 0)', + foregroundDarker: 'rgb(118, 0, 0)', + background: 'rgb(42, 0, 0)', + backgroundDarker: 'rgb(29, 0, 0)', + ansi: '\u001b[0;31m' + }, + [FormattingCodes.DarkPurple]: { + foreground: 'rgb(170, 0, 170)', + foregroundDarker: 'rgb(118, 0, 118)', + background: 'rgb(42, 0, 42)', + backgroundDarker: 'rgb(29, 0, 29)', + ansi: '\u001b[0;35m' + }, + [FormattingCodes.Gold]: { + foreground: 'rgb(255, 170, 0)', + foregroundDarker: 'rgb(178, 118, 0)', + background: 'rgb(42, 42, 0)', + backgroundDarker: 'rgb(29, 29, 0)', + ansi: '\u001b[0;33m' + }, + [FormattingCodes.Gray]: { + foreground: 'rgb(170, 170, 170)', + foregroundDarker: 'rgb(118, 118, 118)', + background: 'rgb(42, 42, 42)', + backgroundDarker: 'rgb(29, 29, 29)', + ansi: '\u001b[0;37m' + }, + [FormattingCodes.DarkGray]: { + foreground: 'rgb(85, 85, 85)', + foregroundDarker: 'rgb(59, 59, 59)', + background: 'rgb(21, 21, 21)', + backgroundDarker: 'rgb(14, 14, 14)', + ansi: '\u001b[0;90m' + }, + [FormattingCodes.Blue]: { + foreground: 'rgb(85, 85, 255)', + foregroundDarker: 'rgb(59, 59, 178)', + background: 'rgb(21, 21, 63)', + backgroundDarker: 'rgb(14, 14, 44)', + ansi: '\u001b[0;94m' + }, + [FormattingCodes.Green]: { + foreground: 'rgb(85, 255, 85)', + foregroundDarker: 'rgb(59, 178, 59)', + background: 'rgb(21, 63, 21)', + backgroundDarker: 'rgb(14, 44, 14)', + ansi: '\u001b[0;92m' + }, + [FormattingCodes.Aqua]: { + foreground: 'rgb(85, 255, 255)', + foregroundDarker: 'rgb(59, 178, 178)', + background: 'rgb(21, 63, 63)', + backgroundDarker: 'rgb(14, 44, 44)', + ansi: '\u001b[0;96m' + }, + [FormattingCodes.Red]: { + foreground: 'rgb(255, 85, 85)', + foregroundDarker: 'rgb(178, 59, 59)', + background: 'rgb(63, 21, 21)', + backgroundDarker: 'rgb(44, 14, 14)', + ansi: '\u001b[0;91m' + }, + [FormattingCodes.LightPurple]: { + foreground: 'rgb(255, 85, 255)', + foregroundDarker: 'rgb(178, 59, 178)', + background: 'rgb(63, 21, 63)', + backgroundDarker: 'rgb(44, 14, 44)', + ansi: '\u001b[0;95m' + }, + [FormattingCodes.Yellow]: { + foreground: 'rgb(255, 255, 85)', + foregroundDarker: 'rgb(178, 178, 59)', + background: 'rgb(63, 63, 21)', + backgroundDarker: 'rgb(44, 44, 14)', + ansi: '\u001b[0;93m' + }, + [FormattingCodes.White]: { + foreground: 'rgb(255, 255, 255)', + foregroundDarker: 'rgb(178, 178, 178)', + background: 'rgb(63, 63, 63)', + backgroundDarker: 'rgb(44, 44, 44)', + ansi: '\u001b[0;97m' + }, [FormattingCodes.Obfuscated]: { ansi: '\u001b[8m' }, [FormattingCodes.Bold]: { ansi: '\u001b[1m' }, @@ -68,7 +163,7 @@ export type SbRecipe = { }; export type InfoType = 'WIKI_URL' | ''; -type Slayer = `${'WOLF' | 'BLAZE' | 'EMAN'}_${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`; +export type Slayer = `${'WOLF' | 'BLAZE' | 'EMAN'}_${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`; export interface RawNeuItem { itemid: McItemId; @@ -128,87 +223,8 @@ export function removeMCFormatting(str: string) { } const repo = path.join(__dirname, '..', '..', '..', '..', '..', 'neu-item-repo-dangerous'); -const itemPath = path.join(repo, 'items'); -const items = await fs.readdir(itemPath); - -// for (let i = 0; i < 5; i++) { -for (const path_ of items) { - // const randomItem = items[Math.floor(Math.random() * items.length)]; - // console.log(randomItem); - const item = (await import(path.join(itemPath, /* randomItem */ path_), { assert: { type: 'json' } })).default as RawNeuItem; - if (/.*?((_MONSTER)|(_NPC)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$/.test(item.internalname)) continue; - if (!/.*?;[0-5]$/.test(item.internalname)) continue; - /* console.log(path_); - console.dir(item, { depth: Infinity }); */ - - /* console.log('==========='); */ - const nbt = parse(item.nbttag) as NbtTag; - - if (nbt?.SkullOwner?.Properties?.textures?.[0]?.Value) { - nbt.SkullOwner.Properties.textures[0].Value = parse( - Buffer.from(nbt.SkullOwner.Properties.textures[0].Value, 'base64').toString('utf-8') - ) as string; - } - - if (nbt.ExtraAttributes?.petInfo) { - nbt.ExtraAttributes.petInfo = JSON.parse(nbt.ExtraAttributes.petInfo as any as string); - } - // delete nbt.display?.Lore; - - console.dir(nbt, { depth: Infinity }); - console.log('==========='); - - /* if (nbt?.display && nbt.display.Name !== item.displayname) - console.log(`${path_} display name mismatch: ${mcToAnsi(nbt.display.Name)} != ${mcToAnsi(item.displayname)}`); - - if (nbt?.ExtraAttributes && nbt?.ExtraAttributes.id !== item.internalname) - console.log(`${path_} internal name mismatch: ${mcToAnsi(nbt?.ExtraAttributes.id)} != ${mcToAnsi(item.internalname)}`); */ - - /* console.log('==========='); - - console.log(mcToAnsi(item.displayname)); - console.log(item.lore.map((l) => mcToAnsi(l)).join('\n')); */ - - /* const keys = [ - 'itemid', - 'displayname', - 'nbttag', - 'damage', - 'lore', - 'recipe', - 'internalname', - 'modver', - 'infoType', - 'info', - 'crafttext', - 'vanilla', - 'useneucraft', - 'slayer_req', - 'clickcommand', - 'x', - 'y', - 'z', - 'island', - 'recipes', - 'parent', - 'noseal' - ]; - - Object.keys(item).forEach((k) => { - if (!keys.includes(k)) throw new Error(`Unknown key: ${k}`); - }); - - if ( - 'slayer_req' in item && - !new Array(10).flatMap((_, i) => ['WOLF', 'BLAZE', 'EMAN'].map((e) => e + (i + 1)).includes(item.slayer_req!)) - ) - throw new Error(`Unknown slayer req: ${item.slayer_req!}`); */ - - /* console.log('=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-'); */ -} - -interface NbtTag { +export interface NbtTag { overrideMeta?: Byte; Unbreakable?: Int; ench?: string[]; @@ -218,22 +234,22 @@ interface NbtTag { ExtraAttributes?: ExtraAttributes; } -interface SkullOwner { +export interface SkullOwner { Id?: string; Properties?: { textures?: { Value?: string }[]; }; } -interface NbtTagDisplay { +export interface NbtTagDisplay { Lore?: string[]; color?: Int; Name?: string; } -type RuneId = string; +export type RuneId = string; -interface ExtraAttributes { +export interface ExtraAttributes { originTag?: Origin; id?: string; generator_tier?: Int; @@ -244,7 +260,7 @@ interface ExtraAttributes { petInfo?: PetInfo; } -interface PetInfo { +export interface PetInfo { type: 'ZOMBIE'; active: boolean; exp: number; @@ -253,7 +269,7 @@ interface PetInfo { candyUsed: number; } -type Origin = 'SHOP_PURCHASE'; +export type Origin = 'SHOP_PURCHASE'; const neuConstantsPath = path.join(repo, 'constants'); const neuPetsPath = path.join(neuConstantsPath, 'pets.json'); @@ -261,14 +277,14 @@ const neuPets = (await import(neuPetsPath, { assert: { type: 'json' } })) as Pet const neuPetNumsPath = path.join(neuConstantsPath, 'petnums.json'); const neuPetNums = (await import(neuPetNumsPath, { assert: { type: 'json' } })) as PetNums; -interface PetsConstants { +export interface PetsConstants { pet_rarity_offset: Record; pet_levels: number[]; custom_pet_leveling: Record; pet_types: Record; } -interface PetNums { +export interface PetNums { [key: string]: { [key: string]: { '1': { @@ -284,7 +300,7 @@ interface PetNums { }; } -class NeuItem { +export class NeuItem { public itemId: McItemId; public displayName: string; public nbtTag: NbtTag; @@ -315,6 +331,8 @@ class NeuItem { const curve = petInfoTier?.stats_levelling_curve?.split(';'); + // todo: finish copying from neu + const minStatsLevel = parseInt(curve?.[0] ?? '0'); const maxStatsLevel = parseInt(curve?.[0] ?? '100'); @@ -323,7 +341,7 @@ class NeuItem { } } -function mcToAnsi(str: string) { +export function mcToAnsi(str: string) { for (const format in formattingInfo) { str = str.replaceAll(format, formattingInfo[format as keyof typeof formattingInfo].ansi); } diff --git a/src/lib/common/util/Minecraft_Test.ts b/src/lib/common/util/Minecraft_Test.ts new file mode 100644 index 0000000..26ca648 --- /dev/null +++ b/src/lib/common/util/Minecraft_Test.ts @@ -0,0 +1,86 @@ +import fs from 'fs/promises'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { mcToAnsi, RawNeuItem } from './Minecraft.js'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const repo = path.join(__dirname, '..', '..', '..', '..', '..', 'neu-item-repo-dangerous'); +const itemPath = path.join(repo, 'items'); +const items = await fs.readdir(itemPath); + +// for (let i = 0; i < 5; i++) { +for (const path_ of items) { + // const randomItem = items[Math.floor(Math.random() * items.length)]; + // console.log(randomItem); + const item = (await import(path.join(itemPath, /* randomItem */ path_), { assert: { type: 'json' } })).default as RawNeuItem; + if (/.*?((_MONSTER)|(_NPC)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$/.test(item.internalname)) continue; + if (!/.*?;[0-5]$/.test(item.internalname)) continue; + /* console.log(path_); + console.dir(item, { depth: Infinity }); */ + + /* console.log('==========='); */ + // const nbt = parse(item.nbttag) as NbtTag; + + // if (nbt?.SkullOwner?.Properties?.textures?.[0]?.Value) { + // nbt.SkullOwner.Properties.textures[0].Value = parse( + // Buffer.from(nbt.SkullOwner.Properties.textures[0].Value, 'base64').toString('utf-8') + // ) as string; + // } + + // if (nbt.ExtraAttributes?.petInfo) { + // nbt.ExtraAttributes.petInfo = JSON.parse(nbt.ExtraAttributes.petInfo as any as string); + // } + + // delete nbt.display?.Lore; + + // console.dir(nbt, { depth: Infinity }); + // console.log('==========='); + + /* if (nbt?.display && nbt.display.Name !== item.displayname) + console.log(`${path_} display name mismatch: ${mcToAnsi(nbt.display.Name)} != ${mcToAnsi(item.displayname)}`); + + if (nbt?.ExtraAttributes && nbt?.ExtraAttributes.id !== item.internalname) + console.log(`${path_} internal name mismatch: ${mcToAnsi(nbt?.ExtraAttributes.id)} != ${mcToAnsi(item.internalname)}`); */ + + // console.log('==========='); + + console.log(mcToAnsi(item.displayname)); + console.log(item.lore.map((l) => mcToAnsi(l)).join('\n')); + + /* const keys = [ + 'itemid', + 'displayname', + 'nbttag', + 'damage', + 'lore', + 'recipe', + 'internalname', + 'modver', + 'infoType', + 'info', + 'crafttext', + 'vanilla', + 'useneucraft', + 'slayer_req', + 'clickcommand', + 'x', + 'y', + 'z', + 'island', + 'recipes', + 'parent', + 'noseal' + ]; + + Object.keys(item).forEach((k) => { + if (!keys.includes(k)) throw new Error(`Unknown key: ${k}`); + }); + + if ( + 'slayer_req' in item && + !new Array(10).flatMap((_, i) => ['WOLF', 'BLAZE', 'EMAN'].map((e) => e + (i + 1)).includes(item.slayer_req!)) + ) + throw new Error(`Unknown slayer req: ${item.slayer_req!}`); */ + + /* console.log('=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-'); */ +} -- cgit From 7894d181d4863e3031c3f7721c345077cc5bc613 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 5 Aug 2022 22:56:44 -0400 Subject: add more mappings --- src/lib/utils/BushConstants.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/lib') diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts index 67723e3..8a7bf03 100644 --- a/src/lib/utils/BushConstants.ts +++ b/src/lib/utils/BushConstants.ts @@ -200,11 +200,22 @@ export const pronounMapping = Object.freeze({ */ export const mappings = deepLock({ guilds: { - bush: '516977525906341928', - tree: '767448775450820639', - staff: '784597260465995796', - space_ship: '717176538717749358', - sbr: '839287012409999391' + "Moulberry's Bush": '516977525906341928', + "Moulberry's Tree": '767448775450820639', + 'MB Staff': '784597260465995796', + "IRONM00N's Space Ship": '717176538717749358' + }, + + channels: { + 'neu-support': '714332750156660756', + 'giveaways': '767782084981817344' + }, + + users: { + IRONM00N: '322862723090219008', + Moulberry: '211288288055525376', + nopo: '384620942577369088', + Bestower: '496409778822709251' }, permissions: { -- cgit From dc0784722cd92f9b2343ee7a5fa36f740cb9926e Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 5 Aug 2022 22:57:41 -0400 Subject: add automod to quote --- src/lib/extensions/discord.js/ExtendedGuild.ts | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/extensions/discord.js/ExtendedGuild.ts b/src/lib/extensions/discord.js/ExtendedGuild.ts index c58916c..56bc1f8 100644 --- a/src/lib/extensions/discord.js/ExtendedGuild.ts +++ b/src/lib/extensions/discord.js/ExtendedGuild.ts @@ -11,6 +11,7 @@ import { type GuildLogType, type GuildModel } from '#lib'; +import assert from 'assert'; import { AttachmentBuilder, AttachmentPayload, @@ -735,10 +736,33 @@ export class ExtendedGuild extends Guild { sendOptions.content = 'Wondering who to invite? Start by inviting anyone who can help you build the server!'; break; + // todo: use enum for this + case 24 as MessageType: { + const embed = quote.embeds[0]; + assert.equal(embed.data.type, 'auto_moderation_message'); + const ruleName = embed.fields!.find((f) => f.name === 'rule_name')!.value; + const channelId = embed.fields!.find((f) => f.name === 'channel_id')!.value; + const keyword = embed.fields!.find((f) => f.name === 'keyword')!.value; + + sendOptions.username = `AutoMod (${quote.member?.displayName ?? quote.author.username})`; + sendOptions.content = `Automod has blocked a message in <#${channelId}>`; + sendOptions.embeds = [ + { + title: quote.member?.displayName ?? quote.author.username, + description: embed.description ?? 'There is no content???', + footer: { + text: `Keyword: ${keyword} • Rule: ${ruleName}` + }, + color: 0x36393f + } + ]; + + break; + } case MessageType.ChannelIconChange: case MessageType.Call: default: - sendOptions.content = `${emojis.error} I cannot quote **${ + sendOptions.content = `${emojis.error} I cannot quote messages of type **${ MessageType[quote.type] || quote.type }** messages, please report this to my developers.`; @@ -746,7 +770,7 @@ export class ExtendedGuild extends Guild { } sendOptions.allowedMentions = AllowedMentions.none(); - sendOptions.username = quote.member?.displayName ?? quote.author.username; + sendOptions.username ??= quote.member?.displayName ?? quote.author.username; sendOptions.avatarURL = quote.member?.displayAvatarURL({ size: 2048 }) ?? quote.author.displayAvatarURL({ size: 2048 }); return await webhook.send(sendOptions); /* .catch((e: any) => e); */ -- cgit From 060349fcabe9e073eca9f6fd334e3355a9756096 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 5 Aug 2022 23:15:35 -0400 Subject: use assert/strict --- src/lib/common/AutoMod.ts | 2 +- src/lib/common/HighlightManager.ts | 2 +- src/lib/common/util/Moderation.ts | 2 +- src/lib/extensions/discord.js/ExtendedGuild.ts | 2 +- src/lib/utils/BushClientUtils.ts | 2 +- src/lib/utils/BushUtils.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/lib') diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts index 21bcb00..093f8af 100644 --- a/src/lib/common/AutoMod.ts +++ b/src/lib/common/AutoMod.ts @@ -1,5 +1,5 @@ import { colors, emojis, format, formatError, Moderation, unmuteResponse } from '#lib'; -import assert from 'assert'; +import assert from 'assert/strict'; import chalk from 'chalk'; import { ActionRowBuilder, diff --git a/src/lib/common/HighlightManager.ts b/src/lib/common/HighlightManager.ts index 4346007..8784b35 100644 --- a/src/lib/common/HighlightManager.ts +++ b/src/lib/common/HighlightManager.ts @@ -1,5 +1,5 @@ import { addToArray, format, Highlight, removeFromArray, timestamp, type HighlightWord } from '#lib'; -import assert from 'assert'; +import assert from 'assert/strict'; import { Collection, GuildMember, diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts index fc01602..60e32c0 100644 --- a/src/lib/common/util/Moderation.ts +++ b/src/lib/common/util/Moderation.ts @@ -12,7 +12,7 @@ import { type ModLogType, type ValueOf } from '#lib'; -import assert from 'assert'; +import assert from 'assert/strict'; import { ActionRowBuilder, ButtonBuilder, diff --git a/src/lib/extensions/discord.js/ExtendedGuild.ts b/src/lib/extensions/discord.js/ExtendedGuild.ts index 56bc1f8..88bf5f1 100644 --- a/src/lib/extensions/discord.js/ExtendedGuild.ts +++ b/src/lib/extensions/discord.js/ExtendedGuild.ts @@ -11,7 +11,7 @@ import { type GuildLogType, type GuildModel } from '#lib'; -import assert from 'assert'; +import assert from 'assert/strict'; import { AttachmentBuilder, AttachmentPayload, diff --git a/src/lib/utils/BushClientUtils.ts b/src/lib/utils/BushClientUtils.ts index af49803..920ff40 100644 --- a/src/lib/utils/BushClientUtils.ts +++ b/src/lib/utils/BushClientUtils.ts @@ -1,4 +1,4 @@ -import assert from 'assert'; +import assert from 'assert/strict'; import { cleanCodeBlockContent, DMChannel, diff --git a/src/lib/utils/BushUtils.ts b/src/lib/utils/BushUtils.ts index 19260c8..af173f9 100644 --- a/src/lib/utils/BushUtils.ts +++ b/src/lib/utils/BushUtils.ts @@ -10,7 +10,7 @@ import { type SlashMessage } from '#lib'; import { humanizeDuration as humanizeDurationMod } from '@notenoughupdates/humanize-duration'; -import assert from 'assert'; +import assert from 'assert/strict'; import cp from 'child_process'; import deepLock from 'deep-lock'; import { Util as AkairoUtil } from 'discord-akairo'; -- cgit