krisppurg / dimscord

A Discord Bot & REST Library for Nim.
https://krisppurg.github.io/dimscord/
MIT License
222 stars 20 forks source link

[Feature Request] Change endpoint base url #27

Closed Technisha closed 4 years ago

Technisha commented 4 years ago

I think a way to change the base URL for endpoints would be a good idea. Because there's things like https://gitlab.com/litecord/litecord which allow people to test their bots out on private discord instances. I think it'd be a neat feature.

You'd also want to check if an endpoint was actually implemented, eg if some thing didn't implement roles (which is /guilds/{guild.id}/members/{user.id}/roles/{role.id}, if i recall correctly), a 404 would be thrown, but you should throw a proper error instead (eg ApiUnimplementedError or something).

Also, if you have this, you also need a way to change the gateway uri (default is wss://discord.gg), because obviously the IDENTIFY payload sent to it would do nothing if you're using another api lol; that's establishing the connection with discord but doing the actions with another api

ktiy commented 4 years ago

~~https://krisppurg.github.io/dimscord/dimscord/objects.html#Shard think you can change the gateway URL?~~

you can change base URL and stuff in constants.nim

Technisha commented 4 years ago

What do you mean?

ktiy commented 4 years ago

think you can change the gateway URL per shard,

the base URL and stuff are just in constants.nim; it would be pretty easy to change these to test on private discord instances and whatnot

Technisha commented 4 years ago

Why would you need to change it per shard? And i was thinking it should be a feature so it's easily doable :P

You'd probably have to initialise the variables per each client this way if this becomes a thing (Probably not)

Technisha commented 4 years ago

It might be out of the scope for this lib, because it's in Nim, no idea though

Technisha commented 4 years ago

I mean that as in, how the lib is structured-

ktiy commented 4 years ago

it is easily doable, you can just edit your constants.nim

Technisha commented 4 years ago

Alright, was just curious if this could be added and made changeable-

Like apiRoute = r"http://string/for/route"

ktiy commented 4 years ago

well.. can you not do that already? constants.nim again,

cdnBase* = "https://cdn.discordapp.com/"
restBase* = "https://discord.com/api/"

im sure you could just... change those

ire4ever1190 commented 4 years ago

it could be made definable though couldn't it?

restBase* {.strdefine.} = "https://discord.com/api/"

so that way it could easily be redefinable like -d:restBase="https://customurl"?

ktiy commented 4 years ago

+1 on @ire4ever1190's suggestion

codic12 commented 4 years ago

You'd also want to check if an endpoint was actually implemented, eg if whatever API Implementation you were using didn't implement, say, adding roles (which is a PUT to /guilds/{guild.id}/members/{user.id}/roles/{role.id}, if i recall correctly), a 404 would be thrown, but you should throw a proper error instead (eg ApiUnimplementedError or something).

Also, if you have this, you would also want a way to change the gateway uri (default is wss://discord.gg), because obviously the IDENTIFY payload sent to it would do nothing if you're using another api lol; that's establishing the connection with discord but doing the actions with another api

krisppurg commented 4 years ago

Like I said in the Discord API Server, Dimscord only interacts with the official Discord API not just some custom api thing or whatever.

If you do want to change base url you can just modify the code, like how hobble suggested.