-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): implement 'bot' class that implements the various classes
- Loading branch information
Showing
26 changed files
with
611 additions
and
214 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,10 @@ | ||
local net = require("@lune/net") | ||
local DiscordLuau = require("@core/init") | ||
|
||
local manager = require("@websocket/manager") | ||
local logger = require("@vendor/logger") | ||
|
||
local gatewayTypes = require("@api-types/gateway/types") | ||
|
||
local DISCORD_BOT_TOKEN = "" | ||
|
||
local instance = manager.new({ | ||
token = DISCORD_BOT_TOKEN, | ||
intents = 512, | ||
webSocketVersion = 10, | ||
}) | ||
|
||
local info = net.request({ | ||
url = "https://discord.com/api/gateway/bot", | ||
headers = { | ||
["authorization"] = `Bot {DISCORD_BOT_TOKEN}`, | ||
["content-type"] = "application/json", | ||
}, | ||
method = "GET", | ||
local discordBot = DiscordLuau.Bot.new({ | ||
token = "", | ||
intents = 0, | ||
}) | ||
|
||
local loggerObject = logger.new("development") | ||
|
||
loggerObject:info(`Requesting connect!`) | ||
|
||
instance:connectAsync(net.jsonDecode(info.body)):await() | ||
|
||
instance.onAllShardsReady:listenOnce(function(data) | ||
local payload = data.payload :: gatewayTypes.ReadyPayload | ||
|
||
loggerObject:info(`All shards are Ready! Logged in as: {payload.d.user.username}#{payload.d.user.discriminator}`) | ||
discordBot:connectAsync():after(function() | ||
print("Connected to Discord!") | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
local future = require("@vendor/future") | ||
local logger = require("@vendor/logger") | ||
|
||
local gateway = require("@rest/gateway") | ||
|
||
local state = require("@classes/state") | ||
|
||
local DISCORD_VERSION = 10 | ||
|
||
local Bot = {} | ||
|
||
Bot.Interface = {} | ||
Bot.Prototype = {} | ||
|
||
function Bot.Prototype.queryGatewayInformation(self: Bot) | ||
return future.new(function() | ||
local request = self.state.rest:newRequest() | ||
|
||
local status, response = gateway.getGatewayBotAsync(request):await() | ||
|
||
assert(status == "Fulfilled", response) | ||
|
||
return response | ||
end) | ||
end | ||
|
||
function Bot.Prototype.connectAsync(self: Bot) | ||
return future.new(function() | ||
local status, gatewayInformation = self:queryGatewayInformation():await() | ||
|
||
assert(status == "Fulfilled", gatewayInformation) | ||
|
||
self.state.webSocketManager:connectAsync(gatewayInformation):await() | ||
end) | ||
end | ||
|
||
function Bot.Interface.new(options: { | ||
token: string, | ||
intents: number, | ||
}) | ||
local self = setmetatable( | ||
{ | ||
state = state.new(options.token, options.intents, DISCORD_VERSION), | ||
logger = logger.new("Bot"), | ||
} :: Bot, | ||
{ __index = Bot.Prototype } | ||
) | ||
|
||
return self | ||
end | ||
|
||
export type Bot = typeof(Bot.Prototype) & { | ||
state: state.State, | ||
logger: logger.Logger, | ||
} | ||
|
||
return Bot.Interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.