-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (35 loc) · 1.47 KB
/
main.py
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
import praw, requests, json
# Initialize the Reddit instance with your credentials
reddit = praw.Reddit(
client_id='yclient_id',
client_secret='your_client_secret',
user_agent='your_user_agent'
)
url = 'https://api.gptzero.me/v2/predict/text'
headers = {
'x-api-key': 'gptzero_api_key'
}
# Define the subreddit where the bot will monitor comments
subreddit = reddit.subreddit('subreddit')
# Define the bot's behavior when it detects a "!checkAI" reply
def check_ai_reply(comment):
# Check if the comment is a reply to a command
if comment.is_root:
return
parent_comment = comment.parent()
# Check if the parent comment contains the "!checkAI" command
if parent_comment.body.startswith('!checkAI'):
# Extract the message content from the parent comment
message_content = parent_comment.body[len('!checkAI'):].strip()
print(f'Message content from comment {parent_comment.id}: {message_content}')
body = {
'document': message_content
}
response = requests.post(url, headers=headers, data=json.dumps(body))
if response.status_code == 200:
response_data = response.json()
average_generated_prob = response_data['documents'][0]['average_generated_prob']
comment.reply(f'Parent message contains {average_generated_prob*100}% AI generated code')
# Monitor the subreddit for new comments
for comment in subreddit.stream.comments():
check_ai_reply(comment)