-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrade.js
73 lines (67 loc) · 1.92 KB
/
trade.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
/**
* This module helps you to create trade messages for Rocket League in Discord servers using code blocks
*
* Author : Firokat
*/
/**
* @description A list of items you have
* @param {Array} items The items you have
*/
class Have{
constructor(items){
this.items = items
}
}
/**
* @description A list of items you want
* @param {Array} items The items you want
*/
class Want{
constructor(items){
this.items = items
}
}
/**
* @description A function to create the message
* @param {Have} have The items you have
* @param {Want} want The items you want
* @param {String} bottomText A text you can add in the list row
*/
function createMessage(have, want, bottomText){
// Checks if all parameters are ok
if (have instanceof Have == false || want instanceof Want == false){
console.error("One of the element is not of the right type")
return undefined
}
if(have.items.length != want.items.length){
console.error("The two arrays have different length")
return undefined
}
//Creates the message
msg = "```css\n----------------------[HAVE]----------------------{}----------------------[WANT]----------------------\n {} \n"
for (let i=0; i<have.items.length; i++) {
msg+=" "
msg+=`[H] ${have.items[i]}`
for (s=0; s<50-(have.items[i].length+7); s++) {
msg += " "
}
msg += "{}"
msg+=" "
msg+=`[W] ${want.items[i]}`
for (s; s<50-(want.items[i].length)+7; s++) {
msg += " "
}
msg+="\n"
}
//Adds a text in the bottom if you wish
if (bottomText != undefined){
msg+=` ${bottomText}\n`
}
msg +="```"
return msg
}
module.exports = {
Have,
Want,
createMessage
}