Coder Social home page Coder Social logo

brokendiscord's Introduction

BrokenDiscord Build Status NuGet

BrokenDiscord is a Discord API Library written in F#. The main purpose is to provide a functional alternative that is both clean and easy to use.

Installation

The library is available through NuGet.

Usage

The classic ping pong example can be found here. More examples will be added in the future.

First you want to import the following modules

    open BrokenDiscord.Client
    open BrokenDiscord.Types
    open BrokenDiscord.Events
    open Hopac

You can then construct a new Discord client which can be used to access both the Discord web API and set callbacks for Discord events.

let client = new Client("DISCORD_BOT_TOKEN_HERE")

In the main function of the program you can add event handlers to the client and then call the start function to start the client which will then connect to the Discord gateway using a websocket.

    // Add functionality for reacting to events here
    let handleEvents = function
        | Ready args -> ()
        | MessageCreate args -> ()
        | TypingStart args -> ()
        | _ -> ()

    [<EntryPoint>]
    let main argv =
        client.Events |> Event.add handleEvents
        client.start()
        Console.ReadLine() |> ignore 
        0

Contributors

brokendiscord's People

Contributors

brokenprogrammer avatar kavorite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

brokendiscord's Issues

EditMessage returns HTTP 400 response

Used a small testing bot but its unable to edit its own messages. I'm putting this on hold for now or incase someone else wants to attempt to fix the issue.

According to the discord api:

400 (BAD REQUEST) | The request was improperly formatted, or the server couldn't understand it

The following request uri was used:

https://discordapp.com/api/channels/481177024707428372/messages/487528139518377995

Which doesn't seem to be a problem.

And the json body sent as a test looks like the following:

{"content":"Test Message","embed":null}

Together with the alternative:

{"content":"Test Message"}

Documentation for Edit Message is available here: https://discordapp.com/developers/docs/resources/channel#edit-message

This issue seems to also affect the following (The ones I know of):

  • ModifyCurrentUserNick

System.MissingMethodException: Method not found: 'Hopac.Job`1...

F# interactive window attempt:

Reflection shows the following are loaded:

mscorlib - "4.0.0.0" - C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll
Hopac.Core - 0.3.23.0
Hopac - 0.3.23.0
FSharp.Core - 4.5.0.0
FSharp.Control.AsyncSeq - 2.0.21.0
BrokenDiscord - 1.0.0.0
https://gist.github.com/ImaginaryDevelopment/b99cd55a70fd0b4faba09bf06d34f3ab

fails with

stdin(230,25): error FS0074: The type referenced through 'FSharp.Control.AsyncSeq1' is defined in an assembly that is not referenced. You must add a reference to assembly 'FSharp.Control.AsyncSeq'`

on the line if m.content = "!ping" then
gist at: https://gist.github.com/ImaginaryDevelopment/b99cd55a70fd0b4faba09bf06d34f3ab

LinqPad attempt:

LINQPad 5 Premium 5.31.00 when trying to !ping in chat for the first time it says:

Listening for pings...
WARNING: You are using single-threaded workstation garbage collection, which means that parallel programs cannot scale.  Please configure your program to use server garbage collection.
Unhandled exception: System.MissingMethodException: Method not found: 'Hopac.Job`1<Microsoft.FSharp.Core.FSharpResult`2<Message,ApiError>> Client.CreateMessage(UInt64, T)'.
   at <StartupCode$query_iqzixz>[email protected](Unit unitVar)
   at Hopac.Core.JobDelay`1.DoJob(Worker& wr, Cont`1 xK)
   at Hopac.Core.Worker.RunOnThisThread[T](Scheduler sr, Job`1 tJ, Cont`1 tK)
No other causes.

Reflection shows the following assemblies loaded if I ask it to check right before client.start()

Newtonsoft.Json - "11.0.0.0"
FSharp.Core - 4.5.0.0
mscorlib - 4.0.0.0
LINQPad - 1.0.0.0
BrokenDiscord - 1.0.0.0
Hopac - "0.3.23.0"
Hopac.Core - 0.3.23.0

Full script code at:

https://github.com/ImaginaryDevelopment/LinqPad/blob/master/LINQPad%20Queries/WIP/DiscordBot.linq

Verify that single Snowflake cases gets parsed from JSON correctly.

The snowflake type which is an alias for uint64 might not get properly get parsed from JSON for the GuildIntegrationsUpdate event. I previously got a null pointer here and before when I was using the .[] operator to access the json data it wouldn't parse correctly.

Serialization: use a camel-case ContractResolver or similar

Currently the diverging naming conventions of our frontend code and the API payloads is bridged by littering Types.fs with [<JsonProperty>] pragmas. This approach is error-prone and fails to leverage the full available API surface of NewtonSoft. One future aim should be to refactor the serialization pipeline in Json.fs to reduce this error by automatically translating the most common mapping, i.e. messageId to message_id, as well as kind to type as we have been to avoid keyword conflicts, automatically.

Update Readme

The readme should contain :

  • More examples
  • Help for new contributors
  • License
  • Purpose and general information?

Add ISO8601 Timestamp

Figure out how to represent an ISO8601 Timestamp then update to be using that Timestamp in Types.fs

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.