AardWolf / MHTimerBot

Discord bot that understands mousehunt timers
MIT License
7 stars 12 forks source link

when looking up a mouse, the bot now responds if there are any problems (changes redone to avoid merge conflicts) #218

Closed fluentinstroll closed 3 years ago

fluentinstroll commented 3 years ago

Sorry folks, I just started contributing to Github in the last few months so I'm a bit new to this, I meant to edit the pull request but ended up accidentally closing it. I'm gonna repost my thoughts from that one.

Addresses issue #210

This code changes the getThings function to check if the response is ok and if not, makes the response null

return await fetch(url)
        .then((response) => {
            if(response.ok){
                return response.json();
            }
            else {
                return null;
            }
        })
        .catch(err => {
            Logger.log(`findThings: Error getting item ${qsOptions.toString()} - ${err}`);
        });

The formatMice function then checks if the results are null and returns a reply.

async function formatMice(isDM, mouse, opts) {
    const results = await findThing('mouse', mouse.id, opts);
    if (results === null) {
        const reply = 'Looks like I\'m having a bit of trouble finding your mouse right now.' ;
        return reply;
    }

I wanted to handle this within the findThings function itself but I'm, not sure there's a way for me to do that.

Please let me know if this is too big a change or if you'd like me to change the formatLoot function to match.

Thanks so much!

AardWolf commented 3 years ago

Looks good! Adding it to the dev branch and will run the dev bot with this and a few other fixes "soon".