-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py.example
More file actions
310 lines (276 loc) · 15.2 KB
/
config.py.example
File metadata and controls
310 lines (276 loc) · 15.2 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
"""
This is the EXAMPLE configuration file for Reddit Bot v2.2.
**IMPORTANT SETUP INSTRUCTIONS:**
1. RENAME this file to `config.py`.
2. FILL IN your secret keys, credentials, and preferences in your new `config.py`.
3. The actual `config.py` file (containing your secrets) is listed in `.gitignore`
and will NOT be committed to version control. This `config.py.example` file,
however, *should* be committed as it serves as a template for all users.
"""
class ApiConfig:
"""
Holds all necessary API keys and credentials for external services.
"""
# --- Gemini API Configuration ---
# Your Google Gemini API Key. Obtain from Google AI Studio.
# This is essential for all AI-driven features (content generation, analysis).
# Example: "AIzaSy..."
GEMINI_API_KEY = "YOUR_GEMINI_API_KEY_HERE"
# The specific Gemini model to use.
# "gemini-1.5-flash-latest" is recommended for its balance of speed,
# capability, and cost-effectiveness for bot operations.
# Other models like "gemini-1.5-pro-latest" can be used for potentially higher quality
# but may have different cost and rate limit implications.
GEMINI_MODEL_NAME = "gemini-1.5-flash-latest"
# --- Reddit API & Account Configuration ---
# A list of dictionaries, where each dictionary represents one Reddit account.
# The bot will randomly pick one account from this list for each operational cycle.
# You can add multiple accounts to distribute activity.
#
# How to get Reddit API credentials:
# 1. Go to: https://www.reddit.com/prefs/apps
# 2. Scroll down and click "are you a developer? create an app..."
# 3. Fill in the form:
# - name: (e.g., "MyRedditBotV2")
# - type: select "script"
# - description: (optional)
# - about url: (optional)
# - redirect uri: http://localhost:8080 (important for script apps)
# 4. Click "create app".
# 5. You will see your app listed. Your `client_id` is the string under "personal use script".
# Your `client_secret` is the string next to "secret".
REDDIT_ACCOUNTS = [
{
"username": "YOUR_REDDIT_USERNAME_1", # Your Reddit username
"password": "YOUR_REDDIT_PASSWORD_1", # Your Reddit password
"client_id": "YOUR_REDDIT_CLIENT_ID_1", # From your Reddit app settings
"client_secret": "YOUR_REDDIT_CLIENT_SECRET_1", # From your Reddit app settings
},
# {
# "username": "YOUR_REDDIT_USERNAME_2",
# "password": "YOUR_REDDIT_PASSWORD_2",
# "client_id": "YOUR_REDDIT_CLIENT_ID_2",
# "client_secret": "YOUR_REDDIT_CLIENT_SECRET_2",
# },
]
# --- Discord Webhook (Optional) ---
# URL for the Discord webhook if you want to use `log_forwarder.py`
# to send bot logs to a Discord channel.
# If not used, leave as "" or "YOUR_DISCORD_WEBHOOK_URL_HERE".
DISCORD_WEBHOOK_URL = "YOUR_DISCORD_WEBHOOK_URL_HERE"
ENABLE_CRYPTO_PRICE_API = True
COINGECKO_API_URL = "https://api.coingecko.com/api/v3/simple/price"
DEFAULT_CRYPTO_IDS_TO_TRACK = ["bitcoin", "ethereum", "solana"]
class PersonaConfig:
"""
Configuration for the bot's dynamic personalities.
A persona defines the AI's tone, style, and background.
"""
# Define various personas the bot can adopt.
# The 'key' (e.g., "default", "expert") is used in SUBREDDIT_PERSONA_MAPPING.
# The 'value' is a descriptive string fed to the AI.
PERSONAS = {
"default": "a neutral, helpful, and friendly community member who writes clear and concise comments.",
"expert": "a helpful and detailed subject matter expert with a formal, precise, and evidence-based tone.",
"comedian": "a witty and slightly sarcastic user who uses clever humor and lighthearted banter, but avoids being offensive.",
"enthusiast": "a very friendly, encouraging, and highly positive community member who loves to share excitement."
# Add your custom personas here, e.g.:
# "crypto_analyst": "a knowledgeable and data-driven crypto analyst providing insightful comments on market trends and technology."
}
# Assign specific personas to subreddits.
# Keys are lowercase subreddit names. Values are keys from the PERSONAS dictionary.
# If a subreddit is not listed here, the "default" persona will be used.
SUBREDDIT_PERSONA_MAPPING = {
"askscience": "expert",
"python": "expert",
"memes": "comedian",
"mademesmile": "enthusiast",
# Example for your crypto strategy:
# "cryptomoonshots": "crypto_enthusiast",
# "cryptocurrency": "crypto_analyst"
}
class BotStrategy:
"""
Defines the bot's high-level operational strategy and action choices.
"""
# --- Action Weighting ---
# Defines the probability of the bot choosing a particular action in each cycle.
# Values should sum to 1.0 for a clear probability distribution.
# Available actions: "comment", "deploy_knowledge_content", "create_post", "update_scores".
# Note: "check_replies" is now an automatic follow-up action after successful
# commenting or posting, not a primary weighted action.
ACTION_WEIGHTS = {
"comment": 0.50, # Comment on relevant "hot" posts in TARGET_SUBREDDITS
"deploy_knowledge_content": 0.35, # Proactively find places for knowledge base content
"create_post": 0.10, # Create new threads (autonomous or predefined)
"update_scores": 0.05 # Periodically update scores of own interactions
}
# --- Subreddit Targeting ---
# List of subreddits for general interaction (actions: "comment", "create_post").
# The bot will randomly pick from this list for these actions.
TARGET_SUBREDDITS = ["AskReddit", "testingground4bots", "FreeKarma4U"]
# List of subreddits for the "deploy_knowledge_content" action.
# This can be the same as TARGET_SUBREDDITS, broader, or more specific.
# If left empty, TARGET_SUBREDDITS will be used.
# Example: ["technology", "artificialintelligence", "futurology", "web3"]
KNOWLEDGE_DEPLOYMENT_SUBREDDITS = []
# --- Knowledge Deployment Search Configuration ---
# Defines how many keywords from a knowledge.json entry are used to construct
# the Reddit search query during the "deploy_knowledge_content" action.
# The bot will use the *first N* keywords from the "keywords" list specified
# in the selected knowledge base entry.
# - A smaller number (e.g., 3-5) creates a more focused, specific search query.
# - A larger number (e.g., 7-10) broadens the search, which might find more
# potential posts but could also include less relevant ones.
KNOWLEDGE_DEPLOYMENT_SEARCH_KEYWORD_COUNT = 5
# --- Commenting Strategy (for "comment" action on hot posts) ---
# If True, bot only comments on posts meeting MIN_UPVOTES and MIN_COMMENTS.
USE_SMART_TARGETING = True
MIN_UPVOTES = 10
MIN_COMMENTS = 5
# --- Sentiment Analysis ---
# If True, bot analyzes sentiment before interacting.
USE_SENTIMENT_GUARDRAIL = True
# Global list of sentiments to avoid if no subreddit-specific rule overrides this.
# Possible values: "Positive", "Neutral", "Negative", "Controversial".
AVOID_SENTIMENTS_GLOBAL = ["Controversial"]
# --- Autonomous Topic Discovery (for "comment" and "create_post" actions) ---
# If True, bot uses AI to identify trending topics in subreddits.
USE_AUTONOMOUS_TOPIC_DISCOVERY = True
# How often (in hours) to refresh the topic cache for a subreddit.
TOPIC_DISCOVERY_COOLDOWN_HOURS = 12
# How many top "hot" posts to analyze for topic discovery.
TOPIC_DISCOVERY_POST_LIMIT = 50
# --- Thread Creation (for "create_post" action) ---
ALLOW_THREAD_CREATION = True
# If True, AI generates post title/body based on discovered topics/persona.
# If False, uses PREDEFINED_POSTS from ContentGeneration class.
USE_AUTONOMOUS_POSTING = True
# --- Burst Mode Configuration ---
# If True, the bot has a chance to enter "Burst Mode" in a cycle.
ENABLE_BURST_MODE = True
# Probability (0.0 to 1.0) of entering Burst Mode in any given cycle.
# Example: 0.15 means a 15% chance.
BURST_MODE_PROBABILITY = 0.15
# Maximum number of actions the bot will attempt to perform during a single Burst Mode session.
ACTIONS_PER_BURST = 3
# Cooldown between individual actions *within* a Burst Mode session (in seconds).
COOLDOWN_BETWEEN_BURST_ACTIONS_MIN_SECONDS = 60 # 1 minute
COOLDOWN_BETWEEN_BURST_ACTIONS_MAX_SECONDS = 300 # 5 minutes
class SubredditRuleConfig:
"""
Per-subreddit rules to customize bot behavior more granularly.
This allows fine-tuning for subreddits with specific posting guidelines or cultures.
Each rule is OPTIONAL. If a key for a rule is not present for a subreddit,
the bot will use global defaults or a generally permissive behavior
(e.g., it will attempt to post, external links are allowed by default).
"""
# Keys are lowercase subreddit names.
SUBREDDIT_RULES = {
"python": {
"allow_external_links": False, # Set to False to prevent adding links from Knowledge Base
"active_hours_utc": [8, 23], # Bot will only operate in this UTC hour range (8:00-22:59)
# Example: Active 8 AM to 10:59 PM UTC
# (List of two integers: start_hour, end_hour (exclusive))
"sentiment_override": {
"avoid": ["Controversial"], # List of sentiments to avoid, overrides AVOID_SENTIMENTS_GLOBAL
"allow_negative_on_critique": True # If True, allows commenting on "Negative" posts if deemed legit critique by persona
},
"can_create_new_posts": True # Explicitly allow creating new submissions (threads)
},
"askreddit": {
"allow_external_links": False,
"active_hours_utc": [0, 23], # Example: Active almost all day
"can_create_new_posts": True # AskReddit is generally for new posts (questions)
},
"some_strict_subreddit": { # Example for a subreddit with many restrictions
"allow_external_links": False,
"can_create_new_posts": False, # Explicitly disallow creating new submissions
"sentiment_override": {
"avoid": ["Negative", "Controversial"], # Stricter sentiment avoidance
"allow_negative_on_critique": False
}
}
# Add more subreddit-specific rules here.
# If 'can_create_new_posts' is not specified for a subreddit, it defaults to True (bot will attempt to create posts).
# If 'allow_external_links' is not specified, it defaults to True.
# If 'active_hours_utc' is not specified, the bot operates 24/7 in that subreddit.
# If 'sentiment_override' is not specified, AVOID_SENTIMENTS_GLOBAL from BotStrategy applies.
}
class ContentGeneration:
"""
Configuration for predefined content.
Used by the "create_post" action if BotStrategy.USE_AUTONOMOUS_POSTING is False.
"""
# A list of dictionaries, each representing a post.
PREDEFINED_POSTS = [
{
"title": "What's a small daily habit that has significantly improved your life?",
"body": "Looking for inspiration to build better routines. What works for you?"
},
{
"title": "What are you learning right now that you're excited about?",
"body": "" # Body can be empty if not needed
}
]
class StealthConfig:
"""
Parameters for bot's file paths, timing, and other low-level behavior.
"""
# --- File Paths ---
# Database file for storing interactions, logs, etc.
DATABASE_FILE = "bot_data.db"
# JSON file for the bot's knowledge base (used for "deploy_knowledge_content").
KNOWLEDGE_FILE = "knowledge.json"
# Note: The main `bot_activity.log` text file is now primarily a fallback if
# the DatabaseLogHandler in `src/utils/logger.py` is disabled or fails.
# The primary log sink is now the SQLite database's `logs` table.
# The `log_forwarder.py` script reads from this DB table.
# --- User-Agent Configuration (Optional) ---
# Set to True to use the FIXED_USER_AGENT_STRING below.
# If False, a random user-agent will be generated for each cycle.
USE_FIXED_USER_AGENT = False
# The string to use if USE_FIXED_USER_AGENT is True.
# Useful for debugging or if you need a consistent User-Agent.
FIXED_USER_AGENT_STRING = "MyCustomRedditBot/1.0 (Contact: yourusername@example.com)"
# --- Timing Configuration ---
# Cooldown after a full action cycle (or two failed attempts). Values in minutes.
COOLDOWN_MIN_MINUTES = 15
COOLDOWN_MAX_MINUTES = 40
# Short random delay (in seconds) after loading a post before replying. Simulates "reading".
READING_DELAY_MIN_SECONDS = 4
READING_DELAY_MAX_SECONDS = 18
# Short random delay (in seconds) after a successful post/comment before checking for immediate replies.
POST_ACTION_REPLY_CHECK_DELAY_MIN_SECONDS = 20 # e.g., 20 seconds
POST_ACTION_REPLY_CHECK_DELAY_MAX_SECONDS = 120 # e.g., 2 minutes
# Limit for the immediate reply check performed after a successful comment or post
# by the bot. This defines how many of the bot's own un-checked comments
# (ordered by recency, usually the one just posted or older un-checked ones)
# are scanned for new user replies during this quick follow-up.
# - Set to 1 (default) for a very fast check focusing on the most likely candidate.
# - Higher values (e.g., 2-3) are more thorough for the immediate follow-up
# but will make this part of the action cycle take slightly longer.
# This does not affect the limit if "check_replies" were a main weighted action.
IMMEDIATE_REPLY_CHECK_LIMIT = 2
class Validation:
"""
Validation checks to ensure critical configuration values are present before starting.
"""
@staticmethod
def validate_config():
"""Checks if critical configuration values are set."""
if not ApiConfig.GEMINI_API_KEY or "YOUR_GEMINI_API_KEY_HERE" in ApiConfig.GEMINI_API_KEY:
return False, "GEMINI_API_KEY is not set in config.py. Please obtain one from Google AI Studio."
if not ApiConfig.REDDIT_ACCOUNTS or not ApiConfig.REDDIT_ACCOUNTS[0].get("username") \
or "YOUR_REDDIT_USERNAME" in ApiConfig.REDDIT_ACCOUNTS[0]["username"]:
return False, "REDDIT_ACCOUNTS is not configured correctly in config.py. Ensure at least one account with all fields is provided."
# Check action weights
if not BotStrategy.ACTION_WEIGHTS:
return False, "ACTION_WEIGHTS in BotStrategy is empty. Bot will do nothing."
if sum(BotStrategy.ACTION_WEIGHTS.values()) <= 0: # Check if sum is positive
return False, "Sum of ACTION_WEIGHTS must be positive. Bot will do nothing."
# Check essential target subreddits
if not BotStrategy.TARGET_SUBREDDITS:
log.warning("TARGET_SUBREDDITS list is empty. The bot will have nowhere for general interaction.")
# Not a fatal error, but a strong warning. Bot might still deploy knowledge if KNOWLEDGE_DEPLOYMENT_SUBREDDITS is set.
return True, "Configuration is valid."