-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules_menuHelper.js.html
More file actions
383 lines (332 loc) · 22.8 KB
/
modules_menuHelper.js.html
File metadata and controls
383 lines (332 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Source: modules/menuHelper.js | Source: modules/menuHelper.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-jsdoc.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/tui-doc.css">
</head>
<body>
<nav class="lnb" id="lnb">
<div class="logo" style="width: 100px; height: 100px">
<a href="https://github.com/Project-Skill-Tree/Skill-Tree-Discord-Bot" rel="noopener noreferrer" target="_blank">
<img src="https://cdn.discordapp.com/attachments/939508059758288939/979289803239608360/FinalLogoAlt2.png" width="100%" height="100%">
</a>
</div>
<div class="title">
<h1><a href="index.html" class="link">Source: modules/menuHelper.js</a></h1>
</div>
<div class="search-container" id="search-container">
<input type="text" placeholder="Search">
<ul></ul>
</div>
<div class="lnb-api hidden"><h3>Modules</h3><ul><li><a href="module-APIHelper.html">APIHelper</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:APIHelper_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-APIHelper.html#.cancel">cancel</a></li><li><a href="module-APIHelper.html#.deleteTask">deleteTask</a></li><li><a href="module-APIHelper.html#.getAllInList">getAllInList</a></li><li><a href="module-APIHelper.html#.getAvailable">getAvailable</a></li><li><a href="module-APIHelper.html#.getCurrentTasks">getCurrentTasks</a></li><li><a href="module-APIHelper.html#.getInProgress">getInProgress</a></li><li><a href="module-APIHelper.html#.getRecentTasks">getRecentTasks</a></li><li><a href="module-APIHelper.html#.revert">revert</a></li><li><a href="module-APIHelper.html#.skip">skip</a></li><li><a href="module-APIHelper.html#.start">start</a></li><li><a href="module-APIHelper.html#.updateTask">updateTask</a></li><li><a href="module-APIHelper.html#~getAPIKey">getAPIKey</a></li></ul></div></li><li><a href="module-badge.html">badge</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:badge_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-badge.html#.drawBadge">drawBadge</a></li><li><a href="module-badge.html#.getBadgeIcon">getBadgeIcon</a></li></ul></div></li><li><a href="module-createSwipePanel.html">createSwipePanel</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:createSwipePanel_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-createSwipePanel.html#.createLargeMultiActionSwipePanel">createLargeMultiActionSwipePanel</a></li><li><a href="module-createSwipePanel.html#.createLargeSwipePanel">createLargeSwipePanel</a></li><li><a href="module-createSwipePanel.html#.createYesNoPanel">createYesNoPanel</a></li></ul></div></li><li><a href="module-frequencyFormatter.html">frequencyFormatter</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:frequencyFormatter_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-frequencyFormatter.html#.dayToDate">dayToDate</a></li><li><a href="module-frequencyFormatter.html#.formatFrequency">formatFrequency</a></li><li><a href="module-frequencyFormatter.html#.getAbsDate">getAbsDate</a></li><li><a href="module-frequencyFormatter.html#.getDaysBetweenDates">getDaysBetweenDates</a></li></ul></div></li><li><a href="module-ProfileRenderer.html">ProfileRenderer</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:ProfileRenderer_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-ProfileRenderer.html#.displayLevelUp">displayLevelUp</a></li><li><a href="module-ProfileRenderer.html#.displayProfile">displayProfile</a></li><li><a href="module-ProfileRenderer.html#.getProfileImage">getProfileImage</a></li><li><a href="module-ProfileRenderer.html#~drawProfile">drawProfile</a></li><li><a href="module-ProfileRenderer.html#~drawProfileInfo">drawProfileInfo</a></li><li><a href="module-ProfileRenderer.html#~drawXP">drawXP</a></li><li><a href="module-ProfileRenderer.html#~getLevelUpProfileImage">getLevelUpProfileImage</a></li></ul></div></li><li><a href="module-romanNumeralHelper.html">romanNumeralHelper</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:romanNumeralHelper_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-romanNumeralHelper.html#.romanise">romanise</a></li></ul></div></li><li><a href="module-UIHelper.html">UIHelper</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:UIHelper_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-UIHelper.html#.addGlow">addGlow</a></li><li><a href="module-UIHelper.html#.codeBlock">codeBlock</a></li><li><a href="module-UIHelper.html#.fillRoundRect">fillRoundRect</a></li><li><a href="module-UIHelper.html#.imageToBuffer">imageToBuffer</a></li><li><a href="module-UIHelper.html#.splitToN">splitToN</a></li><li><a href="module-UIHelper.html#.strokeRoundRect">strokeRoundRect</a></li><li><a href="module-UIHelper.html#.tint">tint</a></li></ul></div></li><li><a href="module-WeeklyReviewRenderer.html">WeeklyReviewRenderer</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:WeeklyReviewRenderer_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-WeeklyReviewRenderer.html#.displayReview">displayReview</a></li><li><a href="module-WeeklyReviewRenderer.html#~drawHeaderFooter">drawHeaderFooter</a></li><li><a href="module-WeeklyReviewRenderer.html#~drawTasks">drawTasks</a></li><li><a href="module-WeeklyReviewRenderer.html#~drawXP">drawXP</a></li><li><a href="module-WeeklyReviewRenderer.html#~getWeeklyReview">getWeeklyReview</a></li></ul></div></li><li><a href="module-XPHandler.html">XPHandler</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:XPHandler_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-XPHandler.html#.calcLevelFromXP">calcLevelFromXP</a></li><li><a href="module-XPHandler.html#.calcXPFromLevel">calcXPFromLevel</a></li><li><a href="module-XPHandler.html#.calcXPToLevelUp">calcXPToLevelUp</a></li><li><a href="module-XPHandler.html#.getCharacter">getCharacter</a></li><li><a href="module-XPHandler.html#.getColor">getColor</a></li><li><a href="module-XPHandler.html#.getRank">getRank</a></li></ul></div></li></ul></div><div class="lnb-api hidden"><h3>Classes</h3><ul><li><a href="Challenge.html">Challenge</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Challenge_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="Challenge.html#.create">create</a></li><li><a href="Challenge.html#update">update</a></li></ul></div></li><li><a href="Item.html">Item</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Item_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="Item.html#.create">create</a></li><li><a href="Item.html#toLine">toLine</a></li><li><a href="Item.html#toString">toString</a></li><li><a href="Item.html#update">update</a></li></ul></div></li><li><a href="ListPage.html">ListPage</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="ListPage_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="ListPage.html#update">update</a></li></ul></div></li><li><a href="Page.html">Page</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Page_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="Page.html#update">update</a></li></ul></div></li><li><a href="Rank.html">Rank</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Rank_sub"></div></li><li><a href="Setting.html">Setting</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Setting_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="Setting.html#start">start</a></li></ul></div></li><li><a href="Skill.html">Skill</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Skill_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="Skill.html#.create">create</a></li><li><a href="Skill.html#update">update</a></li></ul></div></li><li><a href="Task.html">Task</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Task_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="Task.html#.create">create</a></li><li><a href="Task.html#isChecked">isChecked</a></li><li><a href="Task.html#percentChecked">percentChecked</a></li><li><a href="Task.html#setChecked">setChecked</a></li></ul></div></li><li><a href="Unlocked.html">Unlocked</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Unlocked_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="Unlocked.html#update">update</a></li></ul></div></li><li><a href="User.html">User</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="User_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="User.html#.create">create</a></li></ul></div></li></ul></div><div class="lnb-api hidden"><h3>Interfaces</h3><ul><li><a href="Swipeable.html">Swipeable</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Swipeable_sub"></div></li></ul></div><div class="lnb-api hidden"><h3>Global</h3><ul><li><a href="global.html#addXP">addXP</a></li><li><a href="global.html#authUser">authUser</a></li><li><a href="global.html#createUser">createUser</a></li><li><a href="global.html#deleteUser">deleteUser</a></li><li><a href="global.html#getAPIKey">getAPIKey</a></li><li><a href="global.html#getSettings">getSettings</a></li><li><a href="global.html#getUser">getUser</a></li><li><a href="global.html#getUsers">getUsers</a></li><li><a href="global.html#getUsersInTimezone">getUsersInTimezone</a></li><li><a href="global.html#permlevel">permlevel</a></li><li><a href="global.html#saveProfile">saveProfile</a></li><li><a href="global.html#toProperCase">toProperCase</a></li><li><a href="global.html#updateTimezone">updateTimezone</a></li><li><a href="global.html#updateUser">updateUser</a></li><li><a href="global.html#updateXPHistory">updateXPHistory</a></li></ul></div>
</nav>
<div id="resizer"></div>
<div class="main" id="main">
<section>
<article>
<pre class="prettyprint source linenums"><code>const {MessageActionRow, MessageButton, MessageEmbed} = require("discord.js");
const {MessageSelectMenu} = require("discord.js");
/** @module createSwipePanel */
/**
* Create swipeable panel
* Adds left/right embedded buttons to a discord message to navigate through a swipeable list
* List is cyclic and cycles back to the start
* @param interaction - discord interaction
* @param embed - embed to query
* @param files - optional files to include
*/
exports.createYesNoPanel = async (interaction, embed, files=[]) => {
//Add left/right messageButton to message
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId("yes")
.setLabel("YES")
.setStyle("PRIMARY"),
new MessageButton()
.setCustomId("no")
.setLabel("NO")
.setStyle("PRIMARY"),
);
const followUp = await interaction.followUp({embeds: [embed], files: files, components: [row], ephemeral: interaction.settings.hidden});
//Create listener for button events
const filter = i => (i.customId === "yes" || i.customId === "no") && i.user.id === interaction.user.id;
const collector = await followUp.createMessageComponentCollector({componentType : "BUTTON", filter, time: 240000});
return await new Promise((resolve, reject) => {
collector.on("collect", async i => {
await i.deferUpdate();
switch (i.customId) {
case "yes":
resolve(true);
break;
case "no":
resolve(false);
break;
default:
reject(new Error("Invalid option in yes/no panel"));
break;
}
});
});
};
/**
* Create swipeable panel
* Adds left/right embedded buttons to a discord message to navigate through the swipeable list
* List is cyclic and cycles back to the start
* @param {Client} client - Discord bot client
* @param interaction - Message from the user
* @param list - List of swipeable objects
* @param actions - action name: string, description: string, action: function map
* item as parameter - return value is T/F based on whether this item will be removed or not
* @param refresh - action to happen on update
*/
exports.createLargeSwipePanel = async (client, interaction,
list, actions = null, refresh=null) => {
let currentPage = 0;
let options = await update(interaction, list, currentPage, actions);
let message;
// eslint-disable-next-line no-prototype-builtins
if (Object.prototype.hasOwnProperty.call(interaction, "channelType")) {
if (Object.prototype.hasOwnProperty.call(interaction,"options")) {
options = Object.assign({}, options, interaction.options);
}
await interaction.interaction.webhook.editMessage(interaction.message, options);
message = interaction.message;
} else {
message = await interaction.editReply(options);
}
//Create listener for navigation events
const filter = i => (i.customId === "prev"
|| i.customId === "next"
|| i.customId === "first"
|| i.customId === "last") && i.user.id === interaction.user.id;
const collector = message.createMessageComponentCollector({filter, time: 240000});
collector.on("collect", async i => {
if (!i.isButton()) return;
if (i.deferred) {return;}
await i.deferUpdate();
switch (i.customId) {
case "first":
currentPage = 0;
break;
case "prev":
currentPage--;
if (currentPage === -1) currentPage = list.length - 1;
break;
case "next":
currentPage++;
if (currentPage === list.length) currentPage = 0;
break;
case "last":
currentPage = list.length - 1;
if (currentPage === -1) currentPage = list.length - 1;
break;
default:
break;
}
options = await update(interaction, list, currentPage, actions);
message = await i.editReply(options);
});
//Create action listener
if (actions == null) return;
const actionFilter = i => i.user.id === interaction.user.id;
const actionCollector = message.createMessageComponentCollector({actionFilter, time: 120000});
actionCollector.on("collect", async i => {
if (!i.isSelectMenu()) return;
if (i.deferred) return;
await i.deferUpdate();
//If action found
const action = actions.filter(v => v.name === i.values[0])[0];
if (action) {
const deleteItem = await action.action(list[currentPage]);
//Delete item on action
if (deleteItem) {
const toRemove = list[currentPage];
list = list.filter(i => i !== toRemove);
//Set page index
currentPage = Math.max(currentPage - 1, 0);
if (refresh) {
list = await refresh();
}
options = await update(interaction, list, currentPage, actions);
await i.editReply(options);
}
}
});
return message;
};
/**
* Create swipeable panel with different actions for each page
* Adds left/right embedded buttons to a discord message to navigate through the swipeable list
* List is cyclic and cycles back to the start
* @param {Client} client - Discord bot client
* @param interaction
* @param list
* @param actions - action name: string, description: string, action: function map
* item as parameter - return value is T/F based on whether this item will be removed or not
*/
exports.createLargeMultiActionSwipePanel = async (client, interaction,
list, actions = null) => {
let currentPage = 0;
let options = await update(interaction, list, currentPage, actions[currentPage]);
let followUp = await interaction.editReply(options);
//Create listener for navigation events
const filter = i => (i.customId === "prev"
|| i.customId === "next"
|| i.customId === "first"
|| i.customId === "last") && i.user.id === interaction.user.id;
const collector = followUp.createMessageComponentCollector({filter, time: 120000});
collector.on("collect", async i => {
if (!i.isButton()) return;
await i.deferUpdate();
switch (i.customId) {
case "first":
currentPage = 0;
break;
case "prev":
currentPage--;
if (currentPage === -1) currentPage = list.length - 1;
break;
case "next":
currentPage++;
if (currentPage === list.length) currentPage = 0;
break;
case "last":
currentPage = list.length - 1;
if (currentPage === -1) currentPage = list.length - 1;
break;
default:
break;
}
options = await update(interaction, list, currentPage, actions[currentPage]);
await i.editReply(options);
});
//Create action listener
if (actions === null) return;
const actionFilter = i => i.user.id === interaction.user.id;
const actionCollector = followUp.createMessageComponentCollector({actionFilter, time: 120000});
actionCollector.on("collect", async i => {
if (!i.isSelectMenu()) return;
await i.deferUpdate();
//If action found
const action = actions[currentPage].filter(v => v.name === i.values[0])[0];
if (action) {
const actionIndex = actions[currentPage].indexOf(action);
const deleteItem = await action.action(list[currentPage].list[actionIndex]);
//Delete item on action
if (deleteItem) {
list[currentPage].list.splice(actionIndex,1);
actions[currentPage].splice(actionIndex,1);
if (list[currentPage].list.length === 0) {
list.splice(currentPage, 1);
}
//Set page index
currentPage = Math.max(currentPage - 1, 0);
options = await update(interaction, list, currentPage, actions[currentPage]);
followUp = await i.editReply(options);
}
}
});
return followUp;
};
const update = async (interaction, list, currentPage, actions) => {
//check for empty list
if (list.length === 0) {
const embed = new MessageEmbed();
embed.setTitle("EMPTY");
embed.setDescription("No more items to display");
embed.setThumbnail("");
embed.setImage("");
if (Object.prototype.hasOwnProperty.call(interaction,"channelType")) {
await interaction.interaction.webhook.editMessage(interaction.message,
{embeds: [embed], components: [], attachments: [], thumbnails: [], images: []});
} else {
await interaction.editReply({embeds: [embed], components: [], attachments: [], thumbnails: [], images: []});
}
return;
}
//Add navigation buttons to row
const components = [];
const row = createRow(currentPage, list.length);
components.push(row);
if (actions) {
components.push(createDropDownBox(actions));
}
//update embed to show current page
const data = await list[currentPage].update();
return {embeds: data[0], components: components, files: data[1], attachments: [], thumbnails: [], images: []};
}
const createRow = (currentPage, length) => {
return new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId("first")
.setLabel("FIRST")
.setStyle("PRIMARY"),
new MessageButton()
.setCustomId("prev")
.setLabel("PREV")
.setStyle("PRIMARY"),
new MessageButton()
.setCustomId("current")
.setLabel(`${currentPage + 1}/${length}`)
.setStyle("SECONDARY")
.setDisabled(true),
new MessageButton()
.setCustomId("next")
.setLabel("NEXT")
.setStyle("PRIMARY"),
new MessageButton()
.setCustomId("last")
.setLabel("LAST")
.setStyle("PRIMARY"),
);
}
const createDropDownBox = actions => {
const actionList = actions.map(a => a.name).join("/");
return new MessageActionRow().addComponents(
new MessageSelectMenu().setCustomId("actions").setPlaceholder(actionList).addOptions(
actions.map(
action => {
return {
customId: action.name,
label: action.name,
description: action.description,
value: action.name,
};
}
)
)
);
}
</code></pre>
</article>
</section>
</div>
<footer>
<img class="logo" src="https://cdn.discordapp.com/attachments/939508059758288939/979289803239608360/FinalLogoAlt2.png" style="width: 100px; height: 100px">
<div class="footer-text">NHN Entertainment. Frontend Development Lab</div>
</footer>
<script>prettyPrint();</script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tui-doc.js"></script>
<script src="scripts/linenumber.js"></script>
<script>
var id = '_sub'.replace(/"/g, '_');
var selectedApi = document.getElementById(id); // do not use jquery selector
var $selectedApi = $(selectedApi);
$selectedApi.removeClass('hidden');
$selectedApi.parent().find('.glyphicon').removeClass('glyphicon-plus').addClass('glyphicon-minus');
showLnbApi();
</script>
</body>
</html>