-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess.php
149 lines (115 loc) · 4.37 KB
/
process.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
use JetBrains\PhpStorm\Pure;
include_once('pdo.php');
require_once 'vendor/autoload.php';
include_once('php/checklogin.php');
include_once('php/token.inc.php');
include_once('php/login.inc.php');
include_once('php/request.inc.php');
$client = new \GuzzleHttp\Client();
if (isset($_POST['access_token'], $_POST['req_id'], $_POST['action'], $_POST['moderator_id'])) {
$access_key = getenv('BOT_ACCESS_TOKEN');
$req_id = $_POST['req_id'];
$action = $_POST['action'];
$moderator = $_POST['moderator_id'];
$req_id = substr($req_id,1,10);
if ($_POST['access_token'] != $access_key) {
echo 'wrong access key';
exit();
}
$request = new DevmarktRequest($req_id);
if (!$request->valid
|| $request->isProcessed()) {
exit();
}
$login = new User($moderator);
if ($login->isModerator()) {
if ($action == "accept") {
$request->acceptRequest($login);
} else if ($action == "decline") {
if (isset($_POST['reason'])) {
$request->rejectRequest($login, $_POST['reason'], true, false);
}
} else if($action == "silent-decline") {
$request->rejectRequest($login, "Nutzer nicht mehr auf dem DevCord" ,false, true);
}
}
} else if (isset($_GET['action'], $_GET['req_id'])) {
if (!check()) {
header('Location: login.php?req_id=' . testInput($_GET['req_id']) . '&action=' . testInput($_GET['action']));
}
if (isset($_GET['from'])) {
unset($_SESSION['req_id']);
unset($_SESSION['action']);
}
$token = new UserTokenHandler($_SESSION['token']);
$login = new User($token->getDiscordID());
$req_id = testInput($_GET['req_id']);
$request = new DevmarktRequest($req_id);
if (!$login->isModerator()) {
header('Location: index.php?error=perm');
}
$status = testInput($_GET['action']);
$status = str_replace('accept', 'angenommen', $status);
$mysql = new MySQL();
$pdo = $mysql->getPDO();
$stmt = 'SELECT * FROM `anfragen` WHERE `req_id`="' . testInput($_GET['req_id']) . '"';
$qry = $pdo->prepare($stmt);
$qry->execute();
$st = $qry->fetch();
if($qry->rowCount() <= 0) {
echo "Keine Anfrage mit dieser ID gefunden.";
exit();
}
if ($request->isProcessed()) {
$processor = new User($st['processed_by']);
echo 'Diese Anfrage wurde bereits von ' . $processor->getUsername() . '#' . $processor->getDiscriminator() . ' bearbeitet.';
exit();
}
$at = new User($st['by_discord_id']);
if(!$at->inBotGuild() && $status == "angenommen") {
header('Location: case.php?req_id=' . $req_id . "&msg=left");
}
if ($status == 'angenommen') {
$request->acceptRequest($login);
} else if ($status == 'decline') {
if (isset($_POST['reason'])) {
if(isset($_POST['thread'])) {
$req = $client->request("GET", "https://discord.com/api/v8/guilds/" . getenv("GUILD_ID"),[
"headers"=>["Authorization"=>"Bot " . getenv("BOT_TOKEN")]
]);
if(json_decode($req->getBody())->premium_tier >= 2 || in_array("PARTNERED", json_decode($req->getBody())->features)) {
$request->rejectRequest($login, $_POST['reason'], true, false);
return;
}
$request->rejectRequest($login, $_POST['reason'], false, false);
} else {
$request->rejectRequest($login, $_POST['reason'],false, false);
}
} else {
include('reason.php');
}
} else if($status == 'silent-decline') {
$request->rejectRequest($login, "Nutzer nicht mehr auf dem Discord", false, true);
}
}
#[Pure] function testInput($data): string
{
return htmlspecialchars(stripslashes(trim($data)));
}
function sendMessage($channel, $content, $embed, $tts)
{
$client = new GuzzleHttp\Client();
$body = json_encode([
'content' => $content,
'embed' => $embed,
'tts' => $tts,
]);
return $client->request("POST", "https://discord.com/api/v8/channels/" . $channel . "/messages", [
'headers' => [
'Authorization' => 'Bot ' . getenv("BOT_TOKEN"),
'Content-Type' => 'application/json'
],
'body' => $body,]
);
}