Giter Site home page Giter Site logo

Comments (17)

dead8309 avatar dead8309 commented on June 7, 2024

For javscript, You can copy all the codes from the gateway folder from kizzy-demo-ts repository.

It has some basic things implemented, you can add the rest by yourself.

If by nodejs you meant your app won't be able to access browser apis then you just need to replace browser Websocket with Websocket from ws library.

https://github.com/dead8309/kizzy-demo-ts/blob/6a472f6266030d929664a5d82fbd4325913eb19d/lib/gateway/transport/WebsocketTransport.ts#L7

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

For javscript, You can copy all the codes from the gateway folder from kizzy-demo-ts repository.

It has some basic things implemented, you can add the rest by yourself.

If by nodejs you meant your app won't be able to access browser apis then you just need to replace browser Websocket with Websocket from ws library.

https://github.com/dead8309/kizzy-demo-ts/blob/6a472f6266030d929664a5d82fbd4325913eb19d/lib/gateway/transport/WebsocketTransport.ts#L7

This repository is being of great help because I still hadn't found anything about it unfortunately I didn't understand the functions very much because I'm not familiar with the typescript

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

Looking at your code, I was able to contact myself in Javascript but I didn't get where I wanted ;) the custom rich precense can you help me? Follow the code

import WebSocket from 'ws';

const OpCodes = {
  Hello: 10,
  Heartbeat: 1,
  Dispatch: 0,
  Reconnect: 7,
  InvalidSession: 9,
};

const token = 'TOKEN';

const ws = new WebSocket('wss://gateway.discord.gg/?v=9&encoding=json');

let seq = 0;
let session_id = "";
let resume_gateway_url = "";

ws.on("open", () => {
  console.log("Socket Opened");
  ws.send(send(identify(token)));
});

ws.on("message", (event) => {
 const message = event.toString("utf8");
 const { t, op, d } = JSON.parse(message);

  switch (op) {
    case OpCodes.Hello:
     console.log('Got op 10 HELLO');
     const { heartbeat_interval } = d;
     heartbeat(heartbeat_interval, seq);
     send(identify(token));
      break;

        case OpCodes.Heartbeat:
          console.log("Got Op 1 Sending Heartbeat");
          ws.send({
            op: OpCodes.Heartbeat,
            d: seq === 0 ? null : seq.toString(),
          });
          break;

        case OpCodes.Dispatch:
          if (!t) return;
          switch (t) {
            case 'READY':
              console.log('Received READY event');
              const { user } = d;
              ws.emit('open', user);
              session_id = d.session_id;
              resume_gateway_url = d.resume_gateway_url;
              break;
            default:
              break;
          }
          break;

        case OpCodes.Reconnect:
          console.log("Got op 7 Closing and Reconnecting Session");
          ws.close(4000);
          break;

        case OpCodes.InvalidSession:
          console.log("Got Op 9 Reconnect Failed");
          ws.send(identify(token));
          break;

        default:
          console.log("Received unknown message:", parsedData);
      }
});


function heartbeat(ms, seq) {
  setInterval(() => {
    return setInterval(() => {
     send({ op: OpCodes.Heartbeat, d: seq });
    }, ms);
  });
};

function send(data) {
  ws.send(JSON.stringify(data))
}

async function identify(token) {
  if (!token) {
    new Error('Token Not Specified')
  }
  
  return {
    op: 2,
    d: {
      token: token,
      properties: {
        $os: "disco",
        $browser: "chrome",
        $device: "chrome",
      },
      compress: false,
      capabilities: 65,
      largeThreshold: 100
    }
  };
};

from kizzy.

dead8309 avatar dead8309 commented on June 7, 2024

Uh, I think you only need to import ws and replace the Websocket with one from ws then you can just use it like what's described in the readme file

import { Client } from "@dead8309/kizzy-rpc";

const client = new Client();

client.on("ready", () => {
    client.user?.setActivity({
        name: "Hey"
    });
});

client.login(TOKEN);

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

I don't understand anything ,-,

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

Uh, I think you only need to import ws and replace the Websocket with one from ws then you can just use it like what's described in the readme file

import { Client } from "@dead8309/kizzy-rpc";

const client = new Client();

client.on("ready", () => {
    client.user?.setActivity({
        name: "Hey"
    });
});

client.login(TOKEN);

The token has the scope of everything in rpc:

$ tsnd --respawn --transpile-only rpc.ts [INFO] 01:13:53 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.9.1, typescript ver. 5.1.6)
Socket Opened
Got op 10 HELLO
Authentication failed.

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

https://github.com/sebastianjnuwu/gateway

from kizzy.

dead8309 avatar dead8309 commented on June 7, 2024

Socket Opened Got op 10 HELLO Authentication failed.

You need to pass in your token

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

Socket Opened Got op 10 HELLO Autenticação falhou.

Você precisa passar seu token

But I passed, the user token takes it, right? Can you test the code you made and see if the rpc shows up? I made some changes see there

from kizzy.

dead8309 avatar dead8309 commented on June 7, 2024

But I passed, the user token takes it, right? Can you test the code you made and see if the rpc shows up? I made some changes see there

Yes it works fine. maybe you did something wrong ?

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

But I passed, the user token takes it, right? Can you test the code you made and see if the rpc shows up? I made some changes see there

Yes it works fine. maybe you did something wrong ?

So what I did:
• I made the authorization link and marked everything from rpc in discord Developers
• I took the authorization link code and generated the user token
• I put it in the code and ran yarn and yarn dev

from kizzy.

dead8309 avatar dead8309 commented on June 7, 2024

Gateway needs user token not oauth token

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

Gateway needs user token not oauth token

? When you logon to your rpc site it says that user is undefined

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

I think that's why it's failing authentication all the time;
Putting the email and password on your correct website comes to me:
Screenshot_20230713-113708

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024
const client = new Client();

client.on("ready", (user) => {
console.log(user) // idl
    client.user?.setActivity({
        name: "Hey"
    });
});

from kizzy.

dead8309 avatar dead8309 commented on June 7, 2024

Login through email and password is still experimental in that site, you need to use token

from kizzy.

sebastianjnuwu avatar sebastianjnuwu commented on June 7, 2024

O login por e-mail e senha ainda é experimental nesse site, você precisa usar token

Using the token it says error "4000" or "4003" that it was not possible to connect like my code

from kizzy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.