-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbutton.js
115 lines (106 loc) · 3.65 KB
/
button.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
114
115
//require database and instantiating db object
const Database = require('@replit/database')
const db = new Database()
//requiring all other utility functions
const { embedder, profile } = require('./utility')
const { streak } = require('./util-check')
const { listAll } = require('./util-list')
/**
* Creates a messageButton, sets its label, style and id from the given parameters and returns the button
*
* @param {Button Label} label the Label of the newly created button
* @param {Button Style} style the Style of the newly created button
* @param {Button ID} id the ID of the newly created button
* @returns {MessageButton} messageButton the newly created button
*/
function createMessageButton(label, style, id) {
const messageButton = new but.MessageButton()
.setLabel(label)
.setStyle(style)
.setID(id)
return messageButton
}
/**
* Creates a list of buttons for all the basic uses
* And send it to the msg.channel
* The buttons are shown:
* 1. Streak to show current streak
* 2. List to list all Logs
* 3. Profile to show profile
* 4. Info to show information about the bot
* 5. Help to show all the commands the bot can listen to
*
* @param {Discord-buttons(client)} but the object required from discord-buttons.js with the discord.js client
* @param {Message} msg the message with ++buttons prefix
*/
const button = async (but, msg) => {
const btn1 = createMessageButton('Streak', 'red', 'getStreak')
const btn2 = createMessageButton('List', 'green', 'getList')
const btn3 = createMessageButton('Profile', 'green', 'getProfile')
const btn4 = createMessageButton('Info', 'blurple', 'getInfo')
const btn5 = createMessageButton('Help', 'blurple', 'getHelp')
msg.channel.send(
'Discord Updates with buttons!\nNow type less *interact* more\nClick on the streak button to check your streak 😃',
{
buttons: [btn1, btn2, btn3, btn4, btn5],
}
)
}
/**
* To show the current streak for the user who clicked the button and send message accordingly.
*
* @param {MessageButton} button the button which listened to onclick event for streak button
*/
const getStreak = async (button) => {
db.get(button.clicker.user.id + '').then((logs) => {
if (logs != null && typeof logs.info !== 'undefined')
streak(button, button.clicker.user, logs.info, logs.startDate)
else
embedder(
button,
`**${button.clicker.user.username}**, you do not have any current logs. Use \`++add {log}\` to start logging.`
)
})
}
/**
* To show the in embed the profile of the user
* who clicked the button and call utility function
* profile to do so.
*
* @param {MessageButton} button which listened to the onclick event for profile button
*/
const getProfile = async (button) => {
db.get(button.clicker.user.id).then((logs) => {
if (logs != null && typeof logs.info !== 'undefined')
profile(button, button.clicker.user, logs)
else
msg.reply(
`*${button.clicker.user.username}*, You don't have any logs currently. Start logging with us to check out your profile.`
)
})
}
/**
*
* @param {MessageButton} button which listened to onclick for the button List and call accordingly the listAll utility function
*/
const getList = async (button) => {
db.get(button.clicker.user.id + '').then((logs) => {
if (
logs != null &&
typeof logs.info !== 'undefined' &&
logs.info.length > 0
)
listAll(button, logs.info, logs.open)
else
embedder(
msg,
`You do not have any logs ${button.clicker.user.username}. Start logging with \`++add {log}\` to check out your logs.`
)
})
}
module.exports = {
button,
getStreak,
getProfile,
getList,
}