stupidFunctionalTest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /*
  3. * Copyright 2017 Aaron Scherer
  4. *
  5. * This source file is subject to the license that is bundled
  6. * with this source code in the file LICENSE
  7. *
  8. * @package restcord/restcord
  9. * @copyright Aaron Scherer 2017
  10. * @license MIT
  11. */
  12. require __DIR__.'/../vendor/autoload.php';
  13. set_error_handler(
  14. function ($severity, $message, $file, $line) {
  15. if (error_reporting() & $severity) {
  16. throw new ErrorException($message, 0, $severity, $file, $line);
  17. }
  18. }
  19. );
  20. use Assert\Assertion;
  21. use RestCord\DiscordClient;
  22. use RestCord\RateLimit\Provider\RedisRateLimitProvider;
  23. use Symfony\Component\Console\Input\ArgvInput;
  24. use Symfony\Component\Console\Output\ConsoleOutput;
  25. use Symfony\Component\Console\Style\SymfonyStyle;
  26. $output = new SymfonyStyle(new ArgvInput(), new ConsoleOutput());
  27. $output->title('Stupid Functional Test');
  28. $output->text('-> Creating Client');
  29. $client = new DiscordClient(
  30. [
  31. 'token' => $argv[1],
  32. 'rateLimitProvider' => new RedisRateLimitProvider(),
  33. 'throwOnRatelimit' => true,
  34. 'cacheDir' => __DIR__.'/../cache',
  35. 'logger' => new \Psr\Log\NullLogger(),
  36. ]
  37. );
  38. $msg = $client->channel->createMessage(
  39. [
  40. 'channel.id' => 146037311753289737,
  41. 'content' => 'Something real',
  42. ]
  43. );
  44. $client->channel->editMessage(
  45. [
  46. 'channel.id' => 146037311753289737,
  47. 'message.id' => intval($msg['id']),
  48. 'content' => 'Something edited',
  49. ]
  50. );
  51. $output->text('-> Modifying Guild Channel Permissions');
  52. $client->guild->modifyGuildChannelPositions(
  53. [['guild.id' => 146037311753289737, 'id' => 146037311753289737, 'position' => 10]]
  54. );
  55. $client->guild->modifyGuildChannelPositions(
  56. [['guild.id' => 146037311753289737, 'id' => 146037311753289737, 'position' => 0]]
  57. );
  58. $output->text('-> Creating channel invite');
  59. $invite = $client->channel->createChannelInvite(
  60. [
  61. 'channel.id' => (int) $argv[2],
  62. 'max_age' => 5,
  63. 'max_uses' => 1,
  64. 'unique' => true,
  65. 'temporary' => false,
  66. ]
  67. );
  68. $output->text('-> Fetching Guild');
  69. $guild = $client->guild->getGuild(['guild.id' => (int) $argv[2]]);
  70. Assertion::eq(108432868149035008, $guild->owner_id);
  71. $output->text('-> Fetching User');
  72. $user = $client->user->getUser(['user.id' => (int) $guild->owner_id]);
  73. Assertion::eq(0001, $user->discriminator);
  74. $output->text('-> Updating Member');
  75. $client->guild->updateNick(
  76. [
  77. 'guild.id' => (int) $argv[2],
  78. 'nick' => 'Build at: '.time(),
  79. ]
  80. );
  81. $output->text('-> Listing Members');
  82. $users = $client->guild->listGuildMembers(['guild.id' => 146037311753289737, 'limit' => 25]);
  83. Assertion::eq(108432868149035008, $users[0]->user->id);
  84. $output->text('-> Creating Guild Role');
  85. $role = $client->guild->createGuildRole(['guild.id' => 146037311753289737, 'name' => 'Test Role']);
  86. Assertion::eq('Test Role', $role->name);
  87. $output->text('-> Updating Guild Role Permissions');
  88. $roles = $client->guild->modifyGuildRolePositions(
  89. [['guild.id' => 146037311753289737, 'id' => $role->id, 'position' => 5]]
  90. );
  91. foreach ($roles as $r) {
  92. if ((int) $r->id === $role->id) {
  93. Assertion::eq(5, $r->position);
  94. }
  95. }
  96. $output->text('-> Deleting Guild Role');
  97. $response = $client->guild->deleteGuildRole(['guild.id' => 146037311753289737, 'role.id' => $role->id]);
  98. $output->text('-> Getting Guild Channels');
  99. $channels = $client->guild->getGuildChannels(['guild.id' => 146037311753289737]);
  100. Assertion::eq(count($channels), 14);
  101. $output->text('-> Executing Webhook');
  102. /** @var \GuzzleHttp\Command\Result $response */
  103. $response = $client->webhook->executeWebhook(
  104. [
  105. 'webhook.id' => 282261441090813952,
  106. 'webhook.token' => 'NQY9-DzLRT0Sst7Ri5bTsjD3F5cby69PYNXcmbzXYubPbY1KQSQxbGrLIjvMJXcdEBcp',
  107. 'username' => 'RestCord',
  108. 'embeds' => [
  109. ['title' => 'RestCord test at: '.date('Y-m-d H:i:s')],
  110. ],
  111. ]
  112. );
  113. Assertion::eq($response->count(), 0);
  114. $output->text('-> Sending user a DM');
  115. $dm = $client->user->createDm(['recipient_id' => 108432868149035008]);
  116. $client->channel->createMessage(
  117. [
  118. 'channel.id' => $dm->id,
  119. 'embed' => [
  120. 'title' => 'RestCord test at: '.date(
  121. 'Y-m-d H:i:s'
  122. ),
  123. ],
  124. ]
  125. );
  126. $client->channel->createMessage(
  127. [
  128. 'channel.id' => $channels[0]->id,
  129. 'content' => 'this `supports` __a__ **subset** *of* ~~markdown~~ 😃 ```js
  130. function foo(bar) {
  131. console.log(bar);
  132. }
  133. foo(1);```',
  134. 'embed' => [
  135. 'title' => 'title ~~(did you know you can have markdown here too?)~~',
  136. 'description' => "this supports [named links](https://discordapp.com) on top of the previously shown subset of markdown. ```\nyes, even code blocks```",
  137. 'url' => 'https://discordapp.com',
  138. 'color' => 14290439,
  139. 'timestamp' => '2017-02-20T18:05:58.512Z',
  140. 'footer' => [
  141. 'icon_url' => 'https://cdn.discordapp.com/embed/avatars/0.png',
  142. 'text' => 'footer text',
  143. ],
  144. 'thumbnail' => [
  145. 'url' => 'https://cdn.discordapp.com/embed/avatars/0.png',
  146. ],
  147. 'image' => [
  148. 'url' => 'https://cdn.discordapp.com/embed/avatars/0.png',
  149. ],
  150. 'author' => [
  151. 'name' => 'author name',
  152. 'url' => 'https://discordapp.com',
  153. 'icon_url' => 'https://cdn.discordapp.com/embed/avatars/0.png',
  154. ],
  155. 'fields' => [
  156. [
  157. 'name' => 'Foo',
  158. 'value' => 'some of these properties have certain limits...',
  159. ],
  160. [
  161. 'name' => 'Bar',
  162. 'value' => 'try exceeding some of them!',
  163. ],
  164. [
  165. 'name' => ' 😃',
  166. 'value' => 'an informative error should show up, and this view will remain as-is until all issues are fixed',
  167. ],
  168. [
  169. 'name' => '<:thonkang:219069250692841473>',
  170. 'value' => '???',
  171. ],
  172. ],
  173. ],
  174. ]
  175. );
  176. $output->success('Success!');