ToogaInc / ToogaBooga

An open-source Realm of the Mad God Discord chat bot designed for advanced cross-verification, moderation, and raid management.
MIT License
8 stars 4 forks source link

Get guilds from cache instead of requesting it from Discord & removed send announcement command #203

Closed ewang2002 closed 2 years ago

ewang2002 commented 2 years ago

With the addition of error handling (#172), there's now a bunch of errors being printed regarding trying to request a guild that the bot isn't in.

This PR fixes this by having the bot refer to its own guild cache instead of constantly fetching a guild from the API.

This PR also removes the sendannouncements command, since we now have a support server that can do just that.

I'm not sure if there are any downsides to having the bot use its own cache (does it lose any information that we might need?). Let me know if you think there are any downsides.

nyapat commented 2 years ago

does it lose any information that we might need?

nope, when the bot initially makes the gateway connection it sends guilds so that djs can cache them. fetching is pretty much identical to this payload of info and djs handles updating cache as well, so it's reliable

nyapat commented 2 years ago

lol, i just checked because i thought it might be but https://github.com/ToogaInc/ToogaBooga/blob/ae74d01033580b3884e38e29eea5d7cce13951da/src/utilities/fetch-get-request/GlobalFgrUtilities.ts#L73 this already refers to cache (internally, since you don't really need to fetch guilds/channels/roles, like ever), it's only when the guild doesn't exist that it falls back to the actual api fetch

ewang2002 commented 2 years ago

lol, i just checked because i thought it might be but

https://github.com/ToogaInc/ToogaBooga/blob/ae74d01033580b3884e38e29eea5d7cce13951da/src/utilities/fetch-get-request/GlobalFgrUtilities.ts#L73

this already refers to cache (internally, since you don't really need to fetch guilds/channels/roles, like ever), it's only when the guild doesn't exist that it falls back to the actual api fetch

Oh yeah, I completely forgot that's how it works. I believe the reason why the error exists is because Tooga has data for a guild that no longer exists, so it's constantly trying to get data about said guild.

Not exactly much that can be done there, though, unless we want to just delete the guild document entirely if the bot leaves a guild.

nyapat commented 2 years ago

lol, i just checked because i thought it might be but https://github.com/ToogaInc/ToogaBooga/blob/ae74d01033580b3884e38e29eea5d7cce13951da/src/utilities/fetch-get-request/GlobalFgrUtilities.ts#L73

this already refers to cache (internally, since you don't really need to fetch guilds/channels/roles, like ever), it's only when the guild doesn't exist that it falls back to the actual api fetch

Oh yeah, I completely forgot that's how it works. I believe the reason why the error exists is because Tooga has data for a guild that no longer exists, so it's constantly trying to get data about said guild.

Not exactly much that can be done there, though, unless we want to just delete the guild document entirely if the bot leaves a guild.

deleting isn't a bad idea but it's not like it's going to act as if they were left again. Anyways, a possible solution to the last sentence could just be by checking like:

if (!client.guilds.cache.has(IDocumentInfo.guildId)) return;
// We know for certain that the client has the guild information cached, & 
// since every guild is sent during the initial handshake, the only possible way 
// for a return is when the client is not in the guild
ewang2002 commented 2 years ago

lol, i just checked because i thought it might be but https://github.com/ToogaInc/ToogaBooga/blob/ae74d01033580b3884e38e29eea5d7cce13951da/src/utilities/fetch-get-request/GlobalFgrUtilities.ts#L73

this already refers to cache (internally, since you don't really need to fetch guilds/channels/roles, like ever), it's only when the guild doesn't exist that it falls back to the actual api fetch

Oh yeah, I completely forgot that's how it works. I believe the reason why the error exists is because Tooga has data for a guild that no longer exists, so it's constantly trying to get data about said guild.

Not exactly much that can be done there, though, unless we want to just delete the guild document entirely if the bot leaves a guild.

deleting isn't a bad idea but it's not like it's going to act as if they were left again. Anyways, a possible solution to the last sentence could just be by checking like:

if (!client.guilds.cache.has(IDocumentInfo.guildId)) return;
// We know for certain that the client has the guild information cached, & 
// since every guild is sent during the initial handshake, the only possible way 
// for a return is when the client is not in the guild

Fair, yeah. That's more or less what I just did, except I'm making use of the cache directly.

nyapat commented 2 years ago

lol, i just checked because i thought it might be but https://github.com/ToogaInc/ToogaBooga/blob/ae74d01033580b3884e38e29eea5d7cce13951da/src/utilities/fetch-get-request/GlobalFgrUtilities.ts#L73

this already refers to cache (internally, since you don't really need to fetch guilds/channels/roles, like ever), it's only when the guild doesn't exist that it falls back to the actual api fetch

Oh yeah, I completely forgot that's how it works. I believe the reason why the error exists is because Tooga has data for a guild that no longer exists, so it's constantly trying to get data about said guild. Not exactly much that can be done there, though, unless we want to just delete the guild document entirely if the bot leaves a guild.

deleting isn't a bad idea but it's not like it's going to act as if they were left again. Anyways, a possible solution to the last sentence could just be by checking like:

if (!client.guilds.cache.has(IDocumentInfo.guildId)) return;
// We know for certain that the client has the guild information cached, & 
// since every guild is sent during the initial handshake, the only possible way 
// for a return is when the client is not in the guild

Fair, yeah. That's more or less what I just did, except I'm making use of the cache directly.

oh yeah, it's the same thing really, just if you wanted to fetch it works, you can merge if you want