Stackey Bot is an open-source Discord bot that integrates with Yours Wallet and provides XP tracking, leveling, and rewards in the form of BitcoinSV (BSV) satoshis. The bot uses Flask for web service integration and SQLite for local database storage.
- XP Tracking: Tracks users' XP based on message content.
- Level Calculation: Calculates user levels based on XP.
- BSV Rewards: Sends satoshis to users upon leveling up.
- Flask Webhooks: Integrates with web services to handle level-up notifications.
- Discord Commands: Provides a command to display current XP and level.
- Python 3.7+
- Discord Account and Server
- BitcoinSV Wallet
- Yours Wallet
.env
file with necessary environment variables
-
Clone the repository:
git clone https://github.com/ishalliveforever/stackey-bot.git cd stackey-bot
-
Install dependencies:
pip install -r requirements.txt
-
Create and configure
.env
file:DISCORD_TOKEN=your_discord_bot_token WALLET_PRIVATE_KEY=your_bsv_wallet_private_key
-
Run the bot:
python bot.py
- !xp: Displays your current XP, level, and XP needed for the next level.
- /notify_level_up: Endpoint to notify the bot of a user's level-up event. Expects a JSON payload with
user_id
andchannel_id
.
import os
import requests
import logging
import discord
import sqlite3
import threading
import math
from discord.ext import commands
from flask import Flask, request
from dotenv import load_dotenv
from bsvlib import Wallet
# Flask app initialization
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, Flask is running!"
# Logging configuration
logging.basicConfig(level=logging.INFO)
# SQLite database setup
conn = sqlite3.connect('xp_database.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS user_xp (user_id INTEGER PRIMARY KEY, xp INTEGER DEFAULT 0)''')
conn.commit()
# Function definitions (get_user_xp, update_user_xp, calculate_level, etc.)
# Load environment variables
load_dotenv()
# Retrieve bot token and wallet private key
bot_token = os.getenv('DISCORD_TOKEN')
private_key_wif = os.getenv('WALLET_PRIVATE_KEY')
# Discord bot setup
intents = discord.Intents.default()
intents.messages = True
intents.guilds = True
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
# Discord command to display XP
@bot.command(name='xp', help='Displays your current XP.')
async def show_xp(ctx):
# Command implementation
# Event handler for new messages
@bot.event
async def on_message(message):
# Event implementation
# Fetch BSV address function
def fetch_user_address(username):
# Function implementation
# Send satoshis function
def send_sats(private_key_wif, to_address, amount_sats):
# Function implementation
# Send level-up message function
async def send_level_up_message(channel, user, xp, level, address):
# Function implementation
# Flask endpoint for level-up notifications
@app.route('/notify_level_up', methods=['POST'])
def notify_level_up():
# Endpoint implementation
# Run Flask app in a separate thread
def run_flask_app():
app.run(host='0.0.0.0', port=5002)
# Main function to start bot and Flask app
if __name__ == '__main__':
threading.Thread(target=run_flask_app).start()
bot.run(bot_token)
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature
) - Create a new Pull Request