Skip to content

Commit

Permalink
Updated to the lastest version from Discord
Browse files Browse the repository at this point in the history
This version had no crashes since it went online weeks ago.
  • Loading branch information
andrewtookay authored Feb 2, 2018
1 parent e79c7ae commit 06c8266
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions Creedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import asyncio
import json
import re

with open('botParams.json') as json_input_file:
json_bot_input = json.load(json_input_file)
Expand Down Expand Up @@ -31,25 +32,37 @@ async def on_message(message):
coin_ticker = coin_ticker.upper()

goCMC = 0
goCoinsM = 0

cmc_api = 'https://api.coinmarketcap.com/v1/ticker/'
json_cmc = requests.get(cmc_api).json()
for ticker in json_cmc:
for coin in json_cmc:
if ticker['symbol'] == coin_ticker:
goCMC = 1
coinCMC = ticker
coinCMC = coin

if coin_ticker.upper() == 'CRDS':
try:
crds_usd = requests.get('https://crds.co/calc/crds_usd.txt')
crds_usd = float(crds_usd.text)

if goCMC == 0:
coinsm_api = 'https://coinsmarkets.com/apicoin.php'
trade_ticker = 'BTC_' + coin_ticker
json_coinsm = requests.get(coinsm_api).json()
for ticker in json_coinsm:
if ticker == trade_ticker:
goCoinsM = 1
crds_btc = requests.get('https://crds.co/calc/crds_btc.txt')
crds_btc = float(crds_btc.text)

if goCMC == 0 and goCoinsM == 0:
final_message = 'Invalid ticker.'
supply = requests.get('https://crds.co/calc/crds_supply.txt')
supply = supply.text

volume = requests.get('https://crds.co/calc/crds_vol.txt')
volume = float(volume.text)

supply = re.sub(',', '', supply)
supply = float(supply)

marketcap = round(crds_usd * supply, 2)

final_message = 'Coin Name: Credits' + '\nTicker: ' + coin_ticker + '\n' + 'Last price: ' + str('{0:.8f}'.format(round(crds_btc, 8))) + ' BTC\n' + 'Volume(24h): ' + str(volume) + ' BTC\n' + 'Marketcap: ' + str(marketcap) + ' USD'

except:
final_message = 'Invalid command due to factors outside our control.'

elif goCMC == 1:
json_coin_name = coinCMC['name']
Expand All @@ -59,23 +72,17 @@ async def on_message(message):
json_percent_change = coinCMC['percent_change_24h']

final_message = 'Coin Name: ' + str(json_coin_name) + '\nTicker: ' + coin_ticker + '\n' + 'Price (BTC): ' + str(json_price_btc) + '\n' + 'Price (USD): ' + str(json_price_usd) + '\n' + 'Volume(24h): ' + str(json_24h_volume) + ' USD\n' + 'Change (24h): ' + str(json_percent_change) + '%'

elif goCoinsM == 1:
json_last_price = json_coinsm[trade_ticker]['last']
json_24h_volume = json_coinsm[trade_ticker]['24htrade']

final_message = 'Ticker: ' + coin_ticker + '\n' + 'Last price: ' + str(json_last_price) + ' BTC\n' + 'Volume(24h): ' + str(json_24h_volume) + ' BTC'


else:
final_message = 'Something went wrong. Contact the team.'

elif message.content.startswith('!mnroi'):
no_mn = message.content[6:]
ok = 0

try:
no_mn = int(no_mn.strip())
final_message = getMnRoi(no_mn)

except ValueError:
final_message = 'Invalid number of Masternodes.'

Expand All @@ -88,7 +95,7 @@ async def on_message(message):
link = 'http://explorer.crds.co/'

elif len(message.content) > 1 and message.content[1] != ' ' and ((message.content[0] == '!' and message.content[1] != '!' and message.content[1] != '?') or (message.content[0] == '$' and message.content[1] != '$')):
final_message = 'Invalid command. Use ?help to see the available commands.'
final_message = 'Invalid command. Use !help to see the available commands.'

if final_message != '':
await client.send_message(message.channel, '`' + final_message + '`' + link)
Expand All @@ -100,17 +107,17 @@ def getMnRoi(no_mn):
json_cmc = requests.get('https://api.coinmarketcap.com/v1/ticker/').json()
btc_usd = float(json_cmc[0]['price_usd'])

json_coinsm = requests.get('https://coinsmarkets.com/apicoin.php').json()
crds_btc = float(json_coinsm['BTC_CRDS']['last'])
crds_btc = requests.get('https://crds.co/calc/crds_btc.txt')
crds_btc = float(crds_btc.text)

mncount = requests.get('http://explorer.crds.co/mncount.txt')
mncount = float(mncount.text)

blockcount = requests.get('http://explorer.crds.co/blockcount.txt')
blockcount = int(blockcount.text)

except:
final_message = 'Command unavailable due to downtime of explorer or APIs.'
return final_message
return 'Command unavailable due to downtime of explorer or APIs.'

crds_usd = crds_btc * btc_usd

Expand Down Expand Up @@ -139,14 +146,14 @@ def getMnRoi(no_mn):

final_message = 'No. of Masternodes: ' + str(no_mn)
final_message += '\nCollateral (CRDS): ' + str(5000 * no_mn)
final_message += '\nCRDS Value (BTC): ' + str('{0:.8f}'.format(round(crds_btc, 8))) + ' BTC / $' + str(round(crds_usd, 4))
final_message += '\nCRDS Value (BTC): ' + str('{0:.8f}'.format(round(crds_btc, 8))) + ' BTC / ' + str(round(crds_usd, 4)) + ' USD'
final_message += '\n'

total_crds_col = float(no_mn * 5000)
total_btc_col = round(total_crds_col * crds_btc, 8)
total_usd_col = round(total_crds_col * crds_usd, 2)

final_message += '\nTotal collateral cost for ' + str(no_mn) + ' MN: ' + str(total_btc_col) + ' BTC / $' + str(total_usd_col)
final_message += '\nTotal collateral cost for ' + str(no_mn) + ' MN: ' + str(total_btc_col) + ' BTC / ' + str(total_usd_col) + ' USD'
final_message += '\n'

mncount = float(mncount)
Expand Down

0 comments on commit 06c8266

Please # to comment.