-
Notifications
You must be signed in to change notification settings - Fork 1
/
AchievementHandler.py
216 lines (203 loc) · 5.5 KB
/
AchievementHandler.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
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
class AchievementHandler():
def __init__(self,name,sub,coll):
self.coll = coll
self.name = name
self.sub = sub
def get_record(self):
record = coll.find_one({"name":self.name,"sub":self.sub})
if(record):
return record
else:
record = {
"name":self.name,
"sub":self.sub,
"notifications":0,
"replies":0,
"config":0,
"mentions":{},
"gilded":False,
"mod":False,
"admin":False,
"controversial":False
}
return coll.insert_one(record)
def save_record(self,record):
coll.update({"name":self.name,"sub":self.sub},record,upsert=False)
def user_mention(self,user):
record = get_record()
try:
record['mentions']['user']+=1
except KeyError:
record['mentions']['user'] = 1
save_record(record)
value = record['mentions']['user']
if(value==10):
return {
'type':'Single-User',
'name':"Obsession I",
'description': "/u/"+user+" has mentioned your subreddit "+str(value)+" times."
}
elif(value==25):
return {
'type':'Single-User',
'name':"Obsession II",
'description': "/u/"+user+" has mentioned your subreddit "+str(value)+" times."
}
elif(value==50):
return {
'type':'Single-User',
'name':"Obsession III",
'description': "/u/"+user+" has mentioned your subreddit "+str(value)+" times."
}
elif(value==100):
return {
'type':'Single-User',
'name':"Obsession IV",
'description': "/u/"+user+" has mentioned your subreddit "+str(value)+" times."
}
else:
return None
def add_notification(self):
record = get_record
record['notifications']+=1
save_record(record)
value = record['notifications']
if(value==10):
return {
'type':'Notifications',
'name':'Ears Burning I',
'description':"You have received "+str(value)+" notifications."
}
elif(value==100):
return {
'type':'Notifications',
'name':'Ears Burning II',
'description':"You have received "+str(value)+" notifications."
}
elif(value==1000):
return {
'type':'Notifications',
'name':'Ears Burning III',
'description':"You have received "+str(value)+" notifications."
}
elif(value==5000):
return {
'type':'Notifications',
'name':'Ears Burning IV',
'description':"You have received "+str(value)+" notifications."
}
else:
return None
def add_reply(self):
record = get_record()
record['replies']+=1
save_record(record)
#Check value and return possible achievement
value = record['replies']
if(value==5):
return {
'type':'Reply',
'name':'Chatty I',
'description':"You have sent "+str(value)+" replies to subreddit notifications."
}
elif(value==50):
return {
'type':'Reply',
'name':'Chatty II',
'description':"You have sent "+str(value)+" replies to subreddit notifications."
}
elif(value==500):
return {
'type':'Reply',
'name':'Chatty III',
'description':"You have sent "+str(value)+" replies to subreddit notifications."
}
elif(value==5000):
return {
'type':'Reply',
'name':'Chatty IV',
'description':"You have sent "+str(value)+" replies to subreddit notifications."
}
elif(value==10000):
return {
'type':'Reply',
'name':'Chatty V',
'description':"You have sent "+str(value)+" replies to subreddit notifications."
}
else:
return None
def add_config(self):
record = get_record()
record['config']+=1
save_record(record)
#Check value and return possible achievement
value = record['config']
if(value==5):
return {
'type':'Config',
'name':'Stay With The Times I',
'description':"You have updated the config "+str(value)+" times."
}
elif(value==10):
return {
'type':'Config',
'name':'Stay With The Times II',
'description':"You have updated the config "+str(value)+" times."
}
elif(value==50):
return {
'type':'Config',
'name':'Stay With The Times III',
'description':"You have updated the config "+str(value)+" times."
}
elif(value==100):
return {
'type':'Config',
'name':'Stay With The Times IV',
'description':"You have updated the config "+str(value)+" times."
}
else:
return None
def flag_gilded(self):
record = get_record()
if(not record['gilded']):
record['gilded'] = True
save_record(record)
#Return achievement
return {
'type':'Gild',
'name':'Golden Mention',
'description':'Your subreddit has been mentioned in a gilded comment.'
}
def flag_mod(self):
record = get_record()
if(not record['mod']):
record['mod'] = True
save_record(record)
return {
'type':'Mod',
'name':'Mod Mention',
'description':'Your subreddit has been mentioned by a distinguished moderator comment.'
}
def flag_admin(self):
record = get_record()
if(not record['admin']):
record['admin'] = True
save_record(record)
#Return achievement
return {
'type':'Admin',
'name':'Serious Business',
'description':'Your subreddit has been mentioned by a distinguished administrator comment.'
}
def flag_controversial(self):
record = get_record()
if(not record['controversial']):
record['controversial'] = True
save_record(record)
#Return achievement
return {
'type':'Controversial',
'name':'Not The Best PR',
'description':'Your subreddit has been mentioned in a controversial comment.'
}