Skip to content

Commit

Permalink
New fields/endpoints and remove boilerplates regarding multiparts
Browse files Browse the repository at this point in the history
  • Loading branch information
krisppurg committed Jul 31, 2024
1 parent d093a03 commit fd1ffec
Show file tree
Hide file tree
Showing 7 changed files with 396 additions and 441 deletions.
173 changes: 99 additions & 74 deletions dimscord/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ type
cfPinned = 1
cfRequireTag = 4
cfHideMediaDownloadOptions = 15
SkuFlags* = enum
sfAvailable = 2
sfGuildSubscription = 7
sfUserSubscription = 8

const
libName* = "Dimscord"
Expand Down Expand Up @@ -237,6 +241,9 @@ type
matSpectate = 2
matListen = 3
matJoinRequest = 5 # nice skip
MessageReferenceType* = enum
mrtDefault = 0
mrtForward = 1
ChannelType* = enum
ctGuildText = 0
ctDirect = 1
Expand Down Expand Up @@ -425,6 +432,10 @@ type
ApplicationIntegrationType* = enum
aitGuildInstall = 0
aitUserInstall = 1
InteractionContextType* = enum
ictGuild = 0
ictBotDm = 1
ictPrivateChannel = 2
InviteType* = enum
itGuild = 0
itGroupDm = 1
Expand Down Expand Up @@ -510,6 +521,11 @@ type
etUserGift,
etPremiumPurchase,
etApplicationSubscription
SkuType* = enum
stDurable = 2
stConsumable = 3
stSubscription = 5
stSubscriptionGroup = 6
DispatchEvent* = enum
Unknown
VoiceStateUpdate = "VOICE_STATE_UPDATE"
Expand Down Expand Up @@ -605,7 +621,8 @@ const
permSendMessagesInThreads,
permUsePublicThreads,
permUsePrivateThreads,
permSendVoiceMessages}
permSendVoiceMessages,
permUsePolls}
permAllVoice* = {permCreateInstantInvite,
permMentionEveryone,
permManageChannels,
Expand All @@ -628,7 +645,8 @@ const
permUseSoundboard,
permUseExternalSounds,
permStartEmbeddedActivities,
permSendVoiceMessages}
permSendVoiceMessages,
permUsePolls}
permAllStage* = {permCreateInstantInvite,
permUseExternalStickers,
permUseSlashCommands,
Expand Down Expand Up @@ -662,6 +680,7 @@ const
permManageExpressions,
permManageThreads,
permManageEvents,
permUseExternalApps,
permCreateEvents} + permAllChannel
permManageEmojis* = permManageExpressions # ;) no need to thank me

Expand Down Expand Up @@ -747,192 +766,192 @@ proc cdnGuildDiscoverySplash*(gid, splash: string; fmt = "png"): string =
# Rest Endpoints

proc endpointUsers*(uid = "@me"): string =
result = "users/" & uid
"users/" & uid

proc endpointUserChannels*(): string =
result = endpointUsers("@me") & "/channels"
endpointUsers("@me") & "/channels"

proc endpointVoiceRegions*(): string =
result = "voice/regions"
"voice/regions"

proc endpointUserGuilds*(gid=""): string =
result = endpointUsers("@me")&"/guilds"&(if gid != "": "/" & gid else: "")
endpointUsers("@me")&"/guilds"&(if gid != "": "/" & gid else: "")

proc endpointUserGuildMember*(gid: string): string =
result = endpointUserGuilds(gid) & "/member"
endpointUserGuilds(gid) & "/member"

proc endpointChannels*(cid = ""): string =
result = "channels"&(if cid != "": "/" & cid else: "")
"channels"&(if cid != "": "/" & cid else: "")

proc endpointStageInstances*(cid = ""): string =
result = "stage-instances" & (if cid != "": "/" & cid else: "")
"stage-instances" & (if cid != "": "/" & cid else: "")

proc endpointGuilds*(gid = ""): string =
result = "guilds" & (if gid != "": "/" & gid else: "")
"guilds" & (if gid != "": "/" & gid else: "")

proc endpointGuildStickers*(gid: string; sid=""): string =
result = endpointGuilds(gid)&"/stickers"&(if sid != "": "/"&sid else: "")
endpointGuilds(gid)&"/stickers"&(if sid != "": "/"&sid else: "")

proc endpointGuildPreview*(gid: string): string =
result = endpointGuilds(gid) & "/preview"
endpointGuilds(gid) & "/preview"

proc endpointGuildRegions*(gid: string): string =
result = endpointGuilds(gid) & "/regions"
endpointGuilds(gid) & "/regions"

proc endpointGuildMFA*(gid: string): string =
result = endpointGuilds(gid) & "/mfa"
endpointGuilds(gid) & "/mfa"

proc endpointGuildAuditLogs*(gid: string): string =
result = endpointGuilds(gid) & "/audit-logs"
endpointGuilds(gid) & "/audit-logs"

proc endpointGuildAutoModerationRules*(gid: string; rid = ""): string =
endpointGuilds(gid)&"/auto-moderation/rules"&(if rid!="":"/"&rid else:"")

proc endpointGuildMembers*(gid: string; mid = ""): string =
result = endpointGuilds(gid) & "/members" & (if mid != "":"/"&mid else: "")
endpointGuilds(gid) & "/members" & (if mid != "":"/"&mid else: "")

proc endpointGuildScheduledEvents*(gid: string; eid = ""): string =
result = endpointGuilds(gid)&"/scheduled-events"&(if eid!="":"/"&eid else:"")
endpointGuilds(gid)&"/scheduled-events"&(if eid!="":"/"&eid else:"")

proc endpointGuildScheduledEventUsers*(gid, eid: string): string =
result = endpointGuildScheduledEvents(gid, eid) & "/users"
endpointGuildScheduledEvents(gid, eid) & "/users"

proc endpointGuildMembersSearch*(gid: string): string =
result = endpointGuildMembers(gid) & "/search"
endpointGuildMembers(gid) & "/search"

proc endpointGuildMembersNick*(gid: string; mid = "@me"): string =
result = endpointGuildMembers(gid, mid) & "/nick"
endpointGuildMembers(gid, mid) & "/nick"

proc endpointGuildMembersRole*(gid, mid, rid: string): string =
result = endpointGuildMembers(gid, mid) & "/roles/" & rid
endpointGuildMembers(gid, mid) & "/roles/" & rid

proc endpointGuildIntegrations*(gid: string; iid = ""): string =
result = endpointGuilds(gid)&"/integrations"&(if iid!="":"/"&iid else:"")
endpointGuilds(gid)&"/integrations"&(if iid!="":"/"&iid else:"")

proc endpointGuildVoiceStatesUser*(gid, uid = "@me"): string =
result = endpointGuilds(gid) & "/voice-states/" & uid
endpointGuilds(gid) & "/voice-states/" & uid

proc endpointGuildWelcomeScreen*(gid: string): string =
result = endpointGuilds(gid) & "/welcome-screen"
endpointGuilds(gid) & "/welcome-screen"

proc endpointGuildIntegrationsSync*(gid, iid: string): string =
result = endpointGuildIntegrations(gid, iid) & "/sync"
endpointGuildIntegrations(gid, iid) & "/sync"

proc endpointGuildWidget*(gid: string): string =
result = endpointGuilds(gid) & "/widget"
endpointGuilds(gid) & "/widget"

proc endpointGuildEmojis*(gid: string; eid = ""): string =
result = endpointGuilds(gid)&"/emojis"&(if eid != "": "/" & eid else: "")
endpointGuilds(gid)&"/emojis"&(if eid != "": "/" & eid else: "")

proc endpointGuildRoles*(gid: string; rid = ""): string =
result = endpointGuilds(gid) & "/roles" & (if rid!="": "/" & rid else: "")
endpointGuilds(gid) & "/roles" & (if rid!="": "/" & rid else: "")

proc endpointGuildPrune*(gid: string): string =
result = endpointGuilds(gid) & "/prune"
endpointGuilds(gid) & "/prune"

proc endpointInvites*(code = ""): string =
result = "invites" & (if code != "": "/" & code else: "")
"invites" & (if code != "": "/" & code else: "")

proc endpointGuildInvites*(gid: string): string =
result = endpointGuilds(gid) & "/" & endpointInvites()
endpointGuilds(gid) & "/" & endpointInvites()

proc endpointGuildVanity*(gid: string): string =
result = endpointGuilds(gid) & "/vanity-url"
endpointGuilds(gid) & "/vanity-url"

proc endpointGuildOnboarding*(gid: string): string =
result = endpointGuilds(gid) & "/onboarding"
endpointGuilds(gid) & "/onboarding"

proc endpointGuildChannels*(gid: string; cid = ""): string =
result = endpointGuilds(gid) & "/channels" & (if cid != "":"/"&cid else:"")
endpointGuilds(gid) & "/channels" & (if cid != "":"/"&cid else:"")

proc endpointChannelOverwrites*(cid, oid: string): string =
result = endpointChannels(cid) & "/permissions/" & oid
endpointChannels(cid) & "/permissions/" & oid

proc endpointWebhooks*(wid: string): string =
result = "webhooks/" & wid
"webhooks/" & wid

proc endpointChannelWebhooks*(cid: string): string =
result = endpointChannels(cid) & "/webhooks"
endpointChannels(cid) & "/webhooks"

proc endpointGuildTemplates*(gid, tid = ""): string =
result = endpointGuilds(gid) & "/templates" & (if tid!="": "/"&tid else:"")
endpointGuilds(gid) & "/templates" & (if tid!="": "/"&tid else:"")

proc endpointGuildWebhooks*(gid: string): string =
result = endpointGuilds(gid) & "/webhooks"
endpointGuilds(gid) & "/webhooks"

proc endpointWebhookToken*(wid, tok: string): string =
result = endpointWebhooks(wid) & "/" & tok
endpointWebhooks(wid) & "/" & tok

proc endpointWebhookMessage*(wid, tok, mid: string): string =
result = endpointWebhookToken(wid, tok) & "/messages/" & mid
endpointWebhookToken(wid, tok) & "/messages/" & mid

proc endpointWebhookTokenSlack*(wid, tok: string): string =
result = endpointWebhookToken(wid, tok) & "/slack"
endpointWebhookToken(wid, tok) & "/slack"

proc endpointWebhookTokenGithub*(wid, tok: string): string =
result = endpointWebhookToken(wid, tok) & "/github"
endpointWebhookToken(wid, tok) & "/github"

proc endpointChannelMessages*(cid: string; mid = ""): string =
result = endpointChannels(cid) & "/messages"
if mid != "": result = result & "/" & mid
if mid != "": result &= "/" & mid

proc endpointChannelMessagesThreads*(cid, mid: string): string =
result = endpointChannelMessages(cid, mid) & "/threads"
endpointChannelMessages(cid, mid) & "/threads"

proc endpointChannelThreads*(cid: string): string =
result = endpointChannels(cid) & "/threads"
endpointChannels(cid) & "/threads"

proc endpointGuildThreads*(gid: string): string =
result = endpointGuilds(gid) & "/threads"
endpointGuilds(gid) & "/threads"

proc endpointGuildThreadsActive*(gid: string): string =
result = endpointGuildThreads(gid) & "/active"
endpointGuildThreads(gid) & "/active"

proc endpointChannelThreadsArchived*(cid, typ: string): string =
result = endpointChannelThreads(cid) & "/archived/" & typ
endpointChannelThreads(cid) & "/archived/" & typ

proc endpointChannelUsersThreadsArchived*(cid, typ: string): string =
result = endpointChannels(cid) & endpointUsers() & "/archived/" & typ
endpointChannels(cid) & "/" & endpointUsers() & "/archived/" & typ

proc endpointChannelThreadsMembers*(cid: string; uid = ""): string =
result = endpointChannels(cid) & "/thread-members"
if uid != "":
result = result & "/" & uid

proc endpointChannelPollsAnswer*(cid, mid, aid: string): string =
result = endpointChannels(cid) & "/polls/" & mid & "/answers/" & aid
endpointChannels(cid) & "/polls/" & mid & "/answers/" & aid

proc endpointChannelPollsExpire*(cid, mid: string): string =
result = endpointChannels(cid) & "/polls/" & mid & "/expire"
endpointChannels(cid) & "/polls/" & mid & "/expire"

proc endpointChannelMessagesCrosspost*(cid, mid: string): string =
result = endpointChannelMessages(cid, mid) & "/crosspost"
endpointChannelMessages(cid, mid) & "/crosspost"

proc endpointChannelInvites*(cid: string): string =
result = endpointChannels(cid) & "/invites"
endpointChannels(cid) & "/invites"

proc endpointChannelPermissions*(cid, oid: string): string =
result = endpointChannels(cid) & "/permissions/" & oid
endpointChannels(cid) & "/permissions/" & oid

proc endpointGuildBanBulk*(gid: string; uid = ""): string =
result = endpointGuilds(gid) & "/bulk-ban"
endpointGuilds(gid) & "/bulk-ban"

proc endpointGuildBans*(gid: string; uid = ""): string =
result = endpointGuilds(gid) & "/bans" & (if uid != "": "/" & uid else: "")
endpointGuilds(gid) & "/bans" & (if uid != "": "/" & uid else: "")

proc endpointBulkDeleteMessages*(cid: string): string =
result = endpointChannelMessages(cid) & "/bulk-delete"
endpointChannelMessages(cid) & "/bulk-delete"

proc endpointTriggerTyping*(cid: string): string =
result = endpointChannels(cid) & "/typing"
endpointChannels(cid) & "/typing"

proc endpointChannelPins*(cid: string; mid = ""): string =
result = endpointChannels(cid) & "/pins"
if mid != "":
result = result & "/" & mid

proc endpointGroupRecipient*(cid, rid: string): string =
result = endpointChannels(cid) & "/recipients/" & rid
endpointChannels(cid) & "/recipients/" & rid

proc endpointReactions*(cid, mid: string; e, uid = ""): string =
result = endpointChannels(cid) & "/messages/" & mid & "/reactions"
Expand All @@ -941,43 +960,49 @@ proc endpointReactions*(cid, mid: string; e, uid = ""): string =
if uid != "":
result = result & "/" & uid

proc endpointApplications*(aid="@me"): string =
result = "applications/"&aid
proc endpointApplications*(aid:string): string =
"applications/"&aid

proc endpointApplicationEmojis*(aid:string, eid=""): string =
endpointApplications(aid)&"/emojis"&(if eid!="":"/"&eid else:"")

proc endpointOAuth2Application*(): string =
result = "oauth2/applications/@me"
"oauth2/applications/@me"

proc endpointEntitlements*(aid: string; eid = ""): string =
result = "applications/"&aid&"/entitlements"&(if eid!="":"/"&eid else:"")
endpointApplications(aid)&"/entitlements"&(if eid!="":"/"&eid else:"")

proc endpointEntitlementConsume*(aid, eid: string): string =
result = endpointEntitlements(aid, eid) & "/consume"
endpointEntitlements(aid, eid) & "/consume"

proc endpointListSkus*(aid: string): string =
endpointApplications(aid) & "/skus"

proc endpointGlobalCommands*(aid: string; cid = ""): string =
result = "applications/" & aid & "/commands" & (if cid!="":"/"&cid else:"")
endpointApplications(aid)&"/commands"&(if cid!="":"/"&cid else:"")

proc endpointGuildCommands*(aid, gid: string; cid = ""): string =
result = "applications/" & aid & "/guilds/" & gid & "/commands"
result = endpointApplications(aid)&"/guilds/"&gid&"/commands"
if cid != "":
result &= "/" & cid

proc endpointGuildCommandPermission*(aid, gid: string; cid = ""): string =
result = endpointGuildCommands(aid, gid, cid) & "/permissions"
endpointGuildCommands(aid, gid, cid) & "/permissions"

proc endpointInteractionsCallback*(iid, it: string): string =
result = "interactions/" & iid & "/" & it & "/callback"
"interactions/" & iid & "/" & it & "/callback"

proc endpointApplicationRoleConnectionMetadata*(aid: string): string =
result = "/applications/"&aid&"/role-connections/metadata"
"applications/"&aid&"/role-connections/metadata"

proc endpointUserApplications*(aid: string): string =
result = endpointUsers()&"/applications"&(if aid != "": "/"&aid else: "")
endpointUsers()&"/applications"&(if aid != "": "/"&aid else: "")

proc endpointUserApplicationRoleConnection*(aid: string): string =
result = endpointUserApplicationRoleConnection(aid) & "/role-connection"
endpointUserApplicationRoleConnection(aid) & "/role-connection"

proc endpointStickers*(sid: string): string =
result = "stickers/"&sid
"stickers/"&sid

proc endpointStickerPacks*(): string =
result = "sticker-packs"
"sticker-packs"
Loading

0 comments on commit fd1ffec

Please sign in to comment.