Skip to content

Commit 54e53fd

Browse files
committed
Minor changes
### UPDATED - Responses from the Invite Generator will be JSON from now on - Improved Invite Generator template code structure - jquery `v3.6.0` to `v3.6.1` for Invite Generator template ### ADDED - Guild member count and premium tier status passed onto Invite Generator templates as variables
1 parent 83b5567 commit 54e53fd

4 files changed

Lines changed: 132 additions & 78 deletions

File tree

invites-sample.ejs

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<%
2-
const dataSettingsGuildName = data.settingsGuildName;
3-
const dataSettingsRequestUrl = data.settingsRequestUrl;
4-
const dataRecaptchaSiteKey = data.recaptchaSiteKey;
2+
// Default variables you can use.
3+
const dataSettingsGuildName = data.settingsGuildName;
4+
const dataSettingsGuildMemberCount = data.settingsGuildMemberCount;
5+
const dataSettingsPremiumTier = data.settingsGuildPremiumTier;
6+
const dataSettingsRequestUrl = data.settingsRequestUrl;
7+
const dataRecaptchaSiteKey = data.recaptchaSiteKey;
58
%>
69
<!DOCTYPE html>
710
<!--
@@ -16,9 +19,9 @@
1619
-->
1720
<html lang="en">
1821
<head>
19-
<title>Join <%= dataSettingsGuildName %> Discord</title>
22+
<title>Join Discord - <%= dataSettingsGuildName %></title>
2023
<meta name="viewport" content="width=device-width, initial-scale=1.0">
21-
<script src="//code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
24+
<script src="//code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
2225
<script src="//www.google.com/recaptcha/api.js" async defer></script>
2326
<script type="text/javascript">
2427
/**
@@ -35,49 +38,67 @@
3538
$.post(`<%= dataSettingsRequestUrl %>`, {
3639
token: sessionToken,
3740
}, (success) => {
38-
console.log('Google reCAPTCHA verification success');
41+
console.log('Google reCAPTCHA verification success', success);
3942
40-
window.location.replace(success);
43+
$("#messages").html(`<span style="background-color: var(--global-color-success);">Thanks for verifying! Please wait while we redirect you to Discord…</span>`);
44+
45+
setTimeout(() => {
46+
window.location.href = success.url;
47+
}, 1000);
4148
}).fail((fail) => {
42-
console.error('Google reCAPTCHA verification failed');
49+
console.error('Google reCAPTCHA verification failed', fail);
4350
44-
$("#error").html(`<span>${fail.responseText} Please contact your server administrator.</span>`);
51+
$("#messages").html(`<span style="background-color: var(--global-color-error);">${fail.responseJSON.error} Please contact your server administrator.</span>`);
4552
});
4653
});
4754
}
4855
</script>
4956
<style>
57+
html {
58+
--global-color-white: #fff;
59+
--global-color-success: #00b74a;
60+
--global-color-error: #f93154;
61+
--global-color-warning: #ffa900;
62+
--global-color-information: #39c0ed;
63+
}
64+
5065
body {
5166
font-family: Helvetica, Arial, sans-serif;
5267
margin: 0;
53-
padding: 0;
68+
line-height: 1.5;
69+
}
70+
71+
h1,
72+
h2,
73+
h3,
74+
h4,
75+
h5,
76+
h6 {
77+
margin: 20px 0;
78+
}
79+
80+
p {
81+
margin: 20px 0;
5482
}
5583
5684
#content {
5785
display: flex;
86+
width: 100vw;
5887
height: 100vh;
88+
margin: 20px;
5989
text-align: center;
6090
flex-direction: column;
6191
justify-content: center;
6292
}
6393
64-
#content .container {
65-
margin: 5vh;
66-
}
67-
68-
#content #title h1,
69-
#content #title p {
70-
margin: 25px 0;
71-
}
72-
73-
#content #error span {
94+
#content #messages span {
7495
display: block;
75-
background-color: #ffe0e0;
76-
color: #ba3939;
77-
margin-bottom: 15px;
96+
background-color: var(--global-color-information);
97+
color: var(--global-color-white);
98+
margin: 0 0 20px;
7899
padding: 15px;
79-
border-radius: 5px;
80-
border: 1px solid #a33a3a;
100+
font-size: 14px;
101+
border-radius: 3px;
81102
}
82103
83104
#content .g-recaptcha div {
@@ -87,18 +108,17 @@
87108
</head>
88109
<body>
89110
<div id="content">
90-
<div class="container">
91-
<div id="title">
92-
<h1>Join <%= dataSettingsGuildName %> Discord</h1>
93-
<p>Congratulations! You are now using the <strong>custom</strong> invite template.</p>
94-
</div>
95-
<div id="form">
96-
<noscript>
97-
<p>JavaScript is required to view the Google reCAPTCHA widget.</p>
98-
</noscript>
99-
<div id="error"></div>
100-
<div class="g-recaptcha" data-sitekey="<%= dataRecaptchaSiteKey %>" data-callback="onSubmit"></div>
101-
</div>
111+
<div id="title">
112+
<h1>Join <%= dataSettingsGuildName %> Discord</h1>
113+
<p>Congratulations! You are now using the <strong>custom</strong> invite template.</p>
114+
</div>
115+
<div id="messages">
116+
<noscript>
117+
<span style="background-color: var(--global-color-warning);">Oops! JavaScript needs to be enabled in your browser before you can join.</span>
118+
</noscript>
119+
</div>
120+
<div id="form">
121+
<div class="g-recaptcha" data-sitekey="<%= dataRecaptchaSiteKey %>" data-callback="onSubmit"></div>
102122
</div>
103123
</div>
104124
</body>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "discord-stocker-bot",
33
"displayName": "Discord Stonker Bot",
4-
"version": "3.2.0",
4+
"version": "3.2.1",
55
"description": "An advanced bot built for finance-related Discord servers",
66
"main": "build/src/index.js",
77
"private": true,

src/modules/web-app.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ import {
8181
export function inviteGenerator(guild: InviteGeneratorGuild, webServer: InviteGeneratorWebServer, settings: InviteGeneratorSettings): InviteGeneratorReturns {
8282
const guildName = guild.name;
8383
const guildInvites = guild.invites;
84+
const guildMemberCount = guild.memberCount;
85+
const guildPremiumTier = guild.premiumTier;
8486
const guildRulesChannel = guild.rulesChannel;
8587

8688
const settingsOptionsPath = <InviteGeneratorSettingsOptionsPath>_.get(settings, ['options', 'path']);
@@ -217,6 +219,8 @@ export function inviteGenerator(guild: InviteGeneratorGuild, webServer: InviteGe
217219
response.status(200).contentType('text/html').render(loadTemplate(), {
218220
data: {
219221
settingsGuildName: guildName,
222+
settingsGuildMemberCount: guildMemberCount,
223+
settingsGuildPremiumTier: guildPremiumTier,
220224
settingsRequestUrl: requestUrl,
221225
recaptchaSiteKey: settingsRecaptchaSiteKey,
222226
},
@@ -296,7 +300,9 @@ export function inviteGenerator(guild: InviteGeneratorGuild, webServer: InviteGe
296300
}
297301

298302
if (!postResponseDataSuccess) {
299-
response.status(401).contentType('text/plain').send(errorMessage);
303+
response.status(401).contentType('application/json').json({
304+
error: errorMessage,
305+
});
300306
} else if (guildRulesChannel !== null) {
301307
generateLogMessage(
302308
[
@@ -311,6 +317,7 @@ export function inviteGenerator(guild: InviteGeneratorGuild, webServer: InviteGe
311317
maxUses: settingsOptionsMaxUses,
312318
reason: 'Visitor completed the invite verification',
313319
}).then((createResponse) => {
320+
const createResponseCode = createResponse.code;
314321
const createResponseUrl = createResponse.url;
315322

316323
generateLogMessage(
@@ -321,7 +328,10 @@ export function inviteGenerator(guild: InviteGeneratorGuild, webServer: InviteGe
321328
40,
322329
);
323330

324-
response.status(200).contentType('text/plain').send(createResponseUrl);
331+
response.status(200).contentType('application/json').json({
332+
code: createResponseCode,
333+
url: createResponseUrl,
334+
});
325335
}).catch((error: Error) => {
326336
errorMessage = 'The invite link could not be created.';
327337

@@ -334,7 +344,9 @@ export function inviteGenerator(guild: InviteGeneratorGuild, webServer: InviteGe
334344
error,
335345
);
336346

337-
response.status(500).contentType('text/plain').send(errorMessage);
347+
response.status(500).contentType('application/json').json({
348+
error: errorMessage,
349+
});
338350
});
339351
} else {
340352
errorMessage = 'The rules channel is not configured.';
@@ -347,7 +359,9 @@ export function inviteGenerator(guild: InviteGeneratorGuild, webServer: InviteGe
347359
10,
348360
);
349361

350-
response.status(500).contentType('text/plain').send(errorMessage);
362+
response.status(500).contentType('application/json').json({
363+
error: errorMessage,
364+
});
351365
}
352366
}).catch((error: Error) => {
353367
generateLogMessage(

src/views/invites.ejs

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<%
2-
const dataSettingsGuildName = data.settingsGuildName;
3-
const dataSettingsRequestUrl = data.settingsRequestUrl;
4-
const dataRecaptchaSiteKey = data.recaptchaSiteKey;
2+
// Default variables you can use.
3+
const dataSettingsGuildName = data.settingsGuildName;
4+
const dataSettingsGuildMemberCount = data.settingsGuildMemberCount;
5+
const dataSettingsPremiumTier = data.settingsGuildPremiumTier;
6+
const dataSettingsRequestUrl = data.settingsRequestUrl;
7+
const dataRecaptchaSiteKey = data.recaptchaSiteKey;
58
%>
69
<!DOCTYPE html>
710
<!--
@@ -16,9 +19,9 @@
1619
-->
1720
<html lang="en">
1821
<head>
19-
<title>Join <%= dataSettingsGuildName %> Discord</title>
22+
<title>Join Discord - <%= dataSettingsGuildName %></title>
2023
<meta name="viewport" content="width=device-width, initial-scale=1.0">
21-
<script src="//code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
24+
<script src="//code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
2225
<script src="//www.google.com/recaptcha/api.js" async defer></script>
2326
<script type="text/javascript">
2427
/**
@@ -35,49 +38,67 @@
3538
$.post(`<%= dataSettingsRequestUrl %>`, {
3639
token: sessionToken,
3740
}, (success) => {
38-
console.log('Google reCAPTCHA verification success');
41+
console.log('Google reCAPTCHA verification success', success);
3942
40-
window.location.replace(success);
43+
$("#messages").html(`<span style="background-color: var(--global-color-success);">Thanks for verifying! Please wait while we redirect you to Discord…</span>`);
44+
45+
setTimeout(() => {
46+
window.location.href = success.url;
47+
}, 1000);
4148
}).fail((fail) => {
42-
console.error('Google reCAPTCHA verification failed');
49+
console.error('Google reCAPTCHA verification failed', fail);
4350
44-
$("#error").html(`<span>${fail.responseText} Please contact your server administrator.</span>`);
51+
$("#messages").html(`<span style="background-color: var(--global-color-error);">${fail.responseJSON.error} Please contact your server administrator.</span>`);
4552
});
4653
});
4754
}
4855
</script>
4956
<style>
57+
html {
58+
--global-color-white: #fff;
59+
--global-color-success: #00b74a;
60+
--global-color-error: #f93154;
61+
--global-color-warning: #ffa900;
62+
--global-color-information: #39c0ed;
63+
}
64+
5065
body {
5166
font-family: Helvetica, Arial, sans-serif;
5267
margin: 0;
53-
padding: 0;
68+
line-height: 1.5;
69+
}
70+
71+
h1,
72+
h2,
73+
h3,
74+
h4,
75+
h5,
76+
h6 {
77+
margin: 20px 0;
78+
}
79+
80+
p {
81+
margin: 20px 0;
5482
}
5583
5684
#content {
5785
display: flex;
86+
width: 100vw;
5887
height: 100vh;
88+
margin: 20px;
5989
text-align: center;
6090
flex-direction: column;
6191
justify-content: center;
6292
}
6393
64-
#content .container {
65-
margin: 5vh;
66-
}
67-
68-
#content #title h1,
69-
#content #title p {
70-
margin: 25px 0;
71-
}
72-
73-
#content #error span {
94+
#content #messages span {
7495
display: block;
75-
background-color: #ffe0e0;
76-
color: #ba3939;
77-
margin-bottom: 15px;
96+
background-color: var(--global-color-information);
97+
color: var(--global-color-white);
98+
margin: 0 0 20px;
7899
padding: 15px;
79-
border-radius: 5px;
80-
border: 1px solid #a33a3a;
100+
font-size: 14px;
101+
border-radius: 3px;
81102
}
82103
83104
#content .g-recaptcha div {
@@ -87,17 +108,16 @@
87108
</head>
88109
<body>
89110
<div id="content">
90-
<div class="container">
91-
<div id="title">
92-
<h1>Join <%= dataSettingsGuildName %> Discord</h1>
93-
</div>
94-
<div id="form">
95-
<noscript>
96-
<p>JavaScript is required to view the Google reCAPTCHA widget.</p>
97-
</noscript>
98-
<div id="error"></div>
99-
<div class="g-recaptcha" data-sitekey="<%= dataRecaptchaSiteKey %>" data-callback="onSubmit"></div>
100-
</div>
111+
<div id="title">
112+
<h1>Join <%= dataSettingsGuildName %> Discord</h1>
113+
</div>
114+
<div id="messages">
115+
<noscript>
116+
<span style="background-color: var(--global-color-warning);">Oops! JavaScript needs to be enabled in your browser before you can join.</span>
117+
</noscript>
118+
</div>
119+
<div id="form">
120+
<div class="g-recaptcha" data-sitekey="<%= dataRecaptchaSiteKey %>" data-callback="onSubmit"></div>
101121
</div>
102122
</div>
103123
</body>

0 commit comments

Comments
 (0)