working on discord api

This commit is contained in:
Ryan Ward 2023-05-01 23:20:52 -04:00
parent 66d572e1c2
commit d4cabfb48d
8 changed files with 158 additions and 0 deletions

6
.gitmodules vendored Normal file
View File

@ -0,0 +1,6 @@
[submodule "multi"]
path = multi
url = https://github.com/rayaman/multi.git
[submodule "bin"]
path = bin
url = https://github.com/rayaman/bin.git

1
bin Submodule

@ -0,0 +1 @@
Subproject commit 4eb7d84e5eb55158f361d2eb9c9a93d9f9960c0b

17
core/channel.lua Normal file
View File

@ -0,0 +1,17 @@
local cjson = require "cjson"
local channel = {}
channel.__index = channel
channel.TYPES = {
GUILD_TEXT = 0,
DM = 1,
GUILD_VOICE = 2,
GROUP_DM = 3,
GUILD_CATEGORY = 4,
GUILD_ANNOUNCEMENT = 5,
ANNOUNCEMENT_THREAD = 10,
PUBLIC_THREAD = 11,
PRIVATE_THREAD = 12,
GUILD_STAGE_VOICE = 13,
GUILD_DIRECTORY = 14,
GUILD_FORUM = 15
}

36
core/message.lua Normal file
View File

@ -0,0 +1,36 @@
local cjson = require "cjson"
local message = {}
message.__index = message
message.TYPES = {
DEFAULT = {0, true}
RECIPIENT_ADD = {1, false},
RECIPIENT_REMOVE = {2, false},
CALL = {3, false},
CHANNEL_NAME_CHANGE = {4, false},
CHANNEL_ICON_CHANGE = {5, false},
CHANNEL_PINNED_MESSAGE = {6, true},
USER_JOIN = {7, true},
GUILD_BOOST = {8, true},
GUILD_BOOST_TIER_1 = {9, true},
GUILD_BOOST_TIER_2 = {10, true},
GUILD_BOOST_TIER_3 = {11, true},
CHANNEL_FOLLOW_ADD = {12, true},
GUILD_DISCOVERY_DISQUALIFIED = {14, false},
GUILD_DISCOVERY_REQUALIFIED = {15, false},
GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING = {16, false},
GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING = {17, false},
THREAD_CREATED = {18, true},
REPLY = {19, true},
CHAT_INPUT_COMMAND = {20, true},
THREAD_STARTER_MESSAGE = {21, false},
GUILD_INVITE_REMINDER = {22, true},
CONTEXT_MENU_COMMAND = {3, true},
AUTO_MODERATION_ACTION = {24, true},
ROLE_SUBSCRIPTION_PURCHASE = {25, true},
INTERACTION_PREMIUM_UPSELL = {26, true},
STAGE_START = {27, true},
STAGE_END = {28, true},
STAGE_SPEAKER = {29, true},
STAGE_TOPIC = {31, true},
GUILD_APPLICATION_PREMIUM_SUBSCRIPTION = {32, false}
}

0
init.lua Normal file
View File

1
multi Submodule

@ -0,0 +1 @@
Subproject commit 1639de5d0f0863a26c576882c8d6b39c46b2f87a

View File

@ -0,0 +1,34 @@
package = "lucord"
version = "1.0-0"
source = {
url = "git://github.com/rayaman/multi.git",
tag = "1.0.0",
}
description = {
summary = "Lua Multi tasking library",
detailed = [[
This library contains many methods for multi tasking. Features non coroutine based multi-tasking, coroutine based multi-tasking, and system threading (Requires use of an integration).
Check github for documentation.
]],
homepage = "https://github.com/rayaman/lucord",
license = "MIT"
}
dependencies = {
"lua >= 5.1",
"luasocket",
"luasec",
"multi",
"lanes",
"bin",
"lfs"
}
build = {
type = "builtin",
modules = {
["multi"] = "init.lua",
["multi.integration.lanesManager"] = "integration/lanesManager/init.lua",
}
}

63
test.lua Normal file
View File

@ -0,0 +1,63 @@
package.path = "?/init.lua;?.lua;"..package.path
local bin = require("bin")
local infinabits = bin.infinabits
local bits = bin.bits
local chronos = require("chronos")
--infinabits:conv("1")
-- 0000111001000011010011001010001001001110000001000100000001000111
function snowflake_timestamp(snowflake)
local snowflake = tostring(infinabits.new(BigNum.new(snowflake)))
local Timestamp = infinabits.new(snowflake:sub(1,42),true)
local WID = bits.new(snowflake:sub(43,47),true)
local PID = bits.new(snowflake:sub(48,52),true)
local Increment = bits.new(snowflake:sub(53,64),true)
local stamp = (Timestamp:tonumber() + BigNum.new("1420070400000"))/1000
local date = os.date("*t", tonumber(tostring(stamp)))
local temp = {
TIMESTAMP = tonumber(tostring(stamp)),
WID = tostring(WID:tonumber()),
PID = tostring(PID:tonumber()),
Increment = tostring(Increment:tonumber())
}
for i,v in pairs(date) do
temp[i] = v
end
return temp
end
local start = chronos.nanotime()
local data = snowflake_timestamp("1027749399947919431")
local stop = chronos.nanotime()
print(("Data took %s seconds"):format(stop - start))
local cjson = require "cjson"
value = cjson.decode([[
{
"id": "41771983423143937",
"guild_id": "41771983423143937",
"name": "general",
"type": 0,
"position": 6,
"permission_overwrites": [],
"rate_limit_per_user": 2,
"nsfw": true,
"topic": "24/7 chat about how to gank Mike #2",
"last_message_id": "155117677105512449",
"parent_id": "399942396007890945",
"default_auto_archive_duration": 60
}
]])
for i,v in pairs(value) do
print(i,v)
end
-- for i, v in pairs(data) do
-- print(i, v)
-- end