forked from jacobhilty926/mtgbot2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderers.js
37 lines (32 loc) · 1.12 KB
/
renderers.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
const convertCardSymbols = text => {
if (text === undefined) {
return ''
}
return text.replace(/\{([wubrgxc])\}/gi, ':mana$1:')
.replace(/\{t\}/gi, ':tap:')
.replace(/\{q\}/gi, ':untap:')
.replace(/\{([0-9]+)\}/gi, ':mana$1:')
}
const renderCard = (card) => {
// Build our response body
const pt = card.power ? '\u00AD' + card.power + '/' + card.toughness + '\u00AD' : ''
const loyalty = card.loyalty ? 'Loyalty: ' + card.loyalty : ''
const link = 'https://magiccards.info/query?q=' + card.name.replace(' ', '%20')
const nameLink = '<' + link + '|' + card.name + '>'
const cost = convertCardSymbols(card.manaCost)
const oracleText = convertCardSymbols(card.text)
return 'Name: ' + nameLink + '\t\t\tCost: ' + cost +
'\nType: ' + card.type + '\t\t\t\t\t' + card.rarity +
'\n' + oracleText +
'\n' + pt + loyalty
}
const renderListOfCards = (cardList, delimiter) => {
console.log('rendering list')
delimiter = delimiter || '\n---------------------------\n'
return cardList.map(renderCard).join(delimiter)
}
module.exports = {
renderCard,
renderListOfCards,
convertCardSymbols
}