#development

1 messages · Page 70 of 1

digital swan
#

like its not gonna do anything]

fossil bronze
digital swan
#

How intensive is your help command bro

fossil bronze
#

Doesn't matter given enough spam

slender wagon
#

so for calling an api could i just use fetch that was implemented lately on nodejs

#

or should i use axios (i don't like axios)

lyric mountain
#

Kills their fun instantly

north nymph
#

Unless it's a thread-freezing task, which means it's programmed incorrectly

#

Or you're creating a lot of objects each execution and i mean a lot, without clearing them after

earnest phoenix
quartz kindle
#

use http/https

earnest phoenix
#

The good* ol' HTTP(S) implementations, aren't they fun to use

eternal osprey
#
 const filter1 = i =>  i.member.id === gamedatabase[key].team2[3]
                                                        const collector11 =
                                                          r.createMessageComponentCollector({filter1,
                                                            componentType: "BUTTON",
                                                            time: 10000,
                                                            max: 1,
                                                          });
              
                                                        collector11.on(
                                                          "collect",
                                                          async (i) => {
                                                            if(i.member.id !== gamedatabase[key].team2[3]){
                                                              return;
                                                            }```why can everyone react to this collector?
earnest phoenix
#

The solution would be filter: filter1 in this case

tawny crow
#

what's the best way to collect reactions over a period of time in py-cord?

#

i tried sleeping for a set time and then collecting reactions but the count only included the bot's counts so im not sure what the problem is

boreal iron
#

I guess starting a timeout listening to the associated event and collect your data

#

No matter what ur language is

earnest phoenix
tawny crow
earnest phoenix
#

Pycord is a fork of discord.py that was created when discord.py's sole maintainer abandoned it, but they're back to continue maintaining it so it's better as it'll get much better and faster support

tawny crow
#

i see

#

thanks!

boreal iron
earnest phoenix
boreal iron
#

I mean one man projects are a thing but since he knows the time and effort he had to invest into it and was aware about all the people relaxing on his stuff it has been the worst decision to just throw anything away

#

While i fully agree real life comes at first without exception then coming back, flaming about discord and their shitty behavior and maintaining the project again literally because, I assume, too many people flamed him and ask him to continue it was also a weird move

#

Either I have thr time, know how and will to run a project or not

#

And without knowing him personally the stuff he wrote and I read anything and the context to all that makes me seriously say he's just an idiot not much else

#

While I still respect the decision to prioritize real life interests

#

The way he dropped his project and literally the community with the reason discord had a big impact because of their shitty development is nothing else than an excuse

#

I might not find the exact right words here what i want to say but it literally give you a direction what I think about just by reading his statements and getting some infos about the context

earnest phoenix
#

Yeah I agree, although none of it is an excuse to not promote some people they trust to be maintainers, especially the people with the most contributions and stuff; it would've make things much easier and better for not only them but also the project in it's entirety, and for the users as well as it would be maintained better

boreal iron
#

It's also a shame to make people move to the maintained project again after others have put time and effort into forks of his project to at least make it possible for the dpy community to go on

#

And have something they can rely on instead of fearing their code and projects will be completely outdated in the future

earnest phoenix
#

Yeah absolute shame, I've kinda always hate it when a big project is solely maintained by one person, if something happens to that person then oh well

boreal iron
#

Either you stand behind your projects (and community) or not

#

And yes life can always can change unexpectedly forcing you to do things you don't want to but then have the balls to make a decision

#

And not to drop anyone relying on your stuff, pointing the middle finger to them

#

For absolutely no reason

dry imp
#

i dont trust danny enough to use his projects again

#

but i dont even wanna do discord bot dev again so ill probably never gonna use both again lmao

radiant kraken
#

ezpz

dry imp
#

aintnoway 💀

#

my lifespan shorten drastically if i got into discord development

earnest phoenix
#
guildMember.timeout(5 * 60 * 1000, 'They deserved it')

Can someone explain the 5 * 60 * 1000 so I can figure out how to make it from 5 minutes to an hour

blazing flame
#

60 * 60 * 1000

earnest phoenix
#

yes but how does it work exactly

#

I don't want the answer I just don't know how to customize it

blazing flame
earnest phoenix
#

oh

#

thanks

blazing flame
#

Np

tawny crow
#

discord.py doesnt seem to detect my reactions (here is the code)

msg = await interaction.followup.send(stri + "\npick the number of your desired permutation (react with :x: to stop voting): ")
                for x in range(math.factorial(len(units))):
                    try:
                        await msg.add_reaction(emoji[x])
                    except:
                        pass

                await asyncio.sleep(math.factorial(len(units))*1.5)

                await msg.edit(content = f"round over!\n{lrs}")

                cache_msg = discord.utils.get(bot.cached_messages, id=msg.id)
                votes = [e.emoji for e in cache_msg.reactions]


                print(votes) # this line is purely to check in the console

                for e in Counter(votes):
                    print(e, emoji.index(e), Counter(votes)[e]) # this line is purely to check in the console
                    lrs += f"{e}: {Counter(votes)[e]-1}\n```
#

i made the bot edit the original message to display the results but it doesnt seem to be able to count votes (reactions) from my end

#

i had the same issue in py-cord (i switched over today)
does anyone know how to solve this?

sharp geyser
#

@dry imp did you know you can do this?

#

cause I sure didn't

stable eagle
#

woah

dry imp
#

string format stuff

#

i dont like using it tho

sharp geyser
#

Interesting

#
import math
skills = [
  "Farming",
  "Mining",
  "Crafting",
  "Healing",
  "Melee",
  "Archery",
  "Alcehmy",
  "Stealth",
  "Persuasion",
  "Mobility"
]

num_skills = len(skills)
variations = math.comb(num_skills, 3)
print(variations) # -> 120
#

I haven't messed with math stuff in many languages idk if any other lang has a similar comb method

wheat mesa
#

it's just a math equation

#

That's all it's doing for you

sharp geyser
#

What does ! mean though

wheat mesa
#

factorial

radiant kraken
sharp geyser
#

cannot find -lSDL2_image

set(SDL2_IMAGE_INCLUDE_DIR C:/Dev/SDL2-image)

include_directories(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR})
link_directories(${SDL2_LIB_DIR})
target_link_libraries(${PROJECT_NAME} SDL2main SDL2 SDL2_image)
sharp geyser
#

their shorts pop up all the time

sharp geyser
#

but...

#

it does?

#

looking at it rn

wheat mesa
#

chief that ain't what it means lol

radiant kraken
#

the file type is JetBrains CLion

wheat mesa
#

that looks like a shortcut to clion

radiant kraken
#

never knew CMake supported CLion files

sharp geyser
#

Its not CLion specific my guy

radiant kraken
#

what's the file extension

sharp geyser
#

its a header file apparently

wheat mesa
#

SDL_image isn't a header file either way so that doesn't make much sense

radiant kraken
#

either way you don't link with header files

wheat mesa
#

it should look more like that

radiant kraken
#

imagine making file extensions hidden

wheat mesa
#

You need to link the .lib file and set the include folder to that include folder in there

sharp geyser
wheat mesa
#

then you've got something wrong

#

when you downloaded it is that all you got?

radiant kraken
#

make it show file extensions

sharp geyser
radiant kraken
#

all you need are just the header files and .lib files

sharp geyser
#

Got it

sharp geyser
#

Non-const lvalue reference to type 'unsigned int' cannot bind to a temporary of type 'unsigned int'

void Math::fact(unsigned int& n)
{
    if(n == 0 || n == 1)
        n = 1;
    n * fact(n - 1);
}

I guess I can't use references here can I Sadge

radiant kraken
sharp geyser
#

Really

#

Bruh

#

😔

radiant kraken
#

also void Math::fact() {} is not valid C++

sharp geyser
#

Valid enough that it works

#

:^)

radiant kraken
#

unless Math is a class and fact is a static method already declared

#
namespace Math {
  void fact() {}
}
sharp geyser
#
//
// Created by dyeaa on 11/22/2022.
//

#ifndef BLAZE_MATH_H
#define BLAZE_MATH_H


class Math {
public:
    static unsigned int comb(unsigned int n, unsigned int k);
    static void fact(unsigned int& n);
//    static unsigned int fact(unsigned int n);
};


#endif //BLAZE_MATH_H
radiant kraken
#

why

#

just use a namespace

sharp geyser
#

Cause that is how CLion generated it null

#

:C

radiant kraken
#

bad practice

sharp geyser
#

I have to be a rebel at least somewhat null

#

or else im not myself

radiant kraken
#

then idk, haven't used c++ in years

#

@wheat mesa

sharp geyser
#

im kidding

wheat mesa
#

Huh

sharp geyser
#

would the header file just look like

namespace Math {
  void fact(unsigned int n)
}
wheat mesa
#

I believe so

sharp geyser
#

Also there's no way I can calculate the factorial using references can I? Its not needed but it'd be cool not having to save the result to a variable and just modify the existing ones

wheat mesa
#

Bad idea

sharp geyser
#

Oh?

wheat mesa
#

Shouldn’t do it like that

sharp geyser
#

Why so?

wheat mesa
#

It’s a bad practice to modify variables like that, you should be returning a new value for math stuff like that

#

I’m not saying you can’t, you just shouldn’t

#

It’s convoluted

sharp geyser
#

Fair point

#

I was just wondering if its s possible?

wheat mesa
#

Ofc

sharp geyser
#

The only way I'd know how to calculate a factorial would have conflicting types

wheat mesa
#

How do

#

So*

sharp geyser
#
namespace Math {
    unsigned int fact(unsigned int n)
    {
        if (n == 0 || n == 1)
            return 1;
        return n * fact(n - 1);
    }
}

for example if n was a reference instead and I removed the returns and such fact(n - 1) would result in a type confliction like I showed above

wheat mesa
#

Don’t use recursion for that

sharp geyser
#

should I just a for loop ?

wheat mesa
#

You can dereference the n if you want to do it like that though

wheat mesa
#

Recursion is slow

sharp geyser
#

Alright

wheat mesa
#

Should only be used when an iterative solution is difficult/impossible to write

sharp geyser
#

I keep getting an exit code cause I am dividing by 0

#

tf

#

Okay so

#

3628794! = Infinity

#

then I am taking that result and multiplying it by my second factorial (in this instance 6)

#
        std::cout << factorialN << std::endl;
        std::cout << factorialK << std::endl;
        std::cout << factorialN - factorialK << std::endl;
        std::cout << combinedFact << std::endl;
3628800
6
3628794
0
#

🤔 I think I am fucking up somewhere

wheat mesa
#

What types are you using

#

All I see is you subtracting

#

Not multiplying

sharp geyser
#

okay so in python math.comb(10,3) -> 120
factorial of 10 is 3628800
factorial of 3 is 6

(3628800 / (6 * (3628800-6)) -> somehow equals 120 even tho google says 0
#
unsigned int comb(unsigned int n, unsigned int k)
    {
        int factorialN = fact(n);
        int factorialK = fact(k);
        int combinedFact = fact(factorialN-factorialK);

        std::cout << factorialN << std::endl;
        std::cout << factorialK << std::endl;
        std::cout << factorialN - factorialK << std::endl;
        std::cout << combinedFact << std::endl;

        return factorialN / (factorialK * fact(factorialN-factorialK));
    }
wheat mesa
#

You’re not doing the math right

#

Oh wait hold on

#

Are you sure it’s not a massive number?

sharp geyser
#

I am doing it based on the formula though?

#

How can I check?

#

cause console just outputs 0

wheat mesa
#

You have some unsigned integer math

#

Be careful of underflow

sharp geyser
#

This makes no sense

#

😩

wheat mesa
#

Are you sure you’re doing this right

sharp geyser
#

IDFK waffle

#

I am not a math genius

#

which is why i've been googling the formula

wheat mesa
#

Plug it into wolframalpha or something with the same numbers

sharp geyser
#

How the fuck is math.comb getting 120 from these numbers

wheat mesa
#

Plug it in with the actual formula

#

With the factorials

#

What’s your numbers you’re doing

sharp geyser
#

3628800 and 6

wheat mesa
#

No

sharp geyser
#

oh

#

10 3

wheat mesa
#

I meant what are you using for the factorials

#

Ok hold on

#

So that means you should be getting 10! / (3! * 7!)

#

Which is 120

sharp geyser
#

7??

#

Wait

wheat mesa
#

10-3

sharp geyser
#

I am fucking dumb

#

Fixed

#

I was doing the factorial of n and k minusing each other and getting the factorial of that

wheat mesa
#

Yeah

sharp geyser
#

so I was doing 10! / (3! * (10! - 3!)!) like an idiot

#

😔

wheat mesa
#

Yeah that explains it

sharp geyser
#

Well now i have my own factorial and comb methods

#

I already forgor what comb was supposed to be used for

#

I guess get the number of possible combinations

#

so out of 10 and choice of 3 there is a 120 unique combinations possible ig that is what it means

wheat mesa
#

yes

#

(not considering order, otherwise it would be a permutation)

left hemlock
#

.

tawny crow
#

anyone has any idea why my reactions might not be working properly

lyric mountain
lyric mountain
neon leaf
#

alr so I have two numbers that cant be under 0 and can scale infinitely, lets say 5 & 7, Whats the best way to find out the percentage each take up? (with 3 & 7 it would be 30% and 70%)

earnest phoenix
#

percentage math

quartz kindle
#

negative percentage?

#

ah nvm

#

i read it as "can be under 0"

lyric mountain
earnest phoenix
#

scale infinitely probably meaning that they can be anything up to high numbers

quartz kindle
#

he probably wants something like 9374987% damage

neon leaf
#

no, its for voting so the total wont be over 100%

earnest phoenix
#

yeah, so that's normal maths

lyric mountain
#

ok so, you technically will need a maximum value, which in this case will be the number of votes

quartz kindle
#

100 * value / total

lyric mountain
#
total = 100
  X   =  ?

X * 100 / total = ?
earnest phoenix
#

that's like the first thing you learn in math class

#

three something thing

quartz kindle
#

yes

neon leaf
quartz kindle
#

its honestly the single most useful thing in math ever invented

earnest phoenix
#

rule of three actually

lyric mountain
#

yep

earnest phoenix
#

it's the only thing i still use

lyric mountain
#

it's among the most useful formulas out there

earnest phoenix
#

everything else went poof gone

quartz kindle
#

same kinda

#

i still use trig

earnest phoenix
#

thankfully i don't

neon leaf
#

can I somehow get the text of other buttons in d.js?

quartz kindle
#

sure

#

if they are in the same message, access the message then access its components

#

something like interaction.message.components

neon leaf
tawny crow
#

it actually does detect reactions but only those from the bot

#

so im trying to figure out why

lyric mountain
#

additionally, I'd suggest using upvote/downvote icons instead of + and -

neon leaf
#

how do I check if a user has already decided on an option?

#

aka how do I store that

digital swan
#

just put it in an array or a set if its not meant to last long

neon leaf
#

it should probably stay forever since its a poll though

#

would just saving it in my db be a good option?

digital swan
#

well if you want it to last forever it looks like thats the only option

lyric mountain
crystal wigeon
#

Hey im getting high cpu usage on nodejs ubuntu

#

im using htop to check whats causing it and it shows my nodejs program

#

any suggestions i could do to figure out whats causing this?

#

could it be that there are too many calls that would cause high cpu usage?

lyric mountain
#

well, "too many calls" but calls to what?

#

do you have anything you'd consider "intensive" tasks in ur bot?

neon leaf
#

how exactly would I go about storing the userids in the db? Id assume I need some kind of map to know the id and what they voted, how do I do that in postgres? I heard of jsonb but how would I query that?

digital swan
#

you could give each poll and id, store that in a db table. create another db table for votes, with columns for user id and the poll id, then store users in that table when they vote on a poll

#

then you can query based on poll id to figure out if a user has already voted on that poll

neon leaf
#

wouldnt that be pretty inefficient compared to jsonb for example?

digital swan
#

ive never heard of jsonb before, but thats how i would do it

#

probably better ways to do it yeah but it would most likely work well enough

lyric mountain
#

jsonb would be less efficient than a OTM table relationship

lyric mountain
#

"yes"?

neon leaf
#

yes

#

Ill change that

lyric mountain
#

is that a varchar field or...?

neon leaf
#

it is varchar

lyric mountain
#

just use boolean smh

#

what's the type for the other two fields?

neon leaf
#

varchar

lyric mountain
#

ok, those are fine then

#

what abt contraints, PK (messageId, userId)?

neon leaf
#

uhh

#

what

lyric mountain
#

primary key, did u make those 2 fields primary keys?

#

you need to assign a PK for each table, else u get NATURAL search queries

#

which are a fuckton slower than INDEX queries

swift carbon
#

I have been making a bot named ishu-bot it will be published soon!

lyric mountain
#

just run this ALTER TABLE <thetable> ADD CONSTRAINT <name> PRIMARY KEY (messageId, userId)

#

idk the name of ur table, so fill that in

neon leaf
#

should I do that for every one of my tables?

#

with other fields ofc

lyric mountain
#

well, not necessarily with two columns, in this case u have to since both messageId and userId might repeat, but never the same combination

#

but yes, always define a PK for all tables

#

if this table has relationship to other tables you'll also want to define a foreign key

#

for example, Human (PK Name, Sex, Age) --< Pet (FK Owner, PK Name, Race, Age)

#

a human can have multiple pets (--<), while a pet can only have 1 owner

#

a pet is linked to Human through the FK Owner, which will be the same as Human's PK

neon leaf
#

I think im not gonna go through that rn
Looks very complicated, especially with my 15 ish tables

lyric mountain
#

if u were to select it, you'd do

SELECT * 
FROM Human h 
INNER JOIN Pet p ON p.owner = h.name
lyric mountain
#

it's not like advanced min-maxing stuff, it's literally a thing you need to account when creating tables

boreal iron
#

when no pet exists, no match exists means an empty rresult will be returned

#

LEFT JOIN makes sense here

lyric mountain
#

not really, if ur selecting for pets

#

left join would include humans without pets

boreal iron
#

that's what I said, yes

#

because I assume humans exist without pets

#

not vise versa

lyric mountain
#

it all depends on the intent of the query tbh, whether you want only pet owners or all

lyric mountain
boreal iron
#

that's true, but like I said I expect humans without pets and your query would not return humans without pets

lyric mountain
#

and it aint really that hard, just think how tables would interact with eachother

boreal iron
#

just to show him and tell him the case matters and different types of JOINS exist

#

does pg actually require the INNER keyword?

lyric mountain
#

I think so

boreal iron
#

oh ... ok weird tho, usually JOIN should be INNER JOIN by default

#

so the engines really have noticable differences

lyric mountain
#

never looked it up tbh, I got the habit of declaring it everytime

#

yep, inner is the default join

graceful ferry
#

say i had 3 documents:

userId: ...
userBumps: [
{timestamp: 1, count: 1 },
{timestamp: 2, count: 1 },
{timestamp: 3, count: 1 }
]

and

userId: abc
userBumps: [
{timestamp: 0, count: 1 },
{timestamp: 2, count: 1 },
{timestamp: 3, count: 1 }

and

userId: 1234

i need to push some of the data to an array to look like this

[
{userId: ..., count: 3},
{userId: 1234, count: 0},
{userId: abc, count: 2}

if timestamp is greater than 0 (in this instance, this will change depending on the argument)

i have been trying to figure out a solution for a good few hours now and i know it seems so easy but oh my. Can anyone help me please?

lyric mountain
#

what you need is a combo of map + reduce

#

since u said "document" I imagine ur using some nosql database like mongo, but I cant really help with it

#

but if u were to do that with general objects, you'd use map + reduce

crystal wigeon
#

and my calls I mean all the network traffic

#

All the invokes from discord

lyric mountain
#
const test = [
  { a: 1, b: 5 },
  { a: 2, b: 3 },
  { a: 3, b: 6 },
  { a: 4, b: 0 },
  { a: 5, b: 1 },
];

const reduced = test.reduce((obj, out) => {
  if (obj.a < 3) {
    return out;
  }

  return out + obj.b;
});

console.log(reduced); // Will print 7
#

chose to use full-sized ifs for readability

#

but could be a one-liner with ternaries

lyric mountain
pale vessel
lyric mountain
flat copper
#

how can i short the link give by reader.readAsDataURL

earnest phoenix
#

@earnest phoenix is there a place where i can put this for people who wanna know?

https://github.com/pendragons-code/nsfw-reddit/

the thing seems obscure and there are many people in this server likely to use such features. So i'm sorry for ping, but maybe you can put this at a 'useful resources' section or something like that.

if it is not possible than oh, im pretty new to this thing, thank you

GitHub

So this repo helps you determine if a sub or postis nsfw or not - GitHub - pendragons-code/nsfw-reddit: So this repo helps you determine if a sub or postis nsfw or not

earnest phoenix
earnest phoenix
#

If you find someone else having such an issue, don't hesitate to give your input krWriting

earnest phoenix
#

so many things wrong in one function

#

no space between postcheck and (a)
no space between => and {
no camelcase function name
importing a moduke inside a function
awaiting a function but still using promises
postcheck => checkPost
using let unnecessarily

#

@drowsy vault next time please don't ghost ping

#

turks ☕

drowsy vault
earnest phoenix
#

💀

drowsy vault
#

@earnest phoenixAre you sure you spelled it right?

earnest phoenix
#

DM Enigma, not me.

#

Krypton != Enigma

drowsy vault
earnest phoenix
#

Then don't ask me

lyric mountain
#

inb4, make sure you're testing your commands without admin permission

earnest phoenix
#

You said that the king commands don't work, I'm trying it myself, it works perfectly?

No I didn't

earnest phoenix
lyric mountain
#

quick.db + multiple dbs = wtf are you even doing

earnest phoenix
#

quick.db = wtf are you even doing*

lyric mountain
#

quick.db could be so good if they (the devs) actually took their time to setup a proper ORM instead of saving everything in key-json tables

earnest phoenix
earnest phoenix
earnest phoenix
#

i did that because on my actuall prod thing i hosted the db on a seperate device and i was too lazy so i did that for github

#

think of it as a microservice onn a seperate server kinda thing

earnest phoenix
lyric mountain
#

age isn't a justification for bad practices

earnest phoenix
lyric mountain
#

but really, seriously speaking, I don't see the purpose of that whole file

earnest phoenix
lyric mountain
#

nsfw-reddit

#

you're printing to the console whether a sub is nsfw or not

earnest phoenix
lyric mountain
#

that's...not how github works

earnest phoenix
#

🤷‍♂️

lyric mountain
#

what I mean is that the whole file has no meaning since u can just make a request to reddit using any http lib

earnest phoenix
#

tell me, how should i have done it

earnest phoenix
#

that somehow work

#

that said, yes i rather improve

#

quick qtn, how old are you? im kinda conflicted about becoming a developer in the future

lyric mountain
#
const nsfw = await fetch(`https://reddit.com/r/${sub}/about.json`)
        .then(res => res.data.data.over18)
        .catch(console.log);

// Done
earnest phoenix
#

wait if i am not wrong "true", is returned as a string

#

i could be wrong

#

but yeah i get that i should have written it bettetr

neon leaf
#

its a boolean

#

I just tried it

earnest phoenix
#

noice

#

ok thanks

lyric mountain
#

you usually dont need to make wrappers for wrappers because...well...they're already wrappers

earnest phoenix
earnest phoenix
#

that really looks painful to me
await and then doesnt look good

lyric mountain
#

I mean, that's mostly a preference thing, I like to mine whatever data I need inside the same async block

neon leaf
#

turn 0 and 1 into boolean:
!!+0 // false
!!+1 // true

turn strings into boolean
('true' === 'true') // true
('false' === 'true') // false

lyric mountain
#

instead of returning the raw data

#

nope

#

that last part u missed hard

neon leaf
#

why

lyric mountain
#

=== doesn't do any kind of conversion

neon leaf
#

yes

earnest phoenix
lyric mountain
#

it's a strict-type comparison

neon leaf
#

thats the point

lyric mountain
#

it'll compare string content

earnest phoenix
#

Or carrying around the data you don't even need

#

yeah

neon leaf
#

that what its supposed to do

earnest phoenix
#

it compares and retuns a false

#

or true

#

without await could look better for me

#

but thats just my opinion

lyric mountain
#

without await you'd need to use the value inside .then block

earnest phoenix
#

depending if 'false' is 'true', it returns boolean false

lyric mountain
#

since you would not be able to extract the value to the outer scope

neon leaf
#

obv == also works but it doesnt matter in this case if you follow the comment

earnest phoenix
#

and help idk to do some stuff in winforms

#

dont ask why am i using winforms pls

earnest phoenix
#

ah

#

nerdtrex

lyric mountain
#

I also use winforms, they're fine if u don't need its xml cousin

earnest phoenix
earnest phoenix
neon leaf
earnest phoenix
#

3 months

lyric mountain
wheat mesa
#

💀

earnest phoenix
#

anyone an actually working as a dev for a living? if yes, please hear my story out,

i want to become dev, but im dyslexic and i cannot get my acads together
someone i know, a dev, took a similar path to me because they did bad at school and totally regrets becoming one

he takes the same paths as me in acads and basically is very likely me in the future, what should i do?

not even a dev, multiple actually, btw the devs in qtn are my school it guys.
and sysadmins (only 4 of them are sysadmins, the rest are actual devs)

earnest phoenix
lyric mountain
#

being a developer is a "you" thing really, everyone can code but not everyone can think abstractally enough to become a dev

earnest phoenix
lyric mountain
#

like, "typing" or "knowing all the keywords" is the least of the problems, you need to think as if you were building something greater

earnest phoenix
#

PFFFT AHHAHAAHAHHAHA

#

im ugly enough to look like that guy, so that meme is literally me

#

no but seriously, the industry itself is also looking bad

#

How so?

#

mass retrenchment and lay offs in FAANG

#

i mean FAANG isn't everything, but they are major players

lyric mountain
#

nah, they're just the popular guys

earnest phoenix
#

after the pandemic, less people are as reliant on the computers

lyric mountain
#

excuse-me????

earnest phoenix
#

yeah>

earnest phoenix
#

i actually used more electronics before and during the pandemic than after

#

the lockdowns *

neon leaf
#

well you still use some dont you?

earnest phoenix
#

help me

earnest phoenix
# earnest phoenix mass retrenchment and lay offs in FAANG

Well there's logic behind those lay offs and stuff, only the people who are active and working as expected get to stay, not the Daniel sitting on his ass all day doing nothing and slacking off at work, and not reaching the required quotas, so it doesn't make them look bad really

spark flint
#

@earnest phoenix just be patient

#

you asked in support 😭

lyric mountain
#

that's just confinement sickness, IT jobs are even higher than ever

rose warren
#

Please mind your language @earnest phoenix

earnest phoenix
#

not the remote guys too XD

earnest phoenix
spark flint
#

anyways.i was gonna ask something code related and got distracted

earnest phoenix
spark flint
#

what was i gonna ask

earnest phoenix
rose warren
#

The message that got blocked

earnest phoenix
#

:troll:

spark flint
earnest phoenix
earnest phoenix
#

lmao

spark flint
#

you asked in #support, someone will answer there

#

anyways uhhh

rose warren
#

You know what you typed

earnest phoenix
spark flint
#

damn i forgot what to say

earnest phoenix
spark flint
earnest phoenix
#

oh it was

spark flint
#

i feel like trying to bypass the filter is not a good idea lol

rose warren
#

Yes mind your language thanks

oak cliff
#

👀

spark flint
#

oh no so many team members

earnest phoenix
#

why it doesnt show :pain:

spark flint
#

😭

earnest phoenix
#

Development becoming common-sense-development

#

blocked?

spark flint
#

life-development

lyric mountain
earnest phoenix
lyric mountain
spark flint
earnest phoenix
#

no no

#

and a guy that knows nothing about listview

spark flint
#

lol this is funny

earnest phoenix
#

shoot he said blocked

#

im asking what he meant blocked

lyric mountain
#

automod

#

that word caused the message to be deleted and notify the mods of your infraction

earnest phoenix
#

how is it still there, but blocked?

lyric mountain
neon leaf
#

no

earnest phoenix
#

oh bruh

neon leaf
lyric mountain
#

you dont get notified, only the mods

earnest phoenix
#

ok what

lyric mountain
#

it's like a silent alert

neon leaf
earnest phoenix
#

so how was i supposed to know XD

spark flint
#

i did some code work saved on a college PC, i tried to get it from another one and now I can't find it 😭

lyric mountain
#

oh, it's still there

earnest phoenix
#

but yeah, i;ll still not say it tho

lyric mountain
earnest phoenix
#

i can't delete it

#

what the that thing just teleported

lyric mountain
earnest phoenix
#

discord is bugging on me

earnest phoenix
#

the subitem

lyric mountain
#

I never used the ui builder, I always made my forms though code

earnest phoenix
#

insane

#

im currently testing if it works

#

but for some reason its not

earnest phoenix
lyric mountain
#

they're talking abt the winforms component not appearing, from what I understood

earnest phoenix
#

im gonna drink sulfuric acid

lyric mountain
#

I don't think you should chain off an add call

earnest phoenix
#

whatever

lyric mountain
#

tbh, I dont even know what ur attempting to do

earnest phoenix
lyric mountain
#

and what is that?

earnest phoenix
#

html

lyric mountain
#

I refer to the "thing" you're trying to show

crystal wigeon
earnest phoenix
#

its something that i made

#

which is the only popular thing i made

#

see my most popular repo on gh :teef:

crystal wigeon
#

but it usually finishes in like less than 2sec max

#

but its all non blocking code

cursive musk
#

Learning discord.js, what does type mean?

client.user.setActivity(
      `Tutorial bot`,
      {
        type: 3,
      }
    );
earnest phoenix
#

That's the type of the activity

cursive musk
#

I see.

earnest phoenix
#

So 3 represents a watching activity

cursive musk
#

Thanks!

earnest phoenix
visual prairie
#

How to speedup bot verify ?

earnest phoenix
#

You can't, as simple as that

visual prairie
#

Ok, thanks

#

Now I see that you are checking servers from 5 days ago, it's not that bad yet

#

How long does it take to review one request

wheat mesa
#

They get to you when they do, no point in wondering how long it'll take. Queue times vary, there's a pin in #support for estimated times right now

visual prairie
#

I am interested in how long it takes to check one bot, 2min ?

wheat mesa
#

Oh

#

I'm sure it depends on how many features that bot has. The reviewers are looking for things that break the rules of top.gg

craggy pine
#

Depends on how advanced the bot is, if there are any language barriers that needs to be translated during testing, ect

visual prairie
#

I understand, thanks for the reply

lyric mountain
crystal wigeon
#

well its drawing on canvas, let me send code

#
export const createBattleCanvas = async (
    cards: (
    | Pick<
        CollectionCardInfoProps,
        "filepath" | "type" | "rank" | "id" | "metadata"
      >
    | undefined
  )[],
    extras?: {
    isSingleRow: boolean;
    version?: "small" | "medium" | "default";
  }
): Promise<Canvas | undefined> => {
    if (!Array.isArray(cards)) return;
    const canvas = createCanvas(
        CANVAS_DEFAULTS.width,
        extras?.isSingleRow ? CANVAS_DEFAULTS.height / 2 : CANVAS_DEFAULTS.height
    );
    const ctx = canvas.getContext("2d");
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.fillStyle = "#000000";
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    if (!extras?.isSingleRow) {
        const bgPath = await loadImage("./assets/images/background.jpg");
        ctx.drawImage(bgPath, 0, 0, canvas.width, canvas.height);
    }
    try {
        const dh = extras?.isSingleRow ? canvas.height : canvas.height / 2;
 
        const images = await Promise.all(
            cards.map(async (card) => {
                if (card) {
                    // const startImageTimer = loggers.startTimer("[Image] Path: ");
                    // load precomputed images with border and stars
                    let filepath = card?.filepath;
                    const version = extras?.version || (extras?.isSingleRow ? "medium" : "small");
                    if (card.metadata?.assets && card.metadata.assets[version]) {
                        filepath = card.metadata.assets[version].filepath;
                    }
                    // startImageTimer.message = startImageTimer.message + " -> " + filepath;
                    const image = await loadImage(filepath).catch((err) => {
                        loggers.error("canvas.createBattleCanvas: ERROR Unable to load filepath -> " + filepath, err);
                        throw err;
                    });
                    // loggers.endTimer(startImageTimer);
                    return {
                        id: card.id,
                        image,
                    };
                }
            })
        ).then((res) =>
            res.reduce((acc, r) => {
                if (r) {
                    acc[r.id] = r;
                }
                return acc;
            }, {} as { [key: string]: { id: number; image: Image } })
        );
        return await new Promise((resolve) => {
            for (let i = 0; i < cards.length; i++) {
                const card = cards[i];
                if (!card) continue;

                const dy = extras?.isSingleRow
                    ? 0
                    : (canvas.height / 2) * Math.floor(i / 3);

                ctx.drawImage(
                    images[card.id].image,
                    (canvas.width / 3) * (i % 3),
                    dy,
                    canvas.width / 3,
                    dh
                );

            resolve(canvas);
        });
    } catch (err) {
        loggers.error(
            "helpers.adventure.createBattleCanvas: ERROR",
            err
        );
        return;
    }
};```
#

do you see any blocking code here? this function executes in less than 1sec max

lyric mountain
#

yep

#

await

#

if ur going for async u need to go async all the way

#

but well, not to shoot the wrong target, do this:

#
const before = new Date().getTime();
try {
  const cmd = ...;
  // whatever u use to call commands
} finally {
  console.log(`${cmd.name} took ${before - new Date().getTime()}ms`);
}
crystal wigeon
#

mhm alr

crystal wigeon
#

so that should be good no?

lyric mountain
#

well, js has a little issue where tasks inside the promise constructor can halt the entire program (since js is mono-thread)

quartz kindle
#

returning a promise doesnt change anything

crystal wigeon
#

hmm, so how do you recommend i go about this, cause using for loop directly is straight up blocking code no

#

hmm

quartz kindle
#

canvas itself is sync, you cannot make it async

lyric mountain
#

for example

console.log("Before")

new Promise((res) => {
  while (true) {}
})

console.log("After")
quartz kindle
#

ctx.drawImage is sync

lyric mountain
#

although the infiniloop is inside a promise, "After" will never be printed

crystal wigeon
#

so in that case there's nothing much i can do?

#

i see

lyric mountain
#

I cant really say THAT'S what's causing the freeze, put the measurer as I said before

#

then run the commands

#

the one that shows the biggest number is the one that's halting the prog

quartz kindle
#

the only way to make it "async" is to break the loop into diffeent parts and manually introduce delays

#

which is not really recommended, you wont make it faster like that, just slower

crystal wigeon
#

adding delays? but if canvas itself is sync, will it still not halt?

crystal wigeon
#

actually

#

its even less i think

lyric mountain
#

well, 1 sec is a fucklong time

#

just let the bot run for a while

#

when u notice the halt, look at the logs

crystal wigeon
#

hmm alr i'll give that a shot

#

but the question is, if i do find an image taking longer to be drawn, how do i go about it, if its an already down sized image,

#

all of my images are less than 100kb

lyric mountain
#

filesize doesn't usually reflect the actual image size due to compression

crystal wigeon
#

no im manually downsizing them

lyric mountain
#

in java I simply split the image in sections and render each part individually, merging into a final result

#

it might not be as fast as a single task, but it allows me to balance the job across some threads

#

idk how to accomplish that with canvas tho

quartz kindle
#

i believe we talked about this before

#

i suggested pre-rendering the common stuff, like background

crystal wigeon
#

yep, im doing that

#

im precreating the image with required cosmetics like stars etc, then putting 3 images together

#

on the canvas

#

ig can do that, but will that still not become blocking?

#

cause takes cpu

quartz kindle
#

youre still loading the images from disk

#

you can keep them in memory in separate canvas objects

crystal wigeon
#

any example i can use?

#

im actually loading each image from a url dynamically, and combining 3 images into 1 canvas

surreal sage
#

JavaScript function/method or library to make number strings?
e.g 1 > 'one'

lyric mountain
#

oh btw, if possible, dont resize images during render

crystal wigeon
#

its not during render

#

its already pre-computed images

lyric mountain
#

ah ok

crystal wigeon
#

jsut combining 3 images into 1 canvas

quartz kindle
#

this part for example

#

it always loads from disk

lyric mountain
crystal wigeon
#

ah that, yeah i forgot to remove that from snippet but that isnt being used

surreal sage
#

No as in
Number 15 > String "fifteen"

quartz kindle
#

const image = await loadImage(filepath).catch((err) => {

crystal wigeon
quartz kindle
#

yes

lyric mountain
crystal wigeon
#

this is where the image is loaded from a external url

surreal sage
#
quartz kindle
#

how many different cards are there?

crystal wigeon
#

maybe i can store the image buffer once i get from url?

quartz kindle
#

you can cache them

#

yes

crystal wigeon
#

there are many, people can use it in combination

#

600 unique images

lyric mountain
#

ig that one will do

#

tho wtf is a "lakh"

crystal wigeon
#

lmao

#

indian alert

#

hahah

#

thats 100k

#

1 lakh is 100k

#

xd

lyric mountain
#

ah

quartz kindle
#

you can do something like ```js
let image = card.cache;
if(!image) {
image = await loadImage(filepath);
card.cache = image;
}

crystal wigeon
#

gotcha

#

but will it not overload memory

quartz kindle
#

it will use more memory yes

crystal wigeon
#

or is 600 okay enough

#

i got 16GB

#

memory

#

so ig worth a shot

quartz kindle
#

memory is often used to make things faster

#

you have to monitor it

#

and if it gets too much you start balancing it out

#

for example deleting un-used caches

crystal wigeon
#

is there logic i can determine which ones are un-used

quartz kindle
#

set timers, add timestamps for when a cache was used last time

crystal wigeon
#

mm

lyric mountain
crystal wigeon
#

ahh yes

#

wait ttl?

lyric mountain
#

time-to-live

crystal wigeon
#

if its most used why would i use a ttl

#

ik i meant, if its frequently used

#

why ttl after some time and load again

lyric mountain
#

nono, if it's recently used

quartz kindle
#
let image = card.cache;
if(!image) {
  image = await loadImage(filepath);
  card.cache = image;
}
card.lastUsed = Date.now();
crystal wigeon
#

ig thats the best way instead of me building the logic

#

manually

lyric mountain
#

there are 2 types of ttl

#

LRU and LFU

crystal wigeon
#

i see

quartz kindle
#

anyway i g2g

crystal wigeon
#

cya, thanks for the help

lyric mountain
#

LRU will remove the least recently used entries after some time

crystal wigeon
#

tim

#

hmm

lyric mountain
#

LFU will remove the least frequently used ones

crystal wigeon
#

is it possible to set that in redis?

#

does it support

lyric mountain
#

the difference is that LRU simply moves the tail to the head on access

#

while LFU will store a counter to track access count

crystal wigeon
#

i see

lyric mountain
#

I believe redis does

crystal wigeon
#

which would be most optimal

#

in that case

#

LFU or LRU

lyric mountain
#

I prefer LRU

#

but LFU can be good too

crystal wigeon
#

hmm

lyric mountain
#

it all depends on your usage, try both and see what fits the most

crystal wigeon
#

alright, thanks a bunch

lyric mountain
#

I for example use 3 levels of cache for my bot

#

a small, ultrafast heap cache, a larger but not as fast off-heap cache and a big slow file cache

#

the lib I use automatically manages that for me, the cache will go to the next level if it hits the size limit

crystal wigeon
#

i see

#

what lib are you using for that?

lyric mountain
#

cache is tricky to get it right, but it's a fun thing to implement

lyric mountain
crystal wigeon
#

yeah

lyric mountain
#

it's a java lib btw

crystal wigeon
#

nice thanks

#

wew i see haha

lyric mountain
#

java, not "script"

crystal wigeon
#

well there has to be an alternative in js anyway

#

yeah

#

dw

#

lol

lyric mountain
#

probably, I believe all langs have cache-specialized libs

#

redis is good, but it's a single-level cache

crystal wigeon
#

well it says redis is an alternative wlep

lyric mountain
#

perhaps there's a way to configure it for multi level

#

but u dont really need to go into multi level unless ur using a ton of assets constantly

#

my bot is a tcg bot, so I quite literally have to render an entire game (2d) for each frame

#

so I rely a lot on cached assets

crystal wigeon
#

i see

#

demm

#

well its been an interesting topic for me as well, effecient caching

#

i had problems before where the cache was not updating user info or the info in DB and cache were completely out of sync wew

#

because the updates were so frequent

lyric mountain
#

u dont really need a cache for most dbs

#

unless ur dealing with clusters

#

or a big amount of clients

crystal wigeon
#

{ image: [Image:236x315 complete] }

#

how do i store this in redis,

lyric mountain
#

you need to serialize the image

crystal wigeon
#

i see, how?

lyric mountain
#

idk what kinds of formats redis allows

#

if it allows bytes, simply store the image buffer directly

#

else convert the buffer to base64 and store as text

#

do note that base64 is 33% bigger than storing as bytes

crystal wigeon
#

i see, i mean how do i do that for the image

lyric mountain
#

since it uses 3 bytes per 2 bytes (iirc)

lyric mountain
crystal wigeon
#

mm

lyric mountain
#

for byte -> b64 theres atob(bytes)

#

then btoa(string) to reverse

crystal wigeon
#

gotcha

#

mmm

#

dem it only has onload, on error

#

height, width

#

there no data buffer at all in the image object

lyric mountain
#

google time

crystal wigeon
#

ye not able to find anything lel

lyric mountain
#

in java it'd be just image.toByteArray() lmao

#

canvas has some nice features like filters and named colors, but also a fuckin ton of missing features

crystal wigeon
#

well, all the solutions say i need to load image to canvas and convert to dataurl

#

makes no sense

lyric mountain
#

I mean, converting to dataurl is probably converting to base64

#

since base64 is a valid url

crystal wigeon
#

yeah

quartz kindle
#

try image.data

crystal wigeon
#

that prop doesnt exist

#

lemme send ss

quartz kindle
#

it does in their code

crystal wigeon
#

these are all the properties its giving me

#

im using canvas 2.8.0

quartz kindle
#

its private

crystal wigeon
#

hmm, alr let me try

lyric mountain
#

js doesn't care abt privacy does it? KEKW

quartz kindle
crystal wigeon
#

lemme try it real quick

sharp geyser
#

cause you sent it

wheat mesa
#

That’s C

sharp geyser
#

I know

wheat mesa
#

And/or C++

#

Could be either from that ss

quartz kindle
#

because js is all you expect from me huh?

#

:^)

lyric mountain
#

that method has such an odd name tho

#

cairo_image_surface_get_data

quartz kindle
#

so you might as well download the image using http and saving the buffer directly

#

then use loadImage with the buffer

#

but redis is not gonna improve your performance

crystal wigeon
#

i was gonna say image.data was undefined

#

so whats the optimal solution for this in that case

#

mmm

#

well the main goal is to reduce any blocking code

quartz kindle
#

the problematic part of node-canvas is that all images have to be unpacked into the canvas format, which is what loadImage does

crystal wigeon
#

hmm

quartz kindle
#

so no matter where you store the image data, you will always have to use loadImage before you can use it with canvas

crystal wigeon
#

i see, and drawImage is always sync

quartz kindle
#

the only way to improve performance, is to store the loadImage result in memory

crystal wigeon
#

cant do anything about it?

#

yeah well thats what im trying to do

quartz kindle
#

drawImage uses loadImage if you give it a url

crystal wigeon
#

the loadimage result is what i showed earlier

quartz kindle
#

so the only solution is to store the result of loadImage in a variable

#

and reuse it

crystal wigeon
#

and not in cache?

quartz kindle
#

the variable is the cache

crystal wigeon
#

yeah so to store in redis, it should be a string

#

how do i stringify it

quartz kindle
#

no

#

a variable in js

crystal wigeon
#

aa

#

so basically global object

quartz kindle
#

yeah

#

you already have a card object right?

crystal wigeon
#

hope it doesnt cause memory leaks

#

yeah

quartz kindle
#

for all the different cards?

crystal wigeon
#

yep

#

ooo

quartz kindle
#

so you can put it in the object as well

crystal wigeon
#

thats what you mean

#

but then i will have to loadimage at the start of the command

#

in that case

quartz kindle
#

its the same principle as used by video games, all images are loaded into memory, before the game can run

#

it uses a lot of memory, but gives the game the performance it needs to run smoothly

quartz kindle
crystal wigeon
#

so here's the thing

#

the card is not a global object

#

when a user invokes a command the card is fetch from db

quartz kindle
#

then you need a place to store it, for example a Map

crystal wigeon
#

alr, so 600 * 9 is the number of images i have

#

more than 600 actually

#

will that not cause memory leaks

#

or should i wrong

#

ttl logic

quartz kindle
#

so put a timer in the cache items

crystal wigeon
#

like least frequentyl used

#

mm

quartz kindle
#

and delete those that are not used

crystal wigeon
#

isnt using settimeout a bad thing?

#

mm

#

ig thats one way to approach it

quartz kindle
#

its not a bad thing, but you dont need to use it either, there are other ways

#

for example

crystal wigeon
#

just trying to avoid memory leaks

#

hmm

#

while fetching from cache

#

i can delete?

#

but then it would only be deleted if it is accessed

quartz kindle
#
const cache = new Map();
setInterval(() => {
  for(const [key, val] of cache.entries()) {
    if(val.time < Date.now() - 3600000) { // last used more than 1 hour ago
      cache.delete(key);
    }
  }
}, 600000); // run every 10 minutes

// inside the command
... {
  const cached = cache.get(card.id);
  let image;
  if(cached) {
    image = cached.image;
    cached.time = Date.now(); // image is used again, so reset time
  } else {
    image = await loadImage(card.url);
    cache.set(card.id, {
      image,
      time: Date.now();
    });
  }
}
crystal wigeon
#

mmm

#

i was thinking the same logic, ig i have to give this a try

#

thanks a bunch btw, i appreciate it AEMJ_mochity

quartz kindle
#

then you have to monitor your memory usage

#

and find something you're ok with

#

it will use a lot more memory, but it will be much faster when repeatedly loading the same cards

#

you can tweak how often to run the interval and how long to keep the cards in memory

crystal wigeon
#

hmmm

#

makes sense

#

i hope it wont cause any memory leaks. lets see, i'll give this a shot

quartz kindle
#

i usually set my caches to 24 hours

crystal wigeon
#

will the for loop not cause any event blocks no?

crystal wigeon
quartz kindle
#

looping over the Map shouldnt be a big deal

crystal wigeon
#

but ye there will be 600 * 9

#

items

#

in there

#

mm

#

eventually

lyric mountain
#

cant some images be generated procedurally?

quartz kindle
crystal wigeon
#

sikeee

quartz kindle
#

haha cool

graceful ferry
#

Does anyone know the cause for this bug? The bot will occasionally send improper emojis despite having the correct permissions and them being coded as proper emojis.

graceful ferry
lyric mountain
#

ah ok

cursive musk
#

If you did !eval process.exit() as a joke, and now your MongoDB isn't connecting anymore what should you do iu_cry

wheat mesa
#

restart the process entirely

#

perhaps you shouldn't evaluate code like that in the future, just a tip

cursive musk
#
node:events:491
      throw er; // Unhandled 'error' event
      ^
MongooseError: Operation `bots.count()` buffering timed out after 10000ms
    at Timeout.<anonymous> (/home/container/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:153:23)
quartz kindle
cursive musk
drifting cairn
quartz kindle
#

is mongo also local hosted?

#

or is it mongo atlas?

cursive musk
cursive musk
quartz kindle
#

did you whitelist your host's ip address in your atlas configuration?

quartz kindle
#

show your mongodb connection code

earnest phoenix
#

@quartz kindle is this correct code to make the bot reply if someone mention it.

const { MessageEmbed } = require ('discord.js');

module.exports = (client) => {

client.on('messageCreate', (message) => {

const mentionEmbed = new MessageEmbed()
.setTitle(`Hello ${message.author.username}!`)
.setDescription("To view my commands, use </help:0>")
.setColor('#4169E1');

if (message.content === `<@${client.user.id}>` || message.content === `<@!${client.user.id}>`) return message.reply({ embeds: [mentionEmbed]})

}); 

   }
#

I can't try it on my pc since it's been gone for servicing.

Can u plz try and tell? If u dont mind

earnest phoenix
#

How do I get the amount of users in a server without bots included? I haven’t found anything online that helped I’m using discord.js V14

lament rock
#

I love waiting for typedoc to finish compiling for 5 minutes straight

lament rock
#

I read your question wrong. Just filter over the members and exclude bots

earnest phoenix
#

But how I’ve never done it before

#

And couldn’t find it online

lament rock
#

members.cache.filter

earnest phoenix
#

Thank you

lament rock
#

Your editor should help you if you use vscode

earnest phoenix
#

I do

lament rock
#

or any other editor with intellisense

#

great then learn how to use filter

#

Collection<K, V>.filter is the same essentially as Array<T>.filter

earnest phoenix
#

Or I could just have it pull the bots and the members then subtract bots from members

ocean pasture
#

~~I've ran the webhook manager and pressing send test but im not getting anything on my end?

I'm listening to the on_dbl_vote event with discord.py in a cog.~~

I fixed it, was running on a test bot so nothing was firing.

crystal wigeon
#

Does anyone use vultr hosting ?

#

How often do they do “maintenance” this usually means all my vms are pretty much gonna be shut down no? How would I get high availability in that case

#

If I’m running things in production I can’t just shut down these Vms and wait for them to finish maintenance

crystal wigeon
#

do thye have a discord server

earnest phoenix
crystal wigeon
#

ty

crystal wigeon
#

hey is there a way for me cache the images loaded from path in nginx ?

#
    async getImage(req, res) {
        try {
            const filename = req.params.filename;
            const finalPath = `${STORAGE_BUCKET_V3}/${filename}`;
            const { mime } = await FileType.fromFile(finalPath);
            res.type(mime);
            return res.compress(fs.createReadStream(finalPath));
        } catch (err) {
            if (err.code === "ENOENT") {
                return res.notFound();
            }
            return res.serverError();
        }
    },
};```

So i have this code, and everytime the image url is called it serves from disk. which is not ideal right? because the images dont change unless its replaced
lament rock
#

What you'd do is tell the client to cache the image and then the client sends an If-Modified-Since header

#

If it's been modified, you 200 send the image, else, 304

#

This can be done by sending a Last-Modified header to the client

#

Please read the mdn docs for these headers

crystal wigeon
#

Gotcha, thanks

rare mist
lyric mountain
#

for keeping a ws connection alive is sending an empty string once in a while enough?

earnest phoenix
#

If the server sends a ping, the client will answer with a pong

#

Should also work the other way around

#

The ws server you use most likely has them already implemented

lyric mountain
#

don't think so, I'm using bare websockets

#

but implementing it is easy enough, ty

earnest phoenix
#

In that case you need to implement yep, not super hard as you said

lyric mountain
#

funny enough, I already had implemented a ping pong before, but the rate was the same as the conn timeout

#

made it half the timeout, should work correctly now

quartz kindle
#

ping and pong are frames defined by the spec (op code 9 and 10)

#

whatever websocket implementation youre using should already have them

#

if youre making your own websocket with raw tcp then just implement them according to the spec

#

you can also have application level pings, like discord does, which uses regular data frames

#

those are mostly used for situations where the connection can break without breaking the actual websocket connection, ie a zombie connection

lyric mountain
#

I was sending once every minute, but the timeout is also 1 minute

#

I just made it always be half the timeout time

spark flint
quartz kindle
#

forbiden

#

for biden

wide herald
#

@sleek marsh post your problem here. there is like 4k bot devs on this server 😄

lyric mountain
#

more like 12 on this server and 3988 on the list

slender wagon
#

have you guys heard about the new friend request link

lyric mountain
#

yep

wide herald
slender wagon
#

anyway to modify it on creation (make it unlimited)

sleek marsh
#

so the problem in my code is that my core was missing in the code and to add it i did something terrific i deleted the venv file and now i cant restore it

lyric mountain
#

uh oh

sleek marsh
#

any solution to restore it ?

#

there was like 5k+ files in it

slender wagon
sleek marsh
#

i dlted cuz it missed google trans package

wide herald
lyric mountain
#

so...a venv file represents a virtual environment, something akin to a partition

#

if u deleted it I don't think any source control would be able to store a venv file (nor they should)

sleek marsh
wide herald
#

would it be much trouble to set a new environment up and copy your code files over?

lyric mountain
#

that said, I believe u don't really need to restore it

sleek marsh
lyric mountain
#

if I'm not mistaken, venv is exclusively used for python packages

lyric mountain
#

just reinstall those

sleek marsh
#

it is a python code

sleek marsh
#

how ?

lyric mountain
#

like, venv doesn't contain your code, it's only a "place" where your code will be ran

#

together with its dependencies

sleek marsh
#

oh

#

lemme try

wide herald
sleek marsh
#

this came when i tried to run

lyric mountain
#

you'll need to pip all modules again

sleek marsh
#

pip i discord

lyric mountain
#

yep