-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolicies.py
113 lines (98 loc) · 5.15 KB
/
Policies.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
"""
Policies controlling the various actions and responses of the Central Scruitinzer
"""
import Actions
import datetime
import logging
class DefaultPolicy(object):
"""
Historical_Scan_On_New_Database -- if true the bot will populate the database based on the last 900 (available) posts
Scan_Sub_Period -- the wait period (in seconds) between subreddit scans
Pause_Period -- the wait period (in seconds) when the bot is paused
Posts_To_Load -- how many posts to load on a normal scan
Unread_To_Load -- how many unread messages to load on a normal scan
Threads -- how many multiprocessing threads may be used
Max_Retries -- how many retries to use
Retry_Multiplier -- the post multiplier for each retry
Mod_Update_Period -- the frequency of moderator list updates
Errors_Before_Halt -- number of errors before requesting a pause
on_blacklist -- the action to take for a blacklisted post
on_whitelist -- the action to take for a blacklisted post
Blacklist_Query_Period -- the time to wait between BlacklistQuery scans
debug_info -- a method that writes debug messages to a desired place
"""
def __init__(self, homesub):
self.homesub = homesub
def format_viewcount(self, poster, reddit_link, website, viewcount, limit):
return 'All apologies /u/{} but your post has been automatically removed because the artist has too many {} plays. The maximum is {}, this link has {}. \n'.format(poster, website, limit, viewcount) + \
'If you think this is in error, please [contact the mods](https://www.reddit.com/message/compose?to=/r/listentothis&subject=Post+removed+in+error.&message={}. If you\'re new to the subreddit, please read the [full list of removal reasons](https://www.reddit.com/r/listentothis/wiki/removalreasons). \n'.format(reddit_link) + \
'Don\'t blame me, [I\'m just a bot](https://www.youtube.com/watch?v=ljnT49jU9vM).'
def remove_and_post(self, post, comment):
Actions.remove_post(self, post)
Actions.make_comment(post, comment, dist=True)
Historical_Scan_On_New_Database = True
Historical_Scan_On_Startup = False #now handled by it's own object
Scan_Sub_Period = 5 * 60 #seconds
Pause_Period = 5 * 60 #seconds
Scan_Error_Pause = 5 * 60 #second
Posts_To_Load = 25
Unread_To_Load = 10
Mod_Update_Period = datetime.timedelta(days=1)
Threads = 4
Max_Retries = 3
Retry_Multiplier = 2
Errors_Before_Halt = 3
Blacklist_Query_Period = 60 #seconds
Strike_Counter_Scan_History = datetime.timedelta(days=365 * 2) #total history of two years
Strike_Counter_Global_Strike_History = datetime.timedelta(days=180) #global strike counts only go back 6 months
Strike_Counter_Frequency = 12 * 60 * 60 #every 12 hrs
on_blacklist = Actions.remove_post
on_whitelist = lambda x, y: logging.info("Whitelisting {}".format(y.name)) #Actions.approve_post
youtube_viewcount_limit = 500000
soundcloud_viewcount_limit = 500000
exception_list = []
def on_viewcount(self, post, website, viewcount, limit):
self.remove_and_post(post, self.format_viewcount(Actions.get_username(post), post.shortlink, website, viewcount, limit))
Strike_Count_Max = 10 #global strike limit across all users
User_Strike_Count_Max = 3 #user strike limit
Use_Reddit_Analytics_For_Historical_Scan = False #much more detailed history (normally), currently RA seems offline
Historial_Scan_Period = 24 * 60 * 60 # 1 day
force_recount = False
def debug(self, message, text=u""):
logging.debug(message + u"\t" + text)
def debug_url(self, message, url=u""):
logging.debug(message + u"\t" + url)
def info(self, message, text=u""):
logging.info(message + u"\t" + text)
def info_url(self, message, url=u""):
logging.debug(message + u"\t" + url)
class DebugPolicy(DefaultPolicy):
def __init__(self, homesub, altsub):
super(DebugPolicy, self).__init__(homesub)
self.on_blacklist = lambda post: Actions.xpost(post, altsub, "blacklist")
self.on_whitelist = lambda post: Actions.xpost(post, altsub, "whitelist")
self.altsub = altsub
def debug(self, message, text=u""):
logging.debug(message + u"\t" + text )
if __debug__:
if text == u'':
text = u'This has been a test of the Central Scruuuuutinizer'
Actions.make_post_text(self.altsub, message, text)
def debug_url(self, message, url=u''):
logging.debug(message + u"\t" + url)
if __debug__:
if url.startswith(u"t3_"):
url = u"http://redd.it/{}".format(url[3:])
Actions.make_post_url(self.altsub, message, url)
def info(self, message, text=u''):
logging.info(message)
if __debug__:
if text == u'':
text = u'This has been a test of the Central Scruuuuutinizer'
Actions.make_post_text(self.altsub, message, text)
def info_url(self, message, url=u""):
logging.info(message)
if __debug__:
if url.startswith(u"t3_"):
url = u"http://redd.it/{}".format(url[3:])
Actions.make_post_url(self.altsub, message, url)