Advertisement
TechnicCoder

Untitled

Feb 19th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Discord = require('discord.js'),
  2.     Client = new Discord.Client(),
  3.  
  4.     Electron = require('electron'),
  5.     App = Electron.app,
  6.     BrowserWindow = Electron.BrowserWindow,
  7.     ipc = Electron.ipcMain,
  8.     DiscordSettings = require('./settings.json');
  9.  
  10.  
  11. var Windows = Array(),
  12.     Time = null,
  13.     User = {},
  14.     Session = Array(),
  15.     Settings = {
  16.         width: 800,
  17.         height: 625,
  18.         frame: true,
  19.         resizable: false
  20.     };
  21.  
  22. var Library = {},
  23.     UpdateEvents = Array(),
  24.     Connection = Array();
  25.  
  26. Library.add = {};
  27.  
  28. Library.update = function() {
  29.     UpdateEvents.forEach((item, index) => {
  30.         item();
  31.     });
  32. };
  33.  
  34. Library.add.updateEvent = function(e) {
  35.     if (typeof e !== 'function') {
  36.         console.log(Time + 'Expected function at Library.add.updateEvent ( e )');
  37.         return false;
  38.     }
  39.  
  40.     UpdateEvents.push(e);
  41.     return true;
  42. };
  43.  
  44.  
  45.  
  46.  
  47.  
  48. Library.add.updateEvent(() => {
  49.     var d = new Date(),
  50.         h = (d.getHours() < 10 ? '0' : '') + d.getHours(),
  51.         m = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes(),
  52.         s = (d.getSeconds() < 10 ? '0' : '') + d.getSeconds();
  53.     Time = '[' + h + ':' + m + ':' + s + '] ';
  54. });
  55.  
  56.  
  57.  
  58. var upd = setInterval(Library.update, 200);
  59.  
  60.  
  61.  
  62.  
  63. App.on('ready', () => {
  64.     Windows.push(new BrowserWindow(Settings));
  65.     Windows[Windows.length - 1].setMenu(null);
  66.     Windows[Windows.length - 1].loadURL('file://' + __dirname + '/html/login.html');
  67.     Windows[Windows.length - 1].show();
  68. });
  69.  
  70. ipc.on('login-attempt', (event, args) => {
  71.     console.log(Time + 'Login | New sign in attempt triggered!');
  72.  
  73.     if (typeof args !== 'object' || args.token == undefined) {
  74.         console.log(Time + 'Login | Invalid sign in attempt!');
  75.         event.sender.send('login-attempt-error', 'Invalid request!');
  76.         return false;
  77.     }
  78.  
  79.     Client.login(args.token)
  80.         .then(token => {
  81.             console.log(Time + 'Login | Successfully signed into token: ' + token);
  82.             Connection['chatChannel'] = Client.channels.get(DiscordSettings.DiscordStartupChannel);
  83.             Client.channels.get(DiscordSettings.DiscordStartupVChannel).join().then(con => {
  84.                 Connection['voiceChannel'] = con;
  85.             });
  86.  
  87.             Connection['chatChannel'].sendMessage(DiscordSettings.DiscordStartupMessage);
  88.  
  89.         })
  90.         .catch(error => {
  91.             console.log(Time + 'Login | Error:  + ' + error);
  92.         });
  93. });
  94.  
  95. Client.on('ready', () => {
  96.     Windows[Windows.length - 1].loadURL('file://' + __dirname + '/html/home/index.html');
  97. });
  98.  
  99. App.on('before-quit', () => {
  100.     console.log(Time + 'Discord | Disconnecting!');
  101.     Connection['chatChannel'].sendMessage(DiscordSettings.DiscordQuitMessage);
  102.     Connection['voiceChannel'].leave();
  103. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement