Programming Getting replay of a match using a bot

Hi friends. I'm making a bot that can track K/D in a live battle, but that's not what this is about.

I'm trying to get the bot to automatically save the replay of the battle after the match is done. However, I can't seem to get the uploading to work properly. This is the code:
https://hastebin.com/okacuwujaw.js

`response` says "ID needed" even though, as you can see, I POST the ID as well. What's going on, and how can I fix it?
 
Oh oof, it went offline. Lemme post my code directly then (and yes, I'm parsing the response to /savereplay in another part of the code).

JavaScript:
    async requestReplay(data) {
        let replayPostURL = "https://play.pokemonshowdown.com/~~showdown/action.php?act=uploadreplay";
        let replay = "Replay";
        let newData = {
            inputlog: data.log,
            id: data.id
        };

        //console.log(data);
        let response = axios.post(replayPostURL, newData).then((response) => {
            console.log("Replay posted!");
            if (this.serverType === "Standard") {
                replay = `https://replay.pokemonshowdown.com/${data.id}`
            }
            else {
                replay = `https://replay.pokemonshowdown.com/${this.serverType.toLowerCase()}-${data.id}`
            }
            console.log(response);
            return response;
        });
        return replay;
    }
 

Austin

Schismatic
is a Programmeris a Community Contributoris a Forum Moderator Alumnusis a Battle Simulator Moderator Alumnus
I must be missing something, where is your bot actually sending /savereplay to the server?
 
The bot sends `/savereplay` to the server in line 329 of `showdown.js` in that repo I linked above. Then, it looks for the response on line 206 of the same file and calls the `requestreplay` method (this method is not in the master branch of the git repo yet, that's why you don't see it). This `requestreplay` method is the code that I pasted above, in which the bot takes the JSON data received by the `/savereplay` command to then POST it to Showdown so the replay is uploaded and can be watched.
 
Oh forgot to add before lol: idk if you didn't see, but the POSTing doesn't actually work, for some reason. I just need to know what to POST exactly so I can do it right. I tried looking on Github for answers to no avail
 
I have looked further into it, and tried POST requesting using Postman to this URL:
Code:
https://play.pokemonshowdown.com/~~showdown/action.php?act=uploadreplay&id=sports-gen8nationaldexdlclegacy-67000&forcecache=false&name=gen8nationaldexdlclegacy&format=gen8nationaldexdlclegacy&formatid=gen8nationaldexdlclegacy&uploadtime=14:22:25 GMT&date=Thu, 07 May 2020&private=false&p1=e24mcon&p1id=e24mcon&p2=infernapeisawesome&p2id=infernapeisawesome&log=|j|☆e24mcon\\n|j|☆infernapeisawesome\\n|player|p1|e24mcon|clay|\\n|player|p2|infernapeisawesome|1|\\n|teamsize|p1|6\\n|teamsize|p2|6\\n|gametype|singles\\n|gen|8\\n|tier|[Gen 8] National Dex DLC Legacy\\n|rule|Sleep Clause Mod: Limit one foe put to sleep\\n|rule|OHKO Clause: OHKO moves are banned\\n|rule|Evasion Moves Clause: Evasion moves are banned\\n|rule|Endless Battle Clause: Forcing endless battles is banned\\n|rule|HP Percentage Mod: HP is shown in percentages\\n|clearpoke\\n|poke|p1|Tornadus-Therian, M|\\n|poke|p1|Scizor, M|\\n|poke|p1|Alomomola, M|\\n|poke|p1|Nidoqueen, F|\\n|poke|p1|Salamence, M|\\n|poke|p1|Blaziken, M|\\n|poke|p2|Absol, F|\\n|poke|p2|Togekiss, F|\\n|poke|p2|Manaphy|\\n|poke|p2|Jirachi|\\n|poke|p2|Gligar, M|\\n|poke|p2|Vanilluxe, F|\\n|rule|Dynamax Clause: You cannot dynamax\\n|teampreview\\n|c|☆infernapeisawesome|forfeit again\\n|-message|e24mcon forfeited.\\n|\\n|win|infernapeisawesome\\n|j| PorygonTesting\\n&inputlog=|j|☆e24mcon\\n|j|☆infernapeisawesome\\n|player|p1|e24mcon|clay|\\n|player|p2|infernapeisawesome|1|\\n|teamsize|p1|6\\n|teamsize|p2|6\\n|gametype|singles\\n|gen|8\\n|tier|[Gen 8] National Dex DLC Legacy\\n|rule|Sleep Clause Mod: Limit one foe put to sleep\\n|rule|OHKO Clause: OHKO moves are banned\\n|rule|Evasion Moves Clause: Evasion moves are banned\\n|rule|Endless Battle Clause: Forcing endless battles is banned\\n|rule|HP Percentage Mod: HP is shown in percentages\\n|clearpoke\\n|poke|p1|Tornadus-Therian, M|\\n|poke|p1|Scizor, M|\\n|poke|p1|Alomomola, M|\\n|poke|p1|Nidoqueen, F|\\n|poke|p1|Salamence, M|\\n|poke|p1|Blaziken, M|\\n|poke|p2|Absol, F|\\n|poke|p2|Togekiss, F|\\n|poke|p2|Manaphy|\\n|poke|p2|Jirachi|\\n|poke|p2|Gligar, M|\\n|poke|p2|Vanilluxe, F|\\n|rule|Dynamax Clause: You cannot dynamax\\n|teampreview\\n|c|☆infernapeisawesome|forfeit again\\n|-message|e24mcon forfeited.\\n|\\n|win|infernapeisawesome\\n|j| PorygonTesting\\n
however, it STILL doesn't work. any ideas why?
 
Late update, but I fixed it!

First, you have to send the following message to the websocket: `${this.battle}|/uploadreplay`, replacing `this.battle` with the battle id.
Next, you have to look for the message that starts with `|queryresponse|savereplay` then parse the JSON, and run the following function:

async requestReplay(data) {
let url = `https://play.pokemonshowdown.com/~~${this.serverType}/action.php`;
data.id = `${this.serverType === "showdown" ? "" : `${this.serverType}-`}${data.id}`;
let newData = querystring.stringify({
act: "uploadreplay",
log: data.log,
id: data.id
});
console.log("newData: " + JSON.stringify(newData) + "\n");
let response = await axios.post(url, newData);
console.log("Replay posted!");
let replay = `https://replay.pokemonshowdown.com/${data.id}`;
console.log(`Response to replay: ${response.data}`);
return replay;
}

where you pass in the JSON to the function. And it'll return the replay link!
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top