Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ============================== config.json =====================
- {
- "AZZTEK": {
- "USERNAME":"azztek89",
- "OAUTHKEY":"oauth:PAS NAIF",
- "CHANNELS":["R0diK","Haruninho","Skerpio","Antonio_Santana","Ryyydax"],
- "CRYPTKEY":"Ue$MuyxN6G,bEf3UGry9UVj{"
- }
- }
- ========================= bot.js ==============
- const config = require('./config.json');
- const stdio = require('stdio');
- // Pas besoin de npm i crypto, c'est un builtin, il est donc installe par defaut.
- const crypto = require('crypto');
- const tmi = require('tmi.js');
- var options = {
- options: {
- debug: false
- },
- connection: {
- cluster: 'aws',
- reconnect: true
- },
- identity: {
- username: azztek89,
- password: oauth:PAS NAIF
- },
- channels: azztek89
- };
- var client = new tmi.client(options);
- client.connect();
- // Tableau de toutes les chaines du fichier config
- var channels = config.AZZTEK.CHANNELS;
- // Uniquement la premiere chaine du tableau channels
- var channel = channels[0];
- // Cle d'encryption
- var key = config.AZZTEK.CRYPTKEY;
- // Debut de la string du hash pour detecter un hash et decryption auto
- const start = 'hash:';
- // Algorithme d'encryption
- const algorithm = 'aes-128-cbc';
- // Type of encoding
- const encoding = 'utf8';
- // Type of output
- const output = 'base64';
- function encrypt(text) {
- var cipher = crypto.createCipher(algorithm, key);
- var encrypt = cipher.update(text, encoding, output);
- encrypt += cipher.final(output);
- return (encrypt);
- }
- function decrypt(hash) {
- var decipher = crypto.createDecipher(algorithm, key);
- var decrypt = decipher.update(hash, output, encoding);
- decrypt += decipher.final(encoding);
- return (decrypt);
- }
- // Lis la ligne du terminal
- stdio.readByLines(function(line) {
- var split = line.split(' ');
- var first = split[0];
- // Envoyer un message crypte en prive
- if (first.toLowerCase() === 'whisper') {
- var recipient = split[1];
- split.shift();
- split.shift();
- var text = split.join(' ');
- var encrypted = 'hash:' + encrypt(text);
- client.whisper(recipient, encrypted);
- return ;
- }
- // Permet de changer la cle en cas d'urgence
- if (first.toLowerCase() === 'keypass') {
- var newkey = split[1];
- if (newkey === undefined)
- return ;
- key = newkey;
- return ;
- }
- // Change la chaine sur laquelle seront ENVOYES les message cryptes
- if (first.toLowerCase() === 'channel') {
- var index = split[1];
- if (index === undefined) {
- console.log('(CHANNEL) === ' + channel);
- return ;
- }
- channel = channels[index];
- console.log('(CHANNEL) === ' + channel);
- return ;
- }
- // Pour decrypter un hash manuellement
- if (first.toLowerCase() === 'decrypt') {
- var hash = split[1];
- if (hash === undefined)
- return ;
- var filtered = hash.replace(start, '');
- // J'ai utilise un try catch pour eviter un crash en cas de key ou de hash invalide
- try {
- // Decode le {hash} qu'il y a apres l'espace, DECRYPTED {hash} puis le log
- var decrypted = decrypt(filtered);
- } catch (err) {}
- console.log('(MANUAL) === ' + decrypted);
- return ;
- }
- // Encrypte automatiquement ce qui est ecrit sur la console
- var encrypted = 'hash:' + encrypt(line);
- // Puis l'envoie directement sur channel, pas besoin de copier-coller
- client.say(channel, encrypted);
- });
- client.on('message', (channel, userstate, message, self) => {
- // Si le message commence avec le start, qui est le meme a chaque fois, decrypter et log
- if (message.startsWith(start)) {
- // Try catch contre crash key ou hash invalide
- try {
- // Decode le {hash} du MESSAGE ENTIER, le message ENTIER doit etre le {hash}, avec ou sans le debut 'hash:'
- var filtered = message.replace(start, '');
- var decrypted = decrypt(filtered);
- } catch (err) {}
- var location = '[' + channel + ']';
- var sender = '(' + userstate['display-name'] + ')';
- console.log('====================================');
- console.log(location + sender + ' === ' + message);
- console.log(location + sender + ' === ' + decrypted);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement