From 7b01f0d274b2e1598bcfd5437c20967e49a5815e Mon Sep 17 00:00:00 2001 From: Lil Panda Date: Fri, 30 Dec 2022 13:01:57 +0000 Subject: [PATCH 1/8] Update discord.php --- discord.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/discord.php b/discord.php index c421318..ed09d9e 100644 --- a/discord.php +++ b/discord.php @@ -12,7 +12,8 @@ $GLOBALS['base_url'] = "https://discord.com"; # Setting bot token for related requests -$GLOBALS['bot_token'] = null; +require "../config.php"; +$GLOBALS['bot_token'] = $bot_token; # A function to generate a random string to be used as state | (protection against CSRF) function gen_state() @@ -55,6 +56,21 @@ function init($redirect_url, $client_id, $client_secret, $bot_token = null) $_SESSION['access_token'] = $results['access_token']; } +# A function to get the channels in a guild | (requires bot token) +function get_channels($guild_id) +{ + $url = $GLOBALS['base_url'] . "/api/guilds/$guild_id/channels"; + $headers = array('Content-Type: application/x-www-form-urlencoded', 'Authorization: Bot ' . $GLOBALS['bot_token']); + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + $response = curl_exec($curl); + curl_close($curl); + $results = json_decode($response, true); + return $results; +} + # A function to get user information | (identify scope) function get_user($email = null) { From 1285dcc25c9057c51c24dee4e73c80e91c2979d5 Mon Sep 17 00:00:00 2001 From: Lil Panda Date: Fri, 30 Dec 2022 13:03:18 +0000 Subject: [PATCH 2/8] Update discord.php --- demos/simple-demo/includes/discord.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/demos/simple-demo/includes/discord.php b/demos/simple-demo/includes/discord.php index c421318..ed09d9e 100644 --- a/demos/simple-demo/includes/discord.php +++ b/demos/simple-demo/includes/discord.php @@ -12,7 +12,8 @@ $GLOBALS['base_url'] = "https://discord.com"; # Setting bot token for related requests -$GLOBALS['bot_token'] = null; +require "../config.php"; +$GLOBALS['bot_token'] = $bot_token; # A function to generate a random string to be used as state | (protection against CSRF) function gen_state() @@ -55,6 +56,21 @@ function init($redirect_url, $client_id, $client_secret, $bot_token = null) $_SESSION['access_token'] = $results['access_token']; } +# A function to get the channels in a guild | (requires bot token) +function get_channels($guild_id) +{ + $url = $GLOBALS['base_url'] . "/api/guilds/$guild_id/channels"; + $headers = array('Content-Type: application/x-www-form-urlencoded', 'Authorization: Bot ' . $GLOBALS['bot_token']); + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + $response = curl_exec($curl); + curl_close($curl); + $results = json_decode($response, true); + return $results; +} + # A function to get user information | (identify scope) function get_user($email = null) { From f756a4225ddf7938410cb7e6b91492f30bfe5f56 Mon Sep 17 00:00:00 2001 From: Lil Panda Date: Fri, 30 Dec 2022 13:04:25 +0000 Subject: [PATCH 3/8] Update login.php --- demos/simple-demo/includes/login.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/demos/simple-demo/includes/login.php b/demos/simple-demo/includes/login.php index fb1fca5..ddb0c58 100644 --- a/demos/simple-demo/includes/login.php +++ b/demos/simple-demo/includes/login.php @@ -32,11 +32,17 @@ get_user(); # Uncomment this for using it WITH email scope and comment line 32. -#get_user($email=True); +# get_user($email=True); # Adding user to guild | (guilds.join scope) # join_guild('SERVER_ID_HERE'); +# Fetching guild channels | (guilds scope) + +if($guild_id != null) { + $_SESSION['channels'] = get_channels($guild_id); +} + # Fetching user guild details | (guilds scope) $_SESSION['guilds'] = get_guilds(); From 1fccda76e694d33a2f0c92cae4fc4710010f4818 Mon Sep 17 00:00:00 2001 From: Lil Panda Date: Fri, 30 Dec 2022 13:04:41 +0000 Subject: [PATCH 4/8] Update login.php --- demos/simple-demo/includes/login.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/simple-demo/includes/login.php b/demos/simple-demo/includes/login.php index ddb0c58..d1238e3 100644 --- a/demos/simple-demo/includes/login.php +++ b/demos/simple-demo/includes/login.php @@ -32,7 +32,7 @@ get_user(); # Uncomment this for using it WITH email scope and comment line 32. -# get_user($email=True); +#get_user($email=True); # Adding user to guild | (guilds.join scope) # join_guild('SERVER_ID_HERE'); From e1981a9421818fd5d20edf4e6a570cc55b8e60b4 Mon Sep 17 00:00:00 2001 From: Lil Panda Date: Fri, 30 Dec 2022 13:05:06 +0000 Subject: [PATCH 5/8] Update config.php --- demos/simple-demo/config.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/demos/simple-demo/config.php b/demos/simple-demo/config.php index 804bbb0..97d83af 100644 --- a/demos/simple-demo/config.php +++ b/demos/simple-demo/config.php @@ -17,6 +17,12 @@ # example: https://mydomain.com/test/includes/login.php $redirect_url = ""; + +# GETTING CHANNELS +# - Setting the variable below with server ID will provide you with access to all the channels inside the server. +$guild_id = null; + + # IMPORTANT READ THIS: # - Set the `$bot_token` to your bot token if you want to use guilds.join scope to add a member to your server # - Check login.php for more detailed info on this. From c02a938669e3d30bb5723ba63b4361905e9f35d0 Mon Sep 17 00:00:00 2001 From: Lil Panda Date: Fri, 30 Dec 2022 13:05:23 +0000 Subject: [PATCH 6/8] Update config.php From 25595090bde7bd2d24dfa61c3d07303ef02938f5 Mon Sep 17 00:00:00 2001 From: Lil Panda Date: Fri, 30 Dec 2022 13:05:43 +0000 Subject: [PATCH 7/8] Update index.php --- demos/simple-demo/index.php | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/demos/simple-demo/index.php b/demos/simple-demo/index.php index 7531005..c85d475 100644 --- a/demos/simple-demo/index.php +++ b/demos/simple-demo/index.php @@ -84,6 +84,68 @@ ?>
+

Text channels:

+ + + + + + "; + echo ""; + } + } + ?> +
NAMEID
"; + echo $_SESSION['channels'][$i]['name']; + echo ""; + echo $_SESSION['channels'][$i]['id']; + echo "
+
+

Voice channels:

+ + + + + + "; + echo ""; + } + } + ?> +
NAMEID
"; + echo $_SESSION['channels'][$i]['name']; + echo ""; + echo $_SESSION['channels'][$i]['id']; + echo "
+
+

Guild Channels:

+ + + + + + "; + echo ""; + } + ?> +
NAMEID
"; + echo $_SESSION['channels'][$i]['name']; + echo ""; + echo $_SESSION['channels'][$i]['id']; + echo "
+
+

User Guilds Response :

From aa10fbb75766802370119fdced50d3969ec34715 Mon Sep 17 00:00:00 2001 From: Lil Panda Date: Fri, 30 Dec 2022 23:26:37 +0000 Subject: [PATCH 8/8] Update index.php --- demos/simple-demo/index.php | 42 ------------------------------------- 1 file changed, 42 deletions(-) diff --git a/demos/simple-demo/index.php b/demos/simple-demo/index.php index c85d475..6d2b630 100644 --- a/demos/simple-demo/index.php +++ b/demos/simple-demo/index.php @@ -84,48 +84,6 @@ ?>
-

Text channels:

- - - - - - "; - echo ""; - } - } - ?> -
NAMEID
"; - echo $_SESSION['channels'][$i]['name']; - echo ""; - echo $_SESSION['channels'][$i]['id']; - echo "
-
-

Voice channels:

- - - - - - "; - echo ""; - } - } - ?> -
NAMEID
"; - echo $_SESSION['channels'][$i]['name']; - echo ""; - echo $_SESSION['channels'][$i]['id']; - echo "
-

Guild Channels: