Code Monkey home page Code Monkey logo

discord.tcl's Introduction

discord.tcl 0.7.0

Discord API library writtten in Tcl. Tested with Tcl 8.6. Supports Discord Gateway API version 6.

Status/TODO

  • HEARTBEAT and HEARTBEAT_ACK response not implemented. Currently only taking the heartbeat interval from the HELLO payload and ignoring HEARTBEAT and HEARTBEAT_ACK altogether. The bot still runs fine because it will attempt to reconnect on the next failed HEARTBEAT sent.
  • Need to do a full review on Rate Limits.
  • Basic sharding is currently implemented. It ain't broke per se, so not fixing it for now. Also includes this.
  • User Status not implemented
  • Request Guild Members Gateway opcode not implemented
  • Most voice-related stuff not implemented; only the basic ones are implemented

Not sure yet what to do with those from previous owner todo list:

  • Test cases for "pure" procs, send HTTP requests to test both HTTP responses and Gateway events.
  • Find out why zlib inflate fails.
  • Use "return -code error -errorcode ..." when possible for standardized exception handling. See ThrowError in websocket from tcllib for an example.
  • Use the try command.
  • Create a tcltest custommatch to check -errorcode.
  • Test HTTP API and Gateway API with local server.

Libraries

Usage

Check out MarshtompBot for a bot written with this library.

DIY: For when you feel like writing your own discord.tcl.

package require discord

${discord::log}::setlevel info

proc messageCreate {event data} {
    set timestamp [dict get $data timestamp]
    set username [dict get $data author username]
    set discriminator [dict get $data author discriminator]
    set content [dict get $data content]
    puts "$timestamp ${username}#${discriminator}: $content"
}

proc registerCallbacks { sock } {
    discord::gateway setCallback $sock MESSAGE_CREATE messageCreate
}

set token "your token here"
set sock [discord::gateway connect $token registerCallbacks]

vwait forever

# Cleanup
discord::gateway disconnect $sock

Example output

[Wed Nov 23 18:39:19 EST 2016] [discord::gateway] [notice] 'GetGateway: No cached Gateway API URL for https://discordapp.com/api'
[Wed Nov 23 18:39:19 EST 2016] [discord::gateway] [info] 'GetGateway: Retrieving Gateway API URL from https://discordapp.com/api/v6/gateway'
[Wed Nov 23 18:39:19 EST 2016] [discord::gateway] [info] 'GetGateway: Cached Gateway API URL for https://discordapp.com/api: wss://gateway.discord.gg'
[Wed Nov 23 18:39:19 EST 2016] [discord::gateway] [notice] 'connect: wss://gateway.discord.gg/?v=6&encoding=json'
[Wed Nov 23 18:39:19 EST 2016] [discord::gateway] [notice] 'Handler: Connected.'
2016-11-23T23:39:25.953000+00:00 [redacted]#0000: Don't ever reduce achievements. Add more!!

Testing

Sourcing or executing a .test file found under tests/ will test related namespace procedures.

E.g.

tclsh tests/gateway.test

The file local_server.tcl contains procedures for setting up a local HTTP(S) server. The main proc is LocalServerSetupAll.

Links

discord.tcl's People

Contributors

qwename avatar unknown008 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

maxsignal

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.