#development

1 messages · Page 115 of 1

quartz kindle
#

{ ...{ key: value } }

surreal sage
#

ya

quartz kindle
#

or like this

surreal sage
quartz kindle
#

Object.assign({}, { key: value })

surreal sage
#

i aint writing allat

quartz kindle
#

nub

#

this is not correct

#

if x is a primitive, it will be a copy, not a reference

#

it should change it, but depends how you did it

#

show code

#

for example:

neon leaf
quartz kindle
#
globalObject = { a:10 };

x = globalObject;
x.a = 20
console.log(globalObject) // { a: 20 }

// but

x = {} // this is a new object, not a reference
x.a = globalObject.a // this is a copy of the value from one object to another
x.a = 30;

console.log(globalObject) // { a: 20 }
quartz kindle
#

however

#

if the value of a is another object inside the object instead of a number

#

then x.a = globalObject.a will not be a copy

#

it will still be a reference

neon leaf
#

I am confused

hushed robin
#

welcome to the club!

quartz kindle
#
obj = { a: 10, b = {} }

x = {}
x.a = obj.a; // this is a copy, because a is a primitive
x.b = obj.b; // this is a reference, because b is an object
neon leaf
#

that makes sense

#

but why isnt it working in my scenario where I have an array of objects?

quartz kindle
#

which one from your code is causing the issue?

#

which variable

neon leaf
#

this.routes

quartz kindle
#

its a new object, its not the same as the other object

neon leaf
#

oh

#

it still doesnt seem to work though after removing that

#

actually

#

no, its working, some of the time

quartz kindle
#

its still another object

#

not the same reference

neon leaf
#

how can I do that part while keeping it a ref? with a loop and manually assigning?

quartz kindle
#

you need to make everything a reference to the same object

#

without ever using = { ...

#

for example assign the object then edit the props

#

or use Object.assign

#

a = Object.assign(originalref, newProps)

#

a will still be a reference to the original

#

but the new props will be added

neon leaf
#

oh true

quartz kindle
#

so they will be added to the original as well

neon leaf
#

I thought it would always make a new ref

quartz kindle
#

{ ... } yes, but object.assign no

#

{ ... } is always a new ref, because its creating a new blank object, and then filling it

#

Object.assign uses the object in the first param as the base object

#

{ ... } is the same as Object.assign({}, ...)

#

assigning to a blank object

neon leaf
#

yup, thats what I confused it with

#

yup, working

#

thank you so much!

quartz kindle
#

👍

neon leaf
#

do you know if its possible to manually delete something from memory? like I have some cases where I dont want to wait for gc to clean up some buffers, arrays and strings

surreal sage
#

With Mongoose,
Talking about a Schema
I have

        action: {
            type: String,
            enum: ["log", "kick", "ban", "warn"],
            required: true,
        },```
Is there a way to make it fall back to e.g "log" if the value is not one of enum?
#

action: "log" Check
action: "abc" Thumbsdown 👉 action: "log"

wheat mesa
#

Keep in mind that if you have something that depends that heavily on performance, js might not be the proper language to choose from

#

If you want to manually manage memory consider a lower level language like C(++) or Rust

quartz kindle
#

its possible to manually run the gc using the expose gc flag in node

#

but thats a node-only thing (and maybe in some other engine as well)

neon leaf
#

its fine if only node

quartz kindle
#

but running the gc manually does not guarantee your object will be targeted

#

and its not really a good idea

neon leaf
wheat mesa
#

Gc will always decide when to get rid of something

quartz kindle
wheat mesa
#

iirc js uses reference counting right tim?

quartz kindle
#

gc uses a lot of factors when deleting things from memory

#

including delays and timings to avoid blocking the process

#

so even if an object is marked for deletion, it may only be deleted later, when the timing is right

wheat mesa
#

Mark and sweep algorithms my beloved c:

quartz kindle
neon leaf
#

my current problem is that if you for example upload like a 1gb file it will stay in memory for like 15 sec after the request finished

quartz kindle
#

but its up to the implementers to decide

#

so its pretty much an engine-specific feature

#

not part of the js spec

quartz kindle
#

use streams

wheat mesa
neon leaf
#

sometimes you do need the whole file though

quartz kindle
#

why?

neon leaf
#

I need very large jsons for server management, up to 100mb

#

I dont think you can do that in any way with streams

quartz kindle
#

json is lot really a good format for such large storage lol, cant you use a database?

neon leaf
#

its basically a ton of instructions to execute on a linux vps, like a ton a ton

quartz kindle
#

there are some libs that can parse json in a stream-like manner

#

but if its instructions for a linux vps, isnt it something you should be able to do outside of node?

neon leaf
quartz kindle
#

for example, upload the file to disk using streams, then use shell tools to edit it

quartz kindle
#

it would be slower yes, but do you really need a config file to be that performant?

neon leaf
#

true

#

then I guess Ill give the user an option for manual body handling

quartz kindle
#

there are libs that can manage json files in a partial manner, without loading its entirety

wheat mesa
#

What kind of instructions need hundreds of mbs of data 😭

neon leaf
quartz kindle
#

could probably compress that

#

then uncompress and parse in the target machine

undone rose
#

Why do this in node instead of rust or similar

neon leaf
#

because I still havent found a language which has a syntax I like better than js / ts

wheat mesa
#

Syntax shouldn’t be more important than performance (if you need it, which here you do) unless it’s completely unusable but ok

quartz kindle
#

this use case has nothing to do with performance

#

its all about I/O

#

network and disk speeds are pretty much the only factors here

wheat mesa
#

I suppose, but he did say that he wanted the memory to be freed quickly instead of taking up tons of space for longer than the request needed

quartz kindle
#

thats just a matter of streaming

#

well sure, a manual memory language will give you the ability to clear memory sooner

#

but you're still gonna be bloating your ram in and out

#

in some way

hushed robin
#

how do i fix this error with typescript TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"

wheat mesa
#

show your code my man

#

you don't import things via .ts files

hushed robin
wheat mesa
#

...how are you running this

#

what are you using

quartz kindle
#

are you doing node file.ts?

wheat mesa
#

please tell me you didn't do that

#

please 😭

hushed robin
quartz kindle
#

nub

hushed robin
#

bruh

quartz kindle
#

node cannot run ts files

hushed robin
#

why not

quartz kindle
#

ts needs to be compiled into js

#

using tsc

#

but you can use ts-node which is a package that basically does that for you

#

install ts-node as a global package: npm i -g ts-node
then you can run: ts-node index.ts

wheat mesa
hushed robin
#

ok

quartz kindle
#

but the correct way is to build using tsc then run the js files

covert gale
#

Uh

#

Wait

wheat mesa
#

usually you have an out directory for the compiled files

hushed robin
#

cannot be loaded because running scripts is disabled on this system. For more information, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

wheat mesa
#

ah yeah tsc is kinda dumb sometimes

wheat mesa
#

use tsc.cmd

hushed robin
#

what is tsc.cmd

wheat mesa
#

it's just another command for tsc

#

but it doesn't make windows mad

hushed robin
#

where is it

quartz kindle
#

dafuq

#

never had to do that on windows lol

#

just install typescript globally

#

npm i -g typescript

wheat mesa
quartz kindle
hushed robin
#

oh wait

#

it's working in command prompt

quartz kindle
#

follow the link to see how to do that

hushed robin
#

but no in visual studio code terminal

hushed robin
quartz kindle
#

this is a windows security feature that you can disable
follow the link to see how to do that

hushed robin
#

ok

#

what about typeerror tho

quartz kindle
#

did you read what we said about tsc and tsnode?

#

.>

hushed robin
#

yes

#

i did ts-node file.ts

quartz kindle
#

The “Unknown file extension .ts” error occurs in ts-node occurs when "type": "module" is set in your package.json file. To fix it, run the TypeScript file with ts-node --esm my-file.ts, or remove "type": "module" from your package.json file.

hushed robin
#

Cannot find module './config.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.

#

bruh

#

typescript is so buggy

solemn latch
#

thats not a bug

hushed robin
#

but it's erroring when i import config file

solemn latch
#

Its a feature.

hushed robin
#

yay

#

i got typescript working

lyric mountain
#

like, a common user is very unlikely to use pshell at all

#

and an advanced user would fucking know what they're running, I suppose (if not they'd simply use cmd anyway)

#

any virus would also use cmd instead of pshell to execute scripts

hushed robin
#

bro

#

i can't even do if statements in ts without errors

#

oh wait

#

client.once

#

i meant event.once

#

hahahaha

lyric mountain
#

ur moving to ts?

hushed robin
#

yes

quartz kindle
#

thats what ts is for, it warns you of all possible things

#

to help you write stronger more correct code

lyric mountain
#

I'd attempt a practice project before trying to migrate ur bot

quartz kindle
#

id also recommend enabling strict mode in your tsconfig

lyric mountain
#

there's A LOT you'll need to relearn

#

if u learned it before, that is

hushed robin
#

Property 'commands' does not exist on type 'Client<boolean>'.

lyric mountain
#

anyway, a bunch of things u could do in js you wont be able to do anymore

#

which is good, but it'll force u out of zone of confort

hushed robin
lyric mountain
#

not "less", but "more correctly"

hushed robin
#

oh ok

lyric mountain
#

for example you'll need to learn to use typing

hushed robin
#

it works in js

#

but ts is angry

lyric mountain
#

so ```js
let a = 1
a = "test"

is no longer valid
lyric mountain
hushed robin
#

how do i do it in javascript

lyric mountain
#

a previously js project WILL NOT work in right away in ts

#

you'll need to rewrite it

hushed robin
#

well this isn't an existing project

#

i'm just making a practice bot

lyric mountain
#

cant u start with something simple

#

like a calculator or a "hello world" program

#

start correctly ffs

hushed robin
#

console.log('hello world')

#

?????????????????

#

also if i make a calculator don't i also need to make a website

#

that's too hard

lyric mountain
#

no

#

u can make it console-only

quartz kindle
#

ts uses static types, which means everything in ts needs to have fixed type annotations
for example, you cannot do client.a = something because client is already defined as having a set list of types that djs provides, so it detects that you are adding something that is not in the list, therefore not allowed
to do client.a = something you need to change the type of client to make room for a new custom property, there are many different ways to do that, one way is for example like this:

const client = new Client(...) as Client & { something: typeofsomethinghere }
hushed robin
#

i think a calculator is too easy also

#

eval(1 + 1)

lyric mountain
#

but without eval

hushed robin
#

idek how to do math calculations without eval

lyric mountain
#

u can do it with a bunch of switch-cases

#

or a bunch of ifs

hushed robin
#

ah

#

that works beautifully

#

w

lyric mountain
#
> Input first number:
< 1
> Input operation:
< /
> Input second number:
< 2
> Result: 0.5
#

like this

hushed robin
#

i mean

#

that's really simple too

lyric mountain
#

yes, but is great to start

hushed robin
#

ok

#

i will do that first

lyric mountain
#

wait what

#

who are you?

hushed robin
#

what

#

i am battleless

quartz kindle
#

the one and only infamous battleless

lyric mountain
#

it's weird, but he's becoming a real dev now

wheat mesa
lyric mountain
#

who knows, maybe the jokes will finally end

hushed robin
#

bruh

#

how do i take responses in terminal

wheat mesa
#

I usually do something like ```ts
export class MyClient extends Client {
public commands: Collection<string, Something>
}

hushed robin
#

it works fine

#

no errors

wheat mesa
#

There is nothing wrong with it

#

It's just a little hacky

lyric mountain
#

first answer

wheat mesa
#

or RPN

#

or pratt parsers

#

or anything >:)

lyric mountain
#

lmao no need for bodmas yet

wheat mesa
#

just... not for battleless

lyric mountain
#

he's going the right path this time

#

I just hope he stays till the end

#

the old battle wouldn't even get near TS

wheat mesa
#

I won't believe it till I see it

#

From what I'm seeing he was just hopping on the bandwagon because we were saying how great it was

#

I feel it's a matter of time before he starts complaining

quartz kindle
#

he complains like crazy but he slowly does accept what we say and slowly does accept changing his ways and trying new things

#

so he is progressing

wheat mesa
#

inb4 "what's a type"

#

in a month it'll have been a full year since detritus got a commit :c

quartz kindle
#

i type you type we type

wheat mesa
#

makes me sad

quartz kindle
#

rip

lyric mountain
#

detritus died?

wheat mesa
#

yeah

#

May 20th 2022 was the last commit to the beta branch

#

As for the master branch the last merge was September 21st 2021

#

it's crazy how fast time blows by

lyric mountain
#

js/ts frameworks are literally rabbits in the wild

wheat mesa
#

man I just wrote the most scuffed line of code I've written in a while

lyric mountain
#

10 are born, only 2 or 3 stay alive to reproduce

wheat mesa
#

this is so fucking bad

#

but

#

whatever

#

it works

#

™️

lyric mountain
#

lmao

wheat mesa
#

I'm gonna torture my friend and make him javadoc everything

#

To be fair I've committed almost 1000 lines today alone

lyric mountain
#

javadocs are easy to write but oh damn there are a fuckton of stuff to javadoc

wheat mesa
#

Yeah

lyric mountain
#

I think I surpassed 200 javadocs on my lib

wheat mesa
#

Is there a way to count how many functions I have with intellij

lyric mountain
#

and it's not even a big lib

#

kinda

hushed robin
#

this is so difficult

lyric mountain
#

u can scan for non-doc'ed functions

#

at least in gradle/maven

wheat mesa
#

not using gradle or maven B)

lyric mountain
#

idk for pure java, but there's probably a way

lyric mountain
#

but it's worth the effort in the long run

hushed robin
#
const errors = {
    notNumber: 'Please input a number!',
    notOperator: 'Please input a valid operator!',
};

process.stdout.write('Input your first number: ');

process.stdin.on('data', (input) => {
    const firstNumber = Number(input);

    if (isNaN(firstNumber)) {
        console.log(errors.notNumber);
        process.exit();
    };
  
    process.stdout.write('Input your operator: ');

    process.stdin.on('data', (input) => {
        const operator = input.toString().trim();
    
        if (!['+', '-', '*', '/'].includes(operator)) {
            console.log(errors.notOperator);
            process.exit();
        };
    
        process.stdout.write('Input your second number: ');
    
        process.stdin.on('data', (input) => {
            const secondNumber = Number(input);

            if (isNaN(secondNumber)) {
                console.log(errors.notNumber);
                process.exit();
            };

            let result;

            switch (operator) {
            case '+':
                result = firstNumber + secondNumber;
                break;
            case '-':
                result = firstNumber - secondNumber;
                break;
            case '*':
                result = firstNumber * secondNumber;
                break;
            case '/':
                result = firstNumber / secondNumber;
                break;
            };

            console.log('Results:' + result);

            process.exit();
        });
    });
});

???

lyric mountain
#

statically typed langs are able to catch 80% of the errors before running it

hushed robin
#

wtf

#

why is it saying please input a number

lyric mountain
#

hm

#

ur checking if it's a number on all 3 steps

hushed robin
#

how

lyric mountain
#

don't use stdin.on, use the await method I sent earlier

wheat mesa
#

jesus

#

christ

lyric mountain
#

it'll allow a more predictable flow of code

lyric mountain
hushed robin
#

what await method

wheat mesa
#

I HAVENT EVEN ADDED FUCKING COLLISION YET

lyric mountain
wheat mesa
#

This is also only counting public methods, I have a ton of protected methods that need to be documented too

hushed robin
#

yay

lyric mountain
#

write the function once, reuse it for all 3 values

hushed robin
#

i fixed it

#

i just changed .on to .once

#

and now it works

lyric mountain
#

on-demand function would be cleaner

wheat mesa
lyric mountain
#

that way u dont need 3 levels of nesting

hushed robin
#

true

#

ok

lyric mountain
#

you'll need something to practice with arrays too, since they're declared different too

#

and maps ig (this let map = {})

#

other than that there's likely not much before jumping to bot

#

oh, there are classes

hushed robin
#

Argument of type 'unknown' is not assignable to parameter of type 'number'.

#

bruh

lyric mountain
#

but most dont use classes

wheat mesa
#

I'm gonna need to decrease the quality of my javadocs if I ever want to finish this project

lyric mountain
wheat mesa
lyric mountain
#

every variable needs a type

#

functions too

#

in this case you need to specify that the function will return a promise

hushed robin
#

how do i assign types

wheat mesa
#

(Typescript can infer the types IF it has data to infer from)

#

let variable: Type = ...

lyric mountain
#

so it's somewhat close to java's var

wheat mesa
#

But keep in mind you don't need this for everything if you're doing something like ts let num = 5; since ts can see that num is clearly assigned a number value

#

if it complains about a type, you probably need one

#

also, avoid using : any most of the time

covert gale
#

ok so

#

big thing

#

i need ui help

#

i suck ass at frontend

#

i have no idea how to make this look good

#

the colors look ass

#

text looks ass aswell

wheat mesa
#

you need a color scheme

covert gale
#

and i still have yet to add buttons

covert gale
hushed robin
#

const firstNumber: number = await prompt('Input your first number: ');

#

still getting error

#

Type 'unknown' is not assignable to type 'number'.

wheat mesa
wheat mesa
hushed robin
wheat mesa
#

Basically, you need to cast it

#

const firstNumber = await prompt("...") as number;

#

You could also validate input, which I highly suggest doing

#

(Since that's kind of the point of ts)

hushed robin
#

ok wtf

#

now when i try running my file

#

it opens up the video playing app

#

????????

wheat mesa
#

brother

#

you can't just click on it

#

you have to compile it with tsc and then run it with node

#

you can't double click on it... it's not an executible

lyric mountain
#

depending on ur IDE u can also simply click on "execute"

hushed robin
#

no

#

i'm doing ts-node calculator.ts

#

and then it's opening up video playing app

#

with my old code it wasn;t

lyric mountain
#

did u mistakenly remap the default opening program?

#

try returning to the old code to see if it still happens

covert gale
#

ugh i still cant find good colors

hushed robin
#

button is too fat

wheat mesa
#

after we told him how to run it

#

it's quite hilarious

#

.ts is a video extension according to windows

hushed robin
wheat mesa
#

What are you doing

hushed robin
#

as i said i'm doing ts-node calculator.ts in command prompt

wheat mesa
#

tsc.cmd calculator.ts && node calculator.js

hushed robin
#

but why is it opening up video player

#

with my old code it doesnt

#

i just tried

pale vessel
#

transport stream lol

hushed robin
#
import readline from 'readline';

const errors = {
    notNumber: 'Please input a number!',
    notOperator: 'Please input a valid operator!',
};

function prompt(input: string) {
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout,
    });

    return new Promise(resolve => rl.question(input, ans => {
        rl.close();
        resolve(ans);
    }))
};

(async () => {
    const firstNumber = await prompt('Input your first number: ') as number;

    if (isNaN(firstNumber)) {
        console.log(errors.notNumber);
        process.exit();
    };

    const operator = await prompt('Input your operator: ') as string;

    if (!['+', '-', '*', '/'].includes(operator)) {
        console.log(errors.notOperator);
        process.exit();
    };

    const secondNumber = await prompt('Input your second number: ') as number;
    
    if (isNaN(secondNumber)) {
        console.log(errors.notNumber);
        process.exit();
    };

    let result;

    switch (operator) {
        case '+':
            result = firstNumber + secondNumber;
            break;
        case '-':
            result = firstNumber - secondNumber;
            break;
        case '*':
            result = firstNumber * secondNumber;
            break;
        case '/':
            result = firstNumber / secondNumber;
            break;
    };

    console.log('Results: ' + result);

    process.exit();
})();
#

this is my new code btw

covert gale
#

this color kinda works

#

needs shadow tho

lyric mountain
hushed robin
#

i think typescript is broken

lyric mountain
#

Likely just windows being weird

#

Did u try running with the command line waffle sent?

hushed robin
#

it said like

#

blah blah blah is not a command

#

tsc.cmd' is not recognized as an internal or external command

lyric mountain
#

Hm, did u install ts today?

hushed robin
#

wym install ts

lyric mountain
#

Tsc, didn't u add it to path?

#

Else windows won't know where to look for

hushed robin
lyric mountain
#

If u installed with node it should've added automatically

hushed robin
#

what

#

wym

lyric mountain
#

After that reopen the terminal window and try again

#

It should now find tsc

hushed robin
#

bruh

#

it returned like

#

12 errors

lyric mountain
#

On the code or on the terminal?

hushed robin
#

in termal

lyric mountain
#

What is it saying?

boreal iron
#

You can also add the path of the executable to the known environment paths in Windows to run it globally without using the path

hushed robin
#

Cannot find name 'process'. Do you need to install type definitions for node? Try npm i --save-dev @types/node

#

stuff like that

lyric mountain
#

Dependencies ig

hushed robin
#

bro

#

why do i have to do all this

#

ts-node worked before why not now

lyric mountain
#

Follow what it says until it finishes installing

hushed robin
lyric mountain
#

Idk, did u do something different?

hushed robin
#

uh no

hushed robin
#

the old code works fine

lyric mountain
#

Try running a simple console.log() file

#

If it doesn't work then something probably happened with tsc

hushed robin
#

with ts-node?

#

or

lyric mountain
#

Yes, ts node

hushed robin
#

what waffle said

#

ok

lyric mountain
#

Put it in a ts file

#

Perhaps u ran with node before instead of ts-node

hushed robin
#

yes it works

lyric mountain
#

Odd

#

Try using some kind of typing

#

Like, declare a typed variable and print it

hushed robin
#

oh wtf

#

it's working now

lyric mountain
#

?

hushed robin
#

idk what happened earlier but it's working now

#

w

lyric mountain
#

Windows things ig

hushed robin
lyric mountain
#

But well, did it work as expected?

hushed robin
#

yes

lyric mountain
#

Nice, now try setupping a simple ping bot

hushed robin
#

oh wait

#

no

lyric mountain
#

Then start writing commands as you go

hushed robin
#

it's not

#

divide works

#

but add

#

it like

#

adds it to the end

lyric mountain
#

Did u cast it to number?

hushed robin
#

wym

#

what does that mean

lyric mountain
#

as number

hushed robin
#

yes

quartz kindle
#

casting it is not enough

hushed robin
#
const firstNumber = await prompt('Input your first number: ') as number;
const secondNumber = await prompt('Input your second number: ') as number;

case '+':
            result = firstNumber + secondNumber;
            break;
quartz kindle
#

input from cmd is done as strings

#

you need to actually convert it into a number

hushed robin
#

bruh

#

why does divide work then

lyric mountain
#

parseInt then

quartz kindle
#

or Number()

lyric mountain
#

/*- arent valid string operations

quartz kindle
#

js tries to guess the best way to do operations on dynamic types

lyric mountain
#

So it knows you want a numeric operation

#

But + is a valid string operation (concat)

hushed robin
#

wait

lyric mountain
#

So it thinks you want to concat

hushed robin
#

how do i do parseInt

#

without making new variable

quartz kindle
#

parseInt(await prompt)

hushed robin
#

errors

#

Argument of type 'unknown' is not assignable to parameter of type 'string'.

lyric mountain
#

Use Number() as tim said, since you might input a decimal too

quartz kindle
#

thats where you can cast it as string

hushed robin
#

what

#

i do

quartz kindle
#

Number((await prompt()) as string)

hushed robin
#

oh

#

ok

#

it's working now

#

w

lyric mountain
#

It's also worth to attempt using git too, as it's a very important tool for larger projects

hushed robin
#

i mean

#

i do use git

lyric mountain
#

And u can keep ur practice projects there as a progress showcase

#

Nvm then

hushed robin
#

but what i want to learn to do is

#

make it so when i commit something

#

it resets my project with new code

#

i tried once but it didn't work properly

#

it reseted it but not with the new code

lyric mountain
#

To save to remote:
git add .
git commit -m "some message"
git push

#

To get the updated code:
git pull

hushed robin
#

yes

#

but

lyric mountain
#

It won't reset anything, it'll just update the project with the newly added code

hushed robin
#

i want it to do it automatically

lyric mountain
#

For that you'd need to setup some kind of tool to track remote status

#

It's not a good idea, as it might break often

#

And any small change will restart the bot

#

pm2 likely has that feature

#

At least ik it can track folder changes

hushed robin
#

i did it before but it didn't update code

#

i think i used github actions

lyric mountain
#

Did it report any error?

hushed robin
#

idk

#

i just removed it

#

cus i couldn't figure it out

lyric mountain
#

Go with manual git for now, at least you can ensure it doesn't update code when unnecessary

#

Also possible to make a bot command to do it

#

As node can run commands

wheat mesa
#

@lyric mountain can you tell me if this thought process sounds right?

#

I need to make a layers system, and I was originally thinking about just using a map like you said, but the more I think about it, the more it seems like a possibility to just maintain a sorted list of entities to loop over

#

I was thinking that inserting into a sorted list could be O(log(n)) time too because you (I think?) could basically use a binary search for insertion

#

And it doesn't sound like a terrible idea

lyric mountain
#

Treeset uses binary search for all operations

#

The map method has the advantage of not needing sorting at all, it'll at worst be 2 operations

wheat mesa
#

Yeah that's fair

lyric mountain
#

Thoss being map.get() and set.get()

wheat mesa
#

I'm just trying to think about how to modify my ECS to handle it

lyric mountain
#

But it does use more ram than a treeset as you'll be maintaining N sets, instead of 1

#

N being the number of layers

wheat mesa
#

RAM I couldn't care less about

#

I can deal with a few extra mb of allocation

lyric mountain
#

Another advantage is that you can easily discard most entities from collision check

#

If u make different layers not able to collide

#

Otherwise ignore this part

wheat mesa
#

Yeah that's true

lyric mountain
#

Java collections are really memory efficient

#

Try implementing both systems, see which one performs better for your use-case

hushed robin
#

what does the backend of a website mean

lyric mountain
#

The server itself

#

As in, the part not visible to the user, the api

hushed robin
#

oh isee

#

makes sense

#

what if theres no api

lyric mountain
#

A site with no backend is called a static site

hushed robin
#

why

lyric mountain
hushed robin
#

i can write javascript code in the pages files

lyric mountain
#

It's static because you get what you see

#

Dynamic sites might change content with or without user interaction

#

Like a blog

hushed robin
#

but couldn't i do things like API requests?

#

how would that be static

lyric mountain
#

If u use api requests then it does have a backend

#

Even if not yours

hushed robin
#

so for a website

#

i need an api

#

?

quartz kindle
#

no

hushed robin
lyric mountain
#

A purely informational site can fare well without backend

pale vessel
#

I think u should stick to playing roblox

lyric mountain
#

You don't need a backend for every site

#

For example, a portfolio wouldn't benefit from having one

quartz kindle
#

static website = server that holds html/css/js files, when website is accessed, the browser downloads those files and shows them to the user
dynamic website = server that runs a software that receives requests in real time and runs some code then responds with some html+css+js response generated dynamically based on the request type and content

hushed robin
quartz kindle
#

no?

#

a static website is not an api

#

neither is a dynamic website technically

hushed robin
#

but i want my website to show the data i have

lyric mountain
#

Your api would be a webserver running somewhere listening to requests

#

Your site would merely call it to retrieve data

quartz kindle
#

an api is something different, its application programming interface, which means there is an open endpoint that provides some kind of interaction, related to or not related to the website

hushed robin
#

so do i need one to do that

lyric mountain
#

Yes

hushed robin
lyric mountain
#

You can achieve it with express if you're going with js/ts

hushed robin
#

but

#

i want both my bot and website to be able to access the data

#

but i'm using sqlite so it's a file and can only be in one folder

lyric mountain
#

No prob, just have both call the api

hushed robin
lyric mountain
#

Make the api be the only one accessing the database

hushed robin
#

so should i make the api separate from both

lyric mountain
#

Optimally, yes

#

As you'll have a decoupled project

#

So if u ever need to restart the bot it doesn't take the api down

hushed robin
#

true

#

but

#

right now i collect all the data through the bot

#

so i will need to remove that and put it somewhere else uhh

#

but how will i do that with express

lyric mountain
#

You can make an endpoint to insert data

#

Api doesn't necessarily need to be read-only

hushed robin
#

hm

#

wouldn't it be better to do it seperately tho

#

cus if bot down

#

then it will no longer collect data

lyric mountain
#

Nothing u can do about that

#

Actually, what data are we talking about?

#

Is it steam data?

hushed robin
#

no

lyric mountain
#

User data?

hushed robin
#

no

lyric mountain
#

So what?

hushed robin
#

game data

lyric mountain
#

But collecting from where?

hushed robin
#
Roblox

Roblox is ushering in the next generation of entertainment. Imagine, create, and play together with millions of people across an infinite variety of immersive, user-generated 3D worlds.

lyric mountain
#

If it's not from discord, just make the api collect it instead

hushed robin
#

how do i do that

#

idk howw

lyric mountain
#

The same way u did on the bot

#

If it's a command, make it an endpoint

#

Imagine your api is just like someone using a discord command

hushed robin
#

but

#

how will i make it collect the data

#

the endpoint will not collect the data itself

lyric mountain
#

How does the bot do it?

hushed robin
lyric mountain
#

Just do it the same way on the api

hushed robin
#

but

#

how will that work

#

how will endpoint run itself

lyric mountain
#

A bot is literally an api for discord

#

U can make periodic tasks on it too

#

You can make anything you want on the api, it doesn't need to be a request -> answer thing

hushed robin
#

hm

#

ok

#

can anyone see what i do

#

on api?

#

like can they see the code that runs

lyric mountain
#

Not unless you expose it as an endpoint

#

Code is always hidden from the end user

#

They just see what u show them

hushed robin
#

ok

#

thats good

lyric mountain
#

Just dont do shady things

hushed robin
#

for my api i don't need a domain right

lyric mountain
#

Technically, no

#

But it's recommended

hushed robin
#

er

lyric mountain
#

As your site will be calling the api, so people could see your ip

hushed robin
#

but even if i have a domain, can't they see the ip anyways?

lyric mountain
#

They'll only see the domain

#

If you use cloudflare, they'd not be able to see the ip behind the domain even

hushed robin
#

so they can see the ip?

lyric mountain
#

They can see which url you're sending requests to

#

If it's a domain, they can use whois to find out which ip is behind it

hushed robin
#

so, yes

#

so whats the point in the domain uhh

lyric mountain
#

You can make it point to cloudflare

#

domain -> cloudflare -> ip

#

So if they use whois, they'd see cloudflare dns ip

#

Not your real ip

#

The same works for any dns provider

hushed robin
#

is that easy to setup

lyric mountain
#

I think so, just follow a guide

hushed robin
#

hm

lyric mountain
#

Don't worry about it for now

hushed robin
#

all this seems very difficult and if i make a mistake it can end bad uhh

lyric mountain
#

It is if you focus on everything at once

#

Focus on one thing at a time

#

First you need and api, then the site

#

Or the other way around, whatever works for you

#

Only then focus on hiding your ip

#

Also don't make the site public while developing, nobody needs to see an unfinished project

hushed robin
#

should I make the API with TypeScript

lyric mountain
#

Up to you

#

TS is easier to find code errors, but takes more effort (which you save later when debugging)

hushed robin
#

i'll figure that out later

wheat mesa
#

@lyric mountain turns out the treemap solution was really easy to implement and it works like a charm, thank you C:

hushed robin
#

hm

hushed robin
#

how do i even use a domain with express

lyric mountain
#

You don't, you setup the domain on whatever you're using as a webserver

#

Like nginx or apache

quartz kindle
#

you can use node directly, but you need to run it in port 80/443

#

which requires root

hushed robin
#

but why can't i just do it on node

#

when i was testing my api before i just did node index.js

lyric mountain
#

Safety issues

quartz kindle
#

node by default does not run on the root/sudo user

#

ports smaller than 1024 are protected and reserved for root/sudo users only

lyric mountain
#

Also setupping ssl will be awful

quartz kindle
#

so you need to either allow ports somehow or run node as root/sudo

#

then it will work

hushed robin
#

can i use pm2 with nginx

lyric mountain
#

Nginx runs by itself

lyric mountain
#

It's not something u have to start everytime

hushed robin
#

wym

#

start everytime

lyric mountain
#

In windows you'd call it "a service"

boreal iron
#

Putting another webserver to proxy his node process

covert gale
#

Just use docker compose

#

Like simple

lyric mountain
#

It's a background process that works on its own

hushed robin
#

nginx is where is where i'm suppose to do rate limiting and stuff right

covert gale
#

Learn docker compose

#

So much easier

covert gale
#

U can do it in your code aswell

hushed robin
covert gale
#

But nginx can aswell

hushed robin
#

's not good

covert gale
boreal iron
covert gale
#

It’s running code inside the vm

boreal iron
#

Handling traffic on this network layer is just stupid

hushed robin
#

is it easy to do that stuff with nginx

covert gale
#

Yes

#

Try nginx proxy manager

#

For GUI

lyric mountain
#

It takes some practice to learn to use it, but I find it much easier than apache

boreal iron
#

Wut

lyric mountain
#

Fuck xml

hushed robin
#

whats nginx proxy manager

boreal iron
#

Nginx is far more annoying than Apache

hushed robin
#

which should i use

covert gale
#

Does nginx stuff but with web gui

hushed robin
#

oh

#

that sounds complicated

lyric mountain
#

Let's say you have 5 of the same api, each running in a different server

#

With nginx you can send the request to the least busy api, for example

hushed robin
#

hm ok

lyric mountain
#

But don't bother about it for now

hushed robin
#

is nginx used by big companies?

boreal iron
#

To be fair

#

Round robin or generally load balancing isn't something nginx exclusive

lyric mountain
#

Ik

boreal iron
hushed robin
#

i don't really wanna pay for a domain tbh uhh

covert gale
#

Local tunnel?

hushed robin
#

i have one but it's for another project

covert gale
#

Or duckdns

hushed robin
#

i could use it

lyric mountain
#

Make the site first, focus on presentation later

hushed robin
#

true

lyric mountain
#

The domain is useless if you don't have something to use it for

hushed robin
#

i will make the API first

#

with typescript

#

i can use express with typescript right?

lyric mountain
#

Yes

hushed robin
#

ok

lyric mountain
#

Anything useable with js can be used with ts

#

As ts compiles to js

#

Transpiles

hushed robin
#

so since the code i use to collect data is a function

#

can't i just copy the function to my api project and use a cron job like i do on the bot

lyric mountain
#

Ig so

hushed robin
#

whats up with this

#

Property 'use' does not exist on type 'Function'.

wheat mesa
#

Show app

hushed robin
#

also, what would I make the types of like

#

a variable with lots of things

wheat mesa
#

You may need to do npm i @types/express if they require it, some libs do, some don't

hushed robin
hushed robin
#

yup

#

that fixed it

#

ty

hushed robin
wheat mesa
#

For example, if you wanted an object that had a property "name" that held a string, and "age" that held a number, you could represent it like so: ```ts
interface Person {
name: string;
age: number;
}

hushed robin
#

but it includes like a bunch of shit

wheat mesa
#

Note that you cannot implement functions inside of interfaces or types, that's where you would use a class like ```ts
class Person {
public name: string;
public age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}

printName() {
console.log(this.name);
}
}

wheat mesa
#

Chances are someone has defined a type for it

hushed robin
#

idek

#

but it's like

#

a long ass object thing

#

with text

#

n stuff

#

numbers

#

ips

#

data

#

parameters

#

all that shit from API requests that u would need

wheat mesa
#

you have to model that object

#

it depends on the form of it

hushed robin
#

do i have to

wheat mesa
#

if you're getting that data from an API, they likely have documentation for what the object looks like

hushed robin
#

sounds like a lot of work

wheat mesa
#

you don't HAVE to but that defeats the purpose of using ts

hushed robin
#

no

#

i'm making the api

wheat mesa
#

How many properties are we talking here

#

10?

#

20?

hushed robin
#

a lot more than that

wheat mesa
#

Why would you have so many properties

hushed robin
#

bruh

#

why are you asking me

wheat mesa
#

Are you sure you're not in need of a proper data structure to manage that?

hushed robin
#

i didn't create express

wheat mesa
#

Express isn't responsible for the types you serve to your users

hushed robin
#

no

#

this is what express is sending me

wheat mesa
#

Bruh

hushed robin
#

when someone makes a request

wheat mesa
#

Express has types for that

hushed robin
hushed robin
wheat mesa
#

Request and Response

hushed robin
#

how do i use them

wheat mesa
#

import express, { Express, Request, Response } from 'express';

#

In your function you would have like app.get('/somePath', (req: Request, res: Response) => {...}

hushed robin
#

i think express autoatmically does that

hushed robin
#

the underline visual studio code made

#

disappeared

wheat mesa
hushed robin
#

it's gone

#

the underline

wheat mesa
#

I don't understand what you mean

#

Be more specific

hushed robin
#

you see how it's underlined

wheat mesa
#

Yes

hushed robin
#

it's gone now

#

where'd it go

wheat mesa
#

The error squiggly or the req/res dotted underline?

hushed robin
#

second one

wheat mesa
#

That means VSC was making a suggestion to you, probably to add types to the function variables

#

If you remove the typehints on the parameters then that line will appear again

#

You can hover over it to see what it tells you

wheat mesa
#

: TypeName

hushed robin
#

?

#

what

wheat mesa
#

"hints" the compiler what the type is

#

let num: number;

hushed robin
#

but

wheat mesa
#

: number is a "typehint"

hushed robin
#

i didn't add that

#

and it's gone

wheat mesa
#

Then remove the line and hover over it to see what it says

hushed robin
#

🤯

wheat mesa
#

I'm not your compiler

#

And I still don't understand why that matters

hushed robin
#

cus

wheat mesa
#

It's a good thing

hushed robin
#

i wanna use typescript properly

wheat mesa
#

When you have that line it means ts is complaining about something

#

Keep ts happy, keep your code happy

hushed robin
#

L typescript

wheat mesa
#

And it begins

lyric mountain
#

Endure it, it'll be good to hone your skills

hushed robin
#

bruh

#

my api is broken

wheat mesa
#

Just wait until he gets to a strict statically typed language

hushed robin
#

wym endpoint not found

wheat mesa
#

...did you start the script

hushed robin
#

hmm

#

i see why

#

my map is empty

#

why is that

#
const endpoints = new Map();

function setEndpoints(path: string) {
  const files = fs.readdirSync(path, { withFileTypes: true });

  for (const file of files) {
    if (file.isDirectory()) {
      setEndpoints(`${path}/${file.name}`)
    } else if (file.name.endsWith('.js')) {
      endpoints.set(`${path.replace('./endpoints', '')}/${file.name.replace('.js', '')}`, require(`${path}/${file.name}`));
    };
  };
};

setEndpoints('./endpoints');

apparently this doesn't work with ts

#

oh wait

#

ends with .js

#

☠️

#

NEUT Parameter 'res' implicitly has an 'any' type.

#

won't start my damn api because of this

quartz kindle
#

did you install @types/express?

hushed robin
#

yes

#

also whats up with this

import { insertGame } from '../../utils/schemas.js';```
```Module '"../../utils/schemas.js"' has no exported member 'insertGame'. Did you mean to use 'import insertGame from "../../utils/schemas.js"' instead?```
quartz kindle
#

add export to the consts

#

export const getHistory = ...

#

etc

hushed robin
#

ty

#

typescript bro

  Type 'ParsedQs[]' is not comparable to type 'number'.```
#

weird part is that it works in one file, but not the other

lyric mountain
#

Whatever parsedqs is, you can't pass it as an argument

#

I should tell you where it happened

hushed robin
#

but it works here

quartz kindle
#

it cannot be a number

hushed robin
#

why not

#

i want it to be a number

quartz kindle
#

req.query.something is of type string | ParsedQs | string[] | ParsedQs[] | undefined

#

those are all the possible types of req.query.something

hushed robin
#

so

#

how do i make it a number

#

i gotta manually do that?

quartz kindle
#

convert it to a number

#

yes

#

using Number()

#

or parseInt() or whatever

topaz terrace
#

shows 19 days

quartz kindle
#

the type that you get/set in ts is just a hint, it does not affect actual code

#

you have to make sure that the type hints you are giving actually match the code

hushed robin
#

ok this works

wheat mesa
#

Oh boy

quartz kindle
#

you dont need to add as number there

hushed robin
#

whats wrong

quartz kindle
#

because Number() automatically gives you a type number

hushed robin
quartz kindle
#

a lot of things already have types defined

hushed robin
#

why is waffle saying oh boy

#

did i do something bad

quartz kindle
#

for example the function Number() is already defined as a function that accepts a string type and returns a number type

hushed robin
#

hm
Could not find a declaration file for module 'better-sqlite3'

quartz kindle
#

install @types/better-sqlite3

hushed robin
#

why i gotta download types for everything

#

why not downloaded when i download

quartz kindle
#

a library on npm can have types bundled with it, or not

#

the @types libraries are basically to add types to existing libraries that do not have types built in

#

a lot of developers dont bother adding types to their libs

hushed robin
#

w

quartz kindle
#

so someone else does it for them and publishes it in @types

hushed robin
#

my api is now working with typescript

hushed robin
#

i see

#

really appreicate everyone's help today asta_dance

#

i will continue with this tomorrow

#

sleepy time is now

quartz kindle
#

👍

topaz terrace
#
process.on('unhandledRejection', async (reason, p) => {
    return errorChannel.send({
        embeds: [
            new Discord.EmbedBuilder()
                .setTitle("New unhandledRejection encounted")
                .setDescription(`\`\`\`${reason.stack}\`\`\``)
                .setFooter(`${client.user.tag}`)
                .setColor("#f09999")
        ]
    })
});
process.on('uncaughtException', (reason, origin) => {
    return errorChannel.send({
        embeds: [
            new Discord.EmbedBuilder()
                .setTitle("New uncaughtExpection encounted")
                .setDescription(`\`\`\`${reason.stack}\`\`\``)
                .setFooter(`${client.user.tag}`)
                .setColor("#f09999")
        ]
    })
});
process.on('uncaughtExceptionMonitor', (reason, origin) => {
    return errorChannel.send({
        embeds: [
            new Discord.EmbedBuilder()
                .setTitle("New uncaughtExceptionMonitor encounted")
                .setDescription(`\`\`\`${reason.stack}\`\`\``)
                .setFooter(`${client.user.tag}`)
                .setColor("#f09999")
        ]
    })
})

``` why is this error handler not sending anything via the webhook? 
i tried to make an error happen by removing a { it somehow doesn't even log in the console
#

i tried to make an error happen but it doesn't even log the events table

deft wolf
#

I'm not quite sure if you can catch these kinds of errors as they break the basic rules of the language you're programming in, the bot just won't run

lyric mountain
#

Conceptually, there are 2 kinds of errors

#

Which are Errors and Exceptions

#

The latter can be caught and handled as you already know, but the former should never be caught (or be able to be) as they usually represent fatal issues that happened during execution

#

It includes syntax errors, running out of memory, stackoverflow, external interruption, etc

topaz terrace
#

oh

#

ok

#

idk what to even do

lyric mountain
#

Try to ensure it doesn't happen, instead of remedying it

#

Btw, I noticed u have the bot automatically restart after a crash

#

This is very dangerous as it can lead to IDENTIFY ratelimit in case of discord outage (or crash loops)

quartz kindle
# topaz terrace idk what to even do

The correct use of 'uncaughtException' is to perform synchronous cleanup of allocated resources (e.g. file descriptors, handles, etc) before shutting down the process. It is not safe to resume normal operation after 'uncaughtException'.

topaz terrace
#

ok

sharp geyser
#

the only reason I'd see to do that though is if you are overriding another class's default types/methods

#

god reading through that was a pain

pale vessel
#

impl

#

oh wrong language