From 1957c16026bba110ee82c3f027b8d283cc849850 Mon Sep 17 00:00:00 2001 From: Giovani Date: Tue, 27 Jul 2021 22:07:15 -0400 Subject: [PATCH] feat: add crypto command that shows prices --- README | 2 ++ main.py | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..9ae5e29 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +### Credits +
Icons made by Flat Icon \ No newline at end of file diff --git a/main.py b/main.py index c4bb8bb..28db9b2 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,8 @@ import discord +import requests +import json + +LUNAR_CRUSH_API_KEY = "LUNAR_API_KEY" client = discord.Client() @@ -9,19 +13,34 @@ async def on_ready(): @client.event async def on_message(message): msg_str = message.content - print(msg_str) - pass -client.run("") # pass the bot token here + # Help command + if msg_str == '!help': + await message.channel.send("!help - Displays this help message") -""" -from discord.ext import commands + # Resources command + if msg_str == "!resources": + await message.channel.send("Some resources for you here!") -bot = commands.Bot(command_prefix='>') + # Crypto command + if msg_str == "!crypto": + symbols = ["BTC", "ETH", "LTC"] -@bot.command() -async def ping(ctx): - await ctx.send('pong') + # make the call for prices + http_response = requests.get("https://api.lunarcrush.com/v2?data=assets&key=" + LUNAR_CRUSH_API_KEY + "&symbol=" + ",".join(symbols)) + data = json.loads(http_response.text) -bot.run('token') -""" \ No newline at end of file + # extract prices + prices = [] + prices.append(int(data["data"][0]["price"])) # BTC + prices.append(int(data["data"][1]["price"])) # ETH + prices.append(int(data["data"][2]["price"])) # LTC + + # derive message response + msg_response = "Cryptocurrency prices for today!\n" + for i in range(len(symbols)): + msg_response += "**{}** - ${}\n".format(symbols[i], prices[i]) + + await message.channel.send(msg_response) + +client.run("DISCORD_TOKEN") # pass the bot token here \ No newline at end of file