Skip to content

Supernova0417/ABBS_tow_LogBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ABBS_tow_LogBot

1. Introduction

 Discord bot script linking IRC and Discord, written in Node.js

2. Requirements

 Node.js: v16.6.0 이상
 npm: v7.24.0 이상
 discord.js 모듈
 irc-upd 모듈
 자신이 소유한 디스코드 서버의 채널 ID와 봇 토큰

3. Installation Setup (tested on Ubuntu 22.04.2 LTS x86_64)

  1. 미리 설치되어 있는 이전 버전의 node.js, npm, 업데이트 해야하는 모듈은 모두 지워줍니다.

  2. "apt upgrade && apt update" 그리고 apt autoremove (항상 어떤 패키지를 설치하기 전에 다른 패키지 update와 upgrade를 해주면 좋습니다!)

  3. node.js와 npm을 특정 버전으로 설치합니다.
    a. "apt install nodejs npm"
    b. "curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -"로 NodeSource 저장소를 추가한 후
    c. "apt-get install -y nodejs"로 Node.js 16.x 버전을 설치합니다.
    d. 위 방법으로 원하는 버전이 설치가 안 되면 구버전을 다시 지운 후 다음 명령어를 CLI에 차례대로 입력해서 설치합니다.
    "curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource-archive-keyring.gpg"
    "echo 'deb [signed-by=/usr/share/keyrings/nodesource-archive-keyring.gpg] https://deb.nodesource.com/node_16.x hirsute main' | sudo tee /etc/apt/sources.list.d/nodesource.list"
    "echo 'deb-src [signed-by=/usr/share/keyrings/nodesource-archive-keyring.gpg] https://deb.nodesource.com/node_16.x hirsute main' | sudo tee -a /etc/apt/sources.list.d/nodesource.list"
    "apt-get install -y nodejs"
    e. "npm install -g npm@8.0.0"으로 npm을 v8.0.0으로 업데이트합니다.

  4. "node -v"와 "npm -v"로 각각 올바른 버전이 설치되었는지 확인합니다.

  5. 실행할 스크립트가 있는 디렉토리로 이동 후 "npm install discord.js irc-upd"로 discord.js, irc-upd 모듈을 설치합니다.
    필요한 다른 모듈도 업데이트해줍니다.

  6. "node '스크립트명'"으로 스크립트를 실행합니다!

4. Incidental Troubleshooting

실제로 발생한 에러 목록 (자세한 내용은 issue 탭을 참고)

  • HTTPError: Bad Gateway
  • ConnectTimeoutError: Connect Timeout Error (가장 빈번한 에러)
  • Error: getaddrinfo EAI_AGAIN
  • RequestAbortedError [AbortError]: Request aborted

Solutions

 Node 스크립트에 에러가 발생했을 경우 수행할 코드를 만들어 놓습니다.
<Example>
clientIRC.on('uncaughtException', err => {
...
})
 그러나, 이 방법은 Node module에서 에러가 발생하면 스크립트가 깨지기에 완벽한 해결 방법은 아닙니다.

 그래서 다른 방법을 탐색한 결과, PM2, Nodemon, Forever 등의 processs manager 서비스를 이용하는 방법이 있었습니다!
 에러가 발생하면 Node 프로세스는 자동으로 죽는데, process manager를 이용하면 
 Node 프로세스를 자동으로 restart 해주는 기능이 있어 지속적인 서비스 운영이 가능합니다.

How to restart node app from itself
nodejs/help#923

Nodemon
https://nodemon.io/

PM2를 써야하는 이유
https://muna76.tistory.com/259

PM2
https://pm2.keymetrics.io/


Markdown 작성법 참고: https://www.heropy.dev/p/B74sNE

About

Discord bot script linking IRC and Discord, written in Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors