Coder Social home page Coder Social logo

polar-bear's Introduction

polar-bear

open-graph-scraper로 구현한 디스코드 봇

polar-bear 폴더구조

|-- README.md
|-- commands
|   |-- help.js
|   |-- notion.js
|   `-- ping.js
|-- config.json
|-- db-schema.json
|-- deploy-commands.js
|-- index.js
|-- notion
|   |-- api.js
|   |-- create-page-request-body.js
|-- open-graph
|   |-- __snapshots__
|   |   `-- og.spec.js.snap
|   |-- og-mock-data.js
|   |-- og-rules.js
|   |-- og-tagging-mock-data.js
|   |-- og-tagging.js
|   |-- og-tagging.spec.js
|   |-- og.js
|   `-- og.spec.js
|-- package-lock.json
|-- package.json
`-- polar-bear.png

polar-bear 실행

root path

$ ./my-bot

test command

$ npm start

데이터 파이프라인

image

polar-bear 기능설명

디스코드 채팅으로 URL을 입력하면 태그가 자동으로 생성되어 notion database에 row 추가

미리 cache해둔 DB 스키마를 통해 POST 요청하는 방식으로 구현

기술스택

  • node.js
  • discord.js
  • open-graph-scraper
  • vitest

참고자료

삽질-과정을-남긴-블로그

회고록

polar-bear's People

Contributors

darkenpeng avatar twinstae avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

polar-bear's Issues

1.2(cache한 채널을 제외한)다른 채널에서 유저의 입력이 들어왔을 때 에러메세지 embed옵션으로 respond하게 만들기

notion.js에서

import { SlashCommandBuilder } from '@discordjs/builders';
import { MessageEmbed } from 'discord.js';
import notion from "../notion/api.js";

import {ogScraper} from '../og.js';

//터미널에서 og로 받아오는 파일을 따로 빼서 얘만 node 파일명.js
const data = new SlashCommandBuilder()
    .setName('notion')
    .setDescription( "노션 데이터베이스에 자료를 추가")
    // .addChannelOption(option =>
    //     option.setName('destination')
    //         .setDescription('Select a channel'))
    .addStringOption(option =>
        option.setName('url')
            .setDescription('추가하려는 자료의 URL')
            .setRequired(true))


export default {
    data,
    async execute(interaction) {
        //replying to slash commands

        const url = interaction.options.getString('url');
        // console.log(url)
        
        // 토큰이 무효화되기 전에 3초 동안 상호 작용에 응답할 수 있습니다.
        await interaction.deferReply();

        const answer = await notion.getDBSchema();

        const result = await ogScraper(url);

        if(result.success){
            console.log(result)
            const embed = new MessageEmbed()
                .setColor('#EFFF00')
                .setTitle(answer.title[0].plain_text)
                .setURL(answer.url)
                .addFields(
                    { name: 'Definition', value: answer.created_time },
                );
            await interaction.editReply({ embeds: [embed] });
        } else {
            // 실패 처리
            console.error(result)
            
            const embed = new MessageEmbed()
                .setColor('#FF0000')
                .setTitle(error)
            await interaction.editReply({ embeds: [embed] });
        }
        
        return url
    },

};

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.