#development

1 messages ยท Page 2013 of 1

ancient nova
#

so it actually is listed then?

atomic kindle
#

Just process records under result key.

#

It's an array.

ancient nova
#

so should I treat it like one?

atomic kindle
#

It is one.

ancient nova
#

after fetching should I just do
fetched.records[0]?

ancient nova
atomic kindle
#

To get the first three elements from the array just run response.result.records.slice(0, 3);.

quaint rampart
#

i dont see much of a difference, node-fetch does it in 854 ms and undici did it in 850

atomic kindle
quaint rampart
#

is that like a function or? idk i never used undici

ancient nova
atomic kindle
#

And to answer your original question, you can cache DNS records for a start.

atomic kindle
ancient nova
hidden gorge
#

i yeah my bot had a 18k latency

plucky imp
#

is it neccasary to have a help command'

#

if you're using slash commands

atomic kindle
#

No.

plucky imp
#

okey

atomic kindle
#

Discord UI becomes your help command.

sudden geyser
#

best feature

plucky imp
#

okey

quaint rampart
atomic kindle
ancient nova
civic scroll
#

you have to let the impostor in

earnest phoenix
#

hi

#

how can I show the in-server avatar?

livid lichen
#
await axios.post(`https://discord.com/api/v8/channels/${message.member.voice.channel.id}/invites`, {
                data: {
                    max_age: 86400,
                    max_uses: 0,
                    target_application_id: "880218394199220334",
                    target_type: 2,
                    temporary: false,
                    validate: null
                },
                headers: {
                    "Content-Type": "application/json",
                    Authentication: `Bot ${discord.Client.token}`
                }
            }).then(res => res.data).then(async invite => {
                await message.replyT(`${bot.config.emojis.success} | Click the following invite to start playing the selected game! https://discord.com/invite/${invite.code}`);
            });
```Hi, I'm trying to get activities to work. However, it returns the status code 401. I'm not sure what I am doing wrong.
ancient nova
#

lmfaooo my code is so bad it literally breaks Visual Studio's syntax highlighting hahahahahahha

craggy pine
#

Why not axios

split hazel
#

axios is good

craggy pine
split hazel
#

node fetch is an expensive cesspit

#

not the experimental fetch the module one

livid lichen
ancient nova
#

bro why tf my neck started hurting so bad right after I said axios is bad

#

the devs tryna kill me

#

๐Ÿ˜ฎ

split hazel
#

hopefully it gets phased out soon because nodejs added native fetch support under the experimental flag

livid lichen
#

LOL

ancient nova
#

ayo chill

split hazel
#

it uses some efficient http library under the hood

ancient nova
#

I use node-fetch

livid lichen
#

Iโ€™ll use node-fetch again once itโ€™s built in.

near stratus
ancient nova
#

bro no cap my neck is legit hurting as if someone stabbed me

near stratus
#

back again

ancient nova
#

should I go see a doctor

split hazel
#

bros dying as we speak in development ๐Ÿ’€

earnest phoenix
split hazel
#

yeah that library

ancient nova
near stratus
ancient nova
#

btw I beat the next level of bad code

split hazel
#

since tim said its good i say its good

livid lichen
ancient nova
#

visual studio CODE syntax highlighting broke

#

with my code

#

not kidding

near stratus
livid lichen
ancient nova
livid lichen
#

If Iโ€™m being honest, the only reason I use axios is because the package version of node-fetch uses import. So I cannot use future versions of it.

earnest phoenix
#

Just use ESM

ancient nova
#

what's better request, node-fetch or http

livid lichen
#

axios

ancient nova
#

no axios

#

axios bad

#

made my neck hurt

split hazel
#

dont like how libraries suddenly decided to be quirky and "phase out" require through peer pressure despite imports not being enabled by default ๐Ÿ’€

ancient nova
#

๐Ÿ˜ 

livid lichen
#

Thatโ€™s why I donโ€™t like node-fetch.

ancient nova
#

altho using old version also works

livid lichen
#

yep

ancient nova
#

I wonder what voltrex may be typing that's this long

livid lichen
ancient nova
sharp tapir
#

man

livid lichen
#

My badddd

earnest phoenix
#

CJS is just a workaround we've implemented when JavaScript did not have modules, as the specification now officially has modules, which ESM, it's better to use and more performant under the hood, and the reason this is not enabled by default is to not break user code as most people are used to CJS rather than ESM, and the the global require() function and module object doesn't exist in ESM, so that would be extremely breaking

ancient nova
#

I doubt it

#

wait

#

@random maple

#

wrong person

#

@earnest phoenix can you use import and require in the same script?

livid lichen
#

thanks though I will check it out

split hazel
#

yeah it'd be great if all of this would be backwards compatible

ancient nova
#

me trying to do a subdomain scrapper be like:

livid lichen
#

lol

earnest phoenix
# ancient nova <@456226577798135808> can you use import and require in the same script?

You can, in CJS, you can only use the global require() function and dynamic imports (import()) not import statements, in ESM however, you can use import statements, dynamic imports and even the global require() function, although in ESM it's not global, but can be constructed:

import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);

require(...);
sudden geyser
#

which one should you use though: require(...), import(...), or import ... ? ...

ancient nova
#

I use require cause that's what I'm the most used to

#

ยฏ_(ใƒ„)_/ยฏ

civic scroll
#

"i'm the most used to"

#

you are lucky that CommonJS standard is not deprecated yet

ancient nova
#

that's why I used request npm up until like 2 days ago

civic scroll
#

bruh

ancient nova
#

I was set on using it cause I was most used to it

civic scroll
#

learn import syntax

ancient nova
#

I prefer not

civic scroll
#

will be useful if one day you switch to typescript

ancient nova
#

I will also not

#

ever

#

probably

#

most likely

civic scroll
#

why so

ancient nova
#

I don't actually have a reason, but js is like

#

more

#

widely

#

..available?

sudden geyser
civic scroll
civic scroll
#

and now we have import syn in js

#

it's transitioning

#

anywho

#

it's up to you

#

your project, your choice

#

i would rather have silly errors in development than hard-to-trace insanity-inducing error in production code Exudead

#

static typed languages are clearly superior

#

but js is good if you need quick prototyping
but you need to know what you are doing

ancient nova
#

you're not wrong although I'll prefer to use what I know instead of having new errors every week because one of the thousand things I use everyday been updated

civic scroll
#

no???

#

there are no breaking changes

#

bruh they are not gonna release breaking changes in every update

ancient nova
#

by errors I mean new stuff or stuff I was used to that they changed or updated to work differently

civic scroll
#

no

#

you are not working on the bare metal here

ancient nova
#

come on you know what I mean

#

I refuse to believe you've never had an issue like that

sudden geyser
#

What exactly are you using?

ancient nova
#

let response = await axios({
method: "GET",
url: "https://crt.sh/",
params: {
q: %.${domain},
output: "json"
}
});
can you use this with node-fetch instead of axios? lol

#

sorry for the question just curious

sudden geyser
#

yeah

ancient nova
#

trying to do the subdomain finder thing but no get type npm wanted to cooperate

sudden geyser
#

Would look something like this:

fetch("https://crt.sh/?" + URLSearchParams({...}), {
  method: "GET"
})
ancient nova
#
let settings = {
method: "GET",
url: "https://crt.sh/",
params: {
q: %.${domain},
output: "json"
}
};
fetch(settings);
#

no need to hassle

sudden geyser
#

I don't think node-fetch uses params: ...

ancient nova
#

it should?

#

I mean I'm pretty sure I used those in both

earnest phoenix
#

It doesn't have such query helper, just use the URL search params

#
new URLSearchParams({ q: ..., output: ... }).toString()

For example

ancient nova
earnest phoenix
#

The URLSearchParams class is global and built-in yes

ancient nova
#

alright let me try

#

never used that before

#

@earnest phoenix so I'm pretty sure it would look like this?```js
return new Promise((resolve, reject) => {
const settings = new URLSearchParams({ q: %.${domain}, output: "json" }).toString();
fetch(https://crt.sh/ + settings, {
method: "GET"
}, (error, response, body) => {
return resolve({ body, response});
});

earnest phoenix
#

Yes

ancient nova
#

awesome

earnest phoenix
#

Wait a second

ancient nova
#

wat?

earnest phoenix
#

Why are you using a callback

ancient nova
#

because this is a part of my lib

#

I need to await it in my main script in order to resolve the promise

earnest phoenix
#

If that's generally the fetch() function derived from node-fetch, it just returns a promise you can directly resolve without having to use a callback, unless you've modified it

ancient nova
#

no I haven't

#

so it works without async or resolving ??

earnest phoenix
#

Then you can just do

return fetch(...).then((response) => ({
  response,
  body: response.body
}));
ancient nova
#

ah... yeah I guess I could although I still prefer doing the above

#

I'll then use regex to turn the body into a json file lmao

#

since the website doesn't have an API I can just do that instead

earnest phoenix
#

Just use consumers

#
fetch(...).then((res) => res.json());
ancient nova
#

yeah that won't work lol

#

it doesn't actually return a json visit the site

#

I'd "reformat" it into a json using regex

earnest phoenix
#

Oh then alright

ancient nova
#

hopefully it's gonna be as easy as it sounds

ancient nova
#

nevermind

#

it's actually quite hard

earnest phoenix
#

anyone know the code for when someone joins the server it sends a welcome message?
Verision: 12.5.3
Discord.js

sudden geyser
#

discord.js has a v15?

earnest phoenix
#

meant 12

sudden geyser
#

isn't that going to die next month

earnest phoenix
#

think so

#

i need to change my whole code tho

#

and when ever i try changing the version it wont let my bot go online

sudden geyser
#

still sounds better than letting it die ๐Ÿ™ƒ

#

but what you're looking for is the guildMemberAdd event and the members intent

earnest phoenix
#

i got guildMemberAdd and people told me it was add

#

including the videos on youtube

sudden geyser
#

Yeah it's add

#

my bad

earnest phoenix
#

but like i dont get any errors and when i test it out it doesnt work

sudden geyser
#

can you show us what you currently have

earnest phoenix
#
  if (member.user.bot) return
 
  const welcomeChan = member.guild.channels.cache.get('945862410802192384')
 
  if (welcomeChan.type === 'GUILD_TEXT') welcomeChan.type === 'GUILD_TEXT'
  else return
 
  welcomeChan.send(`:right: Welcome to the server ${member}!`)
})```
ancient nova
#

TypeError: result.map is not a function?

#

result is a json file, least I think so

#

as far as I know my regex is working since I got no errors

sudden geyser
#

Try logging the value of welcomeChan

wheat mesa
#

also don't use .type === 'GUILD_TEXT'

sudden geyser
#

Also note that the second welcomeChan.type === 'GUILD_TEXT' is redundant since you should really have if (welcomeChan.type !== 'GUILD_TEXT') return;

wheat mesa
#

use whatever djs's equivalent of ChannelTypes.GUILD_TEXT is

ancient nova
#

Reason: TypeError: Cannot read properties of undefined (reading 'split')

#

WHY

#

wait maybe

wheat mesa
#

because it's undefined

earnest phoenix
#

can someone like remake the code. my brain is off n been coding all day so idk what to change

wheat mesa
#

I don't think anyone here is going to spoonfeed you

earnest phoenix
#

its just one time

wheat mesa
#

no

#

nobody is going to write your code for you

#

that defeats the purpose of this channel

ancient nova
#

I'm literally inputting the json file

wheat mesa
#

because you'll eventually come back for the same issues since you didn't learn how to fix them the first time, we can help, but we're not going to write it for you

ancient nova
#
                const result = `[${body.replace(/}{/g, '},{')}]`
                result = JSON.parse(result.map(value=>value.name_value.split("\n")));
                console.log(result);
``` trying to parse it right now
earnest phoenix
#

i fixed it. dont gotta write me a whole essay about why ppl cant do the code for me

ancient nova
#

TypeError: result.map is not a function

#

TypeError: Assignment to constant variable.

#

?????????????///

lyric mountain
#

you cant change a const's value

#

that's why it's callec constant

ancient nova
#

yeah I realized it

#

changed it to let because if I used var you would've killed me lol

#

TypeError: Cannot read properties of undefined (reading 'split')

#

and I thought I had it

#

why can't I split it now

wheat mesa
#

because JSON.parse returns an object, doesn't it?

#

actually wait no I didn't read the error

lyric mountain
wheat mesa
#

it means your json isn't parsing

ancient nova
#
                let result = `[${body.replace(/}{/g, '},{')}]`
                result = JSON.parse(result);
                result = result.map(value=>value.name_value.split("\n"));
                console.log(result);
``` this is the code and I can show you the entire json if you want
wheat mesa
#

from thje looks of it you're trying to parse an array

#

hold on lemme look at it more in a sec

ancient nova
wheat mesa
#

ok it means name_value is undefined

ancient nova
#

it can't be

wheat mesa
#

because result is a string, and strings don't have properties like that

#

log it, you'll see

ancient nova
#

okay that's why I'm parsing it

#

to turn it into a json

wheat mesa
#

ok ngl I wasn't looking at that

#

log result

ancient nova
#

give sec

lyric mountain
#

just show the json

ancient nova
#

this is the body which I'm changing into json

#

with the regex above

#

do you guys want me to log result and send it too?

lyric mountain
#

just put the json u have here buddy

#

if it's too long cut repeating parts

#

and obviously, hide secret stuff

wheat mesa
#

^^

ancient nova
#

okay I didn't want to cause I have to use fs to write it into a file

wheat mesa
#

you don't have to...

#

just

ancient nova
#

obviously can't copy from console because it's too large

wheat mesa
#

console log it

#

are you not using a debugger..?

ancient nova
#

just the GUI of my program

#

which is a CLI

wheat mesa
#

CLI != GUI

#

but yeah

boreal iron
ancient nova
#

which is CLI based

#

ยฏ_(ใƒ„)_/ยฏ

#

it takes a while to turn on sorry lol

#

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined

#

what even is this

lyric mountain
#

anything is CLI-based if you lower the bar enough

sudden geyser
#

this chat is a cli

ancient nova
#

I'm literally dying

wheat mesa
ancient nova
#

okay

#

got it

#

@wheat mesa @lyric mountain

neat ingot
#

posted about my rpc app on reddit earlier... people seem really salty there for somer eason ๐Ÿ˜‚

lyric mountain
ancient nova
#

I want to commit die

lyric mountain
#

formatted json for better visualization

ancient nova
#

well still I can't do much with it

quartz kindle
ancient nova
neat ingot
#

json-stringify-pretty-compact is a nice node module to spit out pretty json ๐Ÿ™‚

ancient nova
#

I don't need pretty json !!! just need it to work!!!!!

lyric mountain
ancient nova
#

๐Ÿ˜ญ

ancient nova
lyric mountain
#

instead of mapping values then parsing

#

ah nvm

ancient nova
#
                let result = `[${body.replace(/}{/g, '},{')}]`
                result = JSON.parse(result);
                result = result.map(value=>value.name_value.split("\n"));
                console.log(result);
``` first result is body turned into a json, then parsing, then mapping
#

WHY DOES IT NOT WORK!!!!!!!!!!!!!!!!!

lyric mountain
#

cuz u have a 2-level array

ancient nova
lyric mountain
#

first of all, remove [] from let result

#

ur nesting an array inside an array

#

so value indeed doesn't have a name_value property

#

because it's an array

ancient nova
#

oh my god

#

YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

lyric mountain
#

tbh, why are u even replacing it?

ancient nova
#

wdym?

lyric mountain
#

the first line

#

let result = `[${body.replace(/}{/g, '},{')}]`

#

why?

wheat mesa
#

yeah why are you regexing

#

that's gonna slow asf for an array of that size

ancient nova
#

I know it takes like 5000ms to finish however what do you expect me to do

#

write a 500 line parser

#

"body" is legit just a body of a webpage

wheat mesa
#

or just not use regex

#

and ignore it

ancient nova
#

or just can't

#

it's better than writing a huge parser

wheat mesa
#

???? who said you had to write a parser

#

I'm so confused

ancient nova
#

wdym though

#

the above isn't what body is

wheat mesa
#

in json format or in standard html? I would assume json

#

since you're getting a json response from the page

#

you do you

ancient nova
#

I don't get it, how else am I gonna clean the other stuff from the webpage

neat ingot
#

your welcome ๐Ÿ˜˜

#

~ they really should document their api ๐Ÿ˜‚

ancient nova
#

NO WAY

neat ingot
#

yep.. 100% authentic real life actual way.

ancient nova
#

I officially

#

want to die

#

I JUST SPEND

#

like

#

3 hours

#

or 4

#

on this

neat ingot
#

< 3-4 minutes

ancient nova
#
                console.log(white(`\n${lineRepeat()}\n`));
                console.log(white(`${cyan("[ZERO]")} SCRAPPING RESULTS... THIS MAY TAKE UP TO 10 SECONDS...`));

                let result = `${body.replace(/}{/g, '},{')}`
                result = JSON.parse(result);
                result = result.map(value=>value.name_value.split("\n"));
                result = result.filter((value, index, array) => array.indexOf(value) === index && !/^\*/.test(value));
                console.log(result);
#

how did you even find this?

#

I was about to go all out with the regex

neat ingot
#

i literally guessed

wheat mesa
#

99 times out of 100 the solution is not regex to every problem

ancient nova
#

no way lol such luck

wheat mesa
#

I see people using regex to solve everything, definitely not the way to go

neat ingot
#

tried adding &json=true to the query, no luck, tried adding json before the ?, luck.

raven wadi
#

Hello

#

How can I get a role ?

ancient nova
raven wadi
ancient nova
#

there's a channel to get a role

#

somewhere

wheat mesa
#

regex usually increases the complexity and length of your code

ancient nova
#

99/100 times I used regex in my current program I had to write less instead of more

#

what could be a complex function is one if statement thanks to regex

wheat mesa
#

regex is slow, unreadable, and a bad practice if there's a more practical solution

ancient nova
wheat mesa
#

said nobody ever

#

regex has some use cases, but it's usually not the solution

#

chances are there's better options

ancient nova
#

I mean you can try turn some of my code if you want

#

I don't really want to if regex just works

wheat mesa
#

Thatโ€™s not a good mindset to have but you do you ๐Ÿ™‚

ancient nova
#

don't mean to be rude I just prefer to use regex if I can turn a whole function into one if statement

wheat mesa
#

cough cough

ancient nova
#

well that was because I was out of solutions

wheat mesa
#

This is precisely the reason you donโ€™t want to be in a habit of โ€œoh I couldnโ€™t think of a solution so Iโ€™ll look up a regex for itโ€

#

Very bad thing to do

ancient nova
#

but it works

#

๐Ÿ˜

wheat mesa
#

The worst response to that statement ever

#

โ€œBut it worksโ€ is the epitome of every programming meme

#

Definitely donโ€™t want to be using regex for stuff like that

#

/^-?\d+$/ tell me what this regex does

#

Without looking it up

ancient nova
#

uhh

lyric mountain
ancient nova
#

I would have to use a regex tool

#

but that's what I always do

lyric mountain
#

not after the wall of text we had a few days ago

wheat mesa
#

Hint: itโ€™s the same function you wrote

ancient nova
#

even when I'm writing my regex code

wheat mesa
#

You just proved my point ๐Ÿ˜‰

#

You literally used that regex, please donโ€™t use regex everywhere. Nobody will be able to understand it, and you wonโ€™t be able to either without looking it up or using a tool

sudden geyser
#

Now about about this?

function isNumber(x) {
  return /^-?\d+$/.test(x);
}
wheat mesa
#

It leads to unmaintainable hellholes of obscure regexes that have way better solutions

ancient nova
#

above

wheat mesa
#

That is what he wrote above

ancient nova
#

but I'll keep the regex I already wrote

#

I don't wanna rewrite anything

wheat mesa
#

What else did you use regex for

#

Just out of curiosity

ancient nova
#

let me list some things from the top of my head

lyric mountain
#

what even is the usage for that regex?

ancient nova
#

an domain validity checker, proxy checker, IP checker , IP Corrector

#

string checker and float checker

#

specific character finder

#

there's more

wheat mesa
lyric mountain
lyric mountain
ancient nova
wheat mesa
#

???

winter pasture
#

It is better to have a few if/else statements than a complex regex imo.
Better readability and maintainability down the line

wheat mesa
#

โ€œContains didnโ€™t workโ€

#

What are you trying to do?

ancient nova
#

I forgot since I already finished and got it working with regex

lyric mountain
ancient nova
#

it was ages ago when I done that

lyric mountain
#

like in this spotify case

wheat mesa
#

Like indexOf()?

#

If youโ€™re using regex for it, thereโ€™s probably a better solution is my rule of thumb

#

There are exceptions

winter pasture
wheat mesa
#

But they are few and far

ancient nova
#

forgot about this function

#

also

lyric mountain
wheat mesa
#

Yes

ancient nova
#

result = result.filter((value, index, array) => array.indexOf(value) === index && !/^\*/.test(value));

wheat mesa
#

What the fuck

ancient nova
#

have a better idea to do this without using regex?

wheat mesa
#

Does that do

ancient nova
#

filters things that are the same in the array or similar

lyric mountain
#

ok, the regex there is /^\*/

#

so anything that starts with *

#

there literally "somestring".startsWith("*")

sudden geyser
ancient nova
#

...

wheat mesa
#

startsWith is an incredibly basic function, but I couldnโ€™t even understand what that regex did. See my point? Donโ€™t get used to using regex to solve everything

#

Itโ€™s supposed to be a concise method to pattern match complex things, not an infinite spool of duct tape to patch everything up

lyric mountain
wheat mesa
#

Lmao

lyric mountain
#

it took me some time to understand what that ! meant

sudden geyser
#

I think that's just you guys

sudden geyser
#

took me 2 seconds to figure out what it did

ancient nova
#

it's meant to represent is not

lyric mountain
#

albeit "cool", regex is a very expensive operation

ancient nova
#

okay

#

prepare to be amazed

#
/(\d{1,3}.){3}\d{1,3}/.test(ip) ? ip.match(/(\d{1,3}.){3}\d{1,3}/)[0] + ip[4] : (i % 3 === 0) ? ip += '.' : ip += user.toString()[i];
lyric mountain
#

and should only be used when the alternative code would be monstruous or too slow compared to regex

ancient nova
#

guess what ^ is

ancient nova
lyric mountain
#

yes it is

neat ingot
#

splits numbers into groups of 3

ancient nova
#

it's not

ancient nova
lyric mountain
#

\d{1,3} will match from 1 to 3 digits

#

it'll match that 3 times then end with a final check for 3 more digits

neat ingot
#

it seems to be building the ip lol

wheat mesa
#

Multiple experienced devs guessing what a regex does and still getting it wrong precisely proves my point

ancient nova
lyric mountain
#

it is

ancient nova
#

IP generator

neat ingot
#

or some variable called 'ip'

#

lol

lyric mountain
ancient nova
#

IP GENERATOR!!!

#

I just said

lyric mountain
#

the regex is checking the ip

#

regex doesn't build anything

ancient nova
#

I have a different regex for checking IP

neat ingot
#
// returns true if given string is a valid url
static isValidURL(string) {
    return /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g.test(String(string));
}
#

I hate regexp

ancient nova
#

I love this code

sudden geyser
#

regex is fun

ancient nova
#

can I yoink it? @neat ingot lol

sudden geyser
#

though I think the url module in node.js does url checking

neat ingot
#

sure lol

lyric mountain
neat ingot
#
// returns true if given string is a valid image url
static isImageURL(string) {
    if (!this.isValidURL(string)) return false;
    return /.(jpg|gif|png|jpeg)$/i.test(string);
}```
^ goes along with it
sudden geyser
#

not really

#

it's not going to be accurate

wheat mesa
#

Itโ€™s way more valid than using regex for checking if a string is a number

neat ingot
#

according to very lengthy google searches, that seemed to be the most reommended way lol

ancient nova
#

I assume there is no function called endsWith?

neat ingot
#

there is

ancient nova
#

fuck

wheat mesa
#

You can do basically anything with the built in string methods, just saying

ancient nova
#

there can be an if statement but you're gonna have to do || 4 times

#

or a switch case

#

soooo

#

regex gud

wheat mesa
#

No

winter pasture
wheat mesa
#

Stop

neat ingot
wheat mesa
#

Regex is for niche cases

neat ingot
#

as can many others

wheat mesa
#

Regex is not meant to be used everywhere

#

Stop trying to use it everywhere

neat ingot
#

but yea that'd work for my use case too tbh

winter pasture
wheat mesa
#

If you donโ€™t work on your project for like 2 weeks youโ€™ll come back, look at your regexes, and be like, โ€œwhat the fuck does this doโ€

#

When you could make something infinitely more readable for a small bit more space

#

Not to mention regex is slow

neat ingot
ancient nova
#

guys

#

how tf did you count files in a array again

#

a for loop?

sudden geyser
#

.length()

winter pasture
ancient nova
#

oh I forgot that existed

wheat mesa
#

Heโ€™s probably using a regex for it

neat ingot
#

๐Ÿ˜‚

ancient nova
sudden geyser
#

how would you even pull that off

ancient nova
ancient nova
#

๐Ÿ˜‰

winter pasture
#

What annoys me the most about regex is the amount of people that use it to validate IP addresses in Node

#

There is a built in util for it WHYYYYYYYYY

ancient nova
#

and like

neat ingot
#

easy to write? what?

ancient nova
#

a few ms of delay isn't gonna hurt anyone

wheat mesa
#

Lol

ancient nova
wheat mesa
#

Those ms add up when you keep using regex for incredibly inefficient use cases

ancient nova
wheat mesa
#

Except it definitely seems like it

ancient nova
#

even though like 20% of my script is just regex it isn't slow

wheat mesa
#

Itโ€™s bad practice plain and simple

#

No point in trying to defend it

winter pasture
#

Ok to be fair, isIP uses regex behind the scenes KEKW

// IPv4 Segment
const v4Seg = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
const v4Str = `(${v4Seg}[.]){3}${v4Seg}`;
const IPv4Reg = new RegExp(`^${v4Str}$`);

// IPv6 Segment
const v6Seg = '(?:[0-9a-fA-F]{1,4})';
const IPv6Reg = new RegExp('^(' +
  `(?:${v6Seg}:){7}(?:${v6Seg}|:)|` +
  `(?:${v6Seg}:){6}(?:${v4Str}|:${v6Seg}|:)|` +
  `(?:${v6Seg}:){5}(?::${v4Str}|(:${v6Seg}){1,2}|:)|` +
  `(?:${v6Seg}:){4}(?:(:${v6Seg}){0,1}:${v4Str}|(:${v6Seg}){1,3}|:)|` +
  `(?:${v6Seg}:){3}(?:(:${v6Seg}){0,2}:${v4Str}|(:${v6Seg}){1,4}|:)|` +
  `(?:${v6Seg}:){2}(?:(:${v6Seg}){0,3}:${v4Str}|(:${v6Seg}){1,5}|:)|` +
  `(?:${v6Seg}:){1}(?:(:${v6Seg}){0,4}:${v4Str}|(:${v6Seg}){1,6}|:)|` +
  `(?::((?::${v6Seg}){0,5}:${v4Str}|(?::${v6Seg}){1,7}|:))` +
')(%[0-9a-zA-Z-.:]{1,})?$');

function isIPv4(s) {
  return RegExpPrototypeTest(IPv4Reg, s);
}

function isIPv6(s) {
  return RegExpPrototypeTest(IPv6Reg, s);
}

function isIP(s) {
  if (isIPv4(s)) return 4;
  if (isIPv6(s)) return 6;
  return 0;
}
ancient nova
#

AND YOU SAID MINE WAS TERRIBLE

craggy pine
#

Just validates ips it looks like

#

ipv4's and v6's

ancient nova
winter pasture
#

I said it was easier to use the built in one kek

ancient nova
#

but the repetition

ancient nova
sudden geyser
#

isIP is a great example about regexs

ancient nova
#

SyntaxError: Unexpected token u in JSON at position 0

#

excuse me

winter pasture
#

Like I would rather have the node lib folks be responsible for the security and accuracy of isIP than myself

wheat mesa
sudden geyser
#

even though it isn't using its own parser we don't mind it since it's named

neat ingot
#

wish i could get that kinda traffic on my bot pages ๐Ÿ˜„

ancient nova
#

or is it?

winter pasture
wheat mesa
#

Iโ€™m going to trust the error

ancient nova
#

okay.. let me log the json

wheat mesa
#

Usually errors donโ€™t occur for no reason so itโ€™s probably malformed :p

neat ingot
winter pasture
#

lol

ancient nova
#

actually nvm

#

instead of getting the body and parsing it I'll just do response.json

#

I think that's better

neat ingot
#

you were still trying to parse the body after i found the json api? ๐Ÿ’”

ancient nova
#

let result = await response.json();

#

like so

winter pasture
ancient nova
#

I'm sorry

#

I didn't use any regex though ๐Ÿ˜„

neat ingot
ancient nova
winter pasture
#

Just mock some large Norwegian companies page layout

neat ingot
#

yea thats kinda like what i meant ๐Ÿ˜„

lyric mountain
ancient nova
#

the pro way of doing things ^

wheat mesa
winter pasture
#

As long as it is made in rust, it cant be slow right?

wheat mesa
#

True!

winter pasture
#

Rust = speed = not performant functions does not matter

wheat mesa
#

I generated a 188 million line py file with that one

neat ingot
#

nice! good solid logic there too.

wheat mesa
#

7gb

wheat mesa
#

Because it was auto generated

ancient nova
sudden geyser
#

should've had it generate rust

#

but no it's just python :(

wheat mesa
#

^

wheat mesa
quartz kindle
neat ingot
#

i vote converting it to jsfuck

#

is there a fk-ified rust? do that! ๐Ÿ˜„

winter pasture
ancient nova
#

[ZERO] STATUS: FAILURE REASON: WRONG TYPE OF DOMAIN GIVEN.

#

if (response.statusCode !== 200) {
console.log(white(\n${lineRepeat()}\n\n${cyan("[ZERO]")} STATUS: ${red("FAILURE")} REASON: WRONG TYPE OF DOMAIN GIVEN.\n\n${lineRepeat()}\n));
return recursiveAsyncReadLine();
}

#

why would it not be returning 200 if it gives me the json I'm confused?

neat ingot
wheat mesa
#

Uh

neat ingot
#

can at least rust to jsfuck ๐Ÿ˜„

neat ingot
# winter pasture

now that is the language that we should be using instead of regexp!

ancient nova
wheat mesa
#

thereโ€™s no way we gonna start a language war on esolangs right

neat ingot
#

what abbout that shakespear lang? ๐Ÿ˜„

wheat mesa
#

English lang solves the halting problem, best lang

neat ingot
#

thats just messing with my mind tbh

ancient nova
#

code in english zoomeyes
any other language โ›”

sudden geyser
wheat mesa
#

Lmfaoooo

#

Thatโ€™s amazing

ancient nova
wheat mesa
#

Works fine for me

neat ingot
#

same

ancient nova
#

node-fetch has either trouble fetching or somethings wrong with my code

wheat mesa
#

Should I write a json bytecode compiler

#

For the hell of it

ancient nova
#

I meannn if you want to

wheat mesa
#

That would be funny

#

I wouldnโ€™t need any ASTs, just parse and compile to bytecode

neat ingot
#

i preffer using bent over node-fetch. for just grabbing json its really nice and clean imo

ancient nova
#
                await fetch(`https://crt.sh/json?q=${_domain}`).then((response) => {
                    response.json((out) => {
                        resolvedResult = out;
                        resolvedResult = resolvedResult.map(value => value.name_value.split("\n"));
                        resolvedResult = resolvedResult.filter((value, index, array) => array.indexOf(value) === index && value.startsWith("*"));
``` basically my code
#

why does this not work?

neat ingot
#
const bent = require('bent')
const getJSON = bent('json')
let obj = await getJSON('http://site.com/json.api')
``` so clean โค๏ธ
ancient nova
#

I shall not

#

use that

neat ingot
#

well boooooo! ๐Ÿ˜›

ancient nova
#

I am keen on not using npms for things I can do myself

neat ingot
#

your using node fetch...

wheat mesa
#

Yeah, why use npm when you can make a 40,000 char regex am I right

ancient nova
#

.. so whattt?

#

node-fetch is good

neat ingot
#

thats a node package that you could have done yourself.

ancient nova
#

yesn't

#

basically yes but no

wheat mesa
#

In theory, you could just make node.js yourself!

ancient nova
#

well duh

#

but you won't

#

because your node.js will be bad

wheat mesa
#

Tell that to @earnest phoenix

#

๐Ÿ˜‰

neat ingot
#

didnt the node js dev go off and make deno or something?

wheat mesa
#

I donโ€™t think itโ€™s one node js dev

#

Itโ€™s a large team

ancient nova
#

I'm boutto ditch node-fetch and go back to request

neat ingot
#

one of the largest contributors afaik

winter pasture
#

Enable built in fetch

neat ingot
#

request? lmao

ancient nova
#

least better than http

ancient nova
earnest phoenix
#

How do I send a message that only he can see when he clicks the button?
isn't it like that?

winter pasture
#

Wut, Node 17 fetch is the same as browser

wheat mesa
winter pasture
#
    const res = await fetch(jobsApiUrl);
    const json = await res.json();

    console.debug(new Date(), `Found ${json.length} job postings`);

With node --experimental-fetch dist/index.js

wheat mesa
#

Node 17 fetch is literally just node-fetch built into node as a native package

#

They need to hurry up and overhaul the date API though

wheat mesa
#

Just sayin

sudden geyser
#

Oh wait read that wrong No I think I read it right

earnest phoenix
neat ingot
#

did you deferReply() before that?

#

if so, you need to use editReply instead of reply

ancient nova
winter pasture
#

Oh, I did not see the question ๐Ÿ™ˆ

neat ingot
#

ngl, it was the formatting that put me off

#

code should be beautiful!

winter pasture
#

I thought you was just sharing code lol

ancient nova
#

what's wrong with my formatting ๐Ÿ˜ฆ

quartz kindle
#

dafuq is that filter supposed to do?

ancient nova
wheat mesa
#

Yeah Iโ€™m just as confused

ancient nova
wheat mesa
#

Didnt really bother to look too much into it

ancient nova
#

I mean startWith

#

that's my bad

ancient nova
wheat mesa
#

Iโ€™m on mobile and I see callback hell, no thank you sir

wheat mesa
#

Isnโ€™t it supposed to be response.json().then(callbackHell => ...)?

#

Thought response.json() was a promise, isnโ€™t it?

ancient nova
quartz kindle
#

you mean this?

const response = await fetch(`https://crt.sh/json?q=${_domain}`).then(response => response.json());
const result = response.map(value => value.name_value.split("\n").filter(x => x.startsWith("*"))).flat();
ancient nova
#

that's why there's two ."then()"to resolve it

wheat mesa
#

Wtf is happening in this

ancient nova
wheat mesa
#

Why are you parsing the already parsed json data

ancient nova
neat ingot
# ancient nova what's wrong with my formatting ๐Ÿ˜ฆ

tell me this isnt nicer to look at!

try {
    const response = await fetch(`https://crt.sh/json?q=${_domain}`);
    const json = response.json();
    const filter = v => v.startsWith("*");
    const mapper = v=> v.name_value.split("\n");
    return json.map(mapper).filter(filter);
} catch (error) {
    console.error(error);    
}
ancient nova
#

thought that the string didn't parse to json

neat ingot
#

array.indexOf(value) === index is pointless too

wheat mesa
#

so many questions

ancient nova
wheat mesa
#

I suppose errors are a nice thing to look at too, if youโ€™re into that

neat ingot
#

๐Ÿ˜‚

ancient nova
#

no need for that

neat ingot
#

i have a custom console. SnorlaxDab ๐Ÿ’ช

#

fr tho ~ love it, so handy โค๏ธ

wheat mesa
#

What exactly is the point of that though

ancient nova
#

handly too

wheat mesa
#

To funnel console output to a file?

ancient nova
#

and looks nice cause I can have a custom background

neat ingot
#
const logger = new HTTPTransport({path});;
logger.log("some message sent to my server?! what?!");
ancient nova
#

opacity and many more

wheat mesa
#

Ah okay I see

#

That makes sense

ancient nova
#

let me show u an example

wheat mesa
#

I wasnโ€™t talking about your thing, but sure

neat ingot
#

I use it in my bot log handler, mostly for saving error files, but nice to have the options for http logging ๐Ÿ˜„

wheat mesa
#

(That sounded rude, didnโ€™t mean it like that)

ancient nova
#

you still wanna see it tho?

wheat mesa
#

Sure

ancient nova
#

also rate the GUI I talked so much about

neat ingot
#

preparestoroastrate

wheat mesa
neat ingot
#

uhh, synthwave 84 im sure

wheat mesa
#

Iโ€™ll have to give it a try

#

Personally I use Tokyo night but itโ€™s getting a little old

neat ingot
#

ive been using it for years now. makes things so easy to differentiate ๐Ÿ˜„

#

oh hey my rpc thing has like 11 stars on github ~ im a celebrity โค๏ธ

ancient nova
#

this is how it looks like

#

there's also mid level and low level errors

neat ingot
#

woah

ancient nova
#

fatal error is the one that normally would stop the application from continuing

wheat mesa
#

Fancy ANSI codes too

neat ingot
#

not gonna lie, that looks better than expected considering you rendered it with regexp ๐Ÿ˜„

austere surge
#

i tried to say great and amazing at the same time ;-;

neat ingot
#

where does this interface get displayed?

#

in an app? site? console?

ancient nova
#

display the ASCII text also

#

used a different encoding

neat ingot
#

ok i know how to c olor console text ~ my logger does that too ~ but how to get the bg image into the console? 0o

ancient nova
#

and the background is an overlayed image on top of the console. also used regedit to change the opacity

neat ingot
#

aahhhhhh

#

haxx

#

lol

ancient nova
#

it's like innovative as fuck

neat ingot
#

nice result though.. good job so far imo ๐Ÿ™‚

ancient nova
#

I never saw anyone actually do that

ancient nova
#

if you notice it's a V2

#

the V1 looks entirely different, and much worse

neat ingot
#

so uhhh, whats it actually do?

lyric mountain
ancient nova
#

at first I used it like a tool but then started turning it into a sort of program that can do anything

#

you can implement into codes that work as commands from almost any language

neat ingot
#

'do anything'

#

bold claims

ancient nova
#

right now you can do batch, javascript and python

austere surge
ancient nova
#

but plan to add more

ancient nova
neat ingot
#

so how long will it take for it to finish coding my bot if i give it the files?

ancient nova
neat ingot
#

but... you said... sadlinus

ancient nova
#

I bet I could write a program to code a bot for you though

#

but only a simple one

earnest phoenix
neat ingot
#

i was gonna do an app to build a bot, but then i seen the price on steam for well established competitor apps was pennies ~ not much point ๐Ÿ˜„

austere surge
#

i lost it doe

ancient nova
lyric mountain
#

ye

neat ingot
#

yea a few

lyric mountain
#

dbm, dbd, db(insert any letter here)

wheat mesa
#

Yeah, none of them are very good lmao

lyric mountain
#

nothing that codes for you is good

ancient nova
#

a lot of db

neat ingot
#

yea, the nicer looking ones are just like, meh, and the functional ones seem old af

craggy pine
#

"Discord Bot"

ancient nova
#

result.length is not a function

#

oh my god why

craggy pine
#

because it's not an array

ancient nova
#

I thought it was finally a json

craggy pine
lyric mountain
#

sometimes I wonder, how tf do yall code without ever pressing ctrl + space to check if something exists?

wheat mesa
#

An array length is a property, string length is a function, right?

lyric mountain
#

like, at least in java I can't really live without intellisense

wheat mesa
#

Or did js not take a page out of the Java book

neat ingot
#

array.length not array.length()

lyric mountain
#

you can't even have visual errors when something doesn't exist cuz in js everything is schrodinger

craggy pine
#

kinda neato

austere surge
#

loading moment

#

oh

neat ingot
#

soo... intellisense?

ancient nova
#

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Array

austere surge
ancient nova
#

finally found the error

#

wtf does this mean

craggy pine
#

data needs to be an array or string ect..

lyric mountain
ancient nova
#
                const response = await fetch(`https://crt.sh/json?q=${_domain}`).then(response => response.json());
                const result = response.map(value => value.name_value.split("\n").filter(x => x.startsWith("*"))).flat();
#

I used tims correction of my code

lyric mountain
#

I can't understand how people code without it

neat ingot
#

didnt know you coult ctrl+space to bring it up ๐Ÿ˜„

lyric mountain
#

tf

craggy pine
#

Kuu is a wizard

austere surge
#

i just try to type the name of what i think something is and it might appear

neat ingot
#

it just gets suggested when i type ๐Ÿ˜„

lyric mountain
#

also if ur using any jetbrains ide u can use alt + enter to open quick fixes

ancient nova
#

^ can anyone actually check what'ss wrong with my code this time

wheat mesa
#

Oh nvm

lyric mountain
#

and alt + insert to generate methods

wheat mesa
#

I always forget what flat does

lyric mountain
#

alt + O to generate overrides

ancient nova
#

so what exactly is wrong?

neat ingot
#
const arr1 = [0, 1, 2, [3, 4]];

console.log(arr1.flat());
// expected output: [0, 1, 2, 3, 4]

const arr2 = [0, 1, 2, [[[3, 4]]]];

console.log(arr2.flat(2));
// expected output: [0, 1, 2, [3, 4]]
wheat mesa
neat ingot
#

it flattens your array depth

wheat mesa
#

Just saying that stacktrace is very useful for debugging

ancient nova
#

it just shows simple error messages

ancient nova
lyric mountain
#

omitting the stacktrace is terrible

wheat mesa
#

I would consider adding it now

ancient nova
#

so should I start writing it again

neat ingot
#

^

ancient nova
#

I wanna go to sleep

lyric mountain
#

like, it exists for one single reason

wheat mesa
#

Stacktrace is one of the most important parts of an error

ancient nova
#

so rather

ancient nova
wheat mesa
#

Well to be honest, itโ€™s difficult to tell what that error is referring to without a stacktrace

ancient nova
#

unless it's something tiny

neat ingot
#

i mean, its as easy as~ instead of logging error.message, log the error object - stack trace ensues

wheat mesa
#

^

ancient nova
#

might use regex to separate stack trace from the error message

wheat mesa
#

Formatting isnโ€™t important when youโ€™re debugging :p

ancient nova
#

just this once

wheat mesa
#

I hope thatโ€™s a joke

neat ingot
#

format the logs that dont break your app ๐Ÿ˜„

ancient nova
#

soo want it looking nice

neat ingot
ancient nova
wheat mesa
#

I mean, if I owned a plane, I would rather it be painted with cow shit and fly than look nice and not fly

neat ingot
#

thats as formatted as your getting with a stacktrace

#

but at least you can figure out what went wrong

ancient nova
#

okay I now know how to fix it

neat ingot
#

in my case, i tried to eval 'breakme'

#

i love colorful logs โค๏ธ

#

i've missed them so much!! ๐Ÿ˜„

ancient nova
wheat mesa
#

๐Ÿ™‚

ancient nova
#

literally why??

#

why can I not

#

do

#

array.length on this

#

wait

neat ingot
#

show your code?

ancient nova
#

const response = await fetch(https://crt.sh/json?q=${_domain}).then(response => response.json());
const result = response.map(value => value.name_value.split("\n")); //.filter(x => x.startsWith("*"))).flat();

            const arrayLength = result.length();
#

just this

neat ingot
#

length() is not a function

#

length is a property

wheat mesa
#

Length is a property of arrays, not a function

#

Length is a function of strings

ancient nova
#

then who tf told me to do length()

#

when I asked about how to count arrays

austere surge
#

you

neat ingot
ancient nova
#

istg

#

๐Ÿ˜ญ

neat ingot
#

i was trying to count them with regexp, dunno what you guys were upto ๐Ÿ˜„

wheat mesa
#

Lmao

ancient nova
#

also you guys wanna know something

austere surge
#

sur

lyric mountain
#

btw, just a lil tip

#

filter before mapping

ancient nova
#

I have a piece of my code that literally breaks visual studio code's syntax highlighting lol

austere surge
#

nice

#

whats it

lyric mountain
#

it'll be slightly faster than mapping before filtering

#

less items to be processed

neat ingot
#

seems fair

ancient nova
#

a string from my lib

#

ignore the regex

wheat mesa
#

regex

#

Again

lyric mountain
#

yk, that function on the last line...

ancient nova
#

SAID TO IGNORE IT!!!

lyric mountain
#

wrong cropping makes it sus

neat ingot
ancient nova
austere surge
wheat mesa
#

I notice youโ€™re using a lot of the built in lambda functions like .map

lyric mountain
#

exatly KEKW

wheat mesa
#

Again not always the best solution to chain 40 of those together

lyric mountain
#

but well, you could change that regex with length

#

like, catch everything with length less than or equal to 2 chars

wheat mesa
#

No

#

Itโ€™s not mmulu

ancient nova
#

maybe a little fine

wheat mesa
#

Not really

#

Not gonna go back to the whole regex debate again though

#

Weโ€™d just go in circles

sudden geyser
ancient nova
#

almost

wheat mesa
#

Iโ€™m not saying that Iโ€™m just saying that mapping over and over and over seems wrong

neat ingot
#

what gets me is trying to cram 10 lines into one.

wheat mesa
#

Yeah

ancient nova
#

less bloat

wheat mesa
#

What lmfao

ancient nova
#

looks better

wheat mesa
#

The only thing less about that is readability

neat ingot
#

like, you know you can define your functions that you pass into functions like filter and map beforehand using es6 style arrow function decleration?

lyric mountain
#

doesn't sequential map chains get merged by the compiler?

sudden geyser
#

doubt it

wheat mesa
#

V8 will do what it wants to do

lyric mountain
#

chaotic neutral compiler

sudden geyser
#

I don't think any runtime can do that safely

#

at least in its current form

neat ingot
# ancient nova less bloat

worry about bloat when you ship your functional code, and then run it through a minifyer if its of concern, or an obfuscator if its not and needs protecting ๐Ÿ˜›

#

like, an extra line or two to help readability wouldnt hurt is all im saying ๐Ÿ˜„

lyric mountain
#

well yeah, we're probably talking about nanoseconds of difference

wheat mesa
#

I wasnโ€™t even talking about performance

lyric mountain
#

the time saved during maintenance will pay for it

wheat mesa
#

I was just talking about putting it on separate lines

ancient nova
#

I recently got an obfuscator wanted to test if anyone can deobfuscate it

wheat mesa
#

At the very least

#

Lmfao

ancient nova
#

for testing

lyric mountain
wheat mesa
#

Anyone can de obfuscate anything

ancient nova
#

purposes

wheat mesa
#

Just so you know

neat ingot
ancient nova
#

could you deobfuscate mine though?

#

I doubt it

wheat mesa
#

Deobfuscation is easy, obfuscation does nothing

neat ingot
#

ask the website ๐Ÿ˜›

ancient nova
#

200kb of code for only console.log("hello world")

neat ingot
wheat mesa
#

If you want to hide your code, donโ€™t let other people use your program :p

ancient nova
#

๐Ÿ˜‰

wheat mesa
#

There is always a way to get the source code of everything, unless itโ€™s on a remote server

austere surge
#

verytrue

lyric mountain
wheat mesa
#

Lmfao

sudden geyser
#

or that node-ipc dude