-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
executable file
·66 lines (55 loc) · 2.05 KB
/
bot.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! usr/bin/env python3
import discord, asyncio
from crypto_price_scrape import get_price, get_crypto_list
HELP_MESSAGE = """
**This bot does all things crypto the commands are as follows:**\n
!price currency - Gives the current price of your desired currency name, use ticker codes like BTC or ETH
!list - Gives a list of currently supported Crypto-Currencies
!supported currency - Says whether or not a specific currenty is supported
!? currency - See !supported
"""
def main():
TOKEN = input()
client = discord.Client()
@client.event
async def on_ready():
print("The bot is ready!")
@client.event
async def on_message(message):
if message.content[:6].lower() == "!price":
curr = message.content[7:]
price = get_price(curr.upper())
if price:
await message.channel.send("One "+curr.upper()+" is worth $"+str(price))
else:
await message.channel.send("Sorry that is not a recognised currency")
elif message.content[:5].lower() == "!list":
await discord_print(message.channel, "The following currencies are supported: "+', '.join(get_crypto_list()))
elif message.content[:10].lower() == "!supported":
if message.content[11:].upper() in get_crypto_list():
await message.channel.send("That currency *is* supported")
else:
await message.channel.send("That currency *is not* supported")
elif message.content[:2] == '!?':
if message.content[3:].upper() in get_crypto_list():
await message.channel.send("That currency is supported")
else:
await message.channel.send("That currency is not supported")
elif message.content.lower() == "!help" or message.content.lower() == "!h":
await message.channel.send(HELP_MESSAGE)
async def discord_print(channel, text, div=" "):
out = ""
cntr = 0
for a in text.split(div):
if cntr + len(a) > 2000:
await channel.send(out)
out = a + div
cntr = len(a) + 1
else:
out += a + div
cntr += len(a) + 1
if out:
await channel.send(out)
client.run(TOKEN)
if __name__ == "__main__":
main()