-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
114 lines (81 loc) · 3.31 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
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
import praw
import os
import time
import random
from web import keep_alive
answer_list = [
"You're fired",
"$8 please",
"I've laid off most of the staff, and Twitter's still running. Looks like they weren't necessary.",
"You look stupid. Fired.",
"If you really love the company, you should be willing to work here for free.",
"You're fired, now pay me $8",
"I only bought twitter so i wouldnt get bullied anymore",
"What do you mean, You cant work 80 hours a week ?",
"Why have you only written 69 lines of code today?",
"What do you mean: you couldnt code your way out of a paper bag?",
"Disagreeing with me is counterproductive. Fired.",
"I think i am going to buy reddit",
"The secret to success is to fail fast and learn from your mistakes.",
"I don't care about your feelings. I care about facts and logic.",
"The best way to predict the future is to invent it.",
"Don't let anyone tell you what you can or can't do. Unless it's me.",
"I'm not a billionaire. I'm a visionary.",
"The only thing that matters is innovation. And memes.",
"There is no such thing as a bad idea. Except yours.",
"Twitter is my personal diary.",
"I dont follow anyone on twitter because I dont need their opinions.",
"Twitter is the best place to test my ideas and see how people react.",
"Sometimes I tweet just to mess with people's minds.",
"Twitter is like a game for me. The more likes and retweets I get, the more points I score.",
"Twitter is where I announce my plans for world domination."
]
trigger_list = [
"Elon Musk", "elon musk", "Elon musk", "Elon Tusk", "elon tusk",
"Space Karen", "space karen", "u/ElonMusk_bot", "elon-bot", "twitter",
"Twitter", "elon"
]
sub = "ProgrammerHumor"
def bot_login():
reddit = praw.Reddit(client_id="",
client_secret="",
username="",
password="",
user_agent="")
return reddit
def run_bot(reddit, comments_replied_to):
print("Searching last 1,000 comments")
for comment in reddit.subreddit(sub).comments(limit=1000):
res = any(ele in comment.body for ele in trigger_list)
if res == True and comment.id not in comments_replied_to and comment.author != reddit.user.me(
):
print("String with trigger found in comment " + comment.id + "\n")
answer = random.choice(answer_list)
comment.reply(answer)
print("Replied to comment " + comment.id + "\n" + answer)
comments_replied_to.append(comment.id)
with open("comments_replied_to.txt", "a") as f:
f.write(comment.id + "\n")
keep_alive()
sleep()
else:
print("No Comment found, restarting")
print("\nSearch Completed.")
print(comments_replied_to)
def sleep():
print("\nSleeping for 10 min...")
time.sleep(600)
def get_saved_comments():
if not os.path.isfile("comments_replied_to.txt"):
comments_replied_to = []
else:
with open("comments_replied_to.txt", "r") as f:
comments_replied_to = f.read()
comments_replied_to = comments_replied_to.split("\n")
comments_replied_to = [_f for _f in comments_replied_to if _f]
return comments_replied_to
reddit = bot_login()
comments_replied_to = get_saved_comments()
print(comments_replied_to)
while True:
run_bot(reddit, comments_replied_to)