-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcore.js
113 lines (101 loc) · 2.62 KB
/
core.js
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
const {
EmbedBuilder,
ButtonBuilder,
ButtonStyle,
ActionRowBuilder } = require('discord.js');
const moment = require('moment');
const config = require('../config.json');
const packageJSON = require('../../package.json');
/**
* This function determines the current mode of the bot.
* @returns {string} The mode of the bot.
*/
const mode = () => localMode() ? (debugMode() ? "LOCAL-DEBUG" : "LOCAL") : (debugMode() ? "BUILD-DEBUG" : "BUILD");
/**
* send embed message
* @param {string} message
* @returns pre-defined embed style
*/
const sendEmbedMessage = (message) => {
return new EmbedBuilder()
.setDescription(message)
.setColor(`#f213a4`)
.addFields(
{ name: 'Need Help?', value: 'Submit a ticket here: https://thirdweb.com/support', inline: false}
)
.setTimestamp()
.setFooter({ text: `thirdweb @ ${packageJSON.version} ${mode()}`, iconURL: 'https://ipfs.io/ipfs/QmTWMy6Dw1PDyMxHxNcmDmPE8zqFCQMfD6m2feHVY89zgu/Icon/Favicon-01.png' });
}
/**
* close buttons
* @param {string} message
* @returns pre-defined embed style
*/
const CloseButtonComponent = () => {
const support = new ButtonBuilder()
.setLabel('Submit a Ticket')
.setEmoji('💬')
.setURL('https://thirdweb.com/support')
.setStyle(ButtonStyle.Link);
const row = new ActionRowBuilder()
.addComponents(support);
return row
}
/**
* feedback buttons
* @param {string} message
* @returns pre-defined embed style
*/
const FeedbackButtonComponent = () => {
const helpful = new ButtonBuilder()
.setCustomId('helpful')
.setLabel('Helpful')
.setEmoji('😊')
.setStyle(ButtonStyle.Secondary);
const Nothelpful = new ButtonBuilder()
.setCustomId('not-helpful')
.setLabel('Not Helpful')
.setEmoji('😔')
.setStyle(ButtonStyle.Secondary);
const row = new ActionRowBuilder()
.addComponents(helpful, Nothelpful);
return row
}
/**
* format time according to UTC
* @param {number} date - epoch timestamp
* @returns time and date format
*/
const formatTime = (date) => {
return moment.utc(date).utcOffset(config.utc_offset).format('M/DD/YYYY HH:mm:ss');
}
/**
* utility to return server time
* @returns server time
*/
const serverTime = () => {
return moment.utc().utcOffset(config.utc_offset).format('M/DD/YYYY HH:mm:ss');
}
/**
* check if the bot is in local mode or not
* @returns {boolean}
*/
const localMode = () => {
return config.local ? true : false;
}
/**
* check if the bot is in debug mode or not
* @returns {boolean}
*/
const debugMode = () => {
return config.debug ? true : false;
}
module.exports = {
sendEmbedMessage,
CloseButtonComponent,
FeedbackButtonComponent,
formatTime,
serverTime,
localMode,
debugMode
}