-
Notifications
You must be signed in to change notification settings - Fork 1
/
role-channels.php
108 lines (88 loc) · 3.74 KB
/
role-channels.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
103
104
105
106
107
108
<?php
include './vendor/autoload.php';
use RestCord\DiscordClient;
session_start();
if (empty($_SESSION)) {
die("Not logged in!");
}
// get bot token from evironment variable in htaccess file
$token = (getenv('BOT_TOKEN') ? getenv('BOT_TOKEN') : getenv('REDIRECT_BOT_TOKEN'));
$guild_id = intval($_SESSION['guild_id']);
$message = "All fine!";
// New bot client login
$discord = new DiscordClient(['token' => $token]); // Token is required
// get roles and channels from guild
$roles = $discord->guild->getGuildRoles(['guild.id' => $guild_id]);
$channels = $discord->guild->getGuildChannels(['guild.id' => $guild_id]);
if (!empty($_POST)) {
foreach ($_POST['channels'] as $channel) {
$parameters = [
"channel.id" => intval($channel),
"overwrite.id" => strval($_POST['role']),
"allow" => intval($_POST['allow']),
"deny" => intval($_POST['deny']),
"type" => "role"
];
$discord->channel->editChannelPermissions($parameters);
}
$rolename = $roles[array_search(intval($_POST['role']), array_column($roles, 'id'))]->name;
$channelnames = [];
foreach ($_POST['channels'] as $channel) {
array_push($channelnames, $channels[array_search(intval($channel), array_column($channels, 'id'))]->name);
}
$message = "Operation Made. Hopefully changed $rolename in channels " . join(", ", $channelnames) . ". ";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Role-Channels</title>
<?php require "./.components/head.php" ?>
</head>
<body>
<?php require "./.components/navbar.php" ?>
<main>
<div class="container">
<h2>Role-Channels</h2>
<p>Change the permision of one role for multiple channels. </p>
<form method="post">
<div class="row">
<div class="col-md-3 order-md-2">
<div class="form-group">
<label class="form-label" for="channels">Channels</label>
<select name="channels[]" multiple="" required id="channels" class="custom-select" size="10">
<?php
foreach ($channels as $channel) {
echo "<option value=" . $channel->id . ">" . ($channel->type === 0 ? "<b>#</b>" : "<b>🔊</b>") . $channel->name . "</option>";
}
?>
</select>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
<div class="col-md-9">
<div class="form-group">
<label class="form-label" for="role">Role</label>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">@</div>
</div>
<select id="role" name="role" class="form-control">
<?php
foreach ($roles as $role) {
echo "<option value=" . $role->id . ">" . $role->name . "</option>";
}
?>
</select>
</div>
</div>
<hr>
<?php require "./.components/permissions.php" ?>
</div>
</div>
</form>
</div>
</main>
<?php require "./.components/footer.php" ?>
</body>
</html>