Coder Social home page Coder Social logo

discord.jl's Introduction

Welcome! πŸ‘‹

I am glad you landed in my profile, let me tell you real quick who I am and what I do.

  • πŸ˜„ Juan 'Xh4H' JimΓ©nez, 25
  • πŸ” Application Security Engineer at fortris
  • πŸ”­ Former Information Security Manager at adidas
  • 🌎 Cybersecurity researcher & CTF Player
  • 🌱 Always open to learn new technologies.
  • πŸ“« How to reach me: Twitter

Have a good day πŸ˜ƒ

discord.jl's People

Contributors

christopher-dg avatar csskroubledev avatar dave7895 avatar davidloftus avatar flourish38 avatar mrjuicylemon avatar pythonlinks avatar rmsrosa avatar splingush avatar theonlyartz avatar tk3369 avatar totalverb avatar vexatos avatar wookay avatar xh4h avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

discord.jl's Issues

Real documentation, guides and examples

Autodocs is alright but we'll need real written docs when we want to release anything.

Update: This is basically just pending REST API functions being added.

Release checklist (for real this time)

  • Update @command to be friendlier
  • Deal with the OAuth situation: Either allow non-bot tokens and re-add some oauth-only endpoints or delete any remaining ones (are there any?)
  • Retry failed connection in reconnect
  • Examples up to date
  • Tutorial up to date and maybe different/better (notebook would be a nice format)
  • Some more tests for handlers and commands, if I don't feel too lazy

Error: Parsing failed

Error with the basic example:

Error: Parsing failed time = 2019-10-13T20:40:02.979 conn = 1 T = GuildCreate exception = MethodError: no method matching datetime(::Nothing) Closest candidates are: datetime(::Dates.DateTime) at /home/devlcp/.julia/packages/Discord/td6Xq/src/types/types.jl:21 datetime(::Int64) at /home/devlcp/.julia/packages/Discord/td6Xq/src/types/types.jl:19 datetime(::AbstractString) at /home/devlcp/.julia/packages/Discord/td6Xq/src/types/types.jl:20 Stacktrace: [1] #(globalref #<julia: Discord> Member)#279(::Base.Iterators.Pairs{Symbol,Any,NTuple{8,Symbol},NamedTuple{(:nick, :user, :premium_since, :joined_at, :roles, :deaf, :hoisted_role, :mute),Tuple{String,Dict{Symbol,Any},Nothing,String,Array{Any,1},Bool,Nothing,Bool}}}, ::Type{Member}) at /home/devlcp/.julia/packages/Discord/td6Xq/src/types/types.jl:99 [2] (::getfield(Core, Symbol("#kw#Type")))(::NamedTuple{(:nick, :user, :premium_since, :joined_at, :roles, :deaf, :hoisted_role, :mute),Tuple{String,Dict{Symbol,Any},Nothing,String,Array{Any,1},Bool,Nothing,Bool}}, ::Type{Member}) at ./none:0 [3] Member(::Dict{Symbol,Any}) at /home/devlcp/.julia/packages/Discord/td6Xq/src/types/types.jl:100 [4] _broadcast_getindex_evalf at ./broadcast.jl:625 [inlined] [5] _broadcast_getindex at ./broadcast.jl:598 [inlined] [6] getindex at ./broadcast.jl:558 [inlined] [7] macro expansion at ./broadcast.jl:888 [inlined] [8] macro expansion at ./simdloop.jl:77 [inlined] [9] copyto! at ./broadcast.jl:887 [inlined] [10] copyto! at ./broadcast.jl:842 [inlined] [11] copy at ./broadcast.jl:818 [inlined] [12] materialize at ./broadcast.jl:798 [inlined] [13] #(globalref #<julia: Discord> Guild)#340(::Base.Iterators.Pairs{Symbol,Any,NTuple{33,Symbol},NamedTuple{(:presences, :preferred_locale, :channels, :description, :premium_tier, :region, :members, :afk_channel_id, :owner_id, :system_channel_flags, :voice_states, :banner, :splash, :system_channel_id, :default_message_notifications, :member_count, :explicit_content_filter, :application_id, :large, :features, :name, :icon, :joined_at, :unavailable, :lazy, :mfa_level, :vanity_url_code, :id, :emojis, :roles, :verification_level, :premium_subscription_count, :afk_timeout),Tuple{Array{Any,1},String,Array{Any,1},Nothing,Int64,String,Array{Any,1},String,String,Int64,Array{Any,1},Nothing,Nothing,String,Int64,Int64,Int64,Nothing,Bool,Array{Any,1},String,String,String,Bool,Bool,Int64,Nothing,String,Array{Any,1},Array{Any,1},Int64,Int64,Int64}}}, ::Type{Guild}) at /home/devlcp/.julia/packages/Discord/td6Xq/src/types/types.jl:99 [14] Type at ./none:0 [inlined] [15] #GuildCreate#433 at /home/devlcp/.julia/packages/Discord/td6Xq/src/gateway/events/guilds.jl:23 [inlined] [16] (::getfield(Core, Symbol("#kw#Type")))(::NamedTuple{(:presences, :preferred_locale, :channels, :description, :premium_tier, :region, :members, :afk_channel_id, :owner_id, :system_channel_flags, :voice_states, :banner, :splash, :system_channel_id, :default_message_notifications, :member_count, :explicit_content_filter, :application_id, :large, :features, :name, :icon, :joined_at, :unavailable, :lazy, :mfa_level, :vanity_url_code, :id, :emojis, :roles, :verification_level, :premium_subscription_count, :afk_timeout),Tuple{Array{Any,1},String,Array{Any,1},Nothing,Int64,String,Array{Any,1},String,String,Int64,Array{Any,1},Nothing,Nothing,String,Int64,Int64,Int64,Nothing,Bool,Array{Any,1},String,String,String,Bool,Bool,Int64,Nothing,String,Array{Any,1},Array{Any,1},Int64,Int64,Int64}}, ::Type{GuildCreate}) at ./none:0 [17] GuildCreate(::Dict{Symbol,Any}) at /home/devlcp/.julia/packages/Discord/td6Xq/src/gateway/events/guilds.jl:24 [18] tryparse(::Client, ::Type, ::Dict{Symbol,Any}) at /home/devlcp/.julia/packages/Discord/td6Xq/src/client/client.jl:470 [19] dispatch(::Client, ::Dict{Symbol,Any}) at /home/devlcp/.julia/packages/Discord/td6Xq/src/gateway/gateway.jl:313 [20] (::getfield(Discord, Symbol("##724#725")){Client,Dict{Symbol,Any}})() at ./task.jl:268 @ Discord ~/.julia/packages/Discord/td6Xq/src/client/client.jl:473

  • Julia Version 1.2.0
  • Commit c6da87ff4b (2019-08-20 00:03 UTC)
  • Platform Info:
    OS: Linux (x86_64-pc-linux-gnu)
    CPU: Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
    WORD_SIZE: 64
    LIBM: libopenlibm
    LLVM: libLLVM-6.0.1 (ORCJIT, sandybridge)
  • [fcbf000d] Discord v0.1.0 #master (https://github.com/Xh4H/Discord.jl)

Deleting channels triggers a MethodError warning

I happened to find the following warning message when deleting a channel.

β”Œ Warning: Handler function threw an exception
β”‚   time = 2021-07-25T16:49:07.656
β”‚   conn = 1
β”‚   event = ChannelDelete
β”‚   handler = :DJL_DEFAULT
β”‚   exception =
β”‚    MethodError: no method matching delete!(::Guild, ::UInt64)
β”‚    Closest candidates are:
β”‚      delete!(::IdDict{K, V} where V, ::Any) where K at iddict.jl:115
β”‚      delete!(::Base.IdSet, ::Any) at idset.jl:23
β”‚      delete!(::BitSet, ::Integer) at bitset.jl:298
β”‚      ...
β”‚    Stacktrace:
β”‚     [1] handler(c::Client, e::ChannelDelete)
β”‚       @ Discord.Defaults ~/.julia/packages/Discord/3wJXG/src/Defaults.jl:63
β”‚     [2] handler_cached(c::Client, e::ChannelDelete)
β”‚       @ Discord.Defaults ~/.julia/packages/Discord/3wJXG/src/Defaults.jl:189
β”‚     [3] dispatch(c::Client, data::Dict{Symbol, Any})
β”‚       @ Discord ~/.julia/packages/Discord/3wJXG/src/gateway/gateway.jl:338
β”‚     [4] (::Discord.var"#706#707"{Client, Dict{Symbol, Any}})()
β”‚       @ Discord ./task.jl:411
β”” @ Discord ~/.julia/packages/Discord/3wJXG/src/gateway/gateway.jl:342

My versions:

julia> versioninfo()
Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 

(MeetBot) pkg> st
     Project MeetBot v0.1.0
      Status `~/.julia/dev/MeetBot/Project.toml`
  [fcbf000d] Discord v0.1.0 `https://github.com/Xh4H/Discord.jl#master`
  [ade2ca70] Dates

@enum ActivityFlags not exported in Julia 1.4

Version Info:

Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)

The error:

client = Client("MYBOTID";
                 presence=(game=(name="$(curTime)", type=AT_STREAMING ),))
ERROR: LoadError: UndefVarError: AT_STREAMING not defined

Maybe something to do with: @boilerplate ActivityFlags :export :lower ?

Release checklist

As of right now we tick all the boxes for inclusion in the DAPI server, which also indicates that we're pretty close to being able to put out a first release πŸŽ‰.

Some things which still need to be done:

  • Fix #9
  • Audit log change keys (#1)
  • Use the cache for REST stuff, but also offer a means of not using the cache (probably a Client field)
  • Examples for all major feature sets (CRUD API, REST API, event handling, commands, sharding) (#2)
  • Summary docs ("Why Julia/Discord.jl?", CRUD API overview) (#2), add some of this to README
  • Tests: Anything not network-dependent should be tested
  • Take care of some TODOs (this is vague, not all of them are serious problems)
  • Multipart form-data: Handle file uploading.
  • Smarter caching: Things like guilds shouldn't be deleted, but messages, presences etc. should.
  • HTTP.jl #348 merged + released
  • REST wrappers exported

Things which would be nice to have but aren't necessary:

  • Detailed tutorials for a few common bot use cases, which use techniques from examples above (#2) (the current example should be reworked but for now we don't need much more)
  • Command framework (add_command! is not terrible for now)
  • "Helper" functions to chain common ops (update: I think we can basically wait for feedback on this and implement things as they're desired)

We could find a lot of good ideas by looking around at other libraries, the JS and Python ones are probably a good place to start since they have the most users.

First Comments

If you have a general question, please ask on Discord for a faster response.

If you've run into a bug, please supply the following information:

  • Julia and platform version information (with versioninfo())
  • Package version information (with ]status)
  • A MWE which demonstrates the bug

Please do NOT include a bot token in your issue report.

Creating Response always fails by unavailable Guild :/

 Error: Creating response failed
β”‚   time = 2021-07-19T02:51:01.641
β”‚   exception =
β”‚    type UnavailableGuild has no field djl_channels
β”‚    Stacktrace:
β”‚     [1] getproperty(x::Discord.UnavailableGuild, f::Symbol)
β”‚       @ Base .\Base.jl:33
β”‚     [2] put!(s::Discord.State, ch::Discord.DiscordChannel; kwargs::Base.Iterators.Pairs{Symbol, Union{Nothing, UInt64}, NTuple{4, Symbol}, NamedTuple{(:channel, :guild, :message, :user), Tuple{UInt64, Nothing, Nothing, Nothing}}})      
β”‚       @ Discord C:\Users\Aaron\.julia\packages\Discord\S9xlN\src\client\state.jl:256
β”‚     [3] macro expansion
β”‚       @ C:\Users\Aaron\.julia\packages\Setfield\XM37G\src\sugar.jl:182 [inlined]
β”‚     [4] (::Discord.var"#714#716"{Discord.DiscordChannel, Vector{Any}, Discord.Client, Symbol, String, Distributed.Future})()
β”‚       @ Discord C:\Users\Aaron\.julia\packages\Discord\S9xlN\src\rest\rest.jl:197
β”‚     [5] macro expansion
β”‚       @ C:\Users\Aaron\.julia\packages\Discord\S9xlN\src\client\limiter.jl:46 [inlined]
β”‚     [6] (::Discord.var"#574#575"{String, Discord.Limiter, Discord.JobQueue})()
β”‚       @ Discord .\task.jl:411
β”” @ Discord C:\Users\Aaron\.julia\packages\Discord\S9xlN\src\rest\rest.jl:204

Package rename

Avoid using Julia in your package name.
It is usually clear from context and to your users that the package is a Julia package.
Having Julia in the name can imply that the package is connected to, or endorsed by, contributors to the Julia language itself.

Source

I think the second line applies to our package.
Additionally there's a very consistent convention of a ".jl" name suffix across basically the whole language ecosystem (for example), and "Julicord.jl" doesn't really sound nice, it repeats too much IMO.

My vote is still for Discord.jl! It's super obvious.

But someone already made a package called Discord.jl!

That package was never completed nor registered, and I have never heard about anybody using it. Its repository doesn't even exist anymore. So nobody is going to think we are the same people who wrote that, or that we stole their idea.
This name is also better for search results and people googling stuff like "julia discord".

split_message splits the message in the middle of a word

MWE:

julia> split_message(string(repeat('.', 1998), " foo"))[2]
"oo"

julia> split_message("abc def ghi jkl", chunk_limit = 5)
3-element Vector{String}:
 "abc d"
 "ef gh"
 "i jkl"
  • Julia and platform version information (with versioninfo()):
julia> versioninfo()
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.6.0)
  CPU: Intel(R) Core(TM) m5-6Y54 CPU @ 1.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:

* Package version information (with `]status`):
```julia
(Discord) pkg> st
     Project Discord v0.1.0
      Status `~/Documents/git_repositories/julia/Discord/Project.toml`
  [cd3eb016] HTTP v0.9.5
  [682c06a0] JSON v0.21.1
  [8ac3fa9e] LRUCache v1.2.0
  [102dff8d] OpenTrick v0.2.1
  [efcf1570] Setfield v0.7.0
  [37f0c46e] TimeToLive v0.3.0
  [ade2ca70] Dates
  [8ba89e20] Distributed
  [b77e0a4c] InteractiveUtils

I don't remember whether this was there already or not (there was no test for this), before my PR to split_message. Anyways, I am working on a fix to this.

I am also thinking about adding an option parameter if it is desirable to break only on newlines \n.

Slash Commands Not in Permission Overwrite

So pretty much, I was making a nuke command, and I noticed that the slash command permission after the channel nuke was to the default.

function nuke(ctx::Client, message::Message)
    if message.author.id == 337711669306458114
        channel = fetch(get_channel(ctx, message.channel_id)).val

        delete(ctx, channel)

        new_channel = fetch(create_guild_channel(ctx, message.guild_id;
            name=channel.name,
            type=channel.type,
            topic=channel.topic,
            rate_limit_per_user=channel.rate_limit_per_user,
            position=channel.position,
            permission_overwrites=channel.permission_overwrites,
            parent_id=channel.parent_id,
            nsfw=channel.nsfw
        )).val

        create_message(ctx, new_channel.id; content="Nuked!")
    end
end

It works, but it just doesn't keep the original slash command permission

Before Nuke:
image
After Nuke:
image

get_guild_channels never returns

Calling get_guild_channels seems to never return a value in its future. It hangs forever.

Version information:

Julia Version 1.0.1
Commit 0d713926f8 (2018-09-29 19:05 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E3-1231 v3 @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

Project Discord v0.1.0
    Status `~/Development/Discord.jl/Project.toml`
  [cd3eb016] HTTP v0.7.0 #master (https://github.com/JuliaWeb/HTTP.jl.git)
  [682c06a0] JSON v0.19.0
  [102dff8d] OpenTrick v0.2.1
  [efcf1570] Setfield v0.3.0
  [37f0c46e] TimeToLive v0.1.4
  [ade2ca70] Dates 
  [8ba89e20] Distributed 

MWE (also confirmed using REST API get_guild_channels):

using Discord

token = "123456"
gid = 123456

c = Client(token)
open(c)
guild = fetchval(retrieve(c, Guild, gid))
println("Gathering Channels")
channels = fetchval(retrieve(c, DiscordChannel, guild))
println(channels)
close(c)

40 Second Startup Times

If you've run into a bug, please supply the following information:

  • Julia and platform version information (with versioninfo())
    versioninfo()
    Julia Version 1.4.2
    Commit 44fa15b150* (2020-05-23 18:35 UTC)
    Platform Info:
    OS: Linux (x86_64-pc-linux-gnu)
    CPU: AMD EPYC 7601 32-Core Processor
    WORD_SIZE: 64
    LIBM: libopenlibm
    LLVM: libLLVM-8.0.1 (ORCJIT, znver1)

  • Package version information (with ]status)
    [deps]
    Debugger = "31a5f54b-26ea-5ae9-a837-f05ce5417438"
    Discord = "fcbf000d-02fd-53f1-af91-d952191673d3"

HERE IS MY FILE
`
using Discord

function on_message_ready(client::Client, event::Discord.Ready)
println("You are Connected to the server. ")
end
client = Client("DISCORD TOKEN GOES HERE")
open(client)
add_handler!(client, Ready, on_message_ready; tag=:ready)
wait(client)
`

MbedTLS compatibility

TLDR: HTTP requests don't work properly on MbedTLS 0.6.3, and the gateway connection doesn't work properly on newer versions.

With code like this:

julia> c = Client("token"); ch = retrieve(DiscordChannel, c, 1234567890);
julia> fs = map(i -> create(Message, c, ch; content=i), 1:50);

It's somewhat common to see a deadlock where one request grabs the rate limiter bucket lock and makes the request, then hangs, which holds up all the other requests. I've seen the requests go though after a few minutes of waiting which is weird (and I've confirmed that Discord's rate limiting has nothing to do with it).
The really weird bit is that the request actually does reach Discord, i.e. a message is created, but the request still doesn't return. So I'm inclined to think that this could be a bug with HTTP.jl.

Incosistent Int typing

A user reported a bug in the Discord server.

Those variables, parameters, etc. whose type is Int may either be UInt32 or UInt64 based on the system architecture.

This can, and does lead into a crash in 32-bit systems for those values returned by Discord that are supposed to be handled as UInt64.

Solution?: Specify UInt64 directly.

Stable docs not available?

The stable docs link in the README.md seems to be wrong, it gives a 404 for me. Dev docs work though.

Unable to reconnect/re`open` client

I have been talking with @tk3369 about my bot always losing a connection to Discord at some point and I implemented his error handling fix in #32, which alleviated the situation. However it always fails to reconnect at some point.

We discussed the idea of turning on all debug messages to catch what it is doing when it calls

open(c; resume=resume)
and after 3 days of uptime I managed to capture some results: botdebugoutput.txt

The output is rather verbose, so I should annotate what is going on:

  • Ignore the beginning errors, those usually pop up because the script does not run fast enough due to precompilation, but the bot works fine despite all of that. (Still, maybe I could be mistaken and perhaps it is somehow affecting this whole issue.)
  • Ignore most of the Info messages except for the ones with the message Going to reopen and Reopened. Those are @info tags sandwiching the aforementioned open(c; resume=resume) line.
  • These are all the lines where it reopens and successfully reopens. Perhaps something relevant or of interest is that a tasks_pending list starts to get larger and larger over time.
176-228, 254-299, 336-393, 418-475, 510-567, 602-659, 705-748, 783-843, 894-954, 983-1030, 1077-1140, 1166-1214, 1245-1311, 1358-1424, 1458-1504, 1535-1604, 1632-1701, 1726-1795, 1820-1889, 1932-1979, 2020-2092, 2131-2203, 2242-2314, 2348-2420, 2454-2502, 2534-2609
  • The last time it reopens and hangs there (bot fails to respond anymore, client object says Discord.Client(shard=1/1, api=6, not logged in) and does not switch to logged in) is at L2642 to the end of the file.

Sorry for the large text file, I would attempt to assist further but I'm really out of my element at the moment. I hope this somehow helps!

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.