Skip to content

Commit

Permalink
pings visualised lmao
Browse files Browse the repository at this point in the history
  • Loading branch information
kiawildberger committed Apr 15, 2020
1 parent ec93502 commit 52a1a76
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ function createWindow() {

app.whenReady().then(() => {
createWindow()
ps.init(win, process.env.TOKEN)
ipcMain.on("startbot", (event, tok) => {
ps.init(win, tok)
})
})
6 changes: 5 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
</head>

<body>
<div class="container">
<div id="bs">
<label for="bot-secret">bot secret: </label>
<input id="bot-secret" type="password">
</div>
<div class="container" style="display:none;">
<div id="guild-container">
<label for="guilds">active guild:</label>
<select id="guilds"></select>
Expand Down
36 changes: 31 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@ function id(e) { return document.getElementById(e) }
ipcRenderer.on("msg", (event, arg) => {
let ul = document.createElement("ul")
ul.classList.add("msg")
ul.textContent = arg.msg.author.username + "#" + arg.msg.author.discriminator + ": " + arg.msg.content
let ct = arg.msg.content
let mt = ct.match(/.*#[0-9]{4}/)
if(mt) {
mt = mt[0]
mt = mt.split("@")
let sp = []
mt.forEach(e => {
if(e) sp.push(`<span class="png">@${e}</span>`)
})
ct = ct.replace(/@.*#\d{4}/, sp.join(" "))
}
ul.innerHTML = arg.msg.author.username + "#" + arg.msg.author.discriminator + ": " + ct
ul.setAttribute("data-channel", arg.msg.channel)
id("msgdisplay").appendChild(ul)
id('msgdisplay').scrollTop = id('msgdisplay').scrollHeight
})

let gids, gna = [], ccids = [], cna = [];
ipcRenderer.on("gids", (event, arg) => {
let nn = document.createElement('option')
nn.setAttribute("value", "none")
nn.innerText = "none"
id('guilds').appendChild(nn)
arg.forEach(e => {
let opt = document.createElement("option")
opt.setAttribute("value", e.name)
Expand All @@ -20,17 +35,20 @@ ipcRenderer.on("gids", (event, arg) => {
gna.push(e.name)
})
gids = arg
console.log(gna)
})
let currentchannel;
id('guilds').addEventListener('change', e => {
// let r = e.target.innerText.split("\n")
// let guild = gids[r.indexOf(e.target.value)] // is guild ig
// let guild = gids[gna.indexOf(e.target.value)].id
if(e.target.value === "none") {
id('channels').innerHTML = '<option>none</option>'
id('msgdisplay').innerText = ''
return;
}
id('msgdisplay').innerText = ''
let idx = gna.indexOf(e.target.value)
ipcRenderer.send("rcids", idx)
})

id('channels').addEventListener("change", () => id('msgdisplay').innerText = '')

ipcRenderer.on("cids", (event, arg) => {
id('channels').innerHTML = ''
Expand All @@ -44,8 +62,16 @@ ipcRenderer.on("cids", (event, arg) => {
})
})

id('bot-secret').addEventListener("keypress", e => {
if(e.keyCode != 13) return;
ipcRenderer.send("startbot", e.target.value)
id('bs').style.display = "none"
document.querySelector('.container').style.display = "block"
})

id("msgin").addEventListener("keypress", e => {
if (e.keyCode !== 13) return;
if(id("channels").value === "")
currentchannel = ccids[cna.indexOf(id('channels').value)]
ipcRenderer.send("msgin", {
msg: id("msgin").value,
Expand Down
19 changes: 18 additions & 1 deletion src/ps.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let lastmessage;
let isLoggedIn = false
let gids = []
let cids = []
let tagx = /.*#[0-9]{4}/
let uidx = /<@!\d+>/

exports.init = function(win, tok) {
window = win;
Expand All @@ -29,6 +31,13 @@ exports.init = function(win, tok) {
});
client.login(tok);
ipcMain.on("msgin", (event, arg) => {
if(arg.msg.toString().match(tagx)) {
// is ping
let un = arg.msg.toString().match(tagx)[0].toString().split("#")[0].replace("@", '')
let g = client.channels.cache.get(arg.channel).guild.members.cache.filter(x => x.user.username === un).array()
arg.msg = arg.msg.replace(tagx, g[0].user)
}
if(arg.msg.toString().includes("/shrug")) arg.msg = arg.msg.replace("/shrug", "¯\_(ツ)_/¯")
client.channels.cache.get(arg.channel).send(arg.msg)
})
// channels.cache.filter(c => c.type === "text")
Expand All @@ -44,8 +53,16 @@ exports.init = function(win, tok) {

function process(msg) {
if(settings.mode === "user") {
let ct = msg.content
if(msg.mentions) {
let mts = msg.mentions.users.array()
mts.forEach(e => {
let i = `@${e.username}#${e.discriminator}`
ct = ct.replace(uidx, i)
})
}
let m = {
content: msg.content,
content: ct,
author: msg.author,
channel: msg.channel.id
}
Expand Down
4 changes: 3 additions & 1 deletion src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ body { }
overflow-y: scroll;
position:relative;
bottom:0;
}
}

.png { color:red; }

0 comments on commit 52a1a76

Please sign in to comment.