Skip to content

Commit

Permalink
Merge branch 'SinisterRectus:master' into 2.x-full-http-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RiskoZoSlovenska authored Dec 7, 2023
2 parents 39cf5c3 + 82cd6b5 commit 743205b
Show file tree
Hide file tree
Showing 38 changed files with 897 additions and 241 deletions.
108 changes: 102 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,108 @@
# Changelog

## 2.12.0
- Added support for stickers (@Ta-noshii)
- Added `Sticker` class
- Added `Client:getSticker`
- Added `Guild:getSticker`
- Added `Guild:createSticker`
- Added `Guild.stickers`
- Added `Message.sticker`
- Added `Message.stickers`
- Added support for unique and global usernames
- Added support for the raw `embeds` field in `Message:update`
- Fixed a bug in `Member:getPermissions`
- Fixed a bug in `PermissionOverwrite:getObject`
- Fixed a bug in voice connection server discovery

## 2.11.2
- Fixes a crash when messages are received in voice channels

## 2.11.1
- Fixes missing direct message channels on message events

## 2.11.0
- Bumped the internal Discord API version to 8.
- Added support for gateway intents:
- Added `gatewayIntent` enumeration
- Added `gatewayIntents` client option
- Added `Client:getIntents` method
- Added `Client:setIntents` method
- Added `Client:enableIntents` method
- Added `Client:disableIntents` method
- Added `Client:enableAllIntents` method
- Added `Client:disableAllIntents` method
- Added support for permission precision greater than 31 bits
- Deprecated `Client:setGame`, use `Client:setActivity`
- Added support for `embeds` field in `TextChannel:send`
- Added `channelType` enumerations:
- `store`
- `newsThread`
- `publicThread`
- `privateThread`
- `stageVoice`
- `directory`
- `forum`
- Added `webhookType` enumeration:
- `application`
- Added `messageType` enumerations:
- `channelFollowAdd`
- `guildDiscoveryDisqualified`
- `guildDiscoveryRequalified`
- `guildDiscoveryInitialWarning`
- `guildDiscoveryFinalWarning`
- `threadCreated`
- `reply`
- `chatInputCommand`
- `threadStarterMessage`
- `guildInviteReminder`
- `contextMenuCommand`
- `autoModerationAction`
- `roleSubscriptionPurchase`
- Added `activityType` enumerations:
- `watching`
- `competing`
- Added `status` enumeration:
- `offline`
- Added `permission` enumerations:
- `viewGuildInsights`
- `useSlashCommands`
- `requestToSpeak`
- `manageEvents`
- `manageThreads`
- `usePublicThreads`
- `usePrivateThreads`
- Added `messageFlag` enumerations:
- `hasThread`
- `ephemeral`
- `loading`
- Added `actionType` enumerations:
- `stageInstanceCreate`
- `stageInstanceUpdate`
- `stageInstanceDelete`
- `stickerCreate`
- `stickerUpdate`
- `stickerDelete`
- `eventCreate`
- `eventUpdate`
- `eventDelete`
- `threadCreate`
- `threadUpdate`
- `threadDelete`
- `autoModRuleCreate`
- `autoModRuleUpdate`
- `autoModRuleDelete`
- `autoModMessageBlock`
- `autoModMessageFlag`
- `autoModUserTimeout`

## 2.10.0
- Adds support for member timeouts
- Adds `Member:timeoutFor`
- Adds `Member:timeoutUntil`
- Adds `Member:removeTimeout`
- Adds `Member.timedOut`
- Adds `Member.timedOutUntil`
- Added support for member timeouts
- Added `Member:timeoutFor`
- Added `Member:timeoutUntil`
- Added `Member:removeTimeout`
- Added `Member.timedOut`
- Added `Member.timedOutUntil`
- Fixes a bug in trying to sleep where `retry_after` is `nil` on 429.
- Fixes mention consistency in for edited reply messages

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2022 SinisterRectus
Copyright (c) 2016-2023 SinisterRectus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion examples/helpCommandExample.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local commands = {
}

client:on('ready', function()
p(string.format('Logged in as %s', client.user.username))
print(string.format('Logged in as %s', client.user.username))
end)

client:on("messageCreate", function(message)
Expand Down
47 changes: 38 additions & 9 deletions libs/client/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local http = require('coro-http')
local package = require('../../package.lua')
local Mutex = require('utils/Mutex')
local endpoints = require('endpoints')
local constants = require('constants')

local request = http.request
local f, gsub, byte = string.format, string.gsub, string.byte
Expand All @@ -13,8 +14,8 @@ local insert, concat = table.insert, table.concat
local sleep = timer.sleep
local running = coroutine.running

local BASE_URL = "https://discord.com/api/v7"

local API_VERSION = constants.API_VERSION
local BASE_URL = "https://discord.com/api/" .. 'v' .. API_VERSION
local JSON = 'application/json'
local PRECISION = 'millisecond'
local MULTIPART = 'multipart/form-data;boundary='
Expand Down Expand Up @@ -132,22 +133,25 @@ function API:request(method, endpoint, payload, query, files)
local url = BASE_URL .. endpoint

if query and next(query) then
url = {url}
local buf = {url}
for k, v in pairs(query) do
insert(url, #url == 1 and '?' or '&')
insert(url, urlencode(k))
insert(url, '=')
insert(url, urlencode(v))
insert(buf, #buf == 1 and '?' or '&')
insert(buf, urlencode(k))
insert(buf, '=')
insert(buf, urlencode(v))
end
url = concat(url)
url = concat(buf)
end

local req = {
{'User-Agent', USER_AGENT},
{'X-RateLimit-Precision', PRECISION},
{'Authorization', self._token},
}

if API_VERSION < 8 then
insert(req, {'X-RateLimit-Precision', PRECISION})
end

if payloadRequired[method] then
payload = payload and encode(payload) or '{}'
if files and next(files) then
Expand Down Expand Up @@ -396,6 +400,31 @@ function API:deleteGuildEmoji(guild_id, emoji_id) -- Emoji:delete
return self:request("DELETE", endpoint)
end

function API:createGuildSticker(guild_id, payload) -- Guild:createSticker
local endpoint = f(endpoints.GUILD_STICKERS, guild_id)
return self:request("POST", endpoint, payload, nil, {{ "sticker.png", payload.image}})
end

function API:getGuildStickers(guild_id) -- not exposed, use cache
local endpoint = f(endpoints.GUILD_STICKERS, guild_id)
return self:request("GET", endpoint)
end

function API:getGuildSticker(guild_id, sticker_id) -- Guild:getSticker
local endpoint = f(endpoints.GUILD_STICKER, guild_id, sticker_id)
return self:request("GET", endpoint)
end

function API:modifyGuildSticker(guild_id, sticker_id, payload) -- Sticker:_modify
local endpoint = f(endpoints.GUILD_STICKER, guild_id, sticker_id)
return self:request("PATCH", endpoint, payload)
end

function API:deleteGuildSticker(guild_id, sticker_id) -- Sticker:delete
local endpoint = f(endpoints.GUILD_STICKER, guild_id, sticker_id)
return self:request("DELETE", endpoint)
end

function API:createGuild(payload) -- Client:createGuild
local endpoint = endpoints.GUILDS
return self:request("POST", endpoint, payload)
Expand Down
Loading

0 comments on commit 743205b

Please sign in to comment.