|
5 | 5 | # DEPENDENCIES
|
6 | 6 | # sudo apt-get install python3
|
7 | 7 | # sudo apt-get -y install python3-pip
|
8 |
| -# python3 -m pip install discord.py==0.16.12 |
| 8 | +# python3 -m pip install discord.py==1.3.4 |
9 | 9 | #
|
10 | 10 | # HOW TO USE
|
11 | 11 | # Go to https://discordapp.com/developers/applications/
|
|
22 | 22 | import asyncio
|
23 | 23 | import aiohttp
|
24 | 24 | import json
|
| 25 | +from discord.ext import commands |
25 | 26 | from discord.ext.commands import Bot
|
26 | 27 |
|
27 |
| -# bot description |
| 28 | +# bot description |
28 | 29 | # bot description displayed in help section
|
29 | 30 | description = '''Network bot displays a variety of information and statistics on almost any cryptonote network. To use the commands type them with the prefix of ampersand (&). You can find the commands and their use below. Add (&) in front of a command (EXAMPLE: &height)'''
|
30 | 31 |
|
|
51 | 52 | # commmand: &height
|
52 | 53 | # network top block height
|
53 | 54 | @client.command(description="Network top block height.", brief="Blockchain height.")
|
54 |
| -async def height(): |
| 55 | +async def height(context: commands.Context): |
55 | 56 | url = 'http://' + str(HOST) + ':' + str(PORT) + '/getheight'
|
56 | 57 | async with aiohttp.ClientSession() as session: # Async HTTP request
|
57 | 58 | raw_response = await session.get(url)
|
58 | 59 | response = await raw_response.text()
|
59 | 60 | response = json.loads(response)
|
60 | 61 | # you can customize the output message(s) below
|
61 |
| - await client.say("🌐 **Network height:** " + str(response['height'])) |
| 62 | + await context.send("🌐 **Network height:** " + str(response['height'])) |
62 | 63 |
|
63 | 64 | # commmand: &hash
|
64 | 65 | # appx. network hash rate
|
65 | 66 | @client.command(description="Appx. network hash rate.", brief="Network hash rate.")
|
66 |
| -async def hash(): |
| 67 | +async def hash(context: commands.Context): |
67 | 68 | url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
|
68 | 69 | async with aiohttp.ClientSession() as session: # Async HTTP request
|
69 | 70 | raw_response = await session.get(url)
|
70 | 71 | response = await raw_response.text()
|
71 | 72 | response = json.loads(response)
|
72 | 73 | # you can customize the output message(s) below
|
73 |
| - await client.say("🌐 **Network hash rate:** " + str(response['hashrate']) + " H/s") |
| 74 | + await context.send("🌐 **Network hash rate:** " + str(response['hashrate']) + " H/s") |
74 | 75 |
|
75 | 76 | # commmand: &diff
|
76 | 77 | # current network difficulty
|
77 | 78 | @client.command(description="Current network difficulty.", brief="Network difficulty.")
|
78 |
| -async def diff(): |
| 79 | +async def diff(context: commands.Context): |
79 | 80 | url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
|
80 | 81 | async with aiohttp.ClientSession() as session: # Async HTTP request
|
81 | 82 | raw_response = await session.get(url)
|
82 | 83 | response = await raw_response.text()
|
83 | 84 | response = json.loads(response)
|
84 | 85 | # you can customize the output message(s) below
|
85 |
| - await client.say("🌐 **Network difficulty:** " + str(response['difficulty'])) |
| 86 | + await context.send("🌐 **Network difficulty:** " + str(response['difficulty'])) |
86 | 87 |
|
87 | 88 | # commmand: &tx
|
88 | 89 | # total network transactions
|
89 | 90 | @client.command(description="Total network transactions.", brief="Network transactions.")
|
90 |
| -async def tx(): |
| 91 | +async def tx(context: commands.Context): |
91 | 92 | url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
|
92 | 93 | async with aiohttp.ClientSession() as session: # Async HTTP request
|
93 | 94 | raw_response = await session.get(url)
|
94 | 95 | response = await raw_response.text()
|
95 | 96 | response = json.loads(response)
|
96 | 97 | # you can customize the output message(s) below
|
97 |
| - await client.say("🌐 **Network transactions:** " + str(response['tx_count'])) |
| 98 | + await context.send("🌐 **Network transactions:** " + str(response['tx_count'])) |
98 | 99 |
|
99 | 100 | # commmand: &txpool
|
100 | 101 | # current transactions pool size
|
101 | 102 | @client.command(description="Current transactions pool size.", brief="TX pool size.")
|
102 |
| -async def txpool(): |
| 103 | +async def txpool(context: commands.Context): |
103 | 104 | url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
|
104 | 105 | async with aiohttp.ClientSession() as session: # Async HTTP request
|
105 | 106 | raw_response = await session.get(url)
|
106 | 107 | response = await raw_response.text()
|
107 | 108 | response = json.loads(response)
|
108 | 109 | # you can customize the output message(s) below
|
109 |
| - await client.say("🌐 **Transactions pool:** " + str(response['tx_pool_size'])) |
| 110 | + await context.send("🌐 **Transactions pool:** " + str(response['tx_pool_size'])) |
110 | 111 |
|
111 | 112 | # commmand: &ver
|
112 | 113 | # current daemon version
|
113 | 114 | @client.command(description="Current daemon version.", brief="Daemon version.")
|
114 |
| -async def ver(): |
| 115 | +async def ver(context: commands.Context): |
115 | 116 | url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
|
116 | 117 | async with aiohttp.ClientSession() as session: # Async HTTP request
|
117 | 118 | raw_response = await session.get(url)
|
118 | 119 | response = await raw_response.text()
|
119 | 120 | response = json.loads(response)
|
120 | 121 | # you can customize the output message(s) below
|
121 |
| - await client.say("🌐 **Daemon Version:** " + str(response['version'])) |
| 122 | + await context.send("🌐 **Daemon Version:** " + str(response['version'])) |
122 | 123 |
|
123 | 124 | # commmand: &stats
|
124 | 125 | # key network stats all in one place
|
125 | 126 | @client.command(description="Key network stats all in one place.", brief="Network stats.")
|
126 |
| -async def stats(): |
| 127 | +async def stats(context: commands.Context): |
127 | 128 | url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
|
128 | 129 | async with aiohttp.ClientSession() as session: # Async HTTP request
|
129 | 130 | raw_response = await session.get(url)
|
130 | 131 | response = await raw_response.text()
|
131 | 132 | response = json.loads(response)
|
132 | 133 | # you can customize the output message(s) below
|
133 |
| - await client.say("🌐 NETWORK STATS\n**Height:** " + str(response['height']) + " \n**Hash rate:** " + str(response['hashrate']) + " H/s \n**Difficulty:** " + str(response['difficulty']) + " \n**TX total:** " + str(response['tx_count']) + " \n**TX in the pool:** " + str(response['tx_pool_size']) + " \n**Daemon version:** " + str(response['version']) |
| 134 | + await context.send("🌐 NETWORK STATS\n**Height:** " + str(response['height']) + " \n**Hash rate:** " + str(response['hashrate']) + " H/s \n**Difficulty:** " + str(response['difficulty']) + " \n**TX total:** " + str(response['tx_count']) + " \n**TX in the pool:** " + str(response['tx_pool_size']) + " \n**Daemon version:** " + str(response['version']) |
134 | 135 | )
|
135 | 136 |
|
136 | 137 |
|
|
0 commit comments