Giter VIP home page Giter VIP logo

disc's Introduction

disc

light JavaScript wrapper around Discord API written on top of Deno

goals

  • provide a light wrapper around Discord API
  • abstract away the most general details of the API (e.g. WebSocket and authentication) and nothing more
  • have minimal and readable code

example

the following is a bot that replies to 'ping' DMs with a 'pong' and ๐Ÿ™‚ reaction

import std_sender from './rest_std.js'
import std_discorder from './sock_std.js'
import { new_dispatch_listener } from './sock_std.js'

const token = 'my bot token'

const sender = std_sender(`Bot ${token}`)
const bot = await std_discorder(token)(1 << 12)

const responder = new_dispatch_listener('MESSAGE_CREATE')(({ d: { content, channel_id, id } }) => {

	if (content === 'ping') {
		sender.create_message(channel_id)('pong')
		sender.create_reaction(channel_id)(id)('๐Ÿ™‚')
	}

})

await bot.listen(responder)

note: it would be nicer if the program Promise.raced SIGINT and called bot.kill() but idrk how to do that

TODO

  • handle gateway error codes
  • handle dropped connections

disc's People

Contributors

hywn avatar

Watchers

James Cloos avatar  avatar

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.