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==1.3.4
8
+ # python3 -m pip install discord.py>=2.0.0
9
9
#
10
10
# HOW TO USE
11
11
# Go to https://discordapp.com/developers/applications/
21
21
import random
22
22
import asyncio
23
23
import aiohttp
24
+ import discord
24
25
import json
25
26
from discord .ext import commands
26
27
from discord .ext .commands import Bot
46
47
# port used to communicate with the network (your network's RPC port)
47
48
PORT = "YOUR_RPC_PORT_GOES_HERE"
48
49
50
+ # Create bot
51
+ class NetworkBot (Bot ):
52
+ def __init__ (self , * args , ** kwargs ):
53
+ super (NetworkBot , self ).__init__ (* args , ** kwargs )
54
+
55
+ # print list of servers where this bot is active to console
56
+ async def list_servers (self ):
57
+ await self .tree .sync ()
58
+ while not self .is_closed ():
59
+ # you can customize the output message(s) below
60
+ print ("--- NETWORK BOT ONLINE ---" )
61
+ for guild in self .guilds :
62
+ # you can customize the output message(s) below
63
+ print ('Active servers: ' + str (guild .name ))
64
+ await asyncio .sleep (600 )
65
+
66
+ async def on_ready (self ):
67
+ self .loop .create_task (self .list_servers ())
68
+
49
69
# start a bot
50
- client = Bot (command_prefix = BOT_PREFIX , description = description )
70
+ intents = discord .Intents .all ()
71
+ client = NetworkBot (command_prefix = BOT_PREFIX , description = description , intents = intents )
51
72
52
73
# commmand: &height
53
74
# network top block height
54
- @client .command (description = "Network top block height." , brief = "Blockchain height." )
75
+ @client .hybrid_command (description = "Network top block height." , brief = "Blockchain height." )
55
76
async def height (context : commands .Context ):
56
77
url = 'http://' + str (HOST ) + ':' + str (PORT ) + '/getheight'
57
78
async with aiohttp .ClientSession () as session : # Async HTTP request
@@ -63,7 +84,7 @@ async def height(context: commands.Context):
63
84
64
85
# commmand: &hash
65
86
# appx. network hash rate
66
- @client .command (description = "Appx. network hash rate." , brief = "Network hash rate." )
87
+ @client .hybrid_command (description = "Appx. network hash rate." , brief = "Network hash rate." )
67
88
async def hash (context : commands .Context ):
68
89
url = 'http://' + str (HOST ) + ':' + str (PORT ) + '/getinfo'
69
90
async with aiohttp .ClientSession () as session : # Async HTTP request
@@ -75,7 +96,7 @@ async def hash(context: commands.Context):
75
96
76
97
# commmand: &diff
77
98
# current network difficulty
78
- @client .command (description = "Current network difficulty." , brief = "Network difficulty." )
99
+ @client .hybrid_command (description = "Current network difficulty." , brief = "Network difficulty." )
79
100
async def diff (context : commands .Context ):
80
101
url = 'http://' + str (HOST ) + ':' + str (PORT ) + '/getinfo'
81
102
async with aiohttp .ClientSession () as session : # Async HTTP request
@@ -87,7 +108,7 @@ async def diff(context: commands.Context):
87
108
88
109
# commmand: &tx
89
110
# total network transactions
90
- @client .command (description = "Total network transactions." , brief = "Network transactions." )
111
+ @client .hybrid_command (description = "Total network transactions." , brief = "Network transactions." )
91
112
async def tx (context : commands .Context ):
92
113
url = 'http://' + str (HOST ) + ':' + str (PORT ) + '/getinfo'
93
114
async with aiohttp .ClientSession () as session : # Async HTTP request
@@ -99,7 +120,7 @@ async def tx(context: commands.Context):
99
120
100
121
# commmand: &txpool
101
122
# current transactions pool size
102
- @client .command (description = "Current transactions pool size." , brief = "TX pool size." )
123
+ @client .hybrid_command (description = "Current transactions pool size." , brief = "TX pool size." )
103
124
async def txpool (context : commands .Context ):
104
125
url = 'http://' + str (HOST ) + ':' + str (PORT ) + '/getinfo'
105
126
async with aiohttp .ClientSession () as session : # Async HTTP request
@@ -111,7 +132,7 @@ async def txpool(context: commands.Context):
111
132
112
133
# commmand: &ver
113
134
# current daemon version
114
- @client .command (description = "Current daemon version." , brief = "Daemon version." )
135
+ @client .hybrid_command (description = "Current daemon version." , brief = "Daemon version." )
115
136
async def ver (context : commands .Context ):
116
137
url = 'http://' + str (HOST ) + ':' + str (PORT ) + '/getinfo'
117
138
async with aiohttp .ClientSession () as session : # Async HTTP request
@@ -123,7 +144,7 @@ async def ver(context: commands.Context):
123
144
124
145
# commmand: &stats
125
146
# key network stats all in one place
126
- @client .command (description = "Key network stats all in one place." , brief = "Network stats." )
147
+ @client .hybrid_command (description = "Key network stats all in one place." , brief = "Network stats." )
127
148
async def stats (context : commands .Context ):
128
149
url = 'http://' + str (HOST ) + ':' + str (PORT ) + '/getinfo'
129
150
async with aiohttp .ClientSession () as session : # Async HTTP request
@@ -135,17 +156,4 @@ async def stats(context: commands.Context):
135
156
)
136
157
137
158
138
- # print list of servers where this bot is active to console
139
- async def list_servers ():
140
- await client .wait_until_ready ()
141
- while not client .is_closed :
142
- # you can customize the output message(s) below
143
- print ("--- NETWORK BOT ONLINE ---" )
144
- for server in client .servers :
145
- # you can customize the output message(s) below
146
- print ('Active servers: ' + str (server .name ))
147
- await asyncio .sleep (600 )
148
-
149
-
150
- client .loop .create_task (list_servers ())
151
159
client .run (TOKEN )
0 commit comments