-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteemStats.py
More file actions
154 lines (126 loc) · 4.82 KB
/
SteemStats.py
File metadata and controls
154 lines (126 loc) · 4.82 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import discord
import aiohttp
import asyncio
import requests
import re
import json
import logging
import matplotlib.pyplot as plt
from io import BytesIO
from discord import app_commands
import random
import socket
from time import time
import io
from datetime import datetime, timedelta
from discord.ext import commands, tasks
from datetime import datetime, timezone
import json
import os
# Set up logging to suppress PyNaCl warning
logging.basicConfig(level=logging.INFO)
# Get the discord logger
discord_logger = logging.getLogger('discord')
discord_logger.setLevel(logging.ERROR) # Suppress all warnings related to PyNaCl
# Initialize the bot
TOKEN = 'my bot token'
intents = discord.Intents.default()
intents.messages = True
intents.guilds = True
# Set up logging
logging.basicConfig(level=logging.INFO)
# Replace `discord.Client` with `commands.Bot`
bot = commands.Bot(command_prefix="!", intents=intents)
# Log all command usage
@bot.event
async def on_command(ctx):
logging.info(f"Command '{ctx.command}' used by {ctx.author} in {ctx.guild}")
# Define client before using it
client = discord.Client(intents=intents)
tree = discord.app_commands.CommandTree(client)
# Define intents
intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
intents.guilds = True
# Client setup
client = discord.Client(intents=intents)
tree = discord.app_commands.CommandTree(client)
STEEM = 'STEEM'
# Fetaure 7
# Function to fetch vesting stats from the API
async def fetch_vesting_stats(session):
try:
url = 'https://sds0.steemworld.org/accounts_api/getVestingStats'
async with session.get(url) as response:
response.raise_for_status()
data = await response.json()
return data['result']['defs'] # Extracting data under the 'defs' key
except aiohttp.ClientError as e:
print(f"Error fetching vesting stats: {e}")
return {}
except Exception as e:
print(f"Unexpected error: {e}")
return {}
# Function to fetch vests to SP conversion rate
async def fetch_vests_to_sp_conversion_rate(session):
try:
url = 'https://api.justyy.workers.dev/api/steemit/vests/?cached'
async with session.get(url) as response:
response.raise_for_status()
data = await response.json()
return data['vests_to_sp'] # Conversion rate from vests to SP
except aiohttp.ClientError as e:
print(f"Error fetching conversion rate: {e}")
return 0
except Exception as e:
print(f"Unexpected error: {e}")
return 0
# Slash command to get vesting statistics with formatted embed
@tree.command(name="vestingstats", description="Get detailed statistics of vesting accounts with SP conversion")
async def vesting_stats_command(interaction: discord.Interaction):
print("Slash command /vestingstats received.")
await interaction.response.defer()
async with aiohttp.ClientSession() as session:
vesting_data = await fetch_vesting_stats(session)
conversion_rate = await fetch_vests_to_sp_conversion_rate(session)
# Mapping categories to emojis, descriptions, and count
categories = {
'redfish': ('🐟 Redfish', '0 MV - 1 MV'),
'minnow': ('🐠 Minnow', '1 MV - 10 MV'),
'dolphin': ('🐬 Dolphin', '10 MV - 100 MV'),
'orca': ('🐋 Orca', '100 MV - 1,000 MV'),
'whale': ('🐳 Whale', '1,000 MV+') # Handled separately
}
embed = discord.Embed(title="Steem Vesting Stats", color=0x21D19F) # teal or greenish-blue
for category, (emoji, mv_range) in categories.items():
count = vesting_data[category]['count']
if category == 'whale':
min_sp = vesting_data[category]['from'] * conversion_rate
sp_range = f"({min_sp:,.2f} SP +)"
else:
min_vest, max_vest = vesting_data[category]['from'], vesting_data[category]['to']
min_sp = min_vest * conversion_rate
max_sp = max_vest * conversion_rate
sp_range = f"({min_sp:,.2f} SP - {max_sp:,.2f} SP)"
embed.add_field(name=f"{emoji} {mv_range} {sp_range}", value=f"Count: {count:,}", inline=False)
# Adding footer to the embed
embed.set_footer(text="API provided by @steemchiller and @justyy | developed by @dhaka.witness")
await interaction.followup.send(embed=embed)
print("Vesting stats SP embedded message sent.")
# Event when the bot is ready
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
await tree.sync()
print("Slash commands synced with Discord.")
# Main function to start the bot
asyncio.run(client.start(TOKEN))
# Main function to start the bot
async def main():
try:
await client.start(TOKEN)
except Exception as e:
logging.error(f"Error starting the bot: {e}")
if __name__ == "__main__":
asyncio.run(main())