Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/commands/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ export const handleCurrency: Command = {
await fetch(`http://data.fixer.io/api/latest?access_key=${fixerAPIkey}`)
).json() as typeof currency
currency.timestamp = Date.now() // To set the timestamp to the current time of the system.
// to change syp value to blackmarket value
const response = await fetch('https://sp-today.com/en/currency/us_dollar/city/damascus')
const data = await response.text()
const index = data.toString().search('<span class="name">usd damas </span>\n<div class="line-data">\n<span class="value">')
const value = data.substring(index + 81, index + 85)
currency.rates.SYP = Number(value)
}
// For /currency list
if (args.length === 1 && args[0].toLowerCase() === 'list') {
Expand All @@ -491,13 +497,6 @@ letter code + the first letter of the currency name.'
else if (!args[2]) args[2] = '1' // If no amount was provided, the amount should be one.
else if (args.length > 3) return { content: 'Enter a single number for currency conversion.', error: true }
else if (isNaN(+args[2])) return { content: 'Enter a proper number to convert.', error: true }
// to change syp value to blackmarket value
if (from === 'SYP' || to === 'SYP') {
const response = await fetch('https://sp-today.com/en/currency/us_dollar/city/damascus')
const data = await response.text()
const value = data.toString().search('<span class="value">')
currency.rates.SYP = Number(data.substring(value + 20, value + 24))
}
// Now we convert the amount.
const convertedAmount = ((currency.rates[to] / currency.rates[from]) * +args[2])
const roundedOffAmount = Math.ceil(convertedAmount * Math.pow(10, 4)) / Math.pow(10, 4)
Expand Down