-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add websockets #12
add websockets #12
Conversation
Co-Authored-By: SwitchUpCB <81384235+switchupcb@users.noreply.github.com>
Event HandlingEvent Handling will use two functions in order to avoid type asserting. Function OneThe first function will be a generic function to handle all events. Upon receiving events, this function will be called with a The steps are as follows:
Map may be replaced by an alternate data structure or Function TwoFunction two represents the disgo UI for event handling. This can be defined in a similar manner to the Send() function such as // Define an event handler.
handler := disgo.EventHandler{
Event: disgo.EventInteractionCreate,
Call: func (i disgo.ResourceInteraction) {
log.Printf("main called by %s", i.User.Username)
},
}
// Add the event handler to the bot.
bot.Add(handler) Regardless of the choice, we must allow the user to determine the event they are using before runtime, such that we can also add it to the bot at compile time in the correct list of handlers. Function ThreeThe "third function" represents the goroutines that run the event handler functions from the |
Event names were added using the following code: import re
# format formats the given string from CapitalWord to CAPITAL_WORD.
def formatString(s):
words = re.findall('[A-Z][^A-Z]*', s)
formatted = ''
for word in words:
formatted += word.upper() + "_"
return formatted[:len(formatted) - 1]
# flag is appended to the start of the line.
flag = "FlagGatewayEventName"
# create the new file.
newfile = ""
lines = file.split("\n")
for line in lines:
newfile += flag + line + " = " + '"' + formatString(line) + '"' + "\n"
print(newfile) |
This outline works in essentially the same way as above, however we can NOT use the opcode itself to determine the event. Instead, The original idea to use a map was thwarted because a In any case, there will always be a concrete amount of handlers: Storing them via map would involve complexity and type assertion while saving initial memory compared to storing them via slices: Even using pointers, The side effect however is that we must add an easy way for the user to ensure that there is a |
I have added the autogenerated // Add an event handler to the bot.
bot.Handle(disgo.FlagGatewayEventNameInteractionCreate, func(i disgo.InteractionCreate) {
log.Printf("main called by %s", i.User.Username)
}) We will want to ensure the following prior to merging this request (after everything else for this PR is completed):
Here is an example of how one may add a global handler. Keep in mind that this is not yet applicable for the first // check if an event handler for hello events has been added to the bot.
if len(bot.Handlers.Hello) == 0 {
// add the handler to the bot.
bot.Handle(FlagGatewayEventNameHello, func(*Hello) {
// add event handler code here.
})
}
// otherwise, handler isn't added to the bot. This code would be called when the session begins listening for events and a |
The Handle function can implement automatic intent calculation by specifying which intents are required in the |
see TODO
handles missing opcode 11
fixes ticker semantics, highlights issues with hearbeart algorithm, needs context/conn fix
fix heartbeat, error logic Co-Authored-By: t-rog <74488354+t-rog@users.noreply.github.com>
needs readability rewrite
with automatic intent calculation
added zlib compression and fixed listen function Co-Authored-By: SwitchUpCB <81384235+switchupcb@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to self: add nlreturn (?)
event variable initialization; add automod
adds internal socket package, read, write, and disconnect helper functions, improves heartbeat functionality test
connect optimization; needs data race fix
fixes data races
Secrets (and environment secrets) can not be used by forked repositories unless certain conditions are granted.
|
* add connect to gateway * add Reconn and Terminate * add event handler outline * fix semantics for implementation * add heartbeat func * add event handler generation * add listen func * fix connect and disconnect func * fix heartbeat func handles missing opcode 11 * implement mutex fixes ticker semantics, highlights issues with hearbeart algorithm, needs context/conn fix * change heartbeat algorithm * fix heartbeat edge case * review changes fix heartbeat, error logic * add mutex to event generation * add listen optimization note * add automatic intent calculation * fix opcode marshal needs readability rewrite * add Remove func for event handlers; needs documentation * format * refactor session errors * fix client initialization IntentSet * fix Client pointer init * fix Connect with test Co-Authored-By: SwitchUpCB <81384235+switchupcb@users.noreply.github.com> * fix token variable NEVER COMMIT TOKEN Co-Authored-By: SwitchUpCB <81384235+switchupcb@users.noreply.github.com> * add event handler test with automatic intent calculation * fix websocket errors added zlib compression and fixed listen function Co-Authored-By: SwitchUpCB <81384235+switchupcb@users.noreply.github.com> * fix handle function event variable initialization; add automod * edit requested changes * fix test data race * refactor websocket functionality adds internal socket package, read, write, and disconnect helper functions, improves heartbeat functionality test * swap dasgo * changefix heartbeat algorithm * add reconnect test connect optimization; needs data race fix * refactor connect disconnect reconnect fixes data races * update errors * update contributing * update ci * fix ci * remove godotenv move env to steps * debug ci * fix ci on forks Co-authored-by: SwitchUpCB <81384235+switchupcb@users.noreply.github.com> Co-Authored-By: t-rog <74488354+t-rog@users.noreply.github.com>
Co-Authored-By: SwitchUpCB 81384235+switchupcb@users.noreply.github.com