LengoLabs / qbot

Qbot is an advanced, easy to setup, free, and unbranded Discord-Roblox ranking bot. If at any time during setting it up you need assistance, you can join the support server.
https://discord.gg/J47m7t4
MIT License
77 stars 138 forks source link

API - DOES NOT SHOW IN LOG WHO COMPLETED THE ACTION ON THE API REQ #149

Open DJKieranl29 opened 4 months ago

DJKieranl29 commented 4 months ago

For example i have a promote command ingame, how can I log who did this command?

yogurtsyum commented 4 months ago

The API does not currently allow specifying who is responsible for an action. We'll keep this in mind as a future feature request, or you could modify the logAction line of api.ts yourself.

DJKieranl29 commented 4 months ago

ok can you suggest the easiest way to add it?

yogurtsyum commented 4 months ago

Change the responsibleUser parameter to take from a URL query whenever logAction is ran.

DJKieranl29 commented 4 months ago

That dont exist, do i gota make it? image

yogurtsyum commented 4 months ago

It's a placeholder parameter of logAction

DJKieranl29 commented 4 months ago

right, so how do i get who sent the request anyways. would i have to add it to the body of the request? Also can you send me the info needed for "logaction" for example like: logaction(name,user,time)?

yogurtsyum commented 4 months ago

logAction is defined in src/handlers/handleLogging.ts:

async (action: string, moderator: DiscordUser | RobloxUser | GroupMember | any, reason?: string, target?: RobloxUser | PartialUser, rankChange?: string, endDate?: Date, body?: string, xpChange?: string)

You're likely going to want to change the value currently set to "API Action."

DJKieranl29 commented 4 months ago

I am at a stage where i have the user wh odid the action, but the user being effected im getting their username is "null" and i have no idea why... code:

 app.post('/promote', async (req, res) => {
        const id  = req.body.id;
        const ActionByUser = req.body.By
        const ActionuserID = req.body.ByID
        if(!id || !ActionByUser || !ActionuserID) return res.send({ success: false, msg: 'Missing parameters.' });
        try {
            const robloxMember = await robloxGroup.getMember(Number(id));
            if(!robloxMember) throw new Error();
            const groupRoles = await robloxGroup.getRoles();
            const currentRoleIndex = groupRoles.findIndex((role) => role.rank === robloxMember.role.rank);
            const role = groupRoles[currentRoleIndex + 1];
            if(!role) throw new Error();
            await robloxGroup.updateMember(Number(id), role.id);
            console.log(robloxMember)
            console.log(robloxMember.name)
            logAction('Promote', `API Action (By: ` + ActionByUser + ` | ` + ActionuserID + `)`, robloxMember.name, robloxMember, `${robloxMember.role.name} (${robloxMember.role.rank}) → ${role.name} (${role.rank})`);
            return res.send({ success: true });
        } catch (err) {
            return res.send({ success: false, msg: 'Failed to rank.' });
        }
    });
yogurtsyum commented 4 months ago

I'd assume that's an issue with the code that sends the request, because it must be string "null" for !ActionByUser to return false, as it does here.

DJKieranl29 commented 4 months ago

I think I have got a fix for it, just requires 2 extra api requirments: "SenderID" and "SenderUsername". And then now its working :)