Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Discord = require('discord.js'),
- Client = new Discord.Client(),
- Electron = require('electron'),
- App = Electron.app,
- BrowserWindow = Electron.BrowserWindow,
- ipc = Electron.ipcMain,
- DiscordSettings = require('./settings.json');
- var Windows = Array(),
- Time = null,
- User = {},
- Session = Array(),
- Settings = {
- width: 800,
- height: 625,
- frame: true,
- resizable: false
- };
- var Library = {},
- UpdateEvents = Array(),
- Connection = Array();
- Library.add = {};
- Library.update = function() {
- UpdateEvents.forEach((item, index) => {
- item();
- });
- };
- Library.add.updateEvent = function(e) {
- if (typeof e !== 'function') {
- console.log(Time + 'Expected function at Library.add.updateEvent ( e )');
- return false;
- }
- UpdateEvents.push(e);
- return true;
- };
- Library.add.updateEvent(() => {
- var d = new Date(),
- h = (d.getHours() < 10 ? '0' : '') + d.getHours(),
- m = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes(),
- s = (d.getSeconds() < 10 ? '0' : '') + d.getSeconds();
- Time = '[' + h + ':' + m + ':' + s + '] ';
- });
- var upd = setInterval(Library.update, 200);
- App.on('ready', () => {
- Windows.push(new BrowserWindow(Settings));
- Windows[Windows.length - 1].setMenu(null);
- Windows[Windows.length - 1].loadURL('file://' + __dirname + '/html/login.html');
- Windows[Windows.length - 1].show();
- });
- ipc.on('login-attempt', (event, args) => {
- console.log(Time + 'Login | New sign in attempt triggered!');
- if (typeof args !== 'object' || args.token == undefined) {
- console.log(Time + 'Login | Invalid sign in attempt!');
- event.sender.send('login-attempt-error', 'Invalid request!');
- return false;
- }
- Client.login(args.token)
- .then(token => {
- console.log(Time + 'Login | Successfully signed into token: ' + token);
- Connection['chatChannel'] = Client.channels.get(DiscordSettings.DiscordStartupChannel);
- Client.channels.get(DiscordSettings.DiscordStartupVChannel).join().then(con => {
- Connection['voiceChannel'] = con;
- });
- Connection['chatChannel'].sendMessage(DiscordSettings.DiscordStartupMessage);
- })
- .catch(error => {
- console.log(Time + 'Login | Error: + ' + error);
- });
- });
- Client.on('ready', () => {
- Windows[Windows.length - 1].loadURL('file://' + __dirname + '/html/home/index.html');
- });
- App.on('before-quit', () => {
- console.log(Time + 'Discord | Disconnecting!');
- Connection['chatChannel'].sendMessage(DiscordSettings.DiscordQuitMessage);
- Connection['voiceChannel'].leave();
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement