2.0.9 • Published 11 months ago

@d2n0s4ur/chzzk-chat v2.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Chzzk-Chat library

Test workflow status Npm Version Downloads Issues Node version

Javascript를 통해 치지직 채팅을 크롤링하는 코드입니다.

Important Update

  • 각 Handler의 인자가 변경되었습니다.(중괄호로 감쌈) 이전 버전과 호환되지 않습니다.
  • 개발자 여러분들은 바뀐 핸들러 코드를 확인하고 소스코드를 수정해주세요.

Install

Node

NPM

$ npm install @d2n0s4ur/chzzk-chat

Yarn

$ yarn add @d2n0s4ur/chzzk-chat

Usage

import { ChzzkChat } from "@d2n0s4ur/chzzk-chat";

const chzzkChat = new ChzzkChat("YOUR_CHZZK_USER_HASH");
// ex) ChzzkChat('dfffd9591264f43f4cbe3e2e3252c35c')

1. Add message Handler

const messageHandler: messageHandler = ({
  badges: string[],
  nick: string,
  message: string
}) => {
  console.log(`${nick}: ${message}`);
};

chzzkChat.addMessageHandler(messageHandler);

2. Add donation Handler

const donationHandler: donationHandler = ({
  badges: string[],
  nick: string,
  message: string,
  isAnonymous: boolean,
  amount: number
}) => {
  if (!isAnonymous) {
    console.log(`${nick}님이 ${amount}원을 후원했습니다: ${message}`);
  } else {
    console.log(`익명의 후원자가 ${amount}원을 후원했습니다: ${message}`);
  }
};

chzzkChat.addDonationHandler(donationHandler);

3. Add subscription Handler

const subscriptionHandler: subscriptionHandler = ({
  badges: string[],
  nick: string,
  message: string,
  month: number,
  tierName: string,
  tierNo: number
}) => {
  console.log(
    `${nick}님이 ${month}개월 ${tierName}를 구독했습니다: ${message}`
  );
};

chzzkChat.addSubscriptionHandler(subscriptionHandler);

4. get Emoji Url from EmojiID

const emojiRegex = /:\w+:/g;
const emojiMatches = message.match(emojiRegex);

if (emojiMatches) {
    emojiMatches.forEach((emoji) => {
        const emojiName = emoji.slice(1, -1);
        const emojiUrl = chzzkChat.getEmojiUrl(emojiName);
        console.log(emojiUrl);
    });
}

사용이 끝난 후, chzzkChat.close()를 호출하여 웹소켓을 닫아주세요.

After using the library, please call chzzkChat.close() to close the websocket.

chzzkChat.close();
2.0.3

11 months ago

2.0.2

11 months ago

2.0.5

11 months ago

2.0.4

11 months ago

2.0.7

11 months ago

2.0.6

11 months ago

2.0.9

11 months ago

2.0.8

11 months ago

2.0.1

11 months ago

2.0.0

1 year ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago