feat: change message events to commands
This commit is contained in:
47
pyvis.py
47
pyvis.py
@@ -22,41 +22,24 @@ async def on_ready():
|
|||||||
f'{guild.name}(id: {guild.id})'
|
f'{guild.name}(id: {guild.id})'
|
||||||
)
|
)
|
||||||
|
|
||||||
@bot.event
|
@bot.command(name="resources")
|
||||||
async def on_message(message):
|
async def resources(ctx):
|
||||||
# ignore messages from the bot itself
|
await ctx.send("Some resources for you here!")
|
||||||
if message.author == bot.user:
|
|
||||||
return
|
|
||||||
|
|
||||||
msg_str = message.content
|
@bot.command(name="crypto")
|
||||||
|
async def crypto(ctx, *tickers):
|
||||||
|
# default tickers
|
||||||
|
if len(tickers) == 0:
|
||||||
|
tickers = ['BTC', 'ETH', 'LTC']
|
||||||
|
|
||||||
# Help command
|
# make the call for prices
|
||||||
if msg_str == '!help':
|
http_response = requests.get("https://api.lunarcrush.com/v2?data=assets&key=" + LUNAR_CRUSH_API_KEY + "&symbol=" + ",".join(tickers))
|
||||||
await message.channel.send("!help - Displays this help message")
|
data = json.loads(http_response.text)
|
||||||
|
|
||||||
# Resources command
|
# extract prices and derive message response
|
||||||
if msg_str == "!resources":
|
msg_response = "Cryptocurrency prices for today!\n"
|
||||||
await message.channel.send("Some resources for you here!")
|
msg_response += "\n".join([f"**{item['symbol']}**: ${int(item['price'])}" for item in data["data"]])
|
||||||
|
|
||||||
# Crypto command
|
await ctx.send(msg_response)
|
||||||
if msg_str.startswith("!crypto"):
|
|
||||||
symbols = ["BTC", "ETH", "LTC"]
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
bot.run(DISCORD_BOT_TOKEN)
|
bot.run(DISCORD_BOT_TOKEN)
|
||||||
Reference in New Issue
Block a user