1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+ """
4+ Example usage of the karma-based chat membership system.
5+
6+ This script demonstrates how to configure and use the automatic
7+ chat membership management based on user karma levels.
8+ """
9+
10+ # Example configuration that would go in config.py:
11+
12+ EXAMPLE_KARMA_BASED_CHATS = [
13+ {
14+ "chat_id" : 2000000001 , # Main programming chat
15+ "karma_threshold" : 2 , # Users need 2+ karma to join
16+ "name" : "Main Programming Chat"
17+ },
18+ {
19+ "chat_id" : 2000000002 , # Advanced developers chat
20+ "karma_threshold" : 10 , # Users need 10+ karma to join
21+ "name" : "Advanced Developers"
22+ },
23+ {
24+ "chat_id" : 2000000003 , # Expert level chat
25+ "karma_threshold" : 50 , # Users need 50+ karma to join
26+ "name" : "Expert Developers"
27+ },
28+ {
29+ "chat_id" : 2000000004 , # Mentor level chat
30+ "karma_threshold" : 100 , # Users need 100+ karma to join
31+ "name" : "Mentors & Leads"
32+ }
33+ ]
34+
35+ # Example scenarios:
36+
37+ def example_scenarios ():
38+ """Show example scenarios of how the system works."""
39+
40+ scenarios = [
41+ {
42+ "user" : "Alice" ,
43+ "karma" : 1 ,
44+ "description" : "New user with 1 karma - not in any karma chats yet"
45+ },
46+ {
47+ "user" : "Bob" ,
48+ "karma" : 3 ,
49+ "description" : "Gets added to Main Programming Chat (threshold: 2)"
50+ },
51+ {
52+ "user" : "Charlie" ,
53+ "karma" : 15 ,
54+ "description" : "Gets added to Main Programming Chat and Advanced Developers (thresholds: 2, 10)"
55+ },
56+ {
57+ "user" : "David" ,
58+ "karma" : 75 ,
59+ "description" : "Gets added to first three chats (thresholds: 2, 10, 50)"
60+ },
61+ {
62+ "user" : "Eve" ,
63+ "karma" : 150 ,
64+ "description" : "Gets added to all chats (thresholds: 2, 10, 50, 100)"
65+ }
66+ ]
67+
68+ print ("🎯 Karma-Based Chat Membership Examples" )
69+ print ("=" * 50 )
70+
71+ for scenario in scenarios :
72+ print (f"\n 👤 { scenario ['user' ]} (Karma: { scenario ['karma' ]} )" )
73+ print (f" { scenario ['description' ]} " )
74+
75+ # Show which chats they would be in
76+ eligible_chats = []
77+ for chat in EXAMPLE_KARMA_BASED_CHATS :
78+ if scenario ['karma' ] >= chat ['karma_threshold' ]:
79+ eligible_chats .append (f"{ chat ['name' ]} (≥{ chat ['karma_threshold' ]} )" )
80+
81+ if eligible_chats :
82+ print (f" 📩 Eligible for: { ', ' .join (eligible_chats )} " )
83+ else :
84+ print (f" ❌ Not eligible for any karma-based chats" )
85+
86+ def example_commands ():
87+ """Show example bot commands for managing karma chats."""
88+
89+ commands = [
90+ {
91+ "command" : "check chat membership" ,
92+ "description" : "Check your membership in all karma-based chats and update if needed"
93+ },
94+ {
95+ "command" : "check all membership" ,
96+ "description" : "Admin command to check and update all users' memberships"
97+ },
98+ {
99+ "command" : "chat status" ,
100+ "description" : "Show status of current chat (member counts, karma threshold)"
101+ },
102+ {
103+ "command" : "chat status 2000000001" ,
104+ "description" : "Show status of specific chat by ID"
105+ },
106+ {
107+ "command" : "+" ,
108+ "description" : "Give karma to a user (triggers automatic membership check)"
109+ },
110+ {
111+ "command" : "-" ,
112+ "description" : "Remove karma from a user (triggers automatic membership check)"
113+ }
114+ ]
115+
116+ print ("\n 🤖 Available Bot Commands" )
117+ print ("=" * 50 )
118+
119+ for cmd in commands :
120+ print (f"\n 💬 '{ cmd ['command' ]} '" )
121+ print (f" { cmd ['description' ]} " )
122+
123+ def example_workflow ():
124+ """Show example workflow of how the system operates."""
125+
126+ print ("\n ⚙️ System Workflow" )
127+ print ("=" * 50 )
128+
129+ steps = [
130+ "1. User receives karma (+1 or -1) from another user" ,
131+ "2. System automatically checks user's new karma level" ,
132+ "3. For each configured karma-based chat:" ,
133+ " a. Check if user meets karma threshold" ,
134+ " b. Check if user is currently in the chat" ,
135+ " c. Add user to chat if they meet threshold but aren't in it" ,
136+ " d. Remove user from chat if they don't meet threshold but are in it" ,
137+ "4. Log all membership changes for admin review" ,
138+ "5. Send confirmation messages for successful operations"
139+ ]
140+
141+ for step in steps :
142+ print (f"\n { step } " )
143+
144+ def example_configuration_tips ():
145+ """Provide tips for configuring the karma chat system."""
146+
147+ print ("\n 💡 Configuration Tips" )
148+ print ("=" * 50 )
149+
150+ tips = [
151+ "Start with low thresholds (2-5 karma) for basic chats" ,
152+ "Create progressive tiers (2, 10, 25, 50, 100)" ,
153+ "Test with a small group before rolling out to all chats" ,
154+ "Monitor logs to ensure the system is working correctly" ,
155+ "Consider having fallback manual commands for edge cases" ,
156+ "Set up different thresholds for different types of chats" ,
157+ "Use descriptive names for easier administration"
158+ ]
159+
160+ for i , tip in enumerate (tips , 1 ):
161+ print (f"\n { i } . { tip } " )
162+
163+ if __name__ == "__main__" :
164+ example_scenarios ()
165+ example_commands ()
166+ example_workflow ()
167+ example_configuration_tips ()
168+
169+ print ("\n " + "=" * 50 )
170+ print ("🎉 Karma-based chat membership system is ready!" )
171+ print ("Configure your KARMA_BASED_CHATS in config.py to get started." )
0 commit comments