Skip to content

ttxs25830/screeps-all-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

screeps-all-api

Http Api

HttpScreepsApi.raw

Example

const token = "Your Token Here"
const baseURL = "https://screeps.com"
async function getAccountId() {
  return (await new HttpScreepsApi(baseURL, token).raw("GET", "/api/auth/me"))._id
}
getAccountId().then(console.log)
// This code will print your account id on console

HttpScreepsApi.authByPW

Example

const baseURL = "https://screeps.com"
async function getAccountId() {
  const token = await HttpScreepsApi.authByPW("Your username/email","Your password", "https://screeps.com")
  return (await new HttpScreepsApi(baseURL, token).raw("GET", "/api/auth/me"))._id
}
getAccountId().then(console.log)
// This code will print your account id on console

WebSocket Api

WSScreepsApi.rawOnce

Example

const baseURL = "wss://screeps.com"
const baseURL2 = "https://screeps.com"
const token = "Your Token Here"
async function getAccountId() {
  const id = (await new HttpScreepsApi(baseURL2, token).raw("GET", "/api/auth/me"))._id
  const wsApi = new WSScreepsApi(baseURL, token)
  await wsApi.waitTillReady
  return (await wsApi.rawOnce(`user:${id}/cpu`)).cpu
}
getAccountId().then(console.log)
// This code will print your cpu usage for last game tick

WSScreepsApi.rawListen && WSScreepsApi.rawUnlisten

Example

const baseURL = "wss://screeps.com"
const baseURL2 = "https://screeps.com"
const token = "Your Token Here"
async function getAccountId() {
  const id = (await new HttpScreepsApi(baseURL2, token).raw("GET", "/api/auth/me"))._id
  const wsApi = new WSScreepsApi(baseURL, token)
  await wsApi.waitTillReady
  let cnt = 0
  wsApi.rawListen(`user:${id}/cpu`, (curr) => {
    console.log(curr)
    cnt++
    if(cnt === 5) {
        wsApi.rawUnlisten(`user:${id}/cpu`)
    }
  })
}
getAccountId().then(console.log)
// This code will print your cpu usage for last game tick five times

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published