#Event management before deploying a bot on the web

1 messages · Page 1 of 1 (latest)

junior bough
#

Hi ! I was asking myself what was the best way to deploy a bot on the web, so everybody could use it.

As I was thinking on how it would be possible, I was wondering how my bot could manage multiple events coming from multiple guilds. The problem is that I have some commands that may take some time to respond to a request (due to API calls but no one cares), and if a few people start using this type of command at the same time, it would be impossible for the bot to manage all these commands at the same time.

Currently, I am hosting the bot on my small OrangePi5 (Raspberry derivative), and it is enough for my own server, but for other servers ?

#

(I precise that I am not even close to deploy it, but still thinking of it)

digital forge
#

The OrangePi5 that you use could be enough for hosting up to like 1k servers depending on what your bot does (talking from experience).

Additionally, you can reduce memory and CPU strain when using hikari by configuring the cache and specifying only intents you actually need for the usage of your bot.

Once the bot starts growing past your expectations and optimization on your part (feel free to ask for optimization ideas or code review in this server, we are glad to help!!!!), you could move to a cloud provider, which tend to have better performance and, thus, less usage when it comes to CPU and memory.

#

Also, that problem you mentioned about API calls is not something you should be worrying about in the slightest. It's the least of your problems :)

digital sierra
#

relating to the commands you mentioned, are you using an async http lib?

#

because then that shouldn't be an issue

junior bough
digital sierra
#

wait

#

1 command making 80 API calls?

digital forge
#

80 API calls 👀

digital sierra
#

what the hell is that command doing, summoning an eldritch horror?

junior bough
digital forge
#

But yeah, that's something that can defined be optimized a lot, lmao

junior bough
#

Nah to better explain the goal of the bot, it is supposed to be an interface for Modrinth (Minecraft Mods supplier), and for this I have created some commands that allows the user to search for the last version of a list of mods

digital sierra
#

but even then, that command should just be slow to invoke for the end user

#

but shouldn't slow the entire bot down

junior bough
digital sierra
#

since all your bot does is send out requests & wait

#

you don't do much processing, right?

junior bough
#

Nah absolutely not

digital sierra
#

well then I guess it's fine™️

junior bough
#

Actually this is my first attempt with a bot

digital forge
#

Like, be able to select which mod you want

#

Or

#

Even better

digital sierra
#

also does the API you're working with not provide bulk endpoints?

digital forge
#

Just cache the responses and have them timeout every like minute or something

digital sierra
#

that's also probably a sane idea

digital forge
#

So every minute you just fetch the latest information and update your stored information

#

Then just read off a variable instead of API call

junior bough
digital sierra
#

as in, you submit a request for multiple stuff to be returned

#

and do it in one api call instead of 40

digital forge
digital sierra
#

kind of like how you can fetch up to 100 messages on Discord

#

in one api call

#

but that needs support from the api itself obviously

junior bough
digital forge
#

Mind linking the API?

digital sierra
#

also aren't you going to get ratelimited by this?

#

cause this sounds a tiny bit sus

#

also yeah

junior bough
#

Not mine actually

digital sierra
#

so you're using a wrapper catThink

digital forge
#

Oh

digital sierra
#

wait

digital forge
#

Eh

digital sierra
#

is this async

digital forge
#

Thats blocking btw :P

#

Its not async

digital sierra
#

I don't think it is lol

#

yeah

#

that's why your bot shits itself every time you do this

#

it blocks the entire event loop

junior bough
digital sierra
#

well, considering this is not async

#

I'd say so

digital forge
digital sierra
#

build your own little thing around it, and use aiohttp to do the requests

digital forge
#

You can read the docs there

junior bough
digital sierra
#

and what do you know

#

bulk endpoint :P

junior bough
digital sierra
#

or not applicable to your usecase

digital forge
#

^

digital sierra
#

like in this case

#

and besides, once you learn how to interact with 1 REST API

#

you pretty much learned them all

#

for the most part anyways

digital forge
#

Yeah

digital sierra
#

so unless it is a complicated monster like Discord, I don't even use wrappers anymore

digital forge
#

Also, they also have ratelimits in place, but I don't think you have to worry about it since you will only query 1 endpoint

junior bough
#

You guys are so professional that's impressive from a newbie perspective

digital forge
#

Or, if you would like, go try to implement it :)

digital sierra
#

I mean, it is good practice to handle them

digital forge
#

At this point, you are making your own wrapper :)

digital sierra
#

also there's plenty of libraries that have ratelimiters implemented

#

if you don't want to go that deep

digital forge
#

Just handle 429 as an error for the user

#

Anyways

digital sierra
#

but they are not too hard to write, just need to learn how the algorithms work

junior bough
digital sierra
#

JS files?

#

you mean json right?

#

APIs communicate with json typically

junior bough
digital sierra
#

and python has a module built-in called json to deal with it

digital forge
#

What I would do, make a function that fetches information only if the information it has stored is "too old" (you decide how much old is, I would recommend 10s) and then fetches the information, or sends the locally cached one

digital sierra
junior bough
digital forge
#

Then no need for ratelimits or what not

digital forge
#

Ez

digital sierra
#

well yes

#

if you use aiohttp

digital forge
#

This should be good enough for what you want

digital sierra
#

I'll also toss this in here

#

you want to be the client here

junior bough
digital forge
#

Lmaoo

#

This about to be 🚀

digital sierra
#

by the looks of it, if you know the names of the projects you need, you can submit it to the bulk endpoint

#

if you don't, there is a search endpoint

#

so that's like.. 2 API calls at worst?

junior bough
digital sierra
#

specifically you want this page

junior bough
digital sierra
#

I'd say read through the quickstart section

#

should be enough for your needs

#

and if you have any questions feel free to ask

#

also you shouldn't have to install aiohttp as hikari depends on it

#

just fyi

digital forge
#

(it's a good thing to add it to your dependencies tho, because hikari might switch off it)

digital sierra
#

true

digital forge
#

It's just good practice

junior bough
#

Well again thank you very much for your implication. I see now that I was rushing directly to the wall with my project, needs a lot of work ❤️

digital forge
#

Glad could be helpful rooLove