Refactor help plugin, and included metadata to all plugins
This commit is contained in:
+36
-3
@@ -54,6 +54,14 @@ display_name_cache = {}
|
||||
cache_timestamp = {}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helper: pluralize "point" vs "points"
|
||||
# ---------------------------------------------------------------------------
|
||||
def pluralize_points(amount):
|
||||
"""Return 'point' if amount is 1 or -1, else 'points'."""
|
||||
return "point" if abs(amount) == 1 else "points"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Database Setup with Room Support
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -625,7 +633,8 @@ async def handle_karma_command(room, message, bot, config):
|
||||
response = f"🏆 **Top {len(leaderboard)} Karma Leaders**\n\n"
|
||||
for i, entry in enumerate(leaderboard, 1):
|
||||
medal = "🥇" if i == 1 else "🥈" if i == 2 else "🥉" if i == 3 else "📌"
|
||||
response += f"{medal} **{i}.** {entry['display_name']}: {entry['points']} points\n"
|
||||
pts = entry['points']
|
||||
response += f"{medal} **{i}.** {entry['display_name']}: {pts} {pluralize_points(pts)}\n"
|
||||
await bot.api.send_markdown_message(room.room_id, response)
|
||||
else:
|
||||
await bot.api.send_markdown_message(room.room_id, "No karma entries found in this room.")
|
||||
@@ -641,7 +650,8 @@ async def handle_karma_command(room, message, bot, config):
|
||||
if leaderboard:
|
||||
response = f"📉 **Bottom {len(leaderboard)} Karma (Needs Love)**\n\n"
|
||||
for i, entry in enumerate(leaderboard, 1):
|
||||
response += f"⚠️ **{i}.** {entry['display_name']}: {entry['points']} points\n"
|
||||
pts = entry['points']
|
||||
response += f"⚠️ **{i}.** {entry['display_name']}: {pts} {pluralize_points(pts)}\n"
|
||||
await bot.api.send_markdown_message(room.room_id, response)
|
||||
else:
|
||||
await bot.api.send_markdown_message(room.room_id, "No karma entries found in this room.")
|
||||
@@ -661,7 +671,7 @@ async def handle_karma_command(room, message, bot, config):
|
||||
points = get_karma(room_id, user_id)
|
||||
percentile = round((1 - rank/total) * 100, 1) if total > 0 else 0
|
||||
display_name_resolved = get_display_name_from_user_id(bot, room_id, user_id)
|
||||
response = f"📊 **{display_name_resolved}** is ranked #{rank} out of {total} (top {percentile}%)\n💗 Karma: {points} points"
|
||||
response = f"📊 **{display_name_resolved}** is ranked #{rank} out of {total} (top {percentile}%)\n💗 Karma: {points} {pluralize_points(points)}"
|
||||
await bot.api.send_markdown_message(room.room_id, response)
|
||||
else:
|
||||
display_name_resolved = get_display_name_from_user_id(bot, room_id, user_id)
|
||||
@@ -801,3 +811,26 @@ def setup(bot):
|
||||
logging.info("Supports display names (e.g., 'Nexilva' or '🍄 HB🍄') and Matrix IDs")
|
||||
logging.info("Commands: !karma, !karma++, !karma--, !++, !--, and inline ++/--")
|
||||
logging.info("=" * 50)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Plugin Metadata
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
__version__ = "1.0.0"
|
||||
__author__ = "Funguy Bot"
|
||||
__description__ = "Room karma tracking system"
|
||||
__help__ = """
|
||||
<details>
|
||||
<summary><strong>!karma</strong> – Karma system</summary>
|
||||
<ul>
|
||||
<li><code>!karma <user></code> – Show points</li>
|
||||
<li><code>!karma++ <user></code> / <code>!-- <user></code> – Modify karma</li>
|
||||
<li><code>!karma top [n]</code> / <code>!karma bottom [n]</code> – Leaderboard</li>
|
||||
<li><code>!karma rank <user></code> – Position</li>
|
||||
<li><code>!karma stats</code> – Room statistics</li>
|
||||
<li><code>!karma history <user></code> – Recent votes</li>
|
||||
</ul>
|
||||
<p>Shortcuts: <code>!++ user</code>, <code>!-- user</code>, and inline <code>user++</code> / <code>user--</code>.</p>
|
||||
</details>
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user