#development

1 messages · Page 114 of 1

surreal sage
#
app.use((req, res, nextFunc) => {
    if (condition) {
        res.end()
    } else {
        nextFunc() // A.K.A "Get to 'app.get'"
    }
})```
hushed robin
#

i see

#

this is pretty ez

lyric mountain
#

documentation had literal examples of it

#

bet you didn't even open it

earnest phoenix
cold hearth
#

Who is this guy are they actually using gpt

lyric mountain
#

you don't want to know, better leave it as is

cold hearth
#

ok

#

Why do mark down headings only work on one specific server

earnest phoenix
#

It's an experiment

lyric mountain
#

they're doing that?

boreal iron
#

Oh no

#

Different font sizes

#

Next text colors

earnest phoenix
lyric mountain
#

inline links gg

#

only took 10 years

cold hearth
#

It's scamming time

boreal iron
#

Discord will become even more aids than it already is

earnest phoenix
#

Doesn't change much than now

boreal iron
#

Great

cold hearth
#

So excited for big text spam

lyric mountain
#

any

earnest phoenix
#

Any

#

Just make it work

lyric mountain
earnest phoenix
lyric mountain
#

meh

earnest phoenix
#

Would've been awesome 3HC_why

lyric mountain
#

any language can be used to make anything

boreal iron
lyric mountain
#

the only difference is the learning curve

earnest phoenix
#

No as you will use a backend

lyric mountain
earnest phoenix
#

Which can be done in any language

lyric mountain
#

I used it to highlight certain parts, now they look all the same

earnest phoenix
#

Where you can actually make backends

boreal iron
#

Still not even syntax highlighting

hushed robin
#

what is it always spitting out / for the path

boreal iron
#

Or the ability to click and watch a code block full screen

hushed robin
#

bruh

lyric mountain
#

then you hire 5 developers, setup a JIRA account, setup jenkins/github CI/CD, have morning meetings every monday, schedule demos with interested clients

#

oh and dont forget to make the code look as awful as possible

boreal iron
#

Aye

lyric mountain
#

yes, "enterprise codebase" ain't rainbows as everyone think

#

hobby projects are much cleaner and efficient than them

#

just use whatever language and tools you want to achieve your goal

#

don't bother with "standards" unless you're making a public api

boreal iron
#

Wait for it soon text colors will also become a thing maybe exclusively for nitro

lyric mountain
#

ofc, don't also disregard them completely, just not focus entirely on it

boreal iron
#

Pin this

#

That would fit pretty much into their customizability philosophy for nitro users

hushed robin
lyric mountain
cold hearth
#

GPT projects do not count as hobby projects :/

boreal iron
#

Totally up to you which language u use

#

Imagine I'm using php as my backend

lyric mountain
#

just make sure you use a language you like, else your life will be hell maintaining the backend

wheat mesa
#

Languages are tools to solve problems

#

Some are better at solving some problems than others are

hushed robin
#

how can i remove characters at beginning

boreal iron
#

You can't

hushed robin
#

bruh

boreal iron
#

That's a shortened IPv6

cold hearth
#

This is literally how ips look like

hushed robin
#

thats my ip?

#

did i just leak it

lyric mountain
#

oh my

cold hearth
#

Are you a real person

wheat mesa
#

Jesus

#

Get used to it he’s not trolling

hushed robin
boreal iron
hushed robin
#

bro

#

i am a beginner

hushed robin
lyric mountain
#

ok so, waffle how did u make ur projectile collision check?

wheat mesa
#

Aaaahaha

lyric mountain
#

trying to find ideas on how to optimize mine

boreal iron
wheat mesa
#

I’ve totally done that 👍

lyric mountain
#

eh

hushed robin
#

oh ok

#

so should i check for ::ffff:127.0.0.1

boreal iron
#

Can be written like ::1 as well

hushed robin
#

and not 127.0.0.1

wheat mesa
#

I’m probably going to use the bounding volume hierarchy algorithm or whatever it’s called

#

Separate each hitbox into intervals on each axis and check which intervals overlap

#

Then if either axis has an overlap, check if they collide

boreal iron
#

Waffle creating the next battlefield?

wheat mesa
#

That way you reduce your collision iterations a ton

hushed robin
#

ok it's done

#

big w

lyric mountain
#

I mean, that'll still require iterating over each entity wont it?

wheat mesa
#

This is gonna be great

hushed robin
#

it's working

lyric mountain
#

my issue is that it gets quite slow on high entity count

#

since each entity checks for collision

wheat mesa
#

Yeah the bounding volume hierarchy algorithm is to reduce the checks needed

lyric mountain
#

I'll need to look into that

wheat mesa
#

Checking the actual collision is expensive, checking if intervals overlap is cheap

lyric mountain
#

my actual collision check is fairly simply

#

issue is the loop itself

wheat mesa
#

This is an article I just looked up rq to show the algorithm I’m talking about

#

Might explain it better than I can

#

It’s in C++ but should get the idea across just fine

boreal iron
#

Make a prober hit box detecting

#

Don't wanna make a head shot being count as leg shot

wheat mesa
#

if(Math.random() > .5) { hit = true; } 🧌

#

Why bother checking collisions if they’re random anyways

lyric mountain
#

that book is extremely technical lul

wheat mesa
#

Yes it is

#

There’s tons of resources online about collision tho

#

Tons of stuff and algorithms to choose from

lyric mountain
#

I'll give it a read later, eyes aint ready for lightmode reading atm

wheat mesa
#

Just gotta figure out how to implement it

boreal iron
#

To "save" your eyes

lyric mountain
#

I mean, at least paper isn't emitting light on your eyes

#

but then, this also exists

boreal iron
#

At least it isn't brown

hushed robin
#

why is this returning nothing NEUT

boreal iron
#

Where do u pass the parameter?

#

(for your placeholder)

hushed robin
#

a

#

that should definitely return something

#

there are so many things in my database with a in it

boreal iron
#

Where do u pass the parameter?

#

It's not on your screenshots

hushed robin
#

wym

#

it's right there

#

searchGame.all(query)

boreal iron
#

I only see the placeholder ? And no parameter being passed anywhere

hushed robin
#

yes it is

#

right there

#

look

hushed robin
boreal iron
#

I still can't see what query is

#

It's still not on your screenshots

hushed robin
#

i said what query is

boreal iron
#

Ok send me the message link where u did so

hushed robin
boreal iron
#

I Said i wanna see the query not "a"

hushed robin
#

the query is a

quartz kindle
#

he said the query is a

hushed robin
#

bruh

quartz kindle
#

lmao

earnest phoenix
#

LMFAO

boreal iron
#

Is this hidden camera ?

hushed robin
quartz kindle
#

im literally laughing irl rn

boreal iron
#

I'm still not sure if I should laugh or cry

earnest phoenix
#

both

boreal iron
quartz kindle
#

if you laugh hard enough you end up crying

hushed robin
#

😂

#

anyone know the issue tho

earnest phoenix
#

b

hushed robin
#

ok

boreal iron
#

Also I highly doubt the executing method of the prepared statement is called .all()

#

But yet I dunno the lib

hushed robin
#

it is

#

bruh

earnest phoenix
quartz kindle
#

usually LIKE queries require a pattern matching operator, like %

hushed robin
#

i am not stupid

quartz kindle
#

for example LIKE '%a%'

hushed robin
#

lemme see

boreal iron
earnest phoenix
#

yesyes

#

sql world

hushed robin
boreal iron
#

You also use like without % to ignore the case

hushed robin
#

fixed it

quartz kindle
hushed robin
#

yay

#

i forgot about that

boreal iron
#

In other words to match case insensitive matches

earnest phoenix
#

% is not avoiding the case

hushed robin
#

i want that

earnest phoenix
#

It's about any character or multiple

#

It's kind of like * in normal stuff

quartz kindle
#

case sensitivity is defined in the table charset afaik

earnest phoenix
#

Yeah, or just lower everything lmao

boreal iron
#

Well that's just wildly guessing around

hushed robin
#

it's now working

boreal iron
#

I dunno about his table

#

Dude you said you have many records with a as value

boreal iron
#

Not as PART of it

hushed robin
#

no

quartz kindle
#

lmao

hushed robin
#

i said the query is a

boreal iron
#

Oh man... I decided to cry

earnest phoenix
#

fair enough choice

boreal iron
#

For real

hushed robin
#

why cry

#

my api is now fixed

#

big ws

boreal iron
#

Because I feel physical pain

earnest phoenix
#

what do websockets have to do with that

hushed robin
#

i do too kinda

#

i cut my finger today

#

while chopping up some cucumbers

#

guys

#

how can i easily test POST stuff

#

like i can test get in my browser

#

can i do the same with post

boreal iron
#

By sending a post request

hushed robin
#

how do i do that

#

easily

boreal iron
#

Using curl for example

hushed robin
#

?

wheat mesa
#

curl

hushed robin
#

what is curl

boreal iron
#

Available on any OS

hushed robin
#

will it work for my post request?

boreal iron
#

Of course

#

Else I wouldn't suggest it

hushed robin
#

ok

#

i will try it

#

is there a simpler way tho?

#

like in my browser

boreal iron
#

Idk using an online service for testing and debugging stuff which sends request

earnest phoenix
boreal iron
#

Ahh yeah that was the name

hushed robin
#

hm

#

i don't think my api is publicly accessible tho

earnest phoenix
#

That's why there's a goddamn download button

#

To download and test locally

hushed robin
#

oh

#

sorry i didn't know

boreal iron
#

Or simply use curl which already available in your command prompt

hushed robin
#

downloading kinda sus tho

#

is postman trusted

earnest phoenix
#

No definitely not

#

Used by professionals all around the world

hushed robin
#

Google?

earnest phoenix
#

Though it's a malware, don't download it

hushed robin
#

well

#

i am downloading

#

so

#

for post

#

should i do stuff in body

boreal iron
#

My gosh

hushed robin
#

or in url

boreal iron
#

curl -d "param1=value1&param2=value2" -X POST http://localhost:3000/data

earnest phoenix
#

In the cookies

hushed robin
#

cookies?

boreal iron
#

There u go

hushed robin
#

bruh

hushed robin
#

i don't like stuff where i type a lot

boreal iron
#

Imagine even being too lazy to use google for 3s

#

I know that's why I sent it here

earnest phoenix
#

I ask everything to ChatGPT

hushed robin
#

it's ok

#

postman is downloaded already

boreal iron
#

So you can use your most used keys CTRL C and V

hushed robin
#

so

#

will it just automatically work for it

earnest phoenix
#

i swear KEKW

hushed robin
#

or do i need to do something

boreal iron
#

Thankfully I have to do some work now

earnest phoenix
#

same kek

hushed robin
#

bruh

#

how do i make it work for my local api

radiant kraken
earnest phoenix
hushed robin
#

someone help

#

why is this the ip when i request from postman

earnest phoenix
#

It's compressed IPv6

#

0:0:0:0:0:0:0:1 -> ::1

hushed robin
#

bruh

#

is there a list of local ips

earnest phoenix
#

0:0:0:0:0:0:0:1 IPv6
127.0.0.1 IPv4

hushed robin
#

but

#

those won't work if it's ::1

earnest phoenix
#

::1 is exactly the same as 0:0:0:0:0:0:0:1

#

Simply shorter, compressed, version

hushed robin
#

but

#

javascript says otherwise

earnest phoenix
#

I don't care what JavaScript says

#

How you handle the IP is something different

#

I tell you, ::1 is the same as 0:0:0:0:0:0:0:1 but compressed

hushed robin
#

ok

#

how do i make javascript think that

earnest phoenix
#

Replace ::1 with whatever you want????

hushed robin
slender wagon
#

i manage to make users register with postgres

#

isn't that cool?

hushed robin
#

how do i

#

make

slender wagon
#

now i have to do all the sessions and use jwt

hushed robin
#

how

#

do

slender wagon
#

make what?

hushed robin
#

i get body of a request

#

with express

slender wagon
#

uhh did you even read the express docs

hushed robin
#

no

slender wagon
#

req.body usually means that's the body you are looking for

hushed robin
#

uh

#

it's returning undefined

slender wagon
#

if u are passing something into it ofc

#

what are u passing

slender wagon
hushed robin
#

no

#

body

slender wagon
#

show me the req handler in the express

hushed robin
#

what request handler

slender wagon
#

the one u are using to get the body data

hushed robin
#

undefined

slender wagon
#

show me the entire thing

hushed robin
#

ok

slender wagon
#

copy pasting is easier btw

hushed robin
#

i also found another issue unrelated to that

#

ok i fixed it

#

but this issue still presists

slender wagon
hushed robin
#

yes

#

tbh i don't know why it's not workinh

#

i think express is broken

boreal iron
#

Do you still filter by your local address?

#

If so exclude the source ip of postman from your statement

#

Also consider filtering the source IP in your firewall not in your code

#

Filtering on this network layer will make you cry very soon

neon leaf
#

idk why but Im proud of this

hushed robin
#

i am getting the requests

#

but body is undefined

boreal iron
hushed robin
#

idc then

#

i need help with this

#

theres no reason why filtering from my code is bad

#

i dont see the issue

boreal iron
#

Didn't expect you to know anything about network layers

#

I just wanna be able to tell you later "I told you"

hushed robin
#

told me what

pale vessel
#

Did you have app.use(express.json()) in your code?

hushed robin
#

and no

pale vessel
#

You need it for it to parse JSON body

hushed robin
#

so i need to use app.use twice?

pale vessel
#

Yes

#

It's fine

boreal iron
hushed robin
#

okok

#

we're making progress

#

it's empty tho

#

{}

pale vessel
#

The object?

hushed robin
#

yes

pale vessel
#

Did you add content-type: application/json as the header while making the POST request?

hushed robin
#

no

pale vessel
#

Add it

wheat mesa
#

I would trust fake btw, he’s got quite a bit of web api experience in all seriousness

hushed robin
#

YOOOOOOOO

#

W FLAZE

pale vessel
#

It wouldn't know if it's a JSON otherwise so it won't parse it

hushed robin
#

LETS GO

#

😎

hushed robin
#

i don't know how to do what he's saying

#

now i can insert games from my website 😱

quartz kindle
#

gaymes

boreal iron
# hushed robin well

I gave you the tip to at least filter the source IP on a different layer, for example your firewall

#

That's much more "efficient" and reliable when it comes to attack or simply request spam

hushed robin
#

bro

#

guys

#

how can i infinitely loop through

#

folders

wheat mesa
#

Yeah a firewall is probably a lot faster at blocking requests than programmatically doing it

wheat mesa
#

Like recursion?

hushed robin
#

like

#

i want my endpoints to be organized so i can put it in a games folder in my endpoints folder then put the file in there and it'll make that the path

wheat mesa
#

Ah, so like the way nextjs does it

neon leaf
#

just check if the type of something is a folder and then loop it again with the same logic

hushed robin
#

but i want it to infinitely loop if there's more than one folder

neon leaf
#

aka fs.stat exists

hushed robin
#

so if there's another folder in a folder it needs to loop through that one

quartz kindle
#

you dont need fs.stat

wheat mesa
#

Yeah, recursion is usually pretty good for filesystem stuff like this but iteration will be faster

#

Tim has probably done this before :^)

hushed robin
#

how do i do

boreal iron
#

Tim benchmarked em all

wheat mesa
#

Lol

#

Probably not wrong

hushed robin
#

hm

neon leaf
#
import * as fs from "fs"

export const getAllFiles = (dirPath: string, arrayOfFiles?: string[]) => {
    const files = fs.readdirSync(dirPath)
    arrayOfFiles = arrayOfFiles || []

    files.forEach((file) => {
        if (fs.statSync(dirPath + "/" + file).isDirectory()) {
            arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
        } else {
            let filePath = dirPath + "/" + file
            arrayOfFiles?.push(filePath)
        }
    }); return arrayOfFiles
}

export const getAllFilesFilter = (dirPath: string, suffix: string, arrayOfFiles?: string[]) => {
    arrayOfFiles = getAllFiles(dirPath, arrayOfFiles).filter(file => file.endsWith(suffix))
    return arrayOfFiles
}```

I do it like this
quartz kindle
#

readdir or readdirsync with { withFileTypes: true }

hushed robin
#

i use readdirsync already tho

quartz kindle
#

it returns a dirent object instead of a file name

#

if you set withFileTypes true

#

a dirent object contains everything about the file

hushed robin
#

but

#

i am getting an error now

#

Error: Cannot find module './endpoints/[object Object]'

quartz kindle
#

so you no longer need fs.stat

hushed robin
wheat mesa
hushed robin
#

i am doing what tim said

quartz kindle
#

show code?

neon leaf
#

yes and now you need to handle the object

#

if its a file then add it else fetch the folder

quartz kindle
#

also, reread it returns a dirent object instead of a file name

hushed robin
#

bruh

#

why direct object

#

direct object to what

neon leaf
#

*dirent

#

its an object that contains more infos

hushed robin
#

but

quartz kindle
hushed robin
#

ok

#

it's broken

quartz kindle
#

youre broken

neon leaf
#

true

hushed robin
#

this is too confusing

quartz kindle
#

no code no help

hushed robin
#

what does this return fs.readdirSync('./endpoints', { withFileTypes: true });

quartz kindle
#

an array of fs.Dirent objects

hushed robin
#

what is a dirent

quartz kindle
#

an object containing information about the entry

hushed robin
#

what entry

quartz kindle
#

named after Directory Entry

#

entry as in, the file name

#

filesystem entry

#

instead of returning filenames

#

it returns an object with more information about the file

#

not only name

#

to access the name, instead of using the entry directly, you have to add .name

hushed robin
#

how will that help me succeed

neon leaf
#

this is similar to what you need

quartz kindle
#

because it also gives you the isDirectory() method

#

that you can use to check if its a file or a folder

#

which is what you need to check folders infinitely

hushed robin
#

i don't get it

#

how will that help me check it infinitely

#

idk how to do an infinite loop

wheat mesa
#

You don’t need an infinite loop, you need a loop that goes until you meet a condition

neon leaf
#

just like in the screenshot I sent, just call a function over and over until you finish

wheat mesa
#

Aka a while loop

#

Or you can use recursion too that works

hushed robin
#

i don't get

quartz kindle
#

or a recursive function

#

its a function that calls itself

#

for example

#
function abc(path) {
    const files = fs.readdirSync(path, { withFileTypes: true })
    for(const file of files) {
        if(file.isDirectory()) {
            abc(`${path}/${file.name}`) // this is recursion, the function calls itself again, but with the updated path
        }
    }
}
quartz kindle
#

yes

hushed robin
#

ok

#

this helps me understand more

#

thank you

quartz kindle
#

lmao

#

isnt that kinda nsfw

#

xd

covert gale
#

@solemn latch

hushed robin
#

ok

#

it's not working

#
function setEndpoints(path) {
  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(`/${file.name.replace('.js', '')}`, require(`${path}/${file.name}`));
    };
  };
};

setEndpoints('./endpoints');
solemn latch
#

@frosty gale don't post content like that please

wheat mesa
neon leaf
#

quite a bit of files

solemn latch
#

That's a fair ping, I'd rather be pinged for that than not pinged

hushed robin
wheat mesa
#

You have no “base case” to stop the function from calling itself into oblivion

quartz kindle
#

its not infinite

neon leaf
#

it will stop

wheat mesa
#

Oh

#

Mobile formatting

covert gale
#

I’ll let them decide

wheat mesa
#

Didn’t see that it’s outside of the function

hushed robin
#

oh wait

#

it does work

#
function setEndpoints(path) {
  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');
#

w

#

this works

#

yes

#

it works beautifully

surreal sage
#

jesus Christ

#

a client of mine

#

thinks that his 2 mb/s upload ubuntu server

#

is good enough for a discord bot

#

and he keeps complaining that I have to fix it "beCaUse iT wOrKeD for DowNLoaD apPliCaTioNs"

hushed robin
surreal sage
#

that's hella bad bro

#

the discord bot can't even connect

#

it fails or times out

hushed robin
#

damn

#

tuff

boreal iron
wheat mesa
#

2mb/s is awful for a server, but honestly it’s not too far off from a slightly shitty home internet connection

#

16mbps is like half of what I get on average

boreal iron
#

If you would only get what u pay

#

Yeah sad time we're living in

covert gale
#

And costs like 30-50 dollars a month

#

Or smt like that

wheat mesa
#

Close to my router I get like 200 down 10 up

#

cable moment

#

We don't have super good fiber access in our area (plus it's expensive for the stuff that is actually here) and we don't need anything fancy

boreal iron
#

More than fast enough for the average internet user

wheat mesa
#

Plenty

topaz terrace
#
bot.command("homework", async msg => {
    await msg.reply("a", {
        "reply_markup": {
            "one_time_keyboard": true,
            "keyboard": [
                [{
                    text: "Morning",
                    one_time_keyboard: true,
                    callback_data: "morning-class"
                }],
                [{
                    text: "Afternoon",
                    one_time_keyboard: true,
                    callback_data: "afternoonclass"
                }],
            ],
            resize_keyboard: true
        }
    })
})
bot.action("morning-class", async msg => {
    await msg.reply("What's the homework for the Morning class?");
    session.push({
        session: "Morning",
        date: new Date()
    })
})

bot.action("afternoonclass", async msg => {
    await msg.reply("What's the homework for the Afternoon class?");
    session.push({
        session: "Morning",
        date: new Date()
    })
})```somehow the bot doesn't action the thingy
covert gale
#

its all copper

wheat mesa
#

Well yeah I figured since your upload speed is significantly lower than download 😉

#

You just pay for a better plan than I do, so you get more speed

hushed robin
#

who has tips for making a website

slender wagon
deft wolf
#

Anyone know if the new file upload limit also applies to bots or is it just for users?

sterile rover
pale vessel
#

^ but not bootstrap

deft wolf
#

It's hard cuz im on phone rn

#

That's why i asked here

lament rock
#

should apply to bots as well

sharp geyser
#

@neon leaf So I was trying to add my email to gmail but I don't quite get what I am supposed to do here

#

I know that mailcow smtp is on port 25 as for the path for it I don't know what else it could be other than mail.aarondye.dev unless I have to set it somehow

#

and I assume the username and pass would be what I use on sogo to login to the email

deft wolf
brazen violet
#

How can I show my website in my bots description of top.gg

deft wolf
#

Use <iframe>

brazen violet
#

can we use width and height?

#

whats the normal width and height ??

neon leaf
austere mica
#

Hello, I need to talk about how Topgg developers make that red and black theme color on the Topgg page. Can anyone explain it to me, please, in HTML?

slender wagon
#
  <Link color="purple.600" fontWeight="semibold" href="/signup">
 Sign up
 </Link>

i am using nextjs and for some reason when i use <Link> it causes hard refresh?

slender wagon
#

in this case it is chakra-ui

austere mica
slender wagon
#

it's only available for react tho

austere mica
slender wagon
#

i am not sure, but i think you can achieve it with css not sure how as i am shit at frontend

austere mica
#

but this method known as?

slender wagon
#

you might have to do some digging

#

it's just a gradient

#

but they do it very nicely

austere mica
#

hmm thanks

boreal iron
#

The easiest way of doing it is to structure and separate your css files

#

For example one only containing the layout and one your theme adjustments for the entire body

slender wagon
#

@austere mica ^

boreal iron
#

Now load the default theme (css file) in your html head

austere mica
#

get it thanks

#

😇

boreal iron
#

Then create an user interactable element like a button or icon etc. and simply use JS to replace the src attribute of your meta tag

#

Like I said using a button or by registering an event handler for the element

#

On every click you can get the current value of your meta tag that loads your theme file and change the value properly

#

It's nothing special, it not animated etc. but it works smoothly and instant without reloading the site

slender wagon
#

so now that i am thinking of adding a themeswitcher, should i make a config file to set the default one if there is nothing on the local storage?

#

or what's a easy way of getting through it?

boreal iron
#

On every click you can get the current value of your meta tag that loads your theme file and change the value properly

surreal sage
#
console.log("Start")

for (let i = 0; i < 5; i++) {
    if (i === 3) return;
}

console.log("End")```
Would "End" still get logged?
boreal iron
#

Give the meta tag an ID attribute and get the value of the src attribute using JS

boreal iron
#

You will need to use break

austere mica
#

hey @slender wagon what is theme hex color of topgg?

slender wagon
#

I believe thats not what u need

austere mica
#

not need to add texture color

topaz terrace
#

idk why it says 53 years
this is the time variable when the started embed was sent
const timeLeft = Math.floor(Date.now()/1000) - time;
and this is the time variable
Math.floor(Date.now()/1000)

digital swan
#

Believe it or not if you subtract a number by the same (or very similar) number it’ll result in a small number

#

The discord time stamps aren’t really good for showing time taken as far as I’m aware they just show a specific date

versed grove
#

hello i need help to create a discord bot using text-davinci-003 api

#

is it posible

earnest phoenix
#

you just have to request to the openai api so yes

versed grove
#

but the code part messes it up

#

i even asked chap gpt himself

#

chat

earnest phoenix
#

then its most likely that you did something wrong

versed grove
#

could you help set it up

earnest phoenix
#

post your code and the error you get

deft wolf
#

If you have any questions about your code, ask them, but no one will write you a bot from scratch

versed grove
#

ok

#

let me find

versed grove
#

import openai
import discord

Set up the OpenAI API client

openai.api_key = ""
model_engine = "text-davinci-003"

Define the intents for the bot

intents = discord.Intents.default()
intents.members = True

Initialize the Discord client with the specified intents

client = discord.Client(intents=intents)

Define a function to generate responses to user questions

async def generate_response(message):
# Send the user's message to the OpenAI API
response = openai.Completion.create(
engine=model_engine,
prompt=message.content,
max_tokens=1024,
n=1,
stop=None,
temperature=0.7,
)

# Get the generated response from the API
response_text = response.choices[0].text.strip()

# Send the generated response back to the user in the Discord chat
await message.channel.send(response_text)

Define an event listener for incoming messages

@client.event
async def on_message(message):
# Only generate responses to messages in a specific channel
if message.channel.id == :
# Ignore messages from the bot itself
if message.author == client.user:
return

    # Generate a response to the user's message
    await generate_response(message)

Start the Discord bot

client.run(".")

#

chat gpt said its fine

#

it dont answer proberly

#

@earnest phoenix

#

@deft wolf

rustic nova
#

No need to ping multiple users

#

Just wait for someone who can help

versed grove
#

they said they could help

earnest phoenix
#

never said that i could

deft wolf
#

I don't quite understand what response you expect from the bot to the hello message

earnest phoenix
#

```py
code
```
please

deft wolf
#

Then ask your bot the same question and see what the answer is

versed grove
cold hearth
#

Have you tried logging the entire response object and seeing what the prompt being sent to the api is

rustic nova
#

logging the entire response object
not show your generate response function

versed grove
#

@rustic nova in new to this, pls explain

rustic nova
#

have you ever worked with python before?

versed grove
rustic nova
#

you have a response object

#

created by the Completion.create function from openAI

#

that response contains the response

#

now just print that out

versed grove
#

``import openai
import discord

Set up the OpenAI API client

openai.api_key = "sk"
model_engine = "text-davinci-003"

Define the intents for the bot

intents = discord.Intents.default()
intents.members = True

Initialize the Discord client with the specified intents

client = discord.Client(intents=intents)

Define a function to generate responses to user questions

async def generate_response(message):
try:
# Send the user's message to the OpenAI API
response = openai.Completion.create(
engine=model_engine,
prompt=message.content,
max_tokens=1024,
n=1,
stop=None,
temperature=0.7,
)

    # Get the generated response from the API
    response_text = response.choices[0].text.strip()

    # Send the generated response back to the user in the Discord chat
    await message.channel.send(response_text)

except Exception as e:
    # Handle any errors that occur with the OpenAI API
    print("Error generating OpenAI response:", e)
    await message.channel.send("Sorry, there was an error generating a response. Please try again later.")

Define an event listener for incoming messages

@client.event
async def on_message(message):
# Only generate responses to messages in a specific channel
if message.channel.id == :
# Ignore messages from the bot itself
if message.author == client.user:
return

    # Generate a response to the user's message
    await generate_response(message)

Start the Discord bot

try:
client.run("..")
except Exception as e:
# Handle any errors that occur with the Discord API
print("Error starting Discord client:", e)``

rustic nova
#

posting your whole code again wont change anything

versed grove
#

i dont undstand what you mean

rustic nova
#

I really suggest looking into python first (general debugging, possibly even how to use it at first) before approaching openai related things

#

printing out your response object is as simple as doing print(response) or just responding with the response object on your discord on_message

versed grove
#

hmmm

#

understand

rustic nova
#

and dont rely on chatgpt literally giving code if you do not understand what you have just generated

versed grove
#

i think i have a ok understanding of the code

#

mostly doing this to learn

boreal iron
#

and this is the time variable Math.floor(Date.now()/1000)

#

means it's seconds

topaz terrace
#

oh

boreal iron
#

so it's about right

topaz terrace
#

what should i do

#

oh ok

#

thanks

boreal iron
#

why would u perform rounding and dividing multiple times?

#

(Date.now() - timestamp) / 1000

#

errrr... good question, i think 5 was the limit

#

but lemme take a look

#

Select Menu Types

There are 5 different select menu components that can be included in Action Rows.

#

Impossible yet

#

Yes

#

Currently there are only 2 possible styles for text input

#

Name Value Description
Short 1 Single-line input
Paragraph 2 Multi-line input

#

aka text input or text area

#

might have misunderstood you

#

you're talking about rows, right?

#

ah nvm it still seems to be right

#

5 rows

#

djs probably returns the response as string, always

#

You simply use the isNaN() function

#

isNaN("2") will return false

#

basically means it is not not a number

#

means it is a number

#

the function is called "Is Not A Number"

#

not "Is A Number"

#

so you need to rethink what it returns

#

it will return false once the passed argument, for example your response "22" is a number

#

would return true if the response for example "22ff" is not a valid number

#

also something important

#

the entire user input of the text field or text area will be send as response

#

this means if the user accidentally adds a space behind a number, it will be a string

#

"22 "

#

so use trim() when getting the response

#

if I enter one digit only together with one space, it will become a string

#

just add the method when getting the value of the field

#

<modalsubmitinteraction>.fields.fields.get("field-name").value.trim()

#

or by using the methods...

#

<modalsubmitinteraction>.fields.getTextInputValue("field-name").trim()

#

I always prefer to not use the methods and access the data directly

#

As djs tends to change the method names all the time, or their case etc.

#

the structure of accessing them directly will most likely never change is djs tries to keep the structure like as the api structure

#

maybe you will end up to change the name of the methods on the next release of djs

#

as those retards being known to randomly change the names, or case or simply remove existing (useful) methods/guards etc.

#

<modalsubmitinteraction>.fields

#

until here

#

then

#

accessing the field data

#

<modalsubmitinteraction>.fields.fields

#

Type: Collection <string , ModalData>

#

so... you can use the available methods to get the data out of the collection

#

like I wrote above

#

<modalsubmitinteraction>.fields.fields.get("field-name")

#

which returns an object

#

to enter the value for example, you select it's property

#

<modalsubmitinteraction>.fields.fields.get("field-name").value

#

The structure itself is defined by the discord api

real rose
#

Lets be nice please FakE wawaCry

boreal iron
real rose
#

No r words pls aPES_PeepoSadRain

#

other than that i agree with your message

boreal iron
#

wut

real rose
boreal iron
#

ah u're speaking about my words regarding the djs stuff?

boreal iron
#

well it's just the truth imo but I try to formulate things differently

surreal sage
surreal sage
#

Mongo installs have been a pain

rustic nova
#

you installed the db and not the client is my guess

#

never installed mongo under linux

surreal sage
#

reinstall did it

wheat mesa
#

Does anyone know how to tint a BufferedImage in java? I saw this online, but it just produces a white rectangle when I supply it my image: ```java
public static BufferedImage applyTint(BufferedImage src, int r, int g, int b) {
BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TRANSLUCENT);
Graphics2D graphics = img.createGraphics();
graphics.setXORMode(new Color(r, g, b, 0));
graphics.drawImage(src, null, 0, 0);
graphics.dispose();

    return img;
}
#

Perhaps you might know @lyric mountain?

lyric mountain
#

"tint"?

#

Simply draw a translucent rectangle over it

wheat mesa
#

The problem with that is that it would add colors to areas with full transparency

#

I need to preserve the original alpha values if possible

lyric mountain
#

Not if u use DST_IN

#

Or was it SRC_IN

#

Whatever, I have that in my code, just a sec

#

...except I don't remember where

#

Anyway, what u want is setComposite() method

#

Fiddle with it a bit, it's in Graphics2D

#

Remember to return it to original state afterwards

#

From the time oracle was a decent company

wheat mesa
#

So I'm pretty close to getting it to work, but for some reason it looks like it's just completely overpowering the source image

#

I'm using this: ```java
public static BufferedImage applyTint(BufferedImage src, Color color) {
BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = img.createGraphics();
graphics.drawImage(src, null, 0, 0);
graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN));
graphics.setColor(color);
graphics.fillRect(0, 0, src.getWidth(), src.getHeight());
graphics.dispose();

    return img;
}
#

setColor includes alpha right?

lyric mountain
#

Yep

#

Wdym overpowering?

wheat mesa
#

Like, the rectangle is just drawing completely over the original sprite and leaving nothing behind

#

Hold on, let me get an example

#

That's with 50 alpha

#

Even more odd, at 10 alpha the entire thing just disappears

#

Oh, I'm stupid

#

I was using SRC_IN when I should've been using DST_IN

lyric mountain
#

Lul, I always confuse both

wheat mesa
#

Yeah

#

ogl rendering hints are so scuffed in their descriptions lol

lyric mountain
#

They could simply use ORIG_IN and it'd be 100% more intuitive

wheat mesa
#

Actually this is wrong too

#

It seems to ONLY care about alpha now, not the color of the rectangle

lyric mountain
#

Try the other modes, there are a bunch

wheat mesa
#

Actually from looking at the description DST_IN that seems to be exactly what it's meant to do

#

I don't see any modes that seem to match what I'm looking for, it might be a RenderingHints thing

lyric mountain
#

Could be

wheat mesa
#

DST_IN is definitely what I want for alpha tho, I'll try to look for color blending solutions

#

There's a ton of different draw modes but none of them seem to combine color of the src and destination while preserving src alpha

#

maybe chatgpt will know, I'll ask that

#

Ok it appears I wanted SRC_ATOP

#

got it

#

preserves original alpha, applies a transparent tint

lyric mountain
#

Lmao

#

Tho...u wanted to darken it?

wheat mesa
#

(Don't worry about the player shooting stuff rn, that's just a WIP lol)

wheat mesa
#

And this does exactly that

lyric mountain
#

There's RescaleOp for that (darkening or lightening), it's simpler and more performant than alpha ops

#

But if u want colors then alpha is the way

wheat mesa
#

Performance isn't super important here since all of these operations will be done during load time

#

dynamically doing this every frame would be EXPENSIVE

lyric mountain
#

Fair

wheat mesa
#

I suppose I could implement a wrapper over BufferedImage though for something like darken() or lighten() so I could be as performant as possible depending on the operation the user wants to perform

#

But that'll be later since that's not a big priority

lyric mountain
#

I like g2d for how high the skill ceiling is without having to enter too much into opengl

#

like, it can be insanely powerful for advanced users yet simple enough for newbies

wheat mesa
#

It's quite interesting because I can definitely see the almost word-for-word functions that go to ogl, then it also has something as simple as drawImage

#

g.setComposite(AlphaComposite.SrcAtop) is essentially just a fancier version of gl.setBlendMode(SRC_ATOP)

neon leaf
quartz kindle
#

or what

neon leaf
#

yes, like ee.on('foo', () => { throw new Error(123) }) ends up in a unhandledruntimeerror

quartz kindle
#

technically youre not supposed to do that, the consumer of the event is responsible for catching their own errors

#

swallowing errors caused by the consumer may lead to unexpected behavior for users, as they will expect one type of error and get something else

#

but you can do that by using the private _events property

#
try {
    emitter._events[eventname](args)
} catch {}
#

but you need additional handling in case there are multiple listeners

#

if there is more than one listener on the same event, _events[event] becomes an array of callbacks

#

so you have to loop over it

neon leaf
#

if there are none its just undefined / null / ..., right?

quartz kindle
#

you can also add another check for async callbacks

#

yeah

#

undefined

neon leaf
#

alr then imma have a bit of fun handling that, but what do you mean with unexpected behaviour?

quartz kindle
#

updated

#

basically if you have a library that emits events, the user might not expect the library to swallow errors caused by the user

#

and get confused when their code does not error like it should

neon leaf
#

basically I have a ton of events and an event for manual error handling for all events combined

#

and if the error handling event fails there is obv a fallback to prevent infinite loops

quartz kindle
#

ive done exactly what youre doing in the past with my lib

#

but then decided to revert it and let users catch their own errors

#

i feel like it makes more sense that way

#

but you can do that if you feel it makes sense for your project

neon leaf
#

I mean I understand it but I dont want a users webserver to randomly crash

#

I think there its needed

quartz kindle
#

you can check the way i did it

#

it should be in some past commit on github, before i reverted it (tiny-discord repo)

#

i had special handling for all sorts of situations including race conditions from multiple event listeners

neon leaf
#

that sounds very similar to mine

#

this should work as intended, right?

import TypedEventEmitter from "../types/typedEventEmitter"
import { EventHandlerMap } from "../types/event"
import { EventEmitter } from "events"

export default class SafeEventEmitter extends (EventEmitter as unknown as new() => TypedEventEmitter<EventHandlerMap>) {
    emitSafe<E extends keyof EventHandlerMap>(event: E, ...args: Parameters<EventHandlerMap[E]>): Promise<boolean> {
        return new Promise<boolean>(async(resolve, reject) => {
            const callback: undefined | Function | Function[] = (this as any)._events[event]

            if (!callback) return resolve(false)
            if (Array.isArray(callback)) {
                for (const cb of callback) {
                    try {
                        await Promise.resolve(cb(...args))
                    } catch (err) {
                        return reject(err)
                    }
                }

                return resolve(true)
            } else {
                try {
          await Promise.resolve(callback(...args))
        } catch (err) {
          return reject(err)
        }

        return resolve(true)
            }
        })
    }
}```
undone rose
#

Any of yall know if bots can send audio in the top format, instead of the bottom format?

earnest phoenix
#

Yeah bots can

undone rose
#

nice

earnest phoenix
#

Voice messages are not the same as files though

undone rose
#

hmmmmm, I will have to look more into this then

#

Thank you!

earnest phoenix
#

Some magic around it

#

Probably need the X-Super-Properties header as well because it's not documented yet iirc so not really official and may be subject to changes

#

And remember that it's limited for now

#

DMs, GDMs, and servers with fewer than 200 members on mobile

undone rose
#

Oh I did not know that

#

In that case I will not be implementing this

earnest phoenix
#

I mean

#

Every platform can listen

#

But your bot won't be able to send them

#

Can always make fallback to old method if the voice message one fails

undone rose
#

Yeahhh true, it would be super cool to use a voice message instead of an mp3 file

earnest phoenix
#

Just looks way nicer

undone rose
#

It does, and it takes up less space which is another big plus for me

earnest phoenix
#

Yeah definitely

#

Depending your usage you may want to let users seek to a specific time

#

Not sure if that's possible with voice messages

undone rose
#

it is

earnest phoenix
#

Never used it nor listened to one krThisIsFine

undone rose
#

but I dont need that functionality

earnest phoenix
#

Yeah then it's fine

#

Though considering it's iirc undocumented, API related to it may change in the coming days

undone rose
#

fucc it we ball

earnest phoenix
surreal sage
earnest phoenix
surreal sage
#

Is there an opposite of continue then?

#

break right?

earnest phoenix
# surreal sage `break` right?

A break statement completely stops the loop (for, while, and do..while), but doesn't stop the execution of the code in the function or ones outside

surreal sage
#

can you also do something like

for (;;) {
    func(); break
}```?
#

guessing yes

quartz kindle
#

yes that will run the function then exit the loop

#

and continue the rest of the code after the loop, if any

surreal sage
sharp geyser
#

I just dont get it bro

#

Why is it using mail.aarondye.dev

#

I assume it is cause of either my cloudflare DNS settings or nginx itself

#

the only thing that is accessible on my site is mail.aarondye.dev but going to just aarondye.dev gives me a "Your connection is not private"

wheat mesa
#

Krill issue

earnest phoenix
#

@undone rose If you don't want to copy paste the header for voice messages:

'x-super-properties': 'eyJvcyI6IldpbmRvd3MiLCJjbGllbnRfYnVpbGRfbnVtYmVyIjo5OTk5OTk5fQ=='
#

It's base64 for

{"os":"Windows","client_build_number":9999999}

KEKW

twin swift
#

how can I fix this problem:
Error: Cannot find module 'node:events'

#

how can I fix it

twin swift
#

lul I said two times

hushed robin
#

The Error: Cannot find module 'node:events' occurs if you are not using the latest version of node. js 16.6. 0 or above and developing the discord bots. We can fix the issue by upgrading the Node.

#

first google search

#

big w

twin swift
#

I tried but its not fixed

hushed robin
#

hm

wheat mesa
#

Do node --version

hushed robin
#

that's probably a good idea

wheat mesa
#

Or maybe it’s like node -v

#

Something like that

#

One of those two should work

hushed robin
#

yes node -v works

#

thats what i usually use

earnest phoenix
#

or just node

hushed robin
#

both work actually

twin swift
#

oh

#

its 10.24

#

.1

hushed robin
#

well

earnest phoenix
#

nice

wheat mesa
#

Yeah, update it

hushed robin
#

there's your issue

twin swift
#

is it supporting v14?

hushed robin
#

no

#

16.6.0+

earnest phoenix
#

No

#

update to lts

wheat mesa
#

Node v10 is old as shit

wheat mesa
earnest phoenix
#

which is 18.x

twin swift
#

how can I upgrade this

hushed robin
wheat mesa
#

You can download it on their website, or you can use the nvm tool (the recommended way)

twin swift
#

but I m using a site

earnest phoenix
#

Yeah go for nvm

twin swift
#

I know how to upgrade in normally

hushed robin
#

what site

earnest phoenix
#

average replit moment i guess

hushed robin
twin swift
#

glitch

#

lul

earnest phoenix
wheat mesa
#

Oh boy

twin swift
#

xd

#

but I read on forum

#

they are aded node 16

wheat mesa
#

Didn’t glitch ban running discord bots on their services a while ago?

twin swift
#

idk

wheat mesa
#

Or is that just abusing stuff like uptimerobot to keep it up

earnest phoenix
#

doubt

twin swift
#

hmmm

#

but I dont have a vds

lyric mountain
#

glitch does

earnest phoenix
#

Doubt they banned discord bots honestly

twin swift
#

hmm

earnest phoenix
twin swift
#

I dont have a problem

#

about 2 years

hushed robin
#

they banned using third-party services to ping projects to keep them awake

earnest phoenix
#

Just go in your package.json file and write down "node": "18.x"

#

In the engines field

twin swift
#

ok

earnest phoenix
#

So like

{
  "name": "...",
  "version": "...",
  "main": "...",
  "engines": {
    "node": "18.x"
  },
  "scripts": {
    ...
  },
  "dependencies": {
    ...
  },
  "devDependencies": {
    ...  
  }
}
twin swift
#

I m going to good words about this

#

finally mission passed

#

but

#

...

#

I have one more problem

#

which version of the moment is best

hushed robin
#

lts

twin swift
#

thx

#

oh

#

I have a problem again

#

I look like an cave man

#

but

#

who is this person

#

const { SlashCommandBuilder } = require("@discordjs/builders");

#

its erroring

hushed robin
#

require it from discord.js

deft wolf
#

What error?

twin swift
#

requireStack: [ '/app/src/commands/ping.js', '/app/server.js' ]

#

I m not using discord.js

hushed robin
#

what

twin swift
#

probably 5 months

#

I dont know v14

hushed robin
twin swift
#

what?

#

how

#

code: 'MODULE_NOT_FOUND',

hushed robin
#

how is that an error

neon leaf
#

replace @discordjs/builders with discord.js

hushed robin
#

yes

#

i just said that

#

lol

neon leaf
#

its now in the base module

hushed robin
twin swift
#
- /app/src/commands/ping.js
- /app/server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
    at Function.Module._load (node:internal/modules/cjs/loader:871:27)
    at Module.require (node:internal/modules/cjs/loader:1098:19)
    at require (node:internal/modules/cjs/helpers:108:18)
at Object.<anonymous> (/app/src/commands/ping.js:2:33)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Module.require (node:internal/modules/cjs/loader:1098:19) {
  code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/src/commands/ping.js', '/app/server.js' ]
}```
neon leaf
#

matey please just replace the module with what I / battleless said or install it

twin swift
#

oh

#

it works

hushed robin
#

☠️

twin swift
#

thank you so much

neon leaf
#

does someone know quite a bit about js references?
like I have an array thats an object with more nested objects, most of them arent references but I want few of them to be, so I made a variable that acts as my reference (its an object) and add it to the object in the array, now if I use Object.is to see if an object has the same reference the global reference says false when comparing to the first elements reference but is true when comparing to the second objects reference in the array, so all objects in the array share the same reference but it isnt the reference to the global one. why is that and can I fix it?

wheat mesa
#

I didn’t quite understand

neon leaf
#

like I have an array of object, right?

#

and lets say that object has two properties, name which is a string and school which is another object

#

now normally when you do const x = otherobject, x will be a reference so when you do x.name = 'test' the name also changes on otherobject

#

thats what I want for the school object

#

but for some reason when I lets say do people.push({ name: 'foo', school: globalObjectForSchool }) it isnt actually referencing school like I want it

#

imagine globalObjectForSchool being a variable thats accessible everywhere and that contains random properties, doesnt matter for this example

#

but now if I change the global variable for school it doesnt change in the people objects

#

but when I change the school property of one of the people, all change

#

so the reference somehow moved without me wanting it to

quartz kindle
#

all objects are references

surreal sage
#

Is this possible? js {} += {"key": "value"} //Expected outcome: {"key": "value"}

quartz kindle
#

nope

surreal sage
quartz kindle
#

but you can do that like this

neon leaf
surreal sage
#

spread op

neon leaf
#

but I dont really mean generally