Skip to content

Commit 8dba072

Browse files
committed
Added Invites, edit bots, edit code, code editor settings
1 parent 1ea09f9 commit 8dba072

11 files changed

Lines changed: 301 additions & 42 deletions

File tree

forge.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ module.exports = {
3232
},
3333
{
3434
"name": "@electron-forge/maker-zip"
35-
}
35+
},
36+
{
37+
name: 'electron-forge-maker-appimage',
38+
platforms: ['linux'],
39+
},
3640
],
3741
};

package-lock.json

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/BotModals/AddBot.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const shell = require('electron').shell;
77
export const AddBot = ({ htmlFor, bots, setBots }) => {
88
const botDirectory = useRef(0);
99
const botName = useRef(0);
10+
const clientID = useRef(0);
1011
const botToken = useRef(0);
1112

1213
return (
@@ -23,6 +24,8 @@ export const AddBot = ({ htmlFor, bots, setBots }) => {
2324

2425
<div className="divider mx-0"></div>
2526

27+
<input id="clientID" ref={clientID} placeholder="Application/Client ID" className="input w-full bg-neutral" type="text" />
28+
2629
<div className='flex flex-row space-x-3'>
2730
<input id="token" ref={botToken} placeholder="Bot Token (keep private)" className="input w-full bg-neutral" type="password" />
2831
<div className="btn bg-[#5865F2] hover:bg-[#4c58d3] text-shadow-black" onClick={() => {
@@ -49,7 +52,7 @@ export const AddBot = ({ htmlFor, bots, setBots }) => {
4952

5053
botDirectory.current.value == botDirectory.current.value.substr(0 - botDirectory.current.value.lastIndexOf(".zip"))
5154

52-
Store.AddNewBot(botName.current.value, botDirectory.current.value, botToken.current.value)
55+
Store.AddNewBot(botName.current.value, clientID.current.value, botDirectory.current.value, botToken.current.value)
5356

5457
setBots(JSON.parse(localStorage.getItem('bots')))
5558

@@ -63,15 +66,17 @@ export const AddBot = ({ htmlFor, bots, setBots }) => {
6366
});
6467
}
6568

66-
Store.AddNewBot(botName.current.value, botDirectory.current.value, botToken.current.value)
69+
Store.AddNewBot(botName.current.value, clientID.current.value, botDirectory.current.value, botToken.current.value)
6770

6871
setBots(JSON.parse(localStorage.getItem('bots')))
6972

7073
document.getElementById('directory').value = ""
7174
document.getElementById('name').value = ""
75+
document.getElementById('clientID').value = ""
76+
document.getElementById('token').value = ""
7277

7378
activateToast("botAddedToast")
74-
}} htmlFor={htmlFor} className="btn bg-info">Add Bot</label>
79+
}} htmlFor={htmlFor} className="btn bg-info hover:bg-info/70">Add Bot</label>
7580
</div>
7681
</div>
7782
</div>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React, { useRef } from 'react';
2+
import * as Store from "../../Store";
3+
import * as Manager from "../../Manager"
4+
5+
import secureLocalStorage from "react-secure-storage";
6+
7+
import { useNavigate } from "react-router-dom";
8+
9+
10+
export const EditBot = ({ htmlFor, botInfo, setBotInfo }) => {
11+
const botDirectory = useRef(0);
12+
const botName = useRef(0);
13+
const clientID = useRef(0);
14+
const botToken = useRef(0);
15+
16+
const navigate = useNavigate();
17+
18+
return (
19+
<>
20+
<input type="checkbox" id={htmlFor} className="modal-toggle" />
21+
<div className="modal">
22+
<div className="modal-box max-w-[42rem] space-y-2">
23+
<h3 className="font-bold text-lg">Edit details for {botInfo.name}?</h3>
24+
<div className="w-full space-y-3">
25+
<div className='space-y-1.5'>
26+
<h3>Name:</h3>
27+
<input id="name" ref={botName} defaultValue={botInfo.name} placeholder="Bot Name" className="input w-full bg-neutral" type="text" />
28+
</div>
29+
30+
<div className='space-y-1.5'>
31+
<h3>Directory:</h3>
32+
<input id="directory" ref={botDirectory} defaultValue={botInfo.path} placeholder="Path to Bot Folder" className="input w-full bg-neutral" type="text" />
33+
</div>
34+
35+
36+
<div className="divider mx-0"></div>
37+
38+
<div className='space-y-1.5'>
39+
<h3>Application/Client ID:</h3>
40+
<input id="clientID" ref={clientID} defaultValue={botInfo.clientID} placeholder="Application/Client ID" className="input w-full bg-neutral" type="text" />
41+
</div>
42+
43+
<div className='space-y-1.5'>
44+
<h3>Bot Token (leave empty to keep the same):</h3>
45+
<div className='flex flex-row space-x-3'>
46+
<input id="token" ref={botToken} placeholder="Bot Token (keep private)" className="input w-full bg-neutral" type="password" />
47+
<div className="btn bg-[#5865F2] hover:bg-[#4c58d3] text-shadow-black" onClick={() => {
48+
shell.openExternal("https://discord.com/developers/applications")
49+
50+
activateToast("discordToast")
51+
}}>Developer Portal</div>
52+
</div>
53+
</div>
54+
</div>
55+
56+
<div className="divider"></div>
57+
58+
<div className="modal-action">
59+
<label htmlFor={htmlFor} className="btn">Cancel</label>
60+
<label onClick={() => {
61+
Manager.stopBot(botInfo.name).then(() => {
62+
let token = secureLocalStorage.getItem(`${botInfo.name}`)
63+
64+
if (botToken.current.value.length == 0) {
65+
Store.AddNewBot(botName.current.value, clientID.current.value, botDirectory.current.value, token)
66+
} else {
67+
Store.AddNewBot(botName.current.value, clientID.current.value, botDirectory.current.value, botToken.current.value)
68+
}
69+
70+
Store.RemoveBot(botInfo.name)
71+
72+
let botNewData = { name: botName.current.value, clientID: clientID.current.value, path: botDirectory.current.value, invites: botInfo.invites }
73+
74+
setBotInfo(botNewData)
75+
76+
document.getElementById('directory').value = ""
77+
document.getElementById('name').value = ""
78+
document.getElementById('clientID').value = ""
79+
document.getElementById('token').value = ""
80+
81+
navigate("/")
82+
})
83+
}} htmlFor={htmlFor} className="btn bg-info/80 text-shadow-white">Update Details</label>
84+
</div>
85+
</div>
86+
</div>
87+
</>
88+
89+
);
90+
};
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import React, { useEffect, useRef, useState } from 'react';
2+
import { useParams, Link } from "react-router-dom";
3+
4+
const shell = require('electron').shell;
5+
const storage = window.localStorage
6+
7+
import { ToastElement, activateToast } from '../Toast.jsx';
8+
9+
export const Invites = ({ htmlFor, botInfo }) => {
10+
const permsIntRef = useRef(String);
11+
12+
let id = useParams().id
13+
14+
const [botInfoState, setBotInfo] = useState(Array)
15+
const [invites, setInvites] = useState(Array)
16+
17+
useEffect(() => {
18+
JSON.parse(storage.getItem('bots')).forEach(function (item, index) {
19+
if (item.name == id) {
20+
setBotInfo(item)
21+
22+
setInvites(item.invites)
23+
}
24+
});
25+
}, []);
26+
27+
return (
28+
<>
29+
<input type="checkbox" id={htmlFor} className="modal-toggle" />
30+
<div className="modal flex flex-col space-y-5">
31+
<div className="modal-box max-w-[80rem] space-y-2">
32+
<h3 className="font-bold text-lg">Invites</h3>
33+
34+
{invites.length == 0 ? (
35+
<>
36+
<h1 className='p-2'>No Invites Found...</h1>
37+
</>
38+
) : (
39+
<table className="table border-separate table-auto">
40+
<thead>
41+
<tr>
42+
<td className='justify-center text-center'>#</td>
43+
<th className='grow'>Link</th>
44+
<th className='justify-center text-center'>Perms Integer</th>
45+
</tr>
46+
</thead>
47+
<tbody>
48+
{invites.map((invite, index) => (
49+
<tr key={index}>
50+
<td className="w-12 text-center">{index + 1}</td>
51+
<td id={`tooltip-${index}`} className='tooltip transition-all hover:text-white/60' data-tip="Click to copy!" onClick={() => {
52+
navigator.clipboard.writeText(invite.link);
53+
54+
document.getElementById(`tooltip-${index}`).classList.add("opacity-60")
55+
56+
setTimeout(() => {
57+
document.getElementById(`tooltip-${index}`).classList.remove("opacity-60")
58+
}, 200)
59+
}}>{invite.link}</td>
60+
<td className='justify-center text-center'>{invite.perms}</td>
61+
</tr>
62+
))}
63+
</tbody>
64+
</table>
65+
)}
66+
</div>
67+
68+
<div className="modal-box max-w-[80rem] space-y-2">
69+
<h3 className="font-bold text-lg">Generate Bot Invite</h3>
70+
71+
<div className="divider"></div>
72+
73+
<div>
74+
<h2 className='text-md mb-2'>Permissions Integer</h2>
75+
<input id="permsInt" ref={permsIntRef} defaultValue={"8"} placeholder="Permissions Integer" className="input w-full bg-neutral" type="text" />
76+
<div className='text-xs mt-2 opacity-70'>default = administrator (8)</div>
77+
</div>
78+
79+
80+
<div className="divider"></div>
81+
82+
<div className="modal-action">
83+
<label htmlFor={htmlFor} className="btn">Cancel</label>
84+
<label onClick={() => {
85+
const link = `https://discord.com/oauth2/authorize?client_id=${botInfoState.clientID}&scope=bot&permissions=${permsIntRef.current.value}`
86+
87+
JSON.parse(storage.getItem('bots')).forEach(function (item, index) {
88+
if (item.name == id) {
89+
let bots = JSON.parse(storage.getItem('bots'))
90+
91+
let invitesCache = invites
92+
93+
invitesCache.push({
94+
link: `${link}`,
95+
perms: `${permsIntRef.current.value}`
96+
})
97+
98+
setInvites(invitesCache)
99+
100+
item.invites = invitesCache
101+
102+
bots[index] = item
103+
104+
storage.setItem(`bots`, JSON.stringify(bots))
105+
106+
console.log(`Success: Added invite with link: ${link}, And perms: ${permsIntRef.current.value}`)
107+
}
108+
});
109+
}} className="btn bg-info hover:bg-info/70 text-shadow-white">Create Invite</label>
110+
</div>
111+
</div>
112+
</div>
113+
114+
<ToastElement content={"Discord Developer Portal Opened"} type={"info"} toastId={"discordToast"}></ToastElement>
115+
</>
116+
117+
);
118+
};

src/Routes/BotPage.jsx

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,43 @@ import { useParams, Link } from "react-router-dom";
22
import React, { useState, useEffect } from 'react';
33
import * as Bots from "../Store";
44

5+
import { EditBot } from '../Components/BotModals/EditBot.jsx'
56
import { RemoveBot } from '../Components/BotModals/RemoveBotModal.jsx'
7+
import { Invites } from '../Components/BotModals/Invites.jsx'
68

79
import * as Manager from "../Manager"
810

11+
const storage = window.localStorage
12+
913
const BotPage = () => {
14+
const [bots, setBots] = useState(JSON.parse(localStorage.getItem('bots')));
15+
1016
const [botInfo, setBotInfo] = useState(Array);
1117
const [isOnline, setIsOnline] = useState(Boolean);
1218
const [terminal, setTerminal] = useState([]);
1319

1420
let id = useParams().id
21+
1522

1623
useEffect(() => {
17-
JSON.parse(localStorage.getItem('bots')).forEach(function (item, index) {
24+
JSON.parse(storage.getItem('bots')).forEach(function (item, index) {
1825
if (item.name == id) {
1926
setBotInfo(item)
2027
}
2128
});
2229
}, []);
2330

31+
try {
32+
storage.getItem('defaultCodeEditor')
33+
} catch {
34+
storage.setItem('defaultCodeEditor', 'code')
35+
}
36+
2437
return (
2538
<div className="content flex flex-col grow max-h-[calc(100vh_-_4rem)]">
39+
<EditBot htmlFor={"editBot"} botInfo={botInfo} setBotInfo={setBotInfo}></EditBot>
2640
<RemoveBot htmlFor={"removeBot"} botInfo={botInfo}></RemoveBot>
41+
<Invites htmlFor={"invites"} botInfo={botInfo}></Invites>
2742

2843
<div className="mb-5">
2944
<h1 className="text-2xl text-shadow-white">{botInfo.name}</h1>
@@ -46,27 +61,31 @@ const BotPage = () => {
4661
Start
4762
</div>}
4863

49-
<div onClick={() => { }} className="btn bg-info hover:bg-info/75 text-shadow-white">Edit</div>
64+
<div data-tip={`Command: ${storage.getItem('defaultCodeEditor')} <bot folder>`} className="tooltip">
65+
<div onClick={() => {
66+
const { exec } = require('child_process');
67+
const openExplorer = require('open-file-explorer');
68+
69+
exec(`${storage.getItem('defaultCodeEditor')} ${botInfo.path}`, (err, stdout, stderr) => {
70+
if (err) {
71+
openExplorer(`${botInfo.path}`, err => {
72+
if (err) {
73+
console.log(err);
74+
}
75+
})
76+
}
77+
});
78+
}} className="btn bg-info text-shadow-white hover:bg-info/75">Edit Code</div>
79+
</div>
5080

51-
<div onClick={() => {
52-
const { exec } = require('child_process');
53-
const openExplorer = require('open-file-explorer');
5481

55-
exec(`code ${botInfo.path}`, (err, stdout, stderr) => {
56-
if (err) {
57-
// node couldn't execute the command
58-
openExplorer(botinfo.path, err => {
59-
if (err) {
60-
console.log(err);
61-
}
62-
})
63-
}
64-
});
65-
}} className="btn bg-dark hover:bg-dark/75 text-shadow-white">Open</div>
82+
<label htmlFor="invites" className="btn bg-info text-shadow-white hover:bg-info/75">Invites</label>
6683

6784
<div className="divider divider-horizontal"></div>
6885

69-
<label htmlFor="removeBot" className="btn bg-dark/75 hover:bg-error text-shadow-white">Remove bot</label>
86+
<label htmlFor="editBot" className="btn bg-base-100 text-shadow-white hover:bg-info/75">Edit bot</label>
87+
88+
<label htmlFor="removeBot" className="btn bg-base-100 text-shadow-white hover:bg-error/75">Remove bot</label>
7089
</div>
7190

7291
{isOnline &&

0 commit comments

Comments
 (0)