Release 1.0.0

This commit is contained in:
2026-03-12 21:45:01 +00:00
parent 28be3105b6
commit b2a9f74f59
12 changed files with 1028 additions and 522 deletions
+158 -3
View File
@@ -16,7 +16,7 @@ from update_checker import start_update_checker
# Bot version (increment when making changes)
BOT_VERSION = "1.0"
BOT_VERSION = "1.0.0"
# Database file to track posted versions
DB_DIR = os.path.join(os.path.dirname(__file__), 'DB')
@@ -135,21 +135,172 @@ def check_for_updates(reddit):
# Check Bedrock Edition releases if enabled
if config.CHECK_BEDROCK:
print(f"[BOT] Checking Bedrock Edition releases...")
bedrock_release = get_latest_bedrock_release()
if bedrock_release:
bedrock_id = f"bedrock-{bedrock_release['version']}"
source = bedrock_release.get('source', 'unknown')
if bedrock_id not in posted_versions:
print(f"[BOT] New Bedrock release found: {bedrock_release['version']}")
print(f"[BOT] New Bedrock release found: {bedrock_release['version']} (from {source})")
if post_to_subreddit(reddit, bedrock_release):
save_posted_version(bedrock_id)
else:
print(f"[BOT] Bedrock version {bedrock_release['version']} already posted, skipping")
else:
print(f"[BOT] ⚠ No Bedrock release data available")
else:
print(f"[BOT] Bedrock Edition checking is disabled (REDDIT_CHECK_BEDROCK={config.CHECK_BEDROCK})")
except Exception as e:
print(f"[BOT] ✗ Error checking for updates: {e}")
def repost_latest_versions(reddit):
"""
Repost the latest Minecraft releases (Java & Bedrock).
This bypasses the "already posted" check, allowing moderators to
manually repost the latest versions via the "repost-latest" chat command.
Args:
reddit: PRAW Reddit instance
"""
try:
posted_count = 0
# Repost latest Java Edition releases
java_releases = get_latest_releases(config.RELEASE_TYPES)
for version_info in java_releases:
version_id = version_info["id"]
print(f"[BOT] Reposting Java release: {version_id}")
if post_to_subreddit(reddit, version_info):
posted_count += 1
# Repost latest Bedrock Edition release if enabled
if config.CHECK_BEDROCK:
bedrock_release = get_latest_bedrock_release()
if bedrock_release:
version_id = bedrock_release["id"]
print(f"[BOT] Reposting Bedrock release: {version_id}")
if post_to_subreddit(reddit, bedrock_release):
posted_count += 1
else:
print(f"[BOT] ⚠ No Bedrock release data available for repost")
print(f"[BOT] ✓ Reposted {posted_count} version(s)")
return posted_count > 0
except Exception as e:
print(f"[BOT] ✗ Error reposting latest versions: {e}")
return False
def chat_message_watcher(reddit):
"""
Background thread that watches for chat messages with reload commands.
Monitors Reddit chat messages for moderators sending "reload-config"
to trigger a reload of the wiki configuration without restarting the bot.
Args:
reddit: PRAW Reddit instance
"""
chat_requests_file = os.path.join(DB_DIR, 'chat_wiki_requests.txt')
processed_message_ids = set()
subreddit = reddit.subreddit(config.SUBREDDIT)
print("[CHAT] Chat message watcher started")
# Load previously processed message IDs
if os.path.exists(chat_requests_file):
try:
with open(chat_requests_file, 'r', encoding='utf-8') as f:
for line in f:
processed_message_ids.add(line.strip())
except Exception as e:
print(f"[CHAT] Error loading processed message IDs: {e}")
while True:
try:
for message in reddit.inbox.stream():
# Skip if no ID or already processed
if not hasattr(message, 'id') or message.id in processed_message_ids:
continue
# Mark as processed
processed_message_ids.add(message.id)
try:
with open(chat_requests_file, 'a', encoding='utf-8') as f:
f.write(message.id + '\n')
except Exception as e:
print(f"[CHAT] Error saving message ID: {e}")
# Check for reload-config command
if hasattr(message, 'body') and 'reload-config' in message.body.lower():
author = getattr(message, 'author', None)
# Verify sender is a moderator
try:
if author and author in subreddit.moderator():
print(f"[CHAT] Moderator '{author}' requested config reload")
# Reload wiki configuration
try:
wiki_config.fetch_from_wiki()
print("[CHAT] Wiki config reloaded successfully")
reply_text = "✓ Wiki config reloaded successfully!"
except Exception as e:
print(f"[CHAT] Failed to reload wiki config: {e}")
reply_text = f"✗ Failed to reload wiki config: {e}"
# Reply to the message
try:
message.reply(reply_text)
print(f"[CHAT] Replied to message {message.id}")
except Exception as e:
print(f"[CHAT] Error replying to message {message.id}: {e}")
else:
print(f"[CHAT] Non-moderator '{author}' attempted reload-config (ignored)")
except Exception as e:
print(f"[CHAT] Error checking moderator status: {e}")
# Check for repost-latest command
elif hasattr(message, 'body') and 'repost-latest' in message.body.lower():
author = getattr(message, 'author', None)
# Verify sender is a moderator
try:
if author and author in subreddit.moderator():
print(f"[CHAT] Moderator '{author}' requested repost of latest versions")
# Repost latest versions
try:
if repost_latest_versions(reddit):
reply_text = "✓ Latest versions reposted successfully!"
else:
reply_text = "✗ Failed to repost latest versions."
except Exception as e:
print(f"[CHAT] Error reposting latest versions: {e}")
reply_text = f"✗ Error reposting latest versions: {e}"
# Reply to the message
try:
message.reply(reply_text)
print(f"[CHAT] Replied to message {message.id}")
except Exception as e:
print(f"[CHAT] Error replying to message {message.id}: {e}")
else:
print(f"[CHAT] Non-moderator '{author}' attempted repost-latest (ignored)")
except Exception as e:
print(f"[CHAT] Error checking moderator status: {e}")
except Exception as e:
print(f"[CHAT] Error in chat message watcher: {e}")
time.sleep(30)
def bot_thread(reddit):
"""
Background thread that periodically checks for Minecraft updates.
@@ -191,10 +342,14 @@ def start_bot():
# Do an initial check
check_for_updates(reddit)
# Start background thread
# Start background thread for update checking
thread = threading.Thread(target=bot_thread, args=(reddit,), daemon=True)
thread.start()
# Start background thread for chat commands
chat_thread = threading.Thread(target=chat_message_watcher, args=(reddit,), daemon=True)
chat_thread.start()
print("[BOT] ✓ Bot is running")
# Keep main thread alive