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+ } ;
0 commit comments