Skip to content

Commit b3f1e83

Browse files
committed
Update to new Discord API.
1 parent 47fcdb2 commit b3f1e83

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ Cryptonote network stats discord bot that displays a variety of network informat
66
## DEPENDENCIES
77

88
``
9-
apt-get install python3
9+
apt-get -y install python3 python3-pip
1010
``
1111

1212
``
13-
apt-get -y install python3-pip
14-
``
15-
16-
``
17-
python3 -m pip install discord.py==0.16.12
13+
python3 -m pip install discord.py==1.3.4
1814
``
1915

2016
## HOW TO USE

networkbot.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# DEPENDENCIES
66
# sudo apt-get install python3
77
# 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
99
#
1010
# HOW TO USE
1111
# Go to https://discordapp.com/developers/applications/
@@ -22,9 +22,10 @@
2222
import asyncio
2323
import aiohttp
2424
import json
25+
from discord.ext import commands
2526
from discord.ext.commands import Bot
2627

27-
# bot description
28+
# bot description
2829
# bot description displayed in help section
2930
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)'''
3031

@@ -51,86 +52,86 @@
5152
# commmand: &height
5253
# network top block height
5354
@client.command(description="Network top block height.", brief="Blockchain height.")
54-
async def height():
55+
async def height(context: commands.Context):
5556
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getheight'
5657
async with aiohttp.ClientSession() as session: # Async HTTP request
5758
raw_response = await session.get(url)
5859
response = await raw_response.text()
5960
response = json.loads(response)
6061
# 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']))
6263

6364
# commmand: &hash
6465
# appx. network hash rate
6566
@client.command(description="Appx. network hash rate.", brief="Network hash rate.")
66-
async def hash():
67+
async def hash(context: commands.Context):
6768
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
6869
async with aiohttp.ClientSession() as session: # Async HTTP request
6970
raw_response = await session.get(url)
7071
response = await raw_response.text()
7172
response = json.loads(response)
7273
# 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")
7475

7576
# commmand: &diff
7677
# current network difficulty
7778
@client.command(description="Current network difficulty.", brief="Network difficulty.")
78-
async def diff():
79+
async def diff(context: commands.Context):
7980
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
8081
async with aiohttp.ClientSession() as session: # Async HTTP request
8182
raw_response = await session.get(url)
8283
response = await raw_response.text()
8384
response = json.loads(response)
8485
# 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']))
8687

8788
# commmand: &tx
8889
# total network transactions
8990
@client.command(description="Total network transactions.", brief="Network transactions.")
90-
async def tx():
91+
async def tx(context: commands.Context):
9192
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
9293
async with aiohttp.ClientSession() as session: # Async HTTP request
9394
raw_response = await session.get(url)
9495
response = await raw_response.text()
9596
response = json.loads(response)
9697
# 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']))
9899

99100
# commmand: &txpool
100101
# current transactions pool size
101102
@client.command(description="Current transactions pool size.", brief="TX pool size.")
102-
async def txpool():
103+
async def txpool(context: commands.Context):
103104
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
104105
async with aiohttp.ClientSession() as session: # Async HTTP request
105106
raw_response = await session.get(url)
106107
response = await raw_response.text()
107108
response = json.loads(response)
108109
# 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']))
110111

111112
# commmand: &ver
112113
# current daemon version
113114
@client.command(description="Current daemon version.", brief="Daemon version.")
114-
async def ver():
115+
async def ver(context: commands.Context):
115116
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
116117
async with aiohttp.ClientSession() as session: # Async HTTP request
117118
raw_response = await session.get(url)
118119
response = await raw_response.text()
119120
response = json.loads(response)
120121
# 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']))
122123

123124
# commmand: &stats
124125
# key network stats all in one place
125126
@client.command(description="Key network stats all in one place.", brief="Network stats.")
126-
async def stats():
127+
async def stats(context: commands.Context):
127128
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
128129
async with aiohttp.ClientSession() as session: # Async HTTP request
129130
raw_response = await session.get(url)
130131
response = await raw_response.text()
131132
response = json.loads(response)
132133
# 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'])
134135
)
135136

136137

0 commit comments

Comments
 (0)