Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
- Multiple gateway connects are now possible
- Server role methods added
  • Loading branch information
chesrowe committed Jun 2, 2023
1 parent 269bef4 commit ad8cc50
Show file tree
Hide file tree
Showing 20 changed files with 502 additions and 285 deletions.
31 changes: 17 additions & 14 deletions GMDiscord.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added datafiles/cockroach.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 6 additions & 11 deletions objects/obj_controller/Create_0.gml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
myBot = new discordBot(global.config.errorBotToken, global.config.errorApplicationId, true);

// Create a simple slash command where the user types /ping
var _testGuildCommand = new discordGuildCommand("ping", "Just a test.", DISCORD_COMMAND_TYPE.chatInput);

//myBot.guildCommandCreate(global.config.serverId, _testGuildCommand, function(){
// show_debug_message(json_parse(async_load[? "result"]));
//});

var _guildId = "1090453953482866738";
var _userId = "1101162577725227108"
var _userId = "1101162577725227108";
var _channelId = "1113607940977463387"

// Define the callback function to handle the response
var _callback = function() {
show_debug_message("The request responded!");
show_debug_message("Message with an attachment sent!");
};

// Call the method
myBot.guildChannelsGet(_guildId, _callback);
var _fileAttachment = new discordFileAttachment("C:/Users/madma/OneDrive/Desktop/Cockroach-05-1802025153.jpg", "cockroach.jpg", "A cockroach");

// Call the method
myBot.messageEdit(_channelId, "1114011904147468400", "Editeadsfgsadddddd", _callback);
20 changes: 20 additions & 0 deletions objects/obj_controller/KeyPress_32.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var _guildId = "1090453953482866738";
var _userId = "1101162577725227108";
var _channelId = "1113607940977463387"

var _callback = function(_response) {
var _roles = _response;

// Process the roles data
for (var i = 0; i < array_length(_roles); i++) {
var _role = _roles[i];
var _roleId = _role.id;
var _roleName = _role.name;

show_debug_message("Role ID: " + _roleId);
show_debug_message("Role Name: " + _roleName);
}
};

// Call the method
myBot.guildRolesGet(_guildId, _callback);
Empty file.
2 changes: 1 addition & 1 deletion objects/obj_controller/obj_controller.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion objects/obj_discordController/Create_0.gml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
requestCallbacks = [];
botArray = [];
global.lastMessageTest = -1;




Expand Down
Empty file.
46 changes: 33 additions & 13 deletions objects/obj_discordController/Other_68.gml
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,33 @@ repeat(array_length(obj_discordController.botArray)){
case network_type_data:
var _receivedData = discord_gateWay_event_parse();

// Store the sequence number if it exists
if (_receivedData.s != pointer_null) {
var _tester = 0;
_currentBot.__gatewaySequenceNumber = _receivedData.s;
}

// Event Handling
switch (_receivedData.op){
//This event is the first event that is received. For setting up an initial heartbeat with the gateway
case DISCORD_GATEWAY_OP_CODE.hello:
if (_currentBot.__gatewayReconnect){
_currentBot.__gatewaySendResume();
}

_currentBot.__gatewaySendHeartbeat();
var _heartbeatInterval = floor(_receivedData.d.heartbeat_interval / 1000); // Convert ms to seconds
__discordTrace("Heartbeat interval: " + string(_heartbeatInterval));
__discordTrace("Hello - Heartbeat interval - Every " + string(_heartbeatInterval) + " seconds");

//Make sure a heartbeat timesource doesn't already exist
if (time_source_exists(_currentBot.__gatewayHeartbeatTimeSource)){
time_source_destroy(_currentBot.__gatewayHeartbeatTimeSource);
}

//Create a Time Source to send heartbeats
var _heartbeatTimeSource = time_source_create(
_currentBot.__gatewayHeartbeatTimeSource = time_source_create(
time_source_global,
_heartbeatInterval,
time_source_units_seconds,
_currentBot.__gatewaySendHeartbeat,
[],
-1
);
time_source_start(_heartbeatTimeSource);
time_source_start(_currentBot.__gatewayHeartbeatTimeSource);
break;

//Discord acknowledges each heartbeat sent over the gateway
Expand All @@ -70,14 +74,30 @@ repeat(array_length(obj_discordController.botArray)){

//attempt to reconnect and resume
case DISCORD_GATEWAY_OP_CODE.reconnect:
__discordTrace("Reconnect required, attempting...");
network_destroy(_currentBot.__gatewaySocket);
_currentBot.__gatewaySocket = network_create_socket_ext(network_socket_wss, 443);
_currentBot.__gatewayConnection = network_connect_raw_async(_currentBot.__gatewaySocket, _currentBot.__gatewayResumeUrl + "?v=10&encoding=json", 443);
__discordTrace("Reconnect required, attempting...");
__discord_gateway_reconnect(_currentBot);
break;

case DISCORD_GATEWAY_OP_CODE.invalidSession:
__discordTrace("Session invalid, reconnecting...");
var _sessionIsResumable = _receivedData.d;

if (_sessionIsResumable){
__discordTrace("Session invalid is resumable, attempting to resume session");
__discord_gateway_reconnect(_currentBot);
}else{
__discordTrace("Session invalid is NOT resumable, creating new connection");
__discord_gateway_new_connection(_currentBot);
}
break;

//Identity handshakes and normal gateway events sent from your discord app
case DISCORD_GATEWAY_OP_CODE.dispatch:
// Store the sequence number if it exists
if (_receivedData.s != pointer_null) {
_currentBot.__gatewaySequenceNumber = _receivedData.s;
}

if (is_string(_receivedData.t)){
var _eventName = _receivedData.t;
var _eventData = _receivedData.d;
Expand Down
Empty file.
3 changes: 0 additions & 3 deletions objects/obj_discordController/obj_discordController.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rooms/rm_test/RoomCreationCode.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
instance_create_depth(0, 0, 0, obj_discordController);
instance_create_depth(0, 0, 0, obj_controller);
12 changes: 3 additions & 9 deletions rooms/rm_test/rm_test.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ad8cc50

Please sign in to comment.