-
Notifications
You must be signed in to change notification settings - Fork 111
/
stupidFunctionalTest.php
199 lines (176 loc) · 6.25 KB
/
stupidFunctionalTest.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/*
* Copyright 2017 Aaron Scherer
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE
*
* @package restcord/restcord
* @copyright Aaron Scherer 2017
* @license MIT
*/
require __DIR__.'/../vendor/autoload.php';
set_error_handler(
function ($severity, $message, $file, $line) {
if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
}
);
use Assert\Assertion;
use RestCord\DiscordClient;
use RestCord\RateLimit\Provider\RedisRateLimitProvider;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
$output = new SymfonyStyle(new ArgvInput(), new ConsoleOutput());
$output->title('Stupid Functional Test');
$output->text('-> Creating Client');
$client = new DiscordClient(
[
'token' => $argv[1],
'rateLimitProvider' => new RedisRateLimitProvider(),
'throwOnRatelimit' => true,
'cacheDir' => __DIR__.'/../cache',
'logger' => new \Psr\Log\NullLogger(),
]
);
$msg = $client->channel->createMessage(
[
'channel.id' => 146037311753289737,
'content' => 'Something real',
]
);
$client->channel->editMessage(
[
'channel.id' => 146037311753289737,
'message.id' => intval($msg['id']),
'content' => 'Something edited',
]
);
$output->text('-> Modifying Guild Channel Permissions');
$client->guild->modifyGuildChannelPositions(
[['guild.id' => 146037311753289737, 'id' => 146037311753289737, 'position' => 10]]
);
$client->guild->modifyGuildChannelPositions(
[['guild.id' => 146037311753289737, 'id' => 146037311753289737, 'position' => 0]]
);
$output->text('-> Creating channel invite');
$invite = $client->channel->createChannelInvite(
[
'channel.id' => (int) $argv[2],
'max_age' => 5,
'max_uses' => 1,
'unique' => true,
'temporary' => false,
]
);
$output->text('-> Fetching Guild');
$guild = $client->guild->getGuild(['guild.id' => (int) $argv[2]]);
Assertion::eq(108432868149035008, $guild->owner_id);
$output->text('-> Fetching User');
$user = $client->user->getUser(['user.id' => (int) $guild->owner_id]);
Assertion::eq(0001, $user->discriminator);
$output->text('-> Updating Member');
$client->guild->updateNick(
[
'guild.id' => (int) $argv[2],
'nick' => 'Build at: '.time(),
]
);
$output->text('-> Listing Members');
$users = $client->guild->listGuildMembers(['guild.id' => 146037311753289737, 'limit' => 25]);
Assertion::eq(108432868149035008, $users[0]->user->id);
$output->text('-> Creating Guild Role');
$role = $client->guild->createGuildRole(['guild.id' => 146037311753289737, 'name' => 'Test Role']);
Assertion::eq('Test Role', $role->name);
$output->text('-> Updating Guild Role Permissions');
$roles = $client->guild->modifyGuildRolePositions(
[['guild.id' => 146037311753289737, 'id' => $role->id, 'position' => 5]]
);
foreach ($roles as $r) {
if ((int) $r->id === $role->id) {
Assertion::eq(5, $r->position);
}
}
$output->text('-> Deleting Guild Role');
$response = $client->guild->deleteGuildRole(['guild.id' => 146037311753289737, 'role.id' => $role->id]);
$output->text('-> Getting Guild Channels');
$channels = $client->guild->getGuildChannels(['guild.id' => 146037311753289737]);
Assertion::eq(count($channels), 14);
$output->text('-> Executing Webhook');
/** @var \GuzzleHttp\Command\Result $response */
$response = $client->webhook->executeWebhook(
[
'webhook.id' => 282261441090813952,
'webhook.token' => 'NQY9-DzLRT0Sst7Ri5bTsjD3F5cby69PYNXcmbzXYubPbY1KQSQxbGrLIjvMJXcdEBcp',
'username' => 'RestCord',
'embeds' => [
['title' => 'RestCord test at: '.date('Y-m-d H:i:s')],
],
]
);
Assertion::eq($response->count(), 0);
$output->text('-> Sending user a DM');
$dm = $client->user->createDm(['recipient_id' => 108432868149035008]);
$client->channel->createMessage(
[
'channel.id' => $dm->id,
'embed' => [
'title' => 'RestCord test at: '.date(
'Y-m-d H:i:s'
),
],
]
);
$client->channel->createMessage(
[
'channel.id' => $channels[0]->id,
'content' => 'this `supports` __a__ **subset** *of* ~~markdown~~ 😃 ```js
function foo(bar) {
console.log(bar);
}
foo(1);```',
'embed' => [
'title' => 'title ~~(did you know you can have markdown here too?)~~',
'description' => "this supports [named links](https://discordapp.com) on top of the previously shown subset of markdown. ```\nyes, even code blocks```",
'url' => 'https://discordapp.com',
'color' => 14290439,
'timestamp' => '2017-02-20T18:05:58.512Z',
'footer' => [
'icon_url' => 'https://cdn.discordapp.com/embed/avatars/0.png',
'text' => 'footer text',
],
'thumbnail' => [
'url' => 'https://cdn.discordapp.com/embed/avatars/0.png',
],
'image' => [
'url' => 'https://cdn.discordapp.com/embed/avatars/0.png',
],
'author' => [
'name' => 'author name',
'url' => 'https://discordapp.com',
'icon_url' => 'https://cdn.discordapp.com/embed/avatars/0.png',
],
'fields' => [
[
'name' => 'Foo',
'value' => 'some of these properties have certain limits...',
],
[
'name' => 'Bar',
'value' => 'try exceeding some of them!',
],
[
'name' => ' 😃',
'value' => 'an informative error should show up, and this view will remain as-is until all issues are fixed',
],
[
'name' => '<:thonkang:219069250692841473>',
'value' => '???',
],
],
],
]
);
$output->success('Success!');