Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. ============================== config.json =====================
  2. {
  3. "AZZTEK": {
  4. "USERNAME":"azztek89",
  5. "OAUTHKEY":"oauth:PAS NAIF",
  6. "CHANNELS":["R0diK","Haruninho","Skerpio","Antonio_Santana","Ryyydax"],
  7. "CRYPTKEY":"Ue$MuyxN6G,bEf3UGry9UVj{"
  8. }
  9. }
  10. ========================= bot.js ==============
  11. const config = require('./config.json');
  12. const stdio = require('stdio');
  13. // Pas besoin de npm i crypto, c'est un builtin, il est donc installe par defaut.
  14. const crypto = require('crypto');
  15. const tmi = require('tmi.js');
  16.  
  17. var options = {
  18. options: {
  19. debug: false
  20. },
  21. connection: {
  22. cluster: 'aws',
  23. reconnect: true
  24. },
  25. identity: {
  26. username: azztek89,
  27. password: oauth:PAS NAIF
  28. },
  29. channels: azztek89
  30. };
  31.  
  32. var client = new tmi.client(options);
  33. client.connect();
  34.  
  35. // Tableau de toutes les chaines du fichier config
  36. var channels = config.AZZTEK.CHANNELS;
  37. // Uniquement la premiere chaine du tableau channels
  38. var channel = channels[0];
  39. // Cle d'encryption
  40. var key = config.AZZTEK.CRYPTKEY;
  41. // Debut de la string du hash pour detecter un hash et decryption auto
  42. const start = 'hash:';
  43. // Algorithme d'encryption
  44. const algorithm = 'aes-128-cbc';
  45. // Type of encoding
  46. const encoding = 'utf8';
  47. // Type of output
  48. const output = 'base64';
  49.  
  50. function encrypt(text) {
  51.  
  52. var cipher = crypto.createCipher(algorithm, key);
  53. var encrypt = cipher.update(text, encoding, output);
  54. encrypt += cipher.final(output);
  55. return (encrypt);
  56. }
  57.  
  58. function decrypt(hash) {
  59.  
  60. var decipher = crypto.createDecipher(algorithm, key);
  61. var decrypt = decipher.update(hash, output, encoding);
  62. decrypt += decipher.final(encoding);
  63. return (decrypt);
  64. }
  65.  
  66. // Lis la ligne du terminal
  67. stdio.readByLines(function(line) {
  68.  
  69. var split = line.split(' ');
  70. var first = split[0];
  71.  
  72. // Envoyer un message crypte en prive
  73. if (first.toLowerCase() === 'whisper') {
  74.  
  75. var recipient = split[1];
  76. split.shift();
  77. split.shift();
  78.  
  79. var text = split.join(' ');
  80. var encrypted = 'hash:' + encrypt(text);
  81. client.whisper(recipient, encrypted);
  82. return ;
  83. }
  84. // Permet de changer la cle en cas d'urgence
  85. if (first.toLowerCase() === 'keypass') {
  86.  
  87. var newkey = split[1];
  88.  
  89. if (newkey === undefined)
  90. return ;
  91. key = newkey;
  92. return ;
  93. }
  94. // Change la chaine sur laquelle seront ENVOYES les message cryptes
  95. if (first.toLowerCase() === 'channel') {
  96.  
  97. var index = split[1];
  98.  
  99. if (index === undefined) {
  100.  
  101. console.log('(CHANNEL) === ' + channel);
  102. return ;
  103. }
  104. channel = channels[index];
  105. console.log('(CHANNEL) === ' + channel);
  106. return ;
  107. }
  108. // Pour decrypter un hash manuellement
  109. if (first.toLowerCase() === 'decrypt') {
  110.  
  111. var hash = split[1];
  112.  
  113. if (hash === undefined)
  114. return ;
  115. var filtered = hash.replace(start, '');
  116. // J'ai utilise un try catch pour eviter un crash en cas de key ou de hash invalide
  117. try {
  118. // Decode le {hash} qu'il y a apres l'espace, DECRYPTED {hash} puis le log
  119. var decrypted = decrypt(filtered);
  120. } catch (err) {}
  121. console.log('(MANUAL) === ' + decrypted);
  122. return ;
  123. }
  124. // Encrypte automatiquement ce qui est ecrit sur la console
  125. var encrypted = 'hash:' + encrypt(line);
  126. // Puis l'envoie directement sur channel, pas besoin de copier-coller
  127. client.say(channel, encrypted);
  128. });
  129.  
  130. client.on('message', (channel, userstate, message, self) => {
  131.  
  132. // Si le message commence avec le start, qui est le meme a chaque fois, decrypter et log
  133. if (message.startsWith(start)) {
  134.  
  135. // Try catch contre crash key ou hash invalide
  136. try {
  137. // Decode le {hash} du MESSAGE ENTIER, le message ENTIER doit etre le {hash}, avec ou sans le debut 'hash:'
  138. var filtered = message.replace(start, '');
  139. var decrypted = decrypt(filtered);
  140. } catch (err) {}
  141.  
  142. var location = '[' + channel + ']';
  143. var sender = '(' + userstate['display-name'] + ')';
  144.  
  145. console.log('====================================');
  146. console.log(location + sender + ' === ' + message);
  147. console.log(location + sender + ' === ' + decrypted);
  148. }
  149. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement