#development
1 messages Β· Page 206 of 1
This all looks incredibly unsafe though, writing code like this is how you get security vulnerabilities, especially in a lang like C
its 1994 :^)
C is just C++ without classes and templates
in 1994 everything was a security vuln
especially at microsoft
lol
you guys ready for cargo js? the new rust like package manager
Now youβre meant to use strncpy
Pretty much everything that expected the null terminator is now considered unsafe since you could corrupt the heap so easily
Null terminator was a poor design choice for storing strings
Not to mention the extra cost of even just counting the length of a C string
you lose the ability to use a specific character in the data, so you need to watch/check for that, and if for some reason that character gets corrupted you're screwwed
Have to loop over every char
honestly maybe I should never touch C
it sounds annoying

My anger problems that are already fueled by programming would burst through the roof
its cool for simple and small things, but i wouldnt use it for anything remotely complex
I'm in need of an SMTP service/server what would you guys suggest?
like sending emails?
like for email?
It wouldnβt be terrible if you just had more stdlib stuff
Yes
refresh your client
Iβm in the boat that the stdlib of a language should be small, but C takes βsmallβ to a new level
get gamered
timezone issue
cap
well how many emails are you trying to send, and are you looking for something "free"?
anything email related i'd go for a dedicated service like zoho
if you aren't sending a whole lot bun introduced me to https://mailersend.com
email is too annoying to deal with
they are fairly cheap as well if you want to go for something paid
zoho I use for recieving emails
right now not many but this company is gonna be scaling hella
Roger that hoss, thanks
and if you don't care about getting emails in return its perfect
hoss
if you want to get emails as well tho you can set up zoho for that
it's what we currently do

Yeah not to worried for returns as its mainly going to be used for ory stuff. which is auth
Mailer send for programatically sending emails, zoho for receiving/sending business emails
Keep in mind, if you are using rust to send the emails gl
I couldn't figure it out so I had to use the api
which is limited

lmaoo yeah thats for someone else in the team to figure out lmaoo
kekw
what you working on if I dont mind asking
if its top secret then tell me to shut up

its bottom secret
https://hatebin.com/qserytwmhl what you think of this wonderful code
why not just use ts + private instead of #privateClassMemberThing
oh wait you're already using ts
why not private instead of the js version of "private"
cause private doesn't actually make it private
But neither does this
according to voltrex it does
object["#prop"]
always an option
private doesn't make anything private, it just hides it from the consumer of the API
it does if you set your build target to use it

Im just going based off what voltrex said ages ago when he was actually here
either way doesn't really matter to me
the private keyword in ts will get compiled to either _ or # depending on your tsconfig
whats the point of using private in general?
so you don't have to do the #something shit

private is and has always been a concept of hiding things from other people
"encapsulation"
which in js is useless and meaningless
Some methods should not be used by people

it's just a message to others that "hey, this is internal implementation stuff you don't need to touch"
i beg to differ :^)
if i dont, someone else will
real chad move, inject into the memory of v8 instead of trying to mingle with js garbage
i like js because everything is supposed to be hackable
when djs started doing the private crap, it was so anoying to deal with
the primary users of djs are people that have 0 experience so it's understandable why they would want to hide stuff from them
i much prefer the concept of underscore, like the concept of "not recommended to touch" instead of "fuck you cant touch this"
just make it compile to any js version pre-private
Its so bad it made people debate about it
Damn ok
Lol
jk jk lmao
π
i need to decide on an http client to test my api with, people saying postman is old school now
Honestly though what do you think about a plugin system in a djs framework tim
well, why not?
although designing a plugin system is not easy
there are a shit ton of factors to consider
Idk, it seems so out there. Like everything is run off plugins. So there's the core package that has the plugin loader, and the client class. Then you can make plugins like CommandHandler, EventHandler, etc and load them up
I am fairly certain my plugin system is TERRIBLE
you'd probably die and come back to life just to slap the fuck outta me
its very hard to make a plugin system work in a sustainable way
either you lock it down to oblivion and allow only certified/tested plugins, to make sure they work and have quality
or you leave it open and people will dump a ton of garbage on it
the problem with plugins for something like djs is
then you think plugin, you think plug and play, no code
with djs is like
why would i use a plugin when i can code this myself

That's very fair
Technically its virtually no code other than the commands themselves. 
The reason I went this approach though is a lot of frameworks add bloat ontop of djs which is already bloaty. Not to mention you typically wont use everything in a framework.
if you wanna go fully into the idea of a plugin system, make an UI for it or something
some sort of automation
So I thought plugins would be a better idea
Install what you need, leave out what you dont
It'd also allow people to make their own plugins

Since the plugin class is bundled in with the core package you don't really need to make a new package unless you want to share it to the world
how about you enter an array of plugin names, and have the lib automatically download them and install them for you
on client load
i'd avoid filling npm with plugins like npm i mylib/plugins/abc1 mylib/plugin/abc2, its so annoying lel
If I do that I should probably port plugin class over to its own lib tho right?
fairs
heres an idea to bring you above the competition
make your plugin class a lib for djs
when you install it it creates a local webserver that you can open in the browser
in the browser page you can browse/install/configure plugins

This went from just making a framework for zobs, to me thinking lets help everyone
now you give me this golden idea
lmao
Honestly, why not just make my own lib at that point π
be careful tho, the mountain just got a lot bigger
What exactly do you mean by this part tho
make your plugin class a lib for djs
like
person installs djs, then installs your lib
then runs yourlib with the djs client, or something
or just make your lib extend djs idk
you can make your lib already include djs, so the user doesnt need to install both
but the idea is basically turning into something no-code
like bdfd
lmao
Well, that would be suitable for people who can't code.
But I dislike stuff like that π
Coding isn't about the easy way out
indeed
I'd rather not promote something like that
thats why its hard to think about a plugin system
its hard to come up with something that will actually provide something interesting to other coders
The original idea came from cargo's feature flags. So you get rid of what you don't need but keep what you do
so I was like, ight plugin system
It was meant to be for people looking for a framework that had a multitude of options. Like my official command handler plugin only supports slash commands.
Well if someone wanted a hybrid they'd be shit out of luck for the most part, cause typical frameworks bind the handlers to the client, not really letting you do much without ruining the system in place. So my idea of the plugin system was allow them to make their own handler to handle both message & slash commands if they wanted.
They could also publish these to npm to share with others.
well good luck :^)
π
ty
I mean it works well for what it does I think
honestly just going to make an event handler, make some docs call it a day
if people make their own plugins neat!
xD
https://pastebin.com/D63Fm72g
if anyone wants this for their website lol (uses tailwindcss for styles)
I really need to open source my embed visualization
go for it
That's one thing I think I did a decent job on.
I'm sure a few people would appreciate a premade react component

I'd so go for it
even if people don't like it, its something you put effort into.
Show it off
I'll like it
Is it possible to simply check the value of a row in a postgres db? I simply want to see whether a row is true/false.
I don't need the data which is why im asking, as i'd rather just check the value if possible
like if x value equals, contains, and then return bool if it exists?
:c
does anyone here speak dutch who might be able to help me with a really dumb issue? or anyone speak romanian?
(need some help fighting stupid censorship on both)
im trying to update application directory i18n pages
but i cant get my listing in dutch to work, or my listing in romanian
because the romanian word for 'how' reads as a swear in english as does the dutch word for 'can' (put them in gtranslate and see)
and discord, in their wisdom, apply english swear filters to all languages
so if anyone could suggest an alternate word in each case i could use... and i imagine this is kinda a silly question i should never have to ask.
if theres no way around it... i'll just have to put those localisations in english till the situation improves on discord's end...
how come π
Ahem jokes aside, very interesting problem
hope it works out for ya
i might just have to tell everyone who finds my app directory page whos romanian or dutch that tough luck, discord says you gotta read english
I'd just make it english for now tbh.
their swear filter is completely non contextual
If you edit one word, it might mess up the entire translation.
so you could literally fill your english page with "zut alors, Discord c'est merde!"
its french for 'discord is shit' basically
npm just being a little silly goober
LXC is basically a Docker container but with full access by the user
Basically a virtual machine but not, correct?
E.g. I want to run some project in an LXC, it would appear as a fresh install in a way?
my god .com nameserver propagation is crazy fast.
kinda
a vm has its own kernel
non-vm lxc shares with the host
perfeccctttt
im not entirely sure how dockers virtualisation works but i heard if you need to isolate potentially harmful or unpredictable environments then thats not a use for docker
docker is more like the answer to "we cannot ship you machine to the client"
docker is more like the answer to "it works on my machine"
nah its just that i wanted to set up mediawiki
but it requires a ton of stuff to be installed
and i dont want to reinstall my system when i fuck up somehow
@lyric mountain which join do I use again if I only want one side, but the other side is optional?
is it Left Join if I want A but B is fine to be null
or is that Right Join

Can I use this on a parent table query? Or do I have to do it on the child
if you FROM the child table, you need to use RIGHT JOIN since you want all parents, children are optional

the standard is to always FROM the parent, then join the children
okgotcha
time to write my first join statement
π
SELECT x FROM parent p LEFT JOIN child c WHERE p.id = c.id AND email = $1
```?
easy way to remember is that LEFT JOIN priorizes what comes before it, RIGHT JOIN priorizes what comes after
u need to supply the joining column on joins
huh
FROM parent p LEFT JOIN child c ON p.key = c.parent_key
ah
u need to tell which way to "connect" the tables
so it just needs to be the column that has the fk referencing the other?
yes

error returned from database: column reference "student_id" is ambiguous
tf does this mean
π
is it because both tables have the same column name

did u save the file?
oh
ur columns
SELECT ...
u need to state the alias here too
like SELECT x,x,s.x?
yes, for all columns
I mean, u dont need if there are no duplicates, but it's best to
gotcha
hm
either I am doing something wrong, or the lib I am using to interact with pg is
what error?
no error
what issue then?
oh wait
if I want something from the other table
do I have to add that in the selection ?
let student = query!(
"SELECT s.email, s.password, s.student_id FROM student s LEFT JOIN business b ON s.student_id = b.student_id WHERE email = $1",
&login.email
)
well...I am wanting something from the business table
simply use b for accessing the values
b.whatever after the SELECT?
yes, like u do normally
you get what u state there
if u want all then just use *, but it's better to be specific
since rarely you'll need ALL the columns
i never remember my joins
i always have to look them up
rarely do joins anyway because they're quite limited
you cant join something one to many for example because you need them to fit in the row
most of my code theoretically works
have yet to fully test it so I have no idea if my joins work either

code for months without testing anything
try to run the whole thing at once at the end
That's what I was thinking
I like the mystery
You should consider writing unit tests btw
why
Super helpful later on
If you have a feature that you have very clearly defined behavior for, you should be writing unit tests for them
That way if something accidentally breaks, youβll know immediately after you run your tests
how do you write these unit tests
Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries.
I can write these tests in the route files themselves right?
they take so damn long to write
unit testing is a nightmare
integration testing is even worse
unit testing would help me make sure stuff is getting run correctly, but for a api setting idfk how a unit test would look like
I am trying to setup a status page what is the easy way to do it with bot hosting as it shows offline at the moment
I mean I'm sure you have some sort of expected behavior/data returned
It's a bit more difficult when you have to integrate a database into it
That's where you get into patterns like Dependency Injection (Pretty common in C#/ASP)
whoever made the websites go-by-example and rust-by-example are the greatest humans ever.
why are you learning go
well I already know it but still. I was using it before I learned rust a few years ago
lmaoo I agree, but now I'm a rust stan so its good
I am trying to setup a status page on hetrixtools and it is not working when I try and ping the bot hosting and wanted to know if anyone has any easy way to make it ping the server when it is online.
this is something that these ai's like devon would really excel in
Too bad devon wasnβt real and it was a scam
you separate the logic from the endpoint, for example:
export function endpointLogic() { ... }
app.get("/url", (req, res) => {
const result = endpointLogic(req)
res.send(result)
})
then you write tests for the endpointLogic function by importing it separately
meh
because unit tests skip the http stack and test the logic directly
That too
I'd rather do it manually ngl
the postman test is basically integration testing
unit test = test functions independently
integration test = test the whole system inputs and outputs
Well thats what I want to do
You can set up unit tests to automatically run on GitHub as well, that way if you have more people contributing you can guarantee that their behavior passes the tests automatically
integration tests can also be automated, just write tests that run the server then call its own localhost endpoints
Yeah but thatβs a lot of work
Unit tests donβt require additional code in rust, you justβ¦ run them
Ima just continue using postman π thanks for introducing me to unit testing tho
(You have to write the tests, but thereβs no fancy framework you need, itβs built in)
speaking of postman, dont they require an account now?
idk i've always had an account
i switched to Bruno, still didnt play much with it, but gonna probably start using it more
helps me sync my stuff
having an account is not a deal breaker for me
it allows me to sign in anywhere and have my endpoints ready to be tested
its a minor annoyance for me
also Arc browser requires an account
ever heard of a brower that can only be used with an account?
ive actually banned edge from my companys laptop hardening guide policy
way too many analytics indeed
too unsafe
lmao
even if you turn eevrything off in settings they add more and stuff still gets sent
#general message for Medal analytics 
there is absolutely no way
"how many analytics frameworks do we wanna use?"
"yes"
"yes"
im looking into inspect and i dont get as many network requests
but they do literally track everything
i move my mouse and plenty requests get sent
a lot
it nearly crashed my vm
yeah, they track all of that pointer heatmap garbage and conversion funneling and all that marketing analytics bullshit
what has the internet become
Well if we aren't making money off you viewing our site, we gotta make money off you visiting
:D
and sentry really tried to argue their case to get themselves removed from the analytics block list of major extensions
they argued that they only do error reporting and thats their main use purpose
why do 50 different sentry requests happen when i move my mouse on medal.tv then
unless an error is happening every mouse movement
plot twist, it is
though in this case medal.tv is at fault and sentry is only really providing a service that they want
plot twistΒ²: they throw errors on mouse move on purpose to trick sentry into being used for analytics
as expected the lighthouse score for performance on medal is abysmal
this can really quickly be narrowed down to using heavy frameworks and having a lot of bloat like analytics and etc
even on a website with tons of video playing at once you need to do a lot to get an awful lighthouse score
exact same performance score as medal
they both share similarities
tons of analytics and heavy js files
average big corpo moment tbh
yes
heya, let's say a module only says support up to .net framework 6.0 (there must be any right?), can i still use .net 8.0 with that module working? i'm new to c# so yeah 
I mean providing none of what it uses has been removed from .net 8 then possibly
ooo oke thanks!
what is the best strategy for attaching image files to an embed?
depends on the language and library you are using, though most of them are roughly the same
I dont even know how to find the docs for the v13
Essentially you just make a new attachment, then attach that to your interaction.reply
or follow that
woooooo what's up!
ahhh ok i see. I'll take a look at the docs. Thank you!!
Here to bother you again,
I was thinking if I could do "database catching" in my bot's code. I don't know what's the most efficient way to proceed with it tho, would need some advice.
Here's an example code
@commands.command()
async def wallet(self, ctx):
data = await self.bot.economy.find_one()
return await ctx.send(data)
Now instead of having this read request in my code and making my bot send one every time someone runs this command might be slower than just catching it up inside ram temprarity and reading it from there once the command is ran again.
I was hoping someone could tell me what's the best practice I can do to catchup data, I could store it in a global variable but i dunno if it's efficient or ideal.
Json files could also be a go-to but ehhhh
Has anyone done something similar to this before or got experience? It's MongoDB ofc
one straight forward idea I came up with is
catchedData = None
@commands.command()
async def wallet(self, ctx):
if not catchedData:
data = await self.bot.economy.find_one()
catchedData = data
else:
data = catchedData
return await ctx.send(data)
Even tho it's pretty simple and easy idk if it's the best option to store it in variable. Not to mention there'd be much-much complex commands in my bot doing more reads and writes
I think we had a conversation about this once and we came to the conclusion that probably all modern databases may have built-in caching
Does MongoDB handle caching?
Yes. MongoDB keeps most recently used data in RAM. If you have created indexes for your queries and your working data set fits in RAM, MongoDB serves all queries from memory.
MongoDB does not cache the query results in order to return the cached results for identical queries.
For more information on MongoDB and memory use, see WiredTiger and Memory Use.
Hello everyone
I see, I'm working at building a cache manager and attaching it to bot instance itself. Quite a bit fancy way to go around with it, I'll see where it gets me
Like NyNu said MongoDB handles caching for you. But if you still want to make your own cache you could use a tool like Redis or you could build your own by simple creating some form of hashmap with a specific timetolive per item (such that the cache gets cleared from the data if the data is no longer valid) you would then abstract this away by integrating it in your database query which you'd call by doing something like:
async def get(self, item): # Assume self is your database class (probably a MongoDB wrapper in your case)
if item not in self.cache: # Check if the item is found in the cache
data = await self.database.find_one() # If not query the data
self.cache.insert(item, data) # Store the data in the cache
return data # Return the data
return self.cache.get(item) # If it's found in the cache return the data
from threading import Timer
class Cache:
def __init__(self):
self._cache = {} # Initiate the cache
self._lock = threading.lock() # Initiate the lock to ensure thread safety
def insert(key, value, ttl=10):
with self._lock: # Acquire the lock
if key in self._cache: # Check if the key is already present
self._cache[key]['timer'].cancel() # If so cancel the current timer
timer = threading.Timer(ttl, self._remove, [key]) # Create a new timer
self.cache[key] = {'value': value, 'timer': timer} # Insert the key with its value and ttl in the cache
timer.start() # Start the timer
def get(key):
with self.lock: # Acquire the lock
if key in self.cache: # Return the value if the key is present
return self.cache[key]['value']
return None
def remove(key):
with self.lock: # Acquire the lock
if key in self.cache: # Delete the value if the key is present
del self.cache[key]
Then in your commands you'd just do self.database.get('key') and everything is nicely abstracted away for you
ofcourse this is a very simple cache and there's alot of optimizations you could do
it's also an example I just wrote like so and haven't tested so don't trust it that there are no flaws
Ah yes thanks a lot for being detailed with it, I was just building a similar cache manager class, here's what i did
class CacheManager:
def __init__(self, bot):
self.bot = bot
self.economy_cache = {}
async def create_economy(self, user_id):
await self.bot.db.economy.insert_one({
"_id": user_id,
"energy": 100,
"fragmentcap": 100,
"reset": 0,
"vote": 0,
"souls": 0,
"souls_to_give": 0,
"power": 0,
"limit": 0
})
async def load_economy_cache(self):
self.economy_cache = {}
cursor = await self.bot.db.economy.find().to_list(length=None)
for document in cursor:
self.economy_cache[document["_id"]] = document
async def get_economy_cache(self, user_id):
return self.economy_cache.get(user_id)
async def update_economy_cache(self, user_id, data):
self.economy_cache[user_id] = data
async def not_economy_cache(self, user_id):
economyCatch = await self.get_economy_cache(user_id)
if not economyCatch:
economyCatch = await self.bot.db.economy.find_one({"_id": user_id})
if not economyCatch:
economyCatch = await self.create_economy(user_id=user_id)
await self.update_economy_cache(user_id=user_id, data=economyCatch)
return economyCatch
the problem with this is that your cache will pile up since you're not clearning anything
so if your program has a long uptime you might run out of memory
@commands.command(aliases=["bal", "balance", "coins"])
async def wallet(self,ctx,member:disnake.Member=None):
if self.prefix == "." and ctx.author.id != ZEKSY: return
member = member or ctx.author
economy = await self.bot.cache.get_economy_cache(member.id)
if not economy:
print(f"I ran")
economy = await self.bot.cache.not_economy_cache(member.id)
coins = economy["energy"]
resetTokens = economy["reset"]
souls = economy["souls"]
embed = disnake.Embed(title=f"{member.name}'s Wallet", color=disnake.Color.purple())
embed.set_thumbnail(url=member.display_avatar.url)
embed.description = f"""
 **Wallet:**
{ARROW} Cursed Energy: **{coins}** {ENERGY}
{ARROW} Reset Tokens: **{resetTokens}** {RESET}
{ARROW} Souls: **{souls}** {SOUL}
"""
await ctx.reply(embed=embed,allowed_mentions=disnake.AllowedMentions.none())
thats how im calling it for now
Ah I see, but isn't it just one public var storing catched data?
the whole cluster size is 80mbs, storing that much in ram should be fine
or does it increase for some reason?
the whole point of a cache is to take advantage of temporal (and spacial) locality, where the idea is that when an item is queries it is likely to be queried again later on. Thus you want to only save it for a certain amount of time to clear up space
well, are you expecting it to increase?
if not. Why are you using a database if you only have 80mb of data that doesn't change?
it scales up, but I doubt it'd ever scale up so much that storing in ram will cause trouble
then why do you want a cache?
It only stores values in form of lists, dicts, texts etc
essentially what you're doing now is storing everything in the database
then when a user uses the command you permanently save it to memory
and keep it there
so eventually all user's data will be in your memory
and there's no point in using a database anymore
Ima be real...you are just caching already cached data.
I see your point now
The issue I'm facing with database is how slow it is with requests, maybe it's because I'm running it on free plan/regional factors.
Queries such as find_one adds delay to my commands and as some commands have a lot of queries, it increases the delay drastically especially when there are many users running the bot. Half of this is an assumption not point perfect information
Storing the database temprarily in RAM can help to speed up the reading aspect I think and bot only has to do writing to database making it faster performance wise.
Incase the bot shuts down and data is removed from ram it will still stay on the db's server.
Well that's pretty much the ideology
it's still fun to write a cache : )
instead of doing
await bot.db.econ.find_one```
i can just make the bot read it off memory thus making it slightly faster on paper
Well yes, databases are painfully slow because they have to access the file system which is painfully slow. That's why you use caching which like I said take advantage of temporal locality. But your cache doesn't take advantage of temporal locality. All you're doing is saying "Oh, this user tried my bot once, he's probably gonna need their data again for every hour of every day"
If your database scales up to be pretty big you're essentially using memory which you don't need to use
for a discord bot you only have a couple commands right
yeh i see the issue you listed on
so a user only engages with the bot for lets say 5 minutes max
because of cooldowns I suppose
hm
so after these 5 minutes their data is no longer needed to be in the cache
Uhm Vigitillion, why are you spreading misinformation
so you can clear it
Well yes, databases are painfully slow because they have access to the file system which is painfully slow
Incorrect
how come?
Well, cloud databases as he is using rn aren't restricted based off file read/write speeds.
yeah my bad forgot he was using mongo
makes sense. In theory I could possibly store timestamp too with each cached dictionary, and make a function run checks incase their last interaction was x minutes ago it removes the data. Unsure if this is the best approach tho
Even then, an sqlite database which is a file based db is very performant
yup, that's a possibility aswell
problem here is you have when requesting the data you first have to check if the data is still valid
which results in a slower get as apposed to a slower insert
and since you usally save the user to the database after the commands are finished I prefer a slower insert than a slower get since it reduces the time a user has to wait if you get what i mean
sure, they are performant but not as fast as memory
most sqlite clients cache in memory
right, one thats built in
sure
so adding one top is just more overhead
I'm not saying it's the best solution to add one on top
I told them that mongo had one built in
and then told them how to do it if he wanted to build one on top
never told them it's the best approach
I still feel like building your own cache is a good excercise since you're getting more insight on how your data is handled by the database you're using
but caching already cached data by mongo could also increase performance (albeit not by much) because it doesn't require you to send an http request to the mongo database assuming it's hosted in the cloud
Fair enough, not saying don't do it. Just know that doing so for something that has cache already built in, makes little to no sense unless you are able to disable this caching layer and make your own.
Honestly it's such a hassle, the free plan of Atlas provides shared ram and low network performance. For high traffic apps it's super shit
I'm waiting on my host provider and getting a mongodb hosted on the same vps as my bot is hosted on currently.
If both are on same machine queries should be much faster
but once again, those are things you have to measure and choose the best approach based on the trade-offs and gains
I mean, thats not technically how that works from my understanding
hm
Even on the same machine its still restricted by whatever protocol it uses to connect to the database
will its latency be lower? most likely
how about read and write speed
I'd say it'd be no more different than using atlas
that's why I prefer databases without their own cache or one you can disable because i like to optimize everything so I just build my own cache each time
but I also can't say for certain
it'd probably differ a millisecond or 2 but nothing really noticeable
The only time performance comes into question is when you have as many records as bun does
π
@spark flint how many records is that again?
What I currently know is that the read and write speed is much slower when there's more traffic at certain times 
few billion?
how do I check records
How long does it take you to index those
thats also only 2 months worth of data
it took 3 days last time
had to do it via a VM for it to stay online to index 
that's because you can't read and write to a database at the same time or write twice. This results in a data race, so they use something like a lock to ensure that only 1 operation happens at a time, this slows down operations
I hope you find a way to lower that number

So if 10 users run a command at the exact moment, the output will kick in one after other?
if it only has to read no
it grows between 10-100 million a day so 
you can read concurrently
Oh I meant indexing time
the problem is once you have a write, that can only happen on it's own
imagine what happens when you actually do reach your 8 billion goal
It has to write too, in most commands ofc
like .pay @mention 10 to pay 10 coins to someone let's say
yes, the 10 writes will not happen all at the same time
it will also increase ram so I can optimise DB even more
thats not bad, is this a pg db?
yep!
Then that's a big problem, what if the app has 100s of active users running it at the same time? The queue will keep increasing
How do I prevent that
no but a related project
Ah
it's not really
it's more complicated really
databases can handle a lot of traffic
But I'm currently facing it lowkey
as long as your queries are well made but you're using nosql so it's fine I suppose
Im not in your db am I 
example doc entry: js { "id": "ZG9jcy50b3AuZ2ctMTcxMTQzNjEzMjg0NC1mZTY5NWI2Ny03ZGQ2LTRkMWYtYTc2OS1mMTYzMjNkZGM4ZDc", "domain": "docs.top.gg", "addresses": [ "top-gg.github.io", "185.199.108.153", "185.199.109.153", "185.199.110.153", "185.199.111.153" ], "rcode": "NOERROR", "hostname": "top.gg", "subdomain": "docs", "ns": [ "top-gg.github.io" ], "timestamp": "2024-03-26T06:55:32.845Z" },
probably

a write should only take a couple ms to do
Im in the rominik db

i see
Actually im curious, is this logging dns information
well it could be because of free plan of atlas then? i mean the reason why im facing delay as that shit says "low network performance" specifically
first seen 9th may, last seen 14th may
lets not share this 
what modern databases do is use a write buffer, so instead of writing one at a time they store it into a big tray lets say and then write it all at once

ty
that's why the traffic could increase a little for lots of writes since it waits for the writes to fill up this buffer
I know its not "sensitive" information but ye
i should check if any of my stuff is there
hm
check if aarondye.dev is on there

ofcourse, you can't expect blazing fast speeds on a database like mongo, on a free plan
also the speed of the query relates to how big the domain is

nosql databases are usually slower because you can't write your own queries and good queries can increase speeds by quite a bit
yeah no logs
Damn
when the specific time hits, 100s of users run a command which has ~10 writes in it.
it slows down the output to ~5-10 seconds even
if you really want speed i'd suggest to leave mongo and use something like postgres

I bought and registered that domain with cloudflare like 1-2 years ago
started late march
why are you writing 10 times in one command?
yeah that will be why
I wish, but I already wrote ~25000 lines for my bot 
that's a big issue
its probabbly in one of my 2 old databases
uh oh
10 different collections and it's a big command overall
bro got reciptes (fuck cant spell rn)

if you're using a proper database wrapper you don't have to change much
wdmy collections?
you were talkin about a .pay command?
no that was just an example
why would a pay command have 10 writes xd
after the user has gotten all their feedback
I should make it so it first gives the feedback and then does the writing
yes
hm
this way, if something goes wrong in the middle of your code you also haven't changed anything
this way you only write when everything went succesfull
right
and the user doesn't get any delay from the writes
and then you can speed up the commands through a cache since you don't query the database anymore only the first time a user uses it's data
@commands.command()
async def pay(self, ctx):
await ctx.send(f"you paid 100 coins")
await self.bot.db.economy.update_one()
you could even make it so you write to the cache each time the user updates and then when the data gets removed from the cache you write it to the database
the problem you have with that approach however is if your app craches you lose data
what if the user runs the .wallet command to check their wallet right after they get this feedback https://prnt.sc/Tp1fr8vrcLpn
this way you decrease the amount of writes to your database aswell
Like instantly?
yeh but let's say the bot shuts down due to some reason before it gets to do smth
they should get the correct value
pretty much
Discord latency to your bot is prob 60-70ms ping if your bot is hosted in the US
by then the write should have been completed
like writes are stored to cache but bot shuts down before we got to update the db, then it's gone from ram and
what's the best region i could possibly host my bot on? I'm using dallas texas
that's what I said, that's the downside
hm
I think discord's servers are in new york
so closest to that
AH, I had buff ny as an option
but you should double check that cause i'm not sure
yeh someone said that it's us-east
you need to ensure that your bot has 100% uptime in that case
I mean that's never possible. Even you yourself have to re-deploy bot sometimes to push changes or code
and unexpected crashes aren't under control
so its a no go pretty much
Sure but if you have to redeploy your bot you can run a routine to first store all the data to the database
handle all exceptions and you shouldn't crash
also, I'm not sure if it's in python but in javascript you can overwrite the behavior of a crash
so you could first make it store all the data in the cache to the database before it crashes
Interesting
That's doable, but something you must get used to otherwise you run into big trouble
Also is there a way to somehow keep the bot online even when you push the changes 
I wouldn't assume that but like
also, let's say you keep the user's data in the cache for 2 minutes and only write after the item "dies" which means the user hasn't made any changes to their state, in worst case scenario a user would only lose around 2 minutes of progress
Just incase
Got you, for a game bot however it's quite significant as people keep doing rolls and chest openings etc and often land onto rare/extremely rare items
Reverting changes of everyone who lost their roll in those 2mins is a no go that's why I wasn't planning on caching writes
yeah sure
that's the thing, to optimize you usally have to weigh in different aspects of certain solutions
As you said multiple reads can be done at the same time but multiple writes cannot. So can a read and write be done at the same time or nah
no
what if the read happens to read the same thing that gets written?
now you have no guarantee that the data is what you expected it to be
that's called a data race
Essentially what you'd do here is use a process manager like pm2 to spin up 2 environments the "blue" and the "green" environment.
You start off with having the blue environment active. Then once you push your updates and everything you spin up the green environment with your updates and then change the active environment to the green one
this way you essentially only use the blue environment and then push your updates and then build and whatever and once the environment is up and running you just switch and you got 0 downtime
you can hook actions to exit events
as long as u dont ctrl-c the process
Sounds rough
it's not that difficult to implement
I dunno what you mean by that 
it's just that it's unheard of for me
when your process exits a procedure is ran
google it, look at how it works, look at some examples and try it
it's fun to implement such things
I see but like if the host shuts down what is gonna run the process
and you learn a lot by doing it
if you want 100% uptime don't use an unreliable host that might shut down
also depending on what cache solution you use, there might be file-based persistence
like redis
I think I'm not using an unreliable one
which can work off a file, meaning if it shutdowns out of the blue you still have the data onthe file
already told them they could use redis aswell
True
do note, however, you need to develop on linux if you plan to use redis
setting up redis on windows is...awful
I really need to use redis one of these days.
I've not really had a need for it yet
brain pointed this out to me
kind of funny

Well that sucks π
@commands.command()
async def pay(self, ctx, amount):
economy = await self.bot.cache.get_economy_cache(member.id) # getting data from cache
if not economy:
print(f"I ran")
economy = await self.bot.cache.not_economy_cache(member.id)
if amount > economy["coins"]: return
economy["coins"] -= amount
await self.bot.cache.update_economy_cache(member.id, economy) # updating cached data of user
await ctx.reply(f"Paid {amount} coins")
await self.bot.db.economy.update_one() # doing write on db at end
This could possibly work, doing writing at the end, reading from cache and updating the cache itself everytime they run a command before sending result. This way the bot just shows output from cache and does writing on database as a side quest
also the functions get cache, not cache and update cache are the one i defined above
oh nvm, that's your own methods
Don't know the answer to that, but these are custom functions I wrote
they probably implemented it to get the data from the db if the item is not in the cache
yeah, noticed it by the name
wait no
Incase you're wondering it's this bs
economy = await self.bot.cache.get_economy_cache(member.id) # getting data from cache
if not economy:
print(f"I ran")
economy = await self.bot.cache.not_economy_cache(member.id)
you're getting from the cache
so yeah it shouldn't be await
or you implemented it wrong
but I feel like this could be abstracted away like I said
just have a method called .get() which gets from the cache and returns it if it exists and if not requests the database and stores it to the cache
async def get_economy_cache(self, user_id):
return self.economy_cache.get(user_id)
it's an async function I wrote, for cache I'm just string it in a little variable
then instead have your write store the cache
cache operations should be abstracted yeah
you should never need 2 calls to get an item
and then when the item gets "killed" you store it to the db
hm
so you abstract all the cache operations away
it's something the user shouldn't interact with
nor the user neither you
What I see more of a challenge right now is to modify the cache within all commands
well yeah I meant user of the api, being you
first fix your cache to be correctly implemented
this way you dont have to adjust all commands to then fix it and then adjust again
yes thats the first step
eitherway thanks for assisting and having a good talk, I'll work at that code now and see where I get with it
im connecting with contabo on LinkedIn somehow π
Hala madrid βοΈ
hello! is anyone familiar with mongoose with TypeScript? I am trying to use subdocuments in arrays but I am facing a type error.
My type definition of my schema is the following: ```ts
interface Series {
_id: ObjectId
id: number
names: Name[]
}
interface Name {
_id: ObjectId
lang: string
name: string
isAlternative?: boolean
isNative?: boolean
}
type THydratedNamedDocument = {
names: Types.DocumentArray<Name>
}
type GenericNamedModelType<T> = Model<T, {}, {}, {}, THydratedNamedDocument>
const seriesSchema = new Schema<Series, GenericNamedModelType<Series>>({
id: {
type: "Number",
required: true,
unique: true
},
names: [nameSchema]
})
const SeriesModel = model<Series, GenericNamedModelType<Series>>("series", seriesSchema)
When I am trying to use the `save` method on a series document, I am getting the error `Property 'save' doesn't exist in the type 'THydratedNamedDocument'` (example ts
const elt = await SeriesModel.findOne({ id: targetId })
const newname = elt.names.create(name)
elt.names.push(newname)
await elt.save()
it's not about your schema, it's just that save() doesn't exist for elt
press ctrl space to see what methods are valid
whatever doesn't appear in autocomplete doesn't exist
(I am importing Schema, model, Types, Model from mongoose)
^
save does exist on every Document
apparently not on elt
i'm just following the mongoose documentation
btw, the error doesn't match the code you sent
Property 'save' doesn't exist but you didn't call a property, you called a method
it was supposed to say Function 'save()' doesn't exist
or smth like that
check if you saved the file
idk, it's the error I have
also show stacktrace, it should have one
hm
that's in french so
yeah I can guess the translation
but propriΓ©tΓ© means property
whatever you did doesn't include save in elt
and ts2339 is indeed talking about property
is it supposed to be a THydratedNamedDocument?
try casting the result to your document type
btw, ts type THydratedNamedDocument = { names: Types.DocumentArray<Name> } does in fact only include names
well yes it should be, because thats what you set the type as
you are overwriting the default type
so .save no longer exists
you should be extending the type if anything if you want to keep the original methods
yeah that's right, but I have no idea how should I do that
erm
idk ts
make it a interface
interface IHydratedNamedDocument extends Whatever {
names: Types.DocumentArray<Name>
}
extend whatever the default return type of that is before you override it
okay thank you
or if you really want to use type still or are forced to
you can do type whatever = SomeAlreadyDefinedType & { names: Types.DocumentArray<Name> }
that's the way to extend a type in ts
looks hacky af
usually you'd set your type to something else
yeah I am forced to because the type returned by findOne isn't an interface
type YourType = { names: Types.DocumentArray<Name> }
type MergedTypes = SomeDefinedType & YourType

welcome to ts
everything relating to the type system is hacky black magic
wait until you see some of the more complex types
nah I'm fine
type RecursiveType<T> = T extends object ? {
[K in keyof T]: RecursiveType<T[K]>;
} : T;
dk what the fuck this is meant to do
I haven't used typescript in a while
? is a new one for me
funny how my new project despite being much more modular and heavily abusing inheritance is still more optimized than my old code
because mongoose typings are so wierd
1st is new, 2nd is old
I didn't see the : T
so I was like wtf is that random ? doing
java modular?
nice joke
eh, in fact java is built to be modular
mongoose doc is so missleading
i've set my GenericNamedModelType to ```ts
type GenericNamedModelType<T> = Model<T, {}, {}, {}, Document<unknown, {}, T> & T & Required<{ _id: Types.ObjectId; }> & THydratedNamedDocument>
Is this a UML?? Wtf are you working on
that's my bot
bottom row are the commands, the green line is the inheritance of the Executable interface
blue line is likely the Manager class (database acessor)
idk what the bold yellow line is
lul
so i would make the left button white with the outline of the color of the right button
π
why do all languages have "not equal" !=, but dont have not greater than/less than?
That'd be just <= no?
you dont need != either
if (value != 1) {
}
if (!(value == 1)) {
}
it makes no sense value is not greater than 1
well yea then it'd just be less than
value < 1
this will do it

!> would be <= and !< would be >=
im making a preprocessor
or !<!>! not not smaller nor not not greater
or !<=!==>! not less than or equal to not equal greater than or equal to not
this should be its own language
oh wait...jsfuck
oh nvm jsfuck doesn't use <>=
it uses ()[]!+
No parens, braces
huh
I did practice jsfuck a bit
[]+{}[![]+![]+![]+![]+![]] for example is y
i need help with d.py, for my /ban i cant get it to return an error if the user isnt in the server
The logic is pretty simple tbh
Easy to learn, but u can't read old code
![] is 1
is this in binary?
Cuz js converts it to boolean
No, it's just js being funky
[] == 0
So ![] == true
so 1+1+1+1+1
Yes
so 5
It's technically true+true+true+...
how does that equal y tho
But js converts to number cuz u can't sum booleans
is 5 like ascii or smth for y π
[]+{} equals [array Object] for some stupid reason
[]+{}[...] is accessing the char at
So "[array Object]"[5]
Which is the sixth letter
So y
Of the string
what string
There, added quotes
Yeah
There are tricks to unlock the entire unicode dictionary
Some letters are really hard tho
or is it its own esoteric language built on js
π
It works because js does some fcked up conversions
But I don't remember jsfuck using parens
jsfuck indeed uses parans btw
[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(+(!+[]+!+[]+!+[]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([]+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]][([][[]]+[])[+!+[]]+(![]+[])[+!+[]]+((+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]+[])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]]](!+[]+!+[]+!+[]+[!+[]+!+[]])+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]])()((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[+!+[]+[!+[]+!+[]+!+[]]]+[+!+[]]+([+[]]+![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[!+[]+!+[]+[+[]]])
Then that's it
alert(1)
Also the kind of understanding you have to have of js
to come up with this
is insane
easy to teach
but imagine coming up with the idea of js fuck
π
imagine going to shady website and see this code in their completelysafe.js
the same type of idea as the movfuscator
wtf is that
Most of that code is getting eval() text
basically a "what if" turned into a challenge
Since u need it to run arbitrary code
a compiler that compiles code using only MOV instructions
yea (![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[+!+[]+[!+[]+!+[]+!+[]]]+[+!+[]]+([+[]]+![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[!+[]+!+[]+[+[]]] is the actual alert(1)
no idea what that is

its basically like if you were to create a whole program using only variable reassignment
without any other logic
nop lul
ic
cpus have instructions, aka commands they can run
those instructions include math, comparisons, copy, move, etc
asm is all about moving stuff in and out of registries and ram and such no?
that looks confusing
That's assembly
move eax to ecx?
and some dude found a way to make any program run using only move instructions
what eax and ecx are no idea
π
But u have 4 registers
Eax, ebx, ecx and edx
There are some specific uses iirc to each
just pretend you do, clap and nod and pretend you're impressed
thats what i do :^)
Jsfuck is fun to learn, but u need to highlight it somehow or idk, are comments allowed?



