Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Copyright (C) 2017 VerHext <support@allesverhext.de>
  3.  
  4. This work is licensed under the Creative Commons
  5.  
  6. Attribution-NonCommercial-ShareAlike 4.0
  7.  
  8. International License. To view a copy of this license,
  9. visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
  10. */
  11.  
  12. registerPlugin({
  13.  
  14.     name: 'PUBGstats (HazeProduktion)',
  15.     version: '0.1',
  16.     description: 'PUBGstats - Description and Information',
  17.     author: 'VerHext <support@allesverhext.de>',
  18.     engines: '>= 0.9.16',
  19.  
  20.     vars: [{
  21.         name: 'puURL',
  22.         title: 'The URL to the API on your Server with the port.',
  23.         placeholder: 'https://allesverhext:9999',
  24.         type: 'string'
  25.       },{
  26.         name: 'puSetCommand',
  27.         title: 'Define the Command to set the Stats via Description.',
  28.         placeholder: '!set <nickname>',
  29.         indent: 2,
  30.         type: 'string'
  31.       },{
  32.       },{
  33.         name: 'puPokeMessage',
  34.         title: 'Define the Poke message for Invalid TeamSpeak nickname [Variable &u - Username]',
  35.         placeholder: 'Hey [b]&u[/b], i can´t locate your ingame name on teamspeak. :( Please use [b]<playername> | <real name>[/b] as teamspeak name format and reconnect.',
  36.         indent: 2,
  37.         type: 'string'
  38.       },{
  39.           name: "infoVasSolo",
  40.           title: 'You can use lots of Varable for your Client Description [SOLO]',
  41.           indent: 2,
  42.           type: 'array',
  43.           vars: [{
  44.             title: "&sRating = Rating (int)",
  45.           },{
  46.             title: "&sWinPoints = WinPoints (int)",
  47.           },{
  48.             title: "&sKillPoints = KillPoints(int)",
  49.         }],
  50.  
  51.       },{
  52.  
  53.         name: 'puDescription',
  54.         title: 'Define the Command to set the Stats via Description.',
  55.         placeholder: '!set <nickname>',
  56.         indent: 2,
  57.         type: 'string'
  58.  
  59.  
  60.     }],
  61.  
  62. }, function(sinusbot, config, info) {
  63.  
  64.     // NOTE: Require module variables
  65.     var event = require('event');
  66.     var engine = require('engine');
  67.     var backend = require('backend');
  68.  
  69.     var url = config.puURL;
  70.  
  71.     event.on('clientMove', function(ev) {
  72.  
  73.         if (ev.fromChannel == null && ev.toChannel.isDefault() ) {
  74.           setTimeout(function(){
  75.  
  76.             getAccountIdByNickname(ev.client.name());
  77.             ev.client.setDescription('OK');
  78.           },500);
  79.         }
  80.     });
  81.  
  82.      event.on('chat', function(ev) {
  83.          ev.client.setDescription("Text: " + ev.text)
  84.     });
  85.  
  86.  
  87.  
  88.  
  89.  
  90. function getAccountIdByNickname(nickname){
  91.  
  92.   engine.log("Nickname: " + nickname)
  93.         sinusbot.http({
  94.             'method': 'POST',
  95.             'url': url + '/getAccountIdByNickname',
  96.             'timeout': 6000,
  97.             'maxSize': 1024 * 1024 * 5,
  98.             'body':   '{"nickname": "'+nickname+'"}',
  99.             'headers': {
  100.                 'Content-Type': 'application/json'
  101.             }
  102.         }, function(error, response) {
  103.          var res = JSON.parse(response.data);
  104.  
  105.             if (response.statusCode != 200) {
  106.                 engine.log(error);
  107.                 return;
  108.             }
  109.             try {
  110.  
  111.             } catch (err) {
  112.                 engine.log(err.message);
  113.             }
  114.             if (res === undefined) {
  115.                 engine.log("Error in JSON!");
  116.                 return;
  117.             }
  118.        
  119.             if (res.success){
  120.                 setDescription(res.userData.AccountId, nickname);
  121.                 engien.log('PUBG: Stats are setting to ' + nickname + ' description!')
  122.             }else{
  123.                 backend.getClientByNick(nickname).poke(config.puPokeMessage).replace('&u', nickname)
  124.                 engine.log('PUBG: User ' + nickname + " has not an Gameaccount or User unkomw." )
  125.             }
  126.                      
  127.         });
  128.     }
  129.  
  130.  
  131.  
  132.  
  133.     function setDescription( accountId, nickname){
  134.         //Failed to set the Description...
  135.             backend.getClientByNick(nickname).setDescription("Test you are welcome");
  136.  
  137.     }
  138.  
  139.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement