This repository has been archived by the owner on Jan 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.php
102 lines (80 loc) · 3.67 KB
/
dashboard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php session_start();
if(!isset($_SESSION['key']) && !isset($_GET['code'])) {
header("Location: https://discordapp.com/api/oauth2/authorize?client_id=420682957007880223&redirect_uri=https%3A%2F%2Fwww.yuuko.info%2Fdashboard.php&response_type=code&scope=identify%20guilds");
}
if(!isset($_SESSION['key'])) {
include_once 'postOpts.php';
$ch = curl_init("https://discordapp.com/api/oauth2/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_opts));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$obj = json_decode($response, true);
$_SESSION['key'] = $obj['access_token'];
$header = 'Authorization: Bearer ' . $_SESSION['key'];
$ch2 = curl_init("https://discordapp.com/api/users/@me/guilds");
curl_setopt($ch2, CURLOPT_POST, 0);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$guildData = curl_exec($ch2);
$_SESSION['jsonData'] = json_decode($guildData, true);
}
if(isset($_SESSION['jsonData'])) { ?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include 'meta.ssi' ?>
<title>Yuuko > Dashboard</title>
</head>
<body>
<?php include 'navigation.ssi' ?>
<!------------------------------------------------------------------------------------->
<div class="container text-center">
<?php
$permissions = array();
$i = 0;
foreach($_SESSION['jsonData'] as $guild) {
if($guild['permissions'] == 2146958847) {
?>
<div class="guildContainer pointer" <?php echo "data-guild='".$guild['id']."'"?> <?php echo "data-name='".$guild['name']."'"?> data-toggle="tooltip" data-placement="bottom" title="<?php echo $guild['name']?>" style="width: 4rem;">
<img class="card-img-top" src="https://cdn.discordapp.com/icons/<?php echo $guild['id']."/".$guild['icon'].".png" ?>" alt="">
</div>
<?php
array_push($permissions, $guild['id']);
$i++;
}
}
$_SESSION['permissions'] = $permissions;
if($i == 0) {
echo "<span class='flex-fill text-center'>It appears that you haven't got the permissions to manage any guilds! :(<br>Click <a href=\"https://discordapp.com/api/oauth2/authorize?client_id=420682957007880223&permissions=8&scope=bot\" target=\"_blank\">here</a> to invite me to one you do!</span>";
}
?>
</div>
<div id="guildDashboard" class="container">
</div>
<!------------------------------------------------------------------------------------->
<script>
$(document).ready(function () {
function guild(id, name) {
$("#guildDashboard").load("guildSettings.php?guild="+id+"&name="+name);
}
$('.guildContainer').click(function(){
$(".guildContainer").removeClass("border-success text-success");
$(this).addClass("border-success text-success");
guild($(this).data("guild"), encodeURI($(this).data("name"))); return false;
});
});
</script>
<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</body>
</html>
<?php } ?>