Skip to content

Commit

Permalink
resolved issue with duplicate servers
Browse files Browse the repository at this point in the history
  • Loading branch information
kiawildberger committed Aug 14, 2020
1 parent 953a5ba commit a4379a0
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 1,181 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/src/node_modules
/src/.env
/src/config.json
/build/
/build/
/rubber-win32-x64
1,116 changes: 0 additions & 1,116 deletions package-lock.json

This file was deleted.

6 changes: 3 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600,
// frame: false,
icon: "./icon.png",
webPreferences: {
nodeIntegration: true
Expand All @@ -30,12 +31,11 @@ app.whenReady().then(() => {
})

/*
TODO:
- general polish
- FIX THE FUCKING ARROW FROM THE CHANNEL SELECT DIV
- emoji
- pings are fucked
- show user avatars and generally neaten up the displaying of messages
- some weird shit happening with pings like with the terraria message in summer 2950 #events
- show user-uploaded videos (add on to images, i think message.attachments)
- maybe rethink the color scheme but idk
- reduce the spacing between servers
Expand Down
5 changes: 3 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</head>

<body>
<!-- <div id="electron-titlebar" class="drag"><div id="titlebar-title" style="width: 100%; height: 100%; text-align: center; line-height: 40px; ">sign in</div></div> -->
<!-- i submitted an issue about the position:relative div, will uncomment and use electron-titlebar when i get resolution on it -->
<div id="bs">
<div id="bs-helper"></div>
<div class="bs-input-container">
Expand All @@ -26,11 +28,10 @@
<label for="channels">active channel:</label>
<select id="channels"></select>
</div> -->
<div id="serverlist">
<div id="serverlist">
<div class="serverlist-label">servers</div>
</div>
<div id="channellist" style="display:none;">
<img id="channel-triangle" style="top:17.5px;" src="assets/ctri.png">
<div class="channel-label">channels</div>
</div>
<span id="errout"></span>
Expand Down
63 changes: 46 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { ipcRenderer, shell } = require("electron")
const fs = require('fs')
const ps = require("./ps.js")
const elebar = require("electron-titlebar")
let conf = require('./config.json')
let confp = require.resolve('./config.json')
let Rsettings = require("./settings.json")
Expand All @@ -27,7 +28,7 @@ ipcRenderer.on("msg", processmsg)
function processmsg(event, arg) {
let e;
gids[index].channels.forEach(o => {
if(o.id === currentchannel) {
if (o.id === currentchannel) {
e = currentchannel
}
})
Expand Down Expand Up @@ -85,46 +86,74 @@ function processmsg(event, arg) {
}
}

function fillGuildSelect(arg) { // generates and populates guild list..?
function fillGuildSelect(arg) { // generates and populates guild list
if (!loggedin) return;
arg.forEach(e => {
let opt = document.createElement("img")
opt.setAttribute("class", "serverlist-item")
opt.setAttribute("data-index", arg.indexOf(e))
opt.setAttribute("src", e.icon)
opt.title = e.name
id('serverlist').appendChild(opt)
if (!e.abbr) {
let div = document.createElement('div')
let opt = document.createElement("img")
opt.setAttribute("class", "serverlist-item")
opt.setAttribute("data-index", arg.indexOf(e))
div.appendChild(opt)
opt.setAttribute("src", e.icon)
opt.title = e.name
let tri = document.createElement("div")
tri.classList.add("channel-triangle")
div.appendChild(tri)
tri.style.display = 'none'
id('serverlist').appendChild(div)
} else if (e.abbr) {
let opt = document.createElement('div')
opt.setAttribute("data-index", arg.indexOf(e))
opt.classList.add("serverlist-item")
let text = document.createElement("p")
text.textContent = e.abbr
opt.title = e.abbr
opt.appendChild(text)
let tri = document.createElement("div")
tri.classList.add("channel-triangle")
tri.style.display = 'none'
opt.appendChild(tri)
id('serverlist').appendChild(opt)
}
})
gids = arg
let q = [...document.querySelectorAll('.serverlist-item')]
q.forEach(e => {
e.addEventListener("click", () => {
if (q[q.indexOf(e)] != q) q.splice(q.indexOf(e), 1) // if this is duplicate of another one, should remove it
id('msgdisplay').innerHTML = ''
if (id('channellist').style.display === "none") id('channellist').style.display = 'block'
let r = [...document.querySelectorAll('.serverlist-active')]
r.forEach(e => e.classList.remove("serverlist-active"))
e.classList.add("serverlist-active")
let server = gids[e.getAttribute('data-index')]
index = e.getAttribute('data-index')
let tdistance = 17.5 + (75 * parseInt(e.getAttribute('data-index'))) + "px";
console.log(tdistance)
id('channellist').innerHTML = `<div id="channel-triangle"></div><div class="channel-label">channels</div>`
id('channel-triangle').style.top = tdistance;
server.channels.forEach(e => {
let tdistance = 68 + (75 * parseInt(e.getAttribute('data-index'))) + "px";
Array.from(document.querySelectorAll(".channel-triangle")).forEach(e => e.style.display = "none")
if(e.tagName === "IMG") {
e.nextElementSibling.style.display = 'block'
e.nextElementSibling.style.top = tdistance
} else {
e.querySelector('.channel-triangle').style.display = "block"
e.querySelector('.channel-triangle').style.top = tdistance
}
id('channellist').innerHTML = `<div class="channel-label">channels</div>`
let server = gids[e.getAttribute('data-index')]
server.channels.forEach(e => { // server.channels.forEach
let elm = document.createElement("div")
elm.classList.add("channel-item")
elm.textContent = "#" + e.name
elm.setAttribute('data-id', e.id)
elm.addEventListener("click", () => {
currentchannel = e.id
q = [...document.querySelectorAll(".activechannel")]
q.forEach(e => { e.classList.remove("activechannel")})
q.forEach(e => { e.classList.remove("activechannel") })
elm.classList.add("activechannel")
id('msgdisplay').innerHTML = ''
ipcRenderer.send("getChannelContent", e.id)
})
id("channellist").appendChild(elm)
if(server.channels.indexOf(e) === 0) elm.dispatchEvent(new Event('click'))
if (server.channels.indexOf(e) === 0) elm.dispatchEvent(new Event('click'))
})
})
})
Expand Down Expand Up @@ -158,9 +187,9 @@ ipcRenderer.on("validtoken", (event, args) => { // the *one* ipc i will use
setTimeout(() => {
id('userd').innerHTML = `acting as <b>${args.bot.full}</b>`
document.title = args.bot.full
// id('titlebar-title').textContent = args.bot.full
fillGuildSelect(args.guildInfo)
}, 800)
console.log(args)
})
id('bot-secret').addEventListener("keypress", e => {
if (e.keyCode != 13) return;
Expand Down
5 changes: 5 additions & 0 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"dependencies": {
"discord.js": "^12.1.1",
"dotenv": "^8.2.0",
"electron": "^8.2.4"
"electron": "^8.2.4",
"electron-titlebar": "0.0.3"
},
"devDependencies": {
"electron-packager": "^15.0.0"
Expand Down
19 changes: 11 additions & 8 deletions src/ps.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,31 @@ exports.init = function (win, tok) {
let client = new Discord.Client();
window = win;
client.on("ready", () => {
if(isLoggedIn) return;
client.guilds.cache.array().forEach(t => {
let channels = [], msgcontent = [];
t.channels.cache.array().forEach(e => {
if (e.type === "text") {
channels.push({ name: e.name, id: e.id })
}
})
gids.push({
icon: `https://cdn.discordapp.com/icons/${t.id}/${t.icon}.png`,
let ob = {
name: t.name,
id: t.id,
channels: channels
})
channels: channels,
}
if (t.icon) ob.icon = `https://cdn.discordapp.com/icons/${t.id}/${t.icon}.png`
if (!t.icon) ob.abbr = t.nameAcronym
gids.push(ob)
isLoggedIn = true
})
let tokens = {}
let botuser = client.user.username + "#" + client.user.discriminator
uinfo = {
name: client.user.username,
discrim: client.user.discriminator,
full: botuser
full: botuser,
guildNumber: client.guilds.cache.array().length
}
if (conf) tokens = conf;
tokens[botuser] = tok
Expand All @@ -55,7 +59,7 @@ exports.init = function (win, tok) {
});
client.login(tok)
.catch(err => {
console.log('invalid token?')
console.log('invalid token?') // need to send this to the user (something failed, try again?)
return "invalid token"
})
ipcMain.on("getChannelContent", (event, id) => {
Expand Down Expand Up @@ -111,7 +115,6 @@ exports.init = function (win, tok) {
arg.msg = arg.msg.replace(tagx, g[0].user)
}
if (arg.msg.toString().includes("/shrug")) arg.msg = arg.msg.replace("/shrug", "¯\_(ツ)_/¯")
console.log(arg)
client.channels.cache.get(arg.channel).send(arg.msg)
})

Expand Down Expand Up @@ -140,7 +143,7 @@ exports.init = function (win, tok) {
}
window.webContents.send("msg", { msg: m })
if (msg.content.includes("discord.gg")) {
console.log(msg)
console.log('someone sent a discord invite link: ' + msg.content)
}
}
}
Expand Down
28 changes: 21 additions & 7 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
body {
width:100%;
height:100%;
margin:0;
margin-top:2em;
padding:0;
overflow:hidden;
/* font-family:"ubuntu"; */
Expand All @@ -21,6 +21,7 @@ body {
height:80%;
overflow-y: auto;
position:absolute;
/* top:2em; */
top:0;
right:0;
border:1px solid rgb(66, 66, 66);
Expand All @@ -38,11 +39,11 @@ body {
.ping { color:#FA9A4B; }
.selfping { color:#FA001A; background:#C5F9FA; }
#bs {
width:100%;
height:100%;
/* width:100%;
height:50%;
padding-left:5em;
padding-top:2em;
/* background-color:#4A4D5D; */
background-color:#4A4D5D; */
}
#bot-secret {
width:100%;
Expand Down Expand Up @@ -130,6 +131,17 @@ body {
cursor:pointer;
transition:border-radius 0.2s ease;
}
div.serverlist-item {
width:50px;
height:50px;
background-color:#4b4b4b;
}
div.serverlist-item > p {
position:relative;
top:12.5px;
left:12.5px;
}

.serverlist-item:hover, .serverlist-active { border-radius:35%; }

#channellist {
Expand All @@ -145,11 +157,13 @@ body {
left:5.25em;
overflow-y: auto;
}
#channel-triangle {
.channel-triangle {
/* is little mf triangle */
position:absolute;
left:-0.5em;
/* top:attr(distance em 0); https://developer.mozilla.org/en-US/docs/Web/CSS/attr#Specifications */
left:4.75em;
border-top:0.5em solid transparent;
border-bottom:0.5em solid transparent;
border-right:0.5em solid #404040;
}
.channel-label {
font-size:1.2em;
Expand Down
Loading

0 comments on commit a4379a0

Please sign in to comment.