Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ Cryptonote network stats discord bot that displays a variety of network informat
## DEPENDENCIES

``
apt-get install python3
apt-get -y install python3 python3-pip
``

``
apt-get -y install python3-pip
``

``
python3 -m pip install discord.py==0.16.12
python3 -m pip install discord.py==2.0.1
``

## HOW TO USE
Expand Down
83 changes: 46 additions & 37 deletions networkbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# DEPENDENCIES
# sudo apt-get install python3
# sudo apt-get -y install python3-pip
# python3 -m pip install discord.py==0.16.12
# python3 -m pip install discord.py>=2.0.0
#
# HOW TO USE
# Go to https://discordapp.com/developers/applications/
Expand All @@ -21,10 +21,12 @@
import random
import asyncio
import aiohttp
import discord
import json
from discord.ext import commands
from discord.ext.commands import Bot

# bot description
# bot description
# bot description displayed in help section
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)'''

Expand All @@ -45,106 +47,113 @@
# port used to communicate with the network (your network's RPC port)
PORT = "YOUR_RPC_PORT_GOES_HERE"

# Create bot
class NetworkBot(Bot):
def __init__(self, *args, **kwargs):
super(NetworkBot, self).__init__(*args, **kwargs)

# print list of servers where this bot is active to console
async def list_servers(self):
await self.tree.sync()
while not self.is_closed():
# you can customize the output message(s) below
print("--- NETWORK BOT ONLINE ---")
for guild in self.guilds:
# you can customize the output message(s) below
print('Active servers: ' + str(guild.name))
await asyncio.sleep(600)

async def on_ready(self):
self.loop.create_task(self.list_servers())

# start a bot
client = Bot(command_prefix=BOT_PREFIX, description=description)
intents = discord.Intents.all()
client = NetworkBot(command_prefix=BOT_PREFIX, description=description, intents=intents)

# commmand: &height
# network top block height
@client.command(description="Network top block height.", brief="Blockchain height.")
async def height():
@client.hybrid_command(description="Network top block height.", brief="Blockchain height.")
async def height(context: commands.Context):
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getheight'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
# you can customize the output message(s) below
await client.say("🌐 **Network height:** " + str(response['height']))
await context.reply("🌐 **Network height:** " + str(response['height']))

# commmand: &hash
# appx. network hash rate
@client.command(description="Appx. network hash rate.", brief="Network hash rate.")
async def hash():
@client.hybrid_command(description="Appx. network hash rate.", brief="Network hash rate.")
async def hash(context: commands.Context):
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
# you can customize the output message(s) below
await client.say("🌐 **Network hash rate:** " + str(response['hashrate']) + " H/s")
await context.reply("🌐 **Network hash rate:** " + str(response['hashrate']) + " H/s")

# commmand: &diff
# current network difficulty
@client.command(description="Current network difficulty.", brief="Network difficulty.")
async def diff():
@client.hybrid_command(description="Current network difficulty.", brief="Network difficulty.")
async def diff(context: commands.Context):
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
# you can customize the output message(s) below
await client.say("🌐 **Network difficulty:** " + str(response['difficulty']))
await context.reply("🌐 **Network difficulty:** " + str(response['difficulty']))

# commmand: &tx
# total network transactions
@client.command(description="Total network transactions.", brief="Network transactions.")
async def tx():
@client.hybrid_command(description="Total network transactions.", brief="Network transactions.")
async def tx(context: commands.Context):
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
# you can customize the output message(s) below
await client.say("🌐 **Network transactions:** " + str(response['tx_count']))
await context.reply("🌐 **Network transactions:** " + str(response['tx_count']))

# commmand: &txpool
# current transactions pool size
@client.command(description="Current transactions pool size.", brief="TX pool size.")
async def txpool():
@client.hybrid_command(description="Current transactions pool size.", brief="TX pool size.")
async def txpool(context: commands.Context):
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
# you can customize the output message(s) below
await client.say("🌐 **Transactions pool:** " + str(response['tx_pool_size']))
await context.reply("🌐 **Transactions pool:** " + str(response['tx_pool_size']))

# commmand: &ver
# current daemon version
@client.command(description="Current daemon version.", brief="Daemon version.")
async def ver():
@client.hybrid_command(description="Current daemon version.", brief="Daemon version.")
async def ver(context: commands.Context):
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
# you can customize the output message(s) below
await client.say("🌐 **Daemon Version:** " + str(response['version']))
await context.reply("🌐 **Daemon Version:** " + str(response['version']))

# commmand: &stats
# key network stats all in one place
@client.command(description="Key network stats all in one place.", brief="Network stats.")
async def stats():
@client.hybrid_command(description="Key network stats all in one place.", brief="Network stats.")
async def stats(context: commands.Context):
url = 'http://' + str(HOST) + ':' + str(PORT) + '/getinfo'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
# you can customize the output message(s) below
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'])
await context.reply("🌐 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'])
)


# print list of servers where this bot is active to console
async def list_servers():
await client.wait_until_ready()
while not client.is_closed:
# you can customize the output message(s) below
print("--- NETWORK BOT ONLINE ---")
for server in client.servers:
# you can customize the output message(s) below
print('Active servers: ' + str(server.name))
await asyncio.sleep(600)


client.loop.create_task(list_servers())
client.run(TOKEN)