Skip to content

Commit

Permalink
Some more v8 preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
SinisterRectus committed Jan 16, 2023
1 parent eb05579 commit 141c777
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
7 changes: 4 additions & 3 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 VERSION = 7
local BASE_URL = "https://discord.com/api/" .. 'v' .. VERSION
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 @@ -147,7 +148,7 @@ function API:request(method, endpoint, payload, query, files)
{'Authorization', self._token},
}

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

Expand Down
9 changes: 7 additions & 2 deletions libs/client/Client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ local time, difftime = os.time, os.difftime
local format = string.format

local CACHE_AGE = constants.CACHE_AGE
local GATEWAY_VERSION = constants.GATEWAY_VERSION
local API_VERSION = constants.API_VERSION

-- do not change these options here
-- pass a custom table on client initialization instead
Expand Down Expand Up @@ -153,6 +153,11 @@ local function run(self, token)
local users = self._users
local options = self._options

if options.cacheAllMembers and bit.band(self._intents, gatewayIntent.guildMembers) == 0 then
self:warning('Cannot cache all members while guildMembers intent is disabled')
options.cacheAllMembers = false
end

local user, err1 = api:authenticate(token)
if not user then
return self:error('Could not authenticate, check token: ' .. err1)
Expand Down Expand Up @@ -262,7 +267,7 @@ local function run(self, token)
self._shards[id] = Shard(id, self)
end

local path = format('/?v=%i&encoding=json', GATEWAY_VERSION)
local path = format('/?v=%i&encoding=json', API_VERSION)
for _, shard in pairs(self._shards) do
wrap(shard.connect)(shard, url, path)
shard:identifyWait()
Expand Down
3 changes: 3 additions & 0 deletions libs/client/EventHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,7 @@ end
function EventHandler.STAGE_INSTANCE_DELETE(d, client)
end

function EventHandler.GUILD_AUDIT_LOG_ENTRY_CREATE(d, client)
end

return EventHandler
2 changes: 1 addition & 1 deletion libs/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ return {
ID_DELAY = 5000, -- milliseconds
GATEWAY_DELAY = 500, -- milliseconds,
DISCORD_EPOCH = 1420070400000, -- milliseconds
GATEWAY_VERSION = 6,
API_VERSION = 7,
DEFAULT_AVATARS = 5,
ZWSP = '\226\128\139',
NS_PER_US = 1000,
Expand Down
2 changes: 1 addition & 1 deletion libs/containers/Member.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function Member:hasPermission(channel, perm)
end
end

local allow, deny = 0, 0
local allow, deny = Permissions(), Permissions()
for role in self.roles:iter() do
if role.id ~= guild.id then -- just in case
overwrite = overwrites:get(role.id)
Expand Down
2 changes: 1 addition & 1 deletion libs/enums.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ enums.messageFlag = enum {
enums.gatewayIntent = enum {
guilds = flag(0),
guildMembers = flag(1), -- privileged
guildBans = flag(2),
guildModeration = flag(2),
guildEmojis = flag(3),
guildIntegrations = flag(4),
guildWebhooks = flag(5),
Expand Down

0 comments on commit 141c777

Please sign in to comment.