Advertisement
Guest User

Untitled

a guest
Sep 30th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const TwitchJS = require('twitch-js')
  2. const Discord = require('discord.js')
  3. const mysql = require('mysql')
  4. const dClient = new Discord.Client()
  5. const options = {
  6.     connection: {
  7.         reconnect: true,
  8.         secure: true,
  9.     },
  10.     options: {
  11.         clientId: '',
  12.     },
  13.     identity: {
  14.         username: 'relay_discord',
  15.         password: 'oauth:',
  16.     },
  17.     channels: [],
  18. };
  19.  
  20. const data = mysql.createConnection({
  21.     host: 'localhost',
  22.     user: 'root',
  23.     password: '',
  24.     database: 'twitch'
  25. })
  26.  
  27.  data.query(`SELECT * from channels`, (err, row) => {
  28.    row.forEach(rows => {
  29.      options.channels.push(rows.twitch);
  30.   })
  31.   console.log(options.channels)
  32. })
  33.  
  34. const client = new TwitchJS.Client(options);
  35.  
  36. dClient.on('message', msg => {
  37.     data.query(`SELECT * from channels WHERE server = ${msg.guild.id}`, (err, row) => {
  38.         if (row && row.length) {
  39.             if (row[0].channelID !== "0") {
  40.                 if (msg.channel.id === row[0].channelID) {
  41.                     if (msg.author.bot) return;
  42.                     client.say(`${row[0].twitch}`, msg.author.username + "#" +  msg.author.discriminator + ": " + msg.content)
  43.                 }
  44.             }
  45.         }
  46.     })
  47.     if (msg.content.startsWith("!count")) {
  48.         msg.reply("Discord Relay currently monitor " + options.channels.length + " streams!")
  49.     }
  50. })
  51.  
  52. client.on('chat', (channel, userstate, message, self) => {
  53.     console.log(userstate['room-id'])
  54.     data.query(`SELECT * from channels WHERE roomid = ${userstate['room-id']}`, (err, row) => {
  55.         if (row && row.length) {
  56.             if (row[0].channelID !== "0") {
  57.                 let role;
  58.                 switch (true) {
  59.                   case (userstate['subscriber']):
  60.                   role = "{Sub} "
  61.                   break;
  62.                   case  (userstate['mod']):
  63.                   role = "{Mod} "
  64.                   break;
  65.                   case (userstate['turbo']):
  66.                   role = "{Turbo} "
  67.                   break;
  68.                   default:
  69.                   role = "{Viewer} "
  70.                 }
  71.                 if (self) return;
  72.                 if (userstate['display-name'] === "Nightbot") return;
  73.                 dClient.channels.get(row[0].channelID).send({
  74.                     embed: {
  75.                         color: 3447003,
  76.                         fields: [{
  77.                             name: `${role + userstate['display-name']}`,
  78.                             value: `${message}`
  79.                         }, ],
  80.                         timestamp: new Date(),
  81.                     }
  82.                 })
  83.             } else {
  84.                 let role;
  85.                 switch (true) {
  86.                   case (userstate['subscriber']):
  87.                   role = "{Sub} "
  88.                   break;
  89.                   case  (userstate['mod']):
  90.                   role = "{Mod} "
  91.                   break;
  92.                   case (userstate['turbo']):
  93.                   role = "{Turbo} "
  94.                   break;
  95.                   default:
  96.                   role = "{Viewer} "
  97.                 }
  98.                 if (self) return;
  99.                 if (userstate['display-name'] === "Nightbot") return;
  100.                 dClient.channels.find('name', 'general').send({
  101.                     embed: {
  102.                         color: 3447003,
  103.                         fields: [{
  104.                             name: `${role + userstate['display-name']}`,
  105.                             value: `${message}`
  106.                         }, ],
  107.                         timestamp: new Date(),
  108.                     }
  109.                 })
  110.             }
  111.         }
  112.     })
  113. })
  114.  
  115. client.connect();
  116. dClient.login('')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement