#development
1 messages · Page 1961 of 1
lol
This should be the default behavior for java
https://docs.oracle.com/javase/10/docs/api/java/lang/Math.html#addExact(int,int)
issue is that would be a breaking change
I think what's wrong with Java is it tries to be a high-level language but mixes systems programming with it
So a lot of what other programming languages abstract away for you creeps into Java
I find java to be one of the perfect examples of middle level language
Has both sides into it
Can be abstract as hell OR touch JNI
although with jni you'd partially enter into c++
yeah, it not a good idea to try to be both a systems language and an application language.
How does anything cute, like my sweet win end up in a big weird shit, like Java in this case?

You’re all crazy!
And where tf is Tim and his even crazier opinion?
_to anything _
No you're the crazy one
Yeah being normal between so many crazy dudes actually makes me crazy, too, there’s no other explanation for this
there is nothing that is normal
Normal is relative
That’s actually not true
Normal is usually what most of the people think of is normal
Well then nothing is normal
As there’s no actual definition for it
Its hard to gauge what is normal if its put into that definition
It is not, people just try to transform hit how they like
An example:
Most people on earth are not gay, that means we feel like this is the normal condition
People who are gay know they are a minority - in other words they are not normal
Now normal describes a condition in this example basically a relation of a minority and majority
Now people say something being not normal is bad because it’s different, they associate it to something completely different than the original meaning
We always need to find a position as a measuring point
In this a simple majority is what we call normal, that’s our subjective position
In reality it doesn’t actually matter which one is the case but humans always need to break down things
I’m too tired to go on at this point but just the beginning of what would be important to say about this facts
Which means as how we explain things, the nature, physics etc. something normal - common is always the thing with the largest quantity - which mostly occurs and anything else is not normal - just being different to the rest - we also call it an exception
Which means it’s actually not relative
That’s was the short version
Which ends up in normal actually being defined strictly but very different regarding on where to use it
Should change my job to do philosophy
You seem to do better in it
Can someone help me with my code?
I get an odd error
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'gameOver' is not defined
I know this means gameOver is not defined
but it is clearly defined in the code multiple times...
Please ping me if you know how to help me
Also, I have just converted the code into cogs instead of client.command
It was working perfectly before though...
See I don't know python but I am curious, are you allowed to keep doing global gameOver
I'm not entirely sure
I believe it's just there so it can be used again and again within the code
Mmm, but if you keep defining a global variable isn't that just going to mess stuff up?
Or is that not what global does ti seems like that is what it does
I guess so
Also you already have gameOver defined in the class scope so cant you just use that?
Thats more of if gameOver
You should never create global variables in any language since you could accidentally overwrite a built in or a constant someone else has defined. Unlikely in some cases, but still something to consider. Global is also a strange context, so you should only use local context variables
What is the point of defining gameOver with a value if you are going to overwrite that and give it no value
If you need a variable in other files, you should be assigning it to something like a shared required module that acts as a passthrough
What can I do instead then?
Assuming scopes work how i think they do in python you have gameOver = false then in your methods you do global gameOver giving it no value so it doesn't know what the value actually is (I assume this is correct can someone correct me if im wrong)
It will just give me an error for gameOver isn't defined
Alright, I will try that. Thank you!
Ayo dont take what i said to be factual
I dont know python I was more asking a question

the logic checks out.
Honestly just try removing the global stuff and I think it should work. Since you are already defining the values outside the methods with default ones and seems like you are overwriting those values when you need to.
Now that I deleted the global variables, its giving me a "referenced before assingment" error
hmm
Is this some kind of cog error?
Like I said before
It worked perfectly on client.command
I'm very confused
did you assign it a value before accessing it
You need to keep global gamOver before gameOver = True
So are you saying to keep a global value?
Yea but apparently you define it before gameOver = True
Yes
python seems weird
And then it just never finds that variable again...
I think he means like
class Fun(commands.Cog):
def __init__(self, client):
self.client = client
global gameOver
#Tic Tac Toe Command
player1 = ""
player2 = ""
turn = ""
gameOver = True
not entirely sure tho so dont quote me 
There are still errors
Yeah. That's how Global variables work if you wanna defind gameover as a global value.
You should try gameOver = False at start.
I checked code, it's working fine, on gameover = True
figured this might help some folks:
const some_variable = "supyo";
const some_object = { [some_variable]: 5};
console.log( some_object );
// => {supyo: 5}```
Mmm
That is the most confusing thing I have seen in js
oh wait no im stupid thats why
I am also confused by it
I dont see the point
nah I get it
the value of some_variable acts as the key in the object
its simple actually
it just fucks with ur brain
const some_obj = { supyo: 5 }
console.log(some_obj)
ez
Only way I can see it being useful if you are going to use the key name for something else.
its incredibly useful in cases where you have no idea what the keey will be
or, for example, mapping the index of an array to an object property
const some_array = ["supyo"];
const some_object = { [some_array[0]]: 5};
console.log( some_object );
// => {supyo: 5}```
That is when it'd be useful yes.
tbf, i didnt present it as life altering. only potentially useful 😂
I'm confused... What code are you using
Can you send me it?
Everything same. Just include global gameOver before gameOver = True
Just like this.
You can DM. I will share it later. I am outside for now.
What
🤔
Your question makes no sense
Okay cool
You can't change the color of an image with css
Uh what
I've never heard of such a thing
I only know that you could possibly use filters
i mean it just set's the element's background color
and because it's transparent, the background color will show
Mmm true
I thought it was actually changing the pictures color im too tired for this
Not put it behind the p tag?
I wish I could actually help but unfortunately it is almost 2am so im tired
goodnight guys!
https://codepen.io/sosuke/pen/Pjoqqp I found this cool.
Unrelated really
but I thought it was cool so I shared
bot.shard.fetchClientValues('guilds.cache.size').then(total => {
console.log(total.reduce((accumulator, currentValue) => {
accumulator + currentValue
}, 0))
}) // Undefined
How does this return undefined???
const express = require('express')
const Topgg = require('@top-gg/sdk')
const app = express() // Your express app
const webhook = new Topgg.Webhook('Here comes my token') // add your Top.gg webhook authorization (not bot token)
app.post('/dblwebhook', webhook.listener(vote => {
// vote is your vote object
console.log(vote.user) // 221221226561929217
})) // attach the middleware
app.listen(1333)
it is not posting anything
Make sure port 1333 (TCP) is accessible from the 'net
I hope you hit someones car while driving and helping in development and insurance refuses to pay the bill
console.log(bot.guilds.cache.map(guild => guild.name)); // Normal
bot.shard.broadcastEval(client => client.guilds.cache.map(guild => guild.name)).then(results => console.log(...results)); // Via Sharding
Did I do the via sharding correct? .. or is there a simpler way?
Doesn't broadcast eval take in a string?
It takes in a function, I believe.
Although, do you think the way I did to get all the guild names, via sharding, is correct or is there a shorter way?
last time I used it it did take in a string
but that's fine I believe
You sure there isn't a shorter code.
.fetchClientValues() takes in a string, correct, although that won't help into what I want to achieve. It returns a number, not an object that I can use.
you can use this which will grab a prop and return it from the client
you pass something like guilds.cache.size as the string
if you wanted to get amount of guilds in a shard
but actually that's only for simple values
so yeah that's the best way to do it
Yes. ^
if you want it to be shorter wrap it in a function
Although, I want to console log all of the guilds' names for all shards.
the simplest way would probably be to do it via broadcast eval
As an example, like this, in normal bots. console.log(bot.guilds.cache.map(guild => guild.name));
Yup, just like I mentioned, like this, correct?
bot.shard.broadcastEval(client => client.guilds.cache.map(guild => guild.name)).then(results => console.log(...results)); // Via Sharding
``` (you replied, too)
you can do it like that too but it's slower since it has to transfer the data to the shard requesting it
fastest way would be to make the shard log them itself otherwise that's fine
How, so? What do you mean.
I also realised another problem, this is returning the correct data since it's in one shard. I'm scared double shards returns the wrong array output.
Double shards like those outputs. const array = [["Server A", "Server B", "Server C"], ["Server D", "Server E"]];
your way it goes:
- shard requests data from all shards
- shards send the result back to the shard requesting it
- waits for all shards to send back the data
- console log the data
you can skip the sending back part and just make the shard itself log it
but if its just a one time thing it doesn't matter
Although, isn't this what I did?
what do you mean?
Quick question, requests data from all shards is via which discord.js method, the .broadcastEval()?
The following code returns an array of array so I had to use the spread operator to spread the array, although, if it returned two arrays, my spread operator is useless.
bot.shard.broadcastEval(client => client.guilds.cache.map(guild => guild.name))
don't you need to fetch the values fist via. client.shard.fetchClientValues(...) ?
Then processing with the results
If I do bot.shard.fetchClientValues('guilds.cache.size'), it will return an array of numbers.
you can simply use .flat()
since when did that method exist
Nobody said you should fetch the cache.size
Holy, that worked. That's one issue solved.
Tim, quick question. What do you think of this?
I thought we could only input sizes?
lmao
its fine, the only difference from what speedy suggested is that it transfers more data via ipc
Yeah, having hard time understanding how I can achieve what Speedy told me.
easy
Ignore Speedy... he only speaks "OS language"
bot.shard.broadcastEval(client => console.log(client.guilds.cache.map(guild => guild.name)));
Wtf.
yeah
though you might want to return 1 unless just returning the log is fine
or 0:)
the only difference is that it will log X arrays of names, where X is the number of shards, instead of 1 array of all names
but they will all be logged the same way
except you dont have to wait for all shards to finish returning the data
and the heap remains happy
but of course, that only works if logging them is your actual goal
Oh, so if two shards, how will it return? Two arrays?
if you want to do something else with the data, then its different
it will log:
[name1, name2, name3]
[name4, name5]
That's with one shard, right?
with 2
What? Basically the same as the long code with .flat() method?
no
transfering the data with broadcastEval and then only logging it at the end, will always make 1 array
unless you want to log an array of arrays
basically, speedy's method makes each individual shard log its own guilds
Nope, just trying to return the exact output as bot.guilds.cache.map(x => x.name);
this is js, the heap is always unhappy >:C
while your previous method makes each individual shard send its own guilds, then assemble then all together, then log only the final result
can anything even go on to the stack in js since it's interpreted
Oh, thank you! I was trying to get the explanation.
probably not much since everything behind the scenes is a giant object i think
js itself has no concept of stack, but the underlying engine does
Now, with two shards, it will yet return one array with both shard's guild names merged into one array, right?
with your method yes
How about your method?
with speedy's method, you are not returning anything
you are telling the shards themselves to do the logging
so each shard will log once
they will not be merged
they will be logged separately
Oh, I see, makes sense.
Meaning my method can be helpful when it comes to merging, but when it comes to quick logging a shard's own guilds, speedy's way.
did you know items on the stack sometimes end up in the cpu cache
so very fast unlike heap 🤮
nice
xD
well yeah, but stack is very limited
pretty much only works if you know what you'll use it for at compile time
yes
Hi
Sweet.
you could theoretically make a lot of space for objects that might change in value to something larger or smaller in the stack so you dont have to request space in the heap
but it does get fiddly
for short lived data yes, like a cache
since the stack is mostly for short data
we'll see about that when I put my statically allocated 2 billion length array on the stack
i will store massive objects in the stack and then wont release it no one can stop me
xD
actually one of my functions in my os does that
it leaves a huge string buffer in the stack (will change that)
How can I get the current shard ID?
Let's say bot.shard.broadcastEval(client => console.log(client.guilds.cache.map(guild => guild.name))); but something like Shard ID # {}
pretty sure its just client.shard.id
Nope, checked documentation, doesn't work.
client.ws.shards.first().id
i believe
i swear they've changed 90% of this shit
last time i used sharding it was straight forward
That's only doing it for the first shard, how can I do this with multiple shards, let's say doing like this?
it wont do it only for the first
exactly like i said
Supposedly, the [] is the output of bot.shard.broadcastEval(client => console.log(client.guilds.cache.map(guild => guild.name)));
Yours return only the ID of the first shard which would be 0.
OHHH.
so the first is always the correct one
client.shard.ids[0] inside the arrow function??
yes
My bad, sorry about that.
for trolling or to stress-test the ram?
make a troll function that memory leaks on purpose
why do i want to troll myself
:^)
c++ already screams at me when i reference pointers inside of the stack
and take them outside of the function, though its just a warning not an error
When I restart the bot, it sends this error. Error [SHARDING_READY_DIED]: Shard 0's process exited before its Client became ready..
then you have an error in the shard
thats one of the annoying things about c++, its not easy to move stuff around by reference, there is a lot of copying going on
An error?
module.exports = async bot => {
bot.shard.broadcastEval(client => console.log("Shard ID", client.shard.ids[0], client.guilds.cache.map(guild => guild.name)));
bot.shard.fetchClientValues('guilds.cache.size').then(total => console.log(total.reduce((a, b) => a + b, 0)));
};
That's my entire codebase, though?
i never use references i always use pointers
unless i want a terrible performance program
unless i actually want to copy something of course:)
yeah but stuff like memory ownership makes it not always possible
i've had this problem working with node's napi
i didnt find a way to take ownership of the buffer content of a js object
without copying the data to a new object on the heap
though reading and writing memory in a linear buffer is really fast anyways
why would the 2nd deny line be making it so the newRole.id can't see the channel? ```js
const discchannel = await reaction.message.guild.channels.create(${user.username}, {
parent: parentCat[0][0].disctubecat,
permissionOverwrites: [
{ deny: VIEW_CHANNEL, id: reaction.message.guild.id },
{ allow: SEND_MESSAGES, id: member.id },
{ allow: VIEW_CHANNEL, id: member.id },
{ allow: VIEW_CHANNEL, id: newRole.id },
{ deny: SEND_MESSAGES, id: newRole.id }
]
});
i've copied millions of ints and it usually does it under a few milliseconds
yeah but when working with heaps, it causes unnecessary memory fragmentation
how does windows/linux deal with memory fragmentation
depends on the allocator
thats what i find confusing
shouldnt the os be constantly moving things around in the background to ensure maximum amount of heap can be allocated
unless im misunderstanding something
such as paging
i dont fully understand the intrinsics of it either
but the allocator is responsible for dealing with alignment and efficiency of the program's own virtual memory
other than that, the os just gives it chunks of memory as needed
does it do it in pages
likely yes
allocators usually use multiple different page sizes
each program gets a page it can use and if it runs out of space it can grab more pages
depending on the amount being allocated
though i still dont get how it detects memory access violations
unless i dont understand something a page cant be less than 4kb
and you can only apply privileges to pages
dont know exactly
behind the scenes a page is 4kb
thats the hardware definition for it
at least for a 32 bit system
but it can be bigger
can it?
interesting
i still need to ask people that know way more about this stuff
i dont understand the paging concept entirely
i dont exactly know the relationship between architectural allocation and software allocators like mimalloc, jemalloc, tcmalloc etc
i know that jemalloc for example uses multiple different page sizes and pool sizes depending the amount requested
and somehing they call "arenas"
likely yes
so if you were to allocate two different buffers would they possibly end up on the same page
if the page is big enough i guess
that makes a lot more sense
but what i dont understand is if a program owns a whole page how do seg faults happen even if you access just a byte before or after the requested and returned size
inside the same page?
since pages arent the size of the requested buffer you should have permission to access the bytes inside of it
yes
the allocator likely has some kind of book keeping for individual chunks inside the page
console.log(`${bot.shard.fetchClientValues('guilds.cache.size').then(total => total.reduce((a, b) => a + b, 0))}`)
This is returning [object Promise].
.then returns a promise
speaking of which, one of the dumbest things i've ever seen on npm is an "object pre-allocator" for js lmao
but the value inside that .then won't be a promise, so you should use one to log the value
as far as i know internally the only way the os knows if a memory location has been accessed without having permission to is when an interrupt happens when accessing a page that is not marked as currently in memory or has a higher privilege level than the code page running it
aka .then(console.log)
and during a switch of a task the os marks the pages the process owns as present in memory which allows the process to run without segfaults
i'll ask sometime soon on the os forum i'll also let you know about it
👍
Tim, quick question. Can I store the value of this in a variable?
bot.shard.fetchClientValues('guilds.cache.size').then(total => console.log(total.reduce((a, b) => a + b, 0)))
I want to use it in console.log().
yes
How, it keeps returning object promise, though?
await
console.log(`Bot is now online serving ${await bot.shard.fetchClientValues('guilds.cache.size').then(total => console.log(total.reduce((a, b) => a + b, 0)))} servers.`);
Do I have to do this for all?
if its a promise, you have to await it
[object Promise]
although that code above wont work
Just realised, it returned undefined.
WAIT
Yup, figured out why.
Although, I remember in the past, when you told me that you cannot use await with .then() or are there cases you can?
Ohh.
meaning await a.then().then().then().then(() => 10) will return 10
Promise<10>
Since the group of .then()s didn't complete?
Actually I don’t know
they will always complete
i think I’m wrong
just wont return the value you want
Oh, basically, it will complete although you didn't wait for it to return the value.
wait i think i know how it works in depth but not sure
yes
Makes sense.
so the library (std) request 4kb pages from the os or how many it thinks it needs and then the allocation library under it decides and organises where the allocated blocks go inside it
basically, a promise will create a separate branch of code that will execute stuff in a different space
if you dont await it, that branch of code will never merge again with the previous branch
so all kinds of values and processing that happens inside there, will stay inside there
Aha, I see.
|
|
| -> something.then(() => {
| // new branch of code
| |
| |
| |
| v // cannot merge again
| })
|
|
|
v
with await:
|
|
| -> await something.then(() => {
|
|
|
v
<-})
|
|
|
v
OHH, that gave a much clearer image.
I appreciate it, this actually just answered a bunch of other questions I had in mind for about a few days.
👍
if its not awaited, the original branch does not wait for it
so when the new branch completes, the original branch already finished long time ago
so there is no way to return to it
That's why it returned [object Promise] since it completed and it didn't return the value I wanted since it finished a long time ago.
console.log(1)
something.then(() => {
console.log(2)
})
console.log(3)
// result:
// 1
// 3
// 2
.. and then if you add the await before the .then() method then it will return from 1 incrementing, makes sense!
yes, if you await it, the 2 will log before the 3
Yup.
Quick question in sharding, I have this code bot.users.cache.get(args[0]);, and I want to know how I can convert it via sharding, although, what method should I be using?
.fetchClientValues() or .broadcastEval()?
doesnt matter, fetchClientValues and broadcastEval both do the same thing, just broadcastEval is more powerful and can do more things while fetchClientValues can only do simple things. but in this case both should be able to do it.
however this is not strictly a sharding problem, its a caching problem as well, and you cannot retrieve complex data via ipc
meaning that you will be limited to send a simple form of a user as an object
another option is to fetch it from the api instead
ipc meaning?
ipc = inter process communication, which is how shards are connected to each other
Is this a problem with all bots using sharding, which is .cache?
all bots using the ShardingManager yes
Didn't we just use .cache to just map all the guild names or are those just simple things?
yeah thats exactly how it works except also the os can map virtual memory locations so the pages appear linear when they can actually be in completely different areas of ram
that said my heap allocator allocates blocks on the os level which means there is no paging or protection
gonna rewrite that
you are converting an array of Guild objects to an array of strings, so yes its conversion to a simple form
you cannot send a full Guild object
it will either error or lose some data in the way
As in how, exactly?
as in, return the entire object instead of a part of it
broadcastEval((client) => client.guilds.cache.first())
or fetchClientValues("client.guilds.cache.first()")
That will return the first guild?
the first guild in the cache in that shard, yes
Oh, as an example, you're returning the first guild?
yes
Ah, due to that, this happens?
Now, if I cannot use .cache.get(), then that's fine, although, how can I fetch it from the api, instead, using .broadcastEval()?
That's it? That's cool!
Anything else I should be aware of when it comes to sharding?
how can i make this command only used by members having permission manage server
First you need the member instance (https://discord.js.org/#/docs/main/stable/class/Message), then their permissions (https://discord.js.org/#/docs/main/stable/class/GuildMember). You can then check their permissions with .has: https://discord.js.org/#/docs/main/stable/class/Permissions.
Or, in simpler terms, message.member?.permissions.has(...). Note the ? in the expression.
I'd recommend abstracting this into an option for the command rather than performing the check in your execute function.
ello, i have a little problem
i have 2 files and one loads faster than another
i cant explain :d nvm
or can i..
weird thing is that help is required faster than handler
even tho handler is called first
is that a problem..?
can you show some code
it's difficult to tell what you're doing by just speculating
sec
this command (help.js) calls for handler.js
but, variable from handler is initialized after help already called it
so it returns just {}
handler just reads a directory
i know that readdirSync is the issue but idk how to handle it
maybe this makes it clearer
without timeout its just {}
with timeout its ok
i dont get it, is the console.log inside the timeout showing before the console.log outside?
or what is going on?
you mean the fs.readdirSync is not being called before?
help.js needs a variable from handler.commands (in handler.js)
help.js gets a variable but its empty because it calls it faster than handler.commands can finish reading
you will need to show more code
it simply pushes into commands
i need to go trough exports.commands
but not before its finished
like, which files are being loaded, starting from your index.js or whatever is your main file
would need to see the entire load order
which simply means the load order is wrong, or you have some kind of asynchronous code in the loading process
thats how they are loaded
then help calls handler
can i make help wait for handler to finish loading files?
Is this correct? ```js
message.channel.send("...").then(msg => {
msg.delete({ 5000 })
});
depends what version u are on
in v13 u need to delete it urself using timeout
Keep in mind to catch the errors if you aren't already doing that
ok
Imagine your message gets deleted before the 5s are over
fuc is that name tho
And yes, move on using timeouts to prevent to edit you code later on again
Not how that works
I don't use this like months
How was it
It doesn't have a time prop anymore
And yes, move on using timeouts to prevent to edit you code later on again
in v12
Then it's timeout: time
What prevents you from using a timeout?
If he's using v12 and the option is there why make your own timeout
didn't we have this discussion before
...then((message) => { setTimeout(() => { message.delete(); }, 5000); });
wait no that was about deleting a message after a timeout
Fake if the option exists why do it yourself
You really love your brackets
bc I don't give a fuck about the option
Yes I do!
That's cool ig then
You didn't ask for something looking less aggressive, flazepe
So.. that's what you get
.then((message) =>
{
setTimeout(
() =>
{
message.delete();
},
5000
);
}
);```
No
My gosh... eww
That's literally his coding style
can i use a dns record on my domain name to redirect any urls on cc.luckiecrab.nl to crazyclown.luckiecrab.nl
for example if someone enters https://cc.luckiecrab.nl/thing/idk it will redirect to https://crazyclown.luckiecrab.nl/thing/idk
You must be crazy...
c# crave
visual studio syndrome
.then((message) =>
{
setTimeout(() =>
{
message.delete();
...
}, 5000);
});
there you go
While I wouldn't use brackets for the timeout, but who knows what else he would do inside
you are the crazy one here 😠
console.log(handler) here
does it show only {} ?
i fixed it
👍
hai
issue was that i called a variable from handler before it was populated
if that makes sense
step 1 of getting usb to work
oooo
barely anything is standardised so you have to look for the tables left by hardware manually by probing for signatures
Quick question, (ping me), how can I get a text that is written on a website, like get the texts ID or element and stuff and if I can get the text, can I see what the text is?
how exactly does i/o communication work from a c/c++ standpoint? does std have classes and functions to create connections with that? or is it by accessing some particular area in memory in a read/write fashion?
how exactly do you write C code to access some hardware part of the board?
you mean IO as in accessing memory or actual physical IO
as in data busses to hardware
ye
which
idk any, like if you want to read data from the bios
how would you request this data from C?
in this case there is actually a standardised part of the RAM in the first 1mb which contains data left by the BIOS for the operating system to interpret so there is no IO going on
but if I do need to do IO i wrote a wrapper function in pure assembly which allows me to send and receive bytes/words from data busses
i'll show you
cant C access these data busses by itself?
kind of
i wrote it in inline assembly
ignore the weird inlining i just wanted piece of mind
though IO is quite old only down to the metal hardware are connected to it
you can integrate asm code inside C like that?
such as the GPU, keyboard emulation by the BIOS etc
you didnt know?
nop
and thats c++:)
nice
but pretty much c
so thats like eval(asm)
its not really eval but you could say so
It depends on the compiler
on compile time the compiler inserts the ASM inside of it into the actual code
its a bit more complicated than that so optimisations can still take place properly
the more you explain to Tim the earlier he starts making Tim OS
Terry already made the best OS
Enlighten me
ew no
TempleOS
yeah i get it
now i think you'll be interested in how you can access graphics memory
well not exactly graphics memory but the memory which maps actual data onto pixels on the screen
you can actually map certain areas of memory for use in for example graphics memory so whatever you read/write in that area of memory is actually processed on where it is mapped to
though reading is extremely slow from these mapped addresses so you often do whats called a "double buffer" where you write to two locations and you read from the location thats physically in ram

how can i get a date in DD/MM/YYYY format from a mongodb id
yeah
my gosh
entry._id.getTimestamp()
you can format the timestamp with any date formatting lib
like dayjs
assuming that is what you mean
right?
It's my first time making and publishing an API, and I've just started on the "homepage"/"documentation" of it, however I'm not so sure what I need to add or include in it.
For reference, here is the link to the current homepage/documentation: https://ffa.aakhilv.me
If anyone would like to give me some tips or pointers in how I should format it and what I should include, I'd really appreciate it.
i wouldnt send base64 images
hm, how should I deliver the images then?
Image url
if the images are generated on the spot, like via canvas or something, then you already have the endpoints for the image format, just send the raw image as an octet-stream
it would be the same as if the user downloaded the image via direct link
if the images are pregenerated and stored in a folder, give them the image url
hmm okay thanks
i think you dont need the json url at all, just have all the other urls
and have each url deliver the raw data
Yeah, I was deciding whether to remove it or not
like text/plain for the text endpoint, and image/png or similar to the image endpoints
but I was thinking that some people would like all the data under one endpoint
if you want to give them the text plus the image, you can put the text in the response headers
under a custom header
Hm, I'll look into that
if they really want all image variants at once, one way would be to use multipart/formdata
it would basically do the same thing as you're doing with json
but use 30% less data
should commands like "say" be mod locked?
probably yes, unless you want people to be able to say the N word and then delete their message and make it look like the bot said it by itself
and many other ways you could get in trouble
alright, youve convinced me
i dont know how to add commands to my bot. Can someone tell me ? If yes chat me please!
There should be a bunch of tutorials online regarding your specific language choice. Of course, everyone's bot is different and as such, how to add commands is different
what are you using for making the bot?

i do need to implement it anyways because im planning to use a library which will take advantage of these os features
right now you can only spawn processes and thats about it
gonna write a scheduler?
i already have one lol
i wrote it ages ago after much struggle
actually now you reminded me
i need to optimise it
xD
right now you know i kind of wrote it quickly
for code that runs thousands of times a second it needs as much optimisation as it can
and there is no proper cpu scheduling algorithm yet
just first come first serve
mutex locks too i guess
though i dont know how mutex locks work
are they implemented on an os level
pretty sure mutex is implemented by the programs themselves
mmm depends
you normally have to use the OS in some way
because the OS is the only one who knows which thread has current ownership of the lock
there are locks that work off of atomics that are done off the program level but err, they're much more complicated
performance + throughput + mutexes generally dont go together
mutex are an optional feature for thread safety
well will be
my plan would be to make them program sided
sure... But err, you yourself need to maintain some way of synchronisation regardless just as a fyi
mutex lock:
if mutex queue is not empty, sleep until it is empty
once empty, add thread to queue
continue processing
mutex unlock:
remove mutex lock from queue
something like that would work
but then could race conditions happen with the mutex itself
lmao
were talking about a single core os so probably not
well your check to see if a lock is currently in use should be atomic
unless a task switch occurs right after a safety check
so it should be safe from a data race
atomic?
Learn C Language - Atomics as part of the C language are an optional feature that is available since C11.Their purpose is to ensure race-free access to...
so basically a cooler mutex lock
oh wait is that an actual instruction
it also cannot protect / shield values generally like a mutex can
what do you mean
so are mutex locks basically a while sleeping loop
also although this is talking most about rust and databases, john does a good section about synchronisation and how you ensure no race conditions happen https://youtu.be/s19G6n0UjsM?t=1511
This is a guest lecture I gave at Two Sigma in November 2018 where I discussed the experience of using Rust for building larger, high-performance systems. In it, I cover what makes Rust an attractive option for such projects; Noria, the high-performance research database prototype I've built using Rust; an interesting concurrent data-structure ...
well normally they yield control. And just stop execution.
Mutex world broadly:
Is mutex locked?
-
No: -> acquire lock
-> Yes -> Yeild control / park thread until notified
its quite rare that things are on a sleeping loop other than the things driving the original state machines
any idea why its undefined? it seems to work fine in other parts of the code
though yielding control to the scheduler right after a context switch isnt all that expensive
but i get it
will add that to the list
also further would prevent race conditions
since a thread actually has to physically unsuspend another thread
might just rewrite my scheduler tbh
i do have system calls as well
thanks for the knowledge@modest maple very helpful
will probably write a mind map of how i will implement it and then ask y'all for opinions
remove the second Object.keys
also you dont need the first Object.keys either
const command = handler.commands[args[0]];
if(command) {
// do something
}
but i need keys to check if args[0] matches any
the code above implicitly does that
unless you have a key whose value is null or undefined on purpose
or 0 or ""
or NaN
👍
im supposed to be revising for a business and computer science mock exam yet im here doing this stupid shit
college btw + looking for a new part time job
@quartz kindle imagine after adding threads i add async support to c++
cant live without javascript await syntax
hahah
good luck
async should be easier to implement than threading
its just timers and loops
true but i think its a little different with c++
i need some threads under the hood
if i want to be able to use await keywords that is
lmao
threads arent even all about performance
its all single core right now
might make it multicore though
complicated
cursed
C++ nodejs like runetime
Just make nodejs but for c++ ez
no it doesn't
It does if I say it does
burh

it'll make you look dumber
Isn't that the point of portfolios?
LMAO
is node a trademarked name?
dont know but i know among us is
Apparently nodejs is trademarked
according to their website at least
unless I read it wrong
cant be bothered to re-read it
nice
by the way does anyone have an idea for an os process event system
so processes can setup a listener to another process/resource and that process can dispatch events
problem is how would events run/be called in the destination process
queue every single event and handle one event every 3 seconds
Most responsive OS in existence right there
Would recommend look at how systems like the tokio executor work
Because that's essentially how os schedulers work with threads
pretty sure you need ipc for that?
or shared memory
shared memory i dont want because you have to waste a lot of resources checking if an event happened
very inefficient
arent unix domain sockets just a piece of shared memory in a ram disk?
i have no idea lol
how do keyboard process events for windows work
that could be a good example
didnt you say you'd have to query the device to receive data?
i mean i do query it to receive data
but i know when to query due to hardware events
which raise an interrupt letting you know the keyboard/device has data available
dont atomics have events?
atomics?
i have no idea how low level atomics work, but in js you can use atomics to wait for a byte in a buffer to change
never heard of them lmao
js has a SharedArrayBuffer thing, which is essentially shared memory for workers
and it has atomic functions to guarantee any operation on that memory is not interrupted by another worker
it does seem very interesting but it relies on an event loop doesnt it
so you can create locks and events with that
atomic locks are blocking
so they cant be used in the main thread
but inside workers, you set up an atomic wait on a specific byte in the shared array buffer
and that entire thread will be blocked until another thread changes that byte
i think thats basically thread parking under the hood
something like that i guess
my thought on a possible solution is maybe upon a process attaching an event listener to a resource, the os creates a new thread with an execution path of the handler function and events that happen while an event is still being processed are simply queued - and while no event is available the os will simply park the core/suspend it forever
thread* not core
a special kind of thread which will be distinguishable via a flag
yeah but for IPC for example, both processes would need to access a piece of shared memory and exchange data that way, im pretty sure thats how domain sockets work
although they have an entire protocol built around it
mmaps would be a lower level version of domain sockets
but then ipcs would fall under the same problem wouldnt they
it would need to notify the destination that data is incoming
but then that would interrupt executing code
and i dont have an event loop yet lol
yes, and the destination would need to either query the memory for changes, or use an atomic wait, if that exists in C++
ah so an old style c# websocket implementation
but then i want that kind of thing as simple as possible
creating a new thread and applying mutex locks on it is a bit complicated for each event
or i could use that idea and extend on it
creating a listener would create a new thread which is parked until the os unparks it which would be caused by a system call by the host process
if you create an event loop, then everything should be easier, you could just query all sorts of I/O for changes once per loop
the scheduler is sort of an event loop lol
ye
there is no good way of going about it without creating a new thread
thats fine tho
because i really want the main thread to be independent
and be able to run mid events
yeah i know
dont know what they do though
could only find uses for 2 threads
1 main thread 2 runs async tasks
or maybe multiple running async tasks
i want to test something
it runs on libuv
libuv maintains a thread pool
which is called upon for IO operations
what happens on linux when a thread is waiting for user input via cmd line but another thread logs something during that
just so i know how to handle it
because my cmd line system is purely based on system calls
theres a print system call and a get input system call
which blocks the thread until an input has been entered
well process in this case
i believe the window has input streams that multiple processes/threads can send data to
or something like that, i dont know how it works on low level
cmd/terminal should have some sort of signaling, and it receives signals from processes that subscribe to it
have you implemented a circular buffer?
thats one of the ways to handle reading and writing to/from a memory location
my idea is upon something being printed during input mode it will simply keep the input text at the bottom of the terminal until you press enter
right so i think i have pretty much everything i need
i'll do a start on the planning tomorrow when im free from class
yeah i did take notice of that
how do signals work
are signals on a separate thread
When trying to fetch a channel, I get the error saying:
channelThing.delete();
^
TypeError: channelThing.delete is not a function
Is it not possible to fetch a channel by name?
let channelThing = newState.guild.channels.fetch(name => name.name === memberID).catch(() => null);
if (!channelThing) {
return;
} else {
channelThing.delete();
}
you didnt await it
Also why are you catching it like that. I am sure you'd wanna respond to an error that occurs when fetching a channel cause that channel might not exist.
if it doesnt, i dont necessarily need to do anything. but yea ig responding to it would be helpful. tyt
Well tbh you could be left with wondering why something isnt working and it very well could be the channel doesn't exist so at least logging the error is logical then just not doing anything with it
he is doing something with it
yea nothing
Yes but there could be errors that come from that
highly unlikely in this situation
I mean yes but still
It doesn't seem like good practice to just shut an error up like that
thats pretty much a standard way of "do something if exists, otherwise do nothing"

Mm oka ig
the error in this specific case is irrelevant because no matter what kind of error you get, it will always be used the same way
That looks confusing 
using a finite block of memory to process infinite amounts of data
never knew that that's awesome
Update to this. I logged the error:
DiscordAPIError: Invalid Form Body
channel_id: Value "name => name.name === memberID" is not snowflake.
at RequestHandler.execute (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:298:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
at async GuildChannelManager.fetch (/home/container/node_modules/discord.js/src/managers/GuildChannelManager.js:183:20) {
method: 'get',
path: '/channels/name => name.name === memberID',
code: 50035,
httpStatus: 400,
requestData: { json: undefined, files: [] }
}
Current code:
let channelThinge2 = newState.guild.channels.fetch(name => name.name === player2).then((channelThing) => {
if (!channelThing) {
// sorta useless but i keep thsi here just cause lol
return;
}
channelThing.delete();
}).catch((err) => console.error(err));
and I asked some people if they know how signals work in processes
that code makes no sense
you cant use .fetch() the same way you use .find()
ah
oh. i see
ty
thats helpful
When trying to catch finding a cache'd channel, I still get an error which then crashes the bot. How would I use try catch correctly?
let channelThing = message.guild.channels.cache.find((name) => name.name === player1);
setTimeout(function () {
try {
if (!channelThing) {
return;
}
channelThing.delete();
} catch(err) {
console.error(err);
}
}, 4000);
dont you need to .catch when finding?
at the end of channelThing
no, .find() is not a promise
so would this
setTimeout(function () {
try {
let channelThing = message.guild.channels.cache.find((name) => name.name === player1);
if (!channelThing) {
return;
}
channelThing.delete();
} catch(err) {
console.error(err);
}
}, 4000);
be correct?
try/catch only works on promises if they are awaited
ah
so then id need let channelThing = await message.guild.channels.cache.find((name) => name.name === player1);
so one of these: ```js
try {
await channel.delete();
} catch(e) {
}
orjs
channel.delete().catch(...)
syntax highlight fail
xd
aight. ty
can components like buttons not be sent in DMs?
They can?!
i dont think so
the message goes through, but no buttons
sad times
oh wait
nm
You must be don’t something wrong
Interactions and components are global
*globally accessible
Send me an example component object, wanna test it out on mobile
sorry, i figured it out like one sec after i typed that

setTimeout(async () => {
...
}, timeout);
thanks
Thought he meant a timeout promise 
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.

I'm having such a weird issue where emoji mentioning works fine when mentioning a ton of them in a single embed but when broken up into multiple embeds some of them don't resolve correctly and it's making zero sense.
Example.
One has a list of them all (Quite a lot) and they all load fine, but when loading 12 (lol) embeds some of them don't resolve.
It also doesn’t make sense that Discord consistently has trouble to fetch images - from any source - and to show it in Discord.
Even if your webserver logs a successful request.
As the requests are successful and the emojis are known I would assume it’s an issue with the cache.
But who knows
My client? That wouldn't make sense for it to load in one embed and not the other.
Or generally the cdn having trouble to deploy the content on request - probably in time - as I also assume there’s a very short timeout if an image/emoji can’t be delivered by the cdn in time it will be removed
No Discord’s cache not your clients cache
The cdn
Ah.
Hmmm
It always works when sending the single embed, so maybe it's able to get them all there?
Yee I got that and that also doesn’t make sense 
That’s we get when dealing with Discord and it’s API
Trouble, unexpected results and even more weird shit 
Oh I guess you can't react if you don't share servers.
I'm using prod data on my test bot to see fuller results and of course it shouldn't be able to react with emojis it doesn't have access too.
That makes sense.
But the image stuff is weird
I'd almost be convinced it's a non shared server thing if it DIDN'T work when listing in a single embed.
It can only use the emojis of the servers it’s in, right?
If your bot is in a server. It can use all emojis from this server to in all other servers.
For reacting I believe so.
It indeed is
God this makes me so scared to release this rewrite now lmao
lol
What if..
What can go wrong
I ran it on my prod bot
and tested
lmfao
Testing on prod time Xddddddddd
just for these two commands
that's all
Just note somewhere anything going wrong is the result of discord’s unexpected responses
Lmao
What does both even do?
Okay so on prod it's only missing a handfull
Did you mean to say bot?
The commands you mentioned
Ah.
One list all react roles made in the server. The other is more detailed and shows the categories each react role is in.
This is the category one.
And this is just the all list.
Are you going for a react - role assignment bot?
Does that even get the privileged intent?
The current system is so god awful, I've spent the last few months rewritting it into something much more pretty and useful
It literally only needs reaction and member
and it has those
All messages it tracks are its own.
By chance, would someone know why I'm getting a RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings. error on my embed? I did a console.log on all of my values, and they are indeed not empty.
const animeEmbed = client.extends.quickEmbed(anime.animeResult[0].title, anime.animeResult[0].synopsis)
.setURL(anime.animeResult[0].url)
.setImage(anime.animeResult[0].image_url)
.addFields({name: `Episodes`, value: anime.animeResult[0].episodes, inline: true},
{name: `Rating`, value: anime.animeResult[0].rated, inline: true},
{name: `Score`, value: anime.animeResult[0].score + ` / 10`, inline: true},
{name: `Anime Type`, value: anime.animeResult[0].type, inline: true},
{name: `Start Date`, value: moment(anime.animeResult[0].start_date).format(`MM/DD/YYYY`), inline: true},
{name: `End Date`, value: moment(anime.animeResult[0].end_date).format(`MM/DD/YYYY`), inline: true},
{name: `Airing`, value: anime.animeResult[0].airing, inline: true})
message.channel.send({
embeds: [animeEmbed]
})
My console.logs in order by field
13
R+
7.52 / 10
TV
07/24/2004
10/16/2004
false
My partnered server uses it for a god awful amount of roles.
because it's a comp sci uni server
and there are so many classes lol
airing might be the issue.
Well I rewrote my whole bot to a perfectly (for me) OOP based structure I can work with for just a few guilds, now 114 as my target interest group is small but still did the work
I'll remove airing and see if it happends still sec.
Same! I love the structure I made for mine
Very proud
nah same issue. I actually removed all besides "Episodes" just to see, and it still happens
It’s always worth the experience you collect
Sounds redundant, but can you do string(episodes) lmao
false (Boolean) is indeed empty
As it’s no string output for the value
Yeah that's what I thought.
Well as mentioned. I did indeed remove the airing and still recieved the issue
But I will try the string() thing
You could use template strings too.
btw