test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const {MessageEmbed} = require('discord.js');
  2. const help_setup = require('../functions/helpsetup.js');
  3. function cmd_test(lang, msg, args, line, wiki) {
  4. if ( args.join('') ) {
  5. if ( msg.channel.type !== 'text' || !pause[msg.guild.id] ) this.LINK(lang, msg, line, wiki);
  6. } else if ( msg.channel.type !== 'text' || !pause[msg.guild.id] ) {
  7. if ( msg.isAdmin() && msg.defaultSettings ) help_setup(lang, msg);
  8. var text = lang.get('test.text')[Math.floor(Math.random() * lang.get('test.random'))] || lang.get('test.default');
  9. console.log( '- Test: Fully functioning!' );
  10. var now = Date.now();
  11. msg.replyMsg( text ).then( message => {
  12. if ( !message ) return;
  13. var then = Date.now();
  14. var embed = new MessageEmbed().setTitle( lang.get('test.time') ).addField( 'Discord', ( then - now ) + 'ms' );
  15. now = Date.now();
  16. got.get( wiki + 'api.php?action=query&meta=siteinfo&siprop=general|extensions&format=json', {
  17. responseType: 'json'
  18. } ).then( response => {
  19. then = Date.now();
  20. var body = response.body;
  21. if ( body && body.warnings ) log_warn(body.warnings);
  22. var ping = ( then - now ) + 'ms';
  23. if ( response.statusCode !== 200 || !body || !( body instanceof Object ) ) {
  24. if ( wiki.noWiki(response.url) || response.statusCode === 410 ) {
  25. console.log( '- This wiki doesn\'t exist!' );
  26. ping += ' <:unknown_wiki:505887262077353984>';
  27. }
  28. else {
  29. console.log( '- ' + response.statusCode + ': Error while reaching the wiki: ' + ( body && body.error && body.error.info ) );
  30. ping += ' <:error:505887261200613376>';
  31. }
  32. }
  33. embed.addField( wiki, ping );
  34. }, error => {
  35. then = Date.now();
  36. var ping = ( then - now ) + 'ms';
  37. if ( wiki.noWiki(error.message) ) {
  38. console.log( '- This wiki doesn\'t exist!' );
  39. ping += ' <:unknown_wiki:505887262077353984>';
  40. }
  41. else {
  42. console.log( '- Error while reaching the wiki: ' + error );
  43. ping += ' <:error:505887261200613376>';
  44. }
  45. embed.addField( wiki, ping );
  46. } ).finally( () => {
  47. if ( msg.isOwner() ) return msg.client.shard.fetchClientValues('ready').then( values => {
  48. return '```java\n' + values.map( (ready, id) => id + ': ' + ready ).join('\n') + '\n```';
  49. }, error => {
  50. return '```js\n' + error.name + ': ' + error.message + '\n```';
  51. } ).then( shards => {
  52. embed.addField( 'Shards', shards );
  53. message.edit( message.content, {embed,allowedMentions:{users:[msg.author.id]}} ).catch(log_error);
  54. } );
  55. message.edit( message.content, {embed,allowedMentions:{users:[msg.author.id]}} ).catch(log_error);
  56. } );
  57. } );
  58. } else {
  59. console.log( '- Test: Paused!' );
  60. msg.replyMsg( lang.get('test.pause'), {}, true );
  61. }
  62. }
  63. module.exports = {
  64. name: 'test',
  65. everyone: true,
  66. pause: true,
  67. owner: false,
  68. run: cmd_test
  69. };