jeromeludmann / deno-irc

IRC client protocol module for Deno
https://deno.land/x/irc
MIT License
13 stars 4 forks source link

is there a way to run an irc command list /LIST? #5

Closed ralyodio closed 2 years ago

ralyodio commented 2 years ago

I'm looking to join a network and list all channels.

jeromeludmann commented 2 years ago

Hi,

It will be available in the next release.

In the meantime you can do something like:

const client = new Client({ ... });
await client.connect( ... );

interface ChannelItem {
  channel: string; // name of the channel
  count: number; // total users count
  topic: string; // topic description (if set)
}

const allChannelList: ChannelItem[] = [];

client.on("raw", (msg) => {
  switch (msg.command) {
    case "RPL_LIST": {
      const [, channel, count, topic = ""] = msg.params;
      const channelListItem = { channel, count: Number(count), topic };
      allChannelList.push(channelListItem);
      break;
    }
    case "RPL_LISTEND": {
      console.log(allChannelList); // ALL the channel list
      break;
    }
  }
});

// gets the channel list once connected and ready
client.on("register", (msg) => {
  client.send("LIST");
});
jeromeludmann commented 2 years ago

Hi @ralyodio,

New version has been released.

You can now list all channels:

client.on("register", () => {
  client.list();
});

and get the result:

client.on("list_reply", (msg) => {
  for (const { channel, count, topic } of msg.channels) {
    // ...
  }
});
jeromeludmann commented 2 years ago

Due to a recent little breaking change in v0.7.0, it should now be:

client.on("list_reply", (msg) => {
  const { name, count, topic } = msg.params.channels;
});

See also: