From 824ebfd153bf8e63a812ec2b9145bf49c8285435 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 16 Dec 2018 16:11:43 +0000 Subject: added files --- SmallYTChannelBotSubmissions.py | 166 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 SmallYTChannelBotSubmissions.py (limited to 'SmallYTChannelBotSubmissions.py') diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py new file mode 100644 index 0000000..cb1dc21 --- /dev/null +++ b/SmallYTChannelBotSubmissions.py @@ -0,0 +1,166 @@ +from operator import itemgetter +from database import Database +import datetime +import login +import time +import praw +import re + +reddit = login.REDDIT + +subreddit = reddit.subreddit("SmallYTChannel") +#subreddit = reddit.subreddit("jwnskanzkwktest") +db = Database() + +def get_lambda_from_flair(s): + result = re.search("\[(.*)\]", s) + if result is not None and "λ" in result.group(1): + return result.group(1) + else: + return "" + +def update_users_flair(comment): + username = str(comment.author) + flairscore = get_lambda_from_flair(str(comment.author_flair_text)) + flairtext = comment.author_flair_text + if flairtext is None: + flairtext = "" + else: + flairtext = str(flairtext.replace("[%s] " % flairscore, "")) + if username in [str(i) for i in subreddit.moderator()] + ["AutoModerator"]: + newflair = "[∞λ] %s" % (flairtext) + else: + actualscore = db.get_lambda(username)[0] + newflair = "[%iλ] %s" % (actualscore, flairtext) + subreddit.flair.set(redditor = username, text = newflair) + +def get_mods(): + return [str(i) for i in subreddit.moderator()] + ["AutoModerator"] + +def update_tables(): + content = "" + date = str(datetime.date.today()) + mods = get_mods() + data = db.get_scores() + bylambda = [i for i in sorted(data, key = itemgetter(1), reverse = True) if i[0] not in mods][:10] + byhelps = sorted(data, key = itemgetter(2), reverse = True)[:10] + + content += "\n\n#/r/SmallYTChannel lambda tables: %s" % date + + content += "\n\n##By lambda:" + content += "\n\nUsername|Lambda|Help given\n:--|:--|:--" + for line in bylambda: + content += "\n/u/%s|%i|%i" % (line[0], line[1], line[2]) + + content += "\n\n##By Help given:" + content += "\n\nUsername|Lambda|Help given\n:--|:--|:--" + for line in byhelps: + λ = str(line[1]) + if line[0] in mods: + λ = "∞" + content += "\n/u/%s|%s|%i" % (line[0], λ, line[2]) + + subreddit.wiki["lambdatables"].edit(content, reason = "Update: %s" % date) + +def main(): + tail = "\n\n\n ^/u/SmallYTChannelBot ^*made* ^*by* ^/u/jwnskanzkwk. ^*PM* ^*for* ^*bug* ^*reports.* ^*For* ^*more* ^*information,* ^*read* ^*the* ^[FAQ.](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)" + + comment_stream = subreddit.stream.comments(pause_after=-1) + submission_stream = subreddit.stream.submissions(pause_after=-1) + while True: + try: + for comment in comment_stream: + if comment is None: + break + if not db.id_in_blacklist(comment.id): + db.add_to_blacklist(comment.id) + + if "!mylambda" in comment.body and str(comment.author) != "SmallYTChannelBot": + author = str(comment.author) + λ, links = db.get_lambda(author) + if author in get_mods(): + text = "/u/%s is a moderator, and therefore has ∞λ." % author + else: + if λ == 0: + text = "/u/%s has 0λ." % author + else: + text = "/u/%s has %iλ, from helping the following posts:" % (author, λ) + count = 0 + for link in links: + if "www.reddit.com" not in link: + link = "https://www.reddit.com" + link + + #set a max limit on the number of times this will iterate to stop it + #breaking because of Reddit's character limit. + count += 1 + text += "\n\n- [%s](%s)" % (reddit.submission(url = link).title, link) + if count > 20: #experminent with this number + text += "\n\n[%i more...]" % len(links) - count + break + + reply = comment.reply(text + tail) + reply.mod.distinguish(sticky = False) + update_users_flair(comment) + + + if "!givelambda" in comment.body and str(comment.author) != "SmallYTChannelBot": + submission = comment.submission + parentauthour = str(comment.parent().author) + op = str(comment.author) + if op == parentauthour: + text = "You cannot give yourself λ." + elif op == "SmallYTChannelBot": + text = "Please only give lambda to humans." + elif op != str(submission.author): + text = "Only the OP can give λ." + elif comment.is_root: + text = "You can only give λ to top-level comments." + else: + print("'/u/%s' has given '/u/%s' lambda!" % (op, parentauthour)) + text = "You have given /u/%s 1λ. /u/%s now has %iλ" % (parentauthour, parentauthour, db.get_lambda(parentauthour)[0] + 1) + + if not db.link_in_db(submission.permalink) or not db.link_in_db(submission.permalink.replace("https://www.reddit.com", "")): + db.give_lambda(parentauthour, submission.permalink, op) + print("The OP has received lambda too!") + else: + db.give_lambda(parentauthour, submission.permalink) + + update_users_flair(comment) + update_users_flair(comment.parent()) + reply = comment.reply(text + tail) + reply.mod.distinguish() + + for submission in submission_stream: + if submission is None: + break + if not db.id_in_blacklist(submission.id): + db.add_to_blacklist(submission.id) + print("There has been a new submission: '%s', with flair '%s'" % (submission.title, submission.link_flair_text)) + + if str(submission.author) not in get_mods(): + score = db.get_lambda(str(submission.author))[0] + if submission.link_flair_text in ["Discussion", "Meta", "Collab"]: + text = "Your post is a discussion, meta or collab post so it costs 0λ." + else: + if score < 3: + text = """Thank you for submitting to /r/SmallYTChannel. Please be aware that soon you will need to have at least 3λ to submit here. + You currently have %iλ. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You will be rewarded 1λ if you + do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score, str(submission.author)) + #submission.mod.remove() + else: + #db.change_lambda(str(submission.author), -3) + text = """Thank you for submitting to /r/SmallYTChannel. You have spent 3λ to submit here, making your current balance %iλ. Soon + you will have to spend your λ to post here. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You + will be rewarded 1λ if you do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score, str(submission.author)) + + update_users_flair(submission) + reply = submission.reply(text + tail) + reply.mod.distinguish(sticky = True) + + except Exception as e: + print("[ERROR]\t%s" % e) + continue + +if __name__ == "__main__": + main() + -- cgit v1.2.3 From fcf50be2e34e0eb82fbd301e119f8873d2735cf9 Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 17 Dec 2018 16:37:46 +0000 Subject: added statistics --- SmallYTChannelBotSubmissions.py | 77 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 7 deletions(-) (limited to 'SmallYTChannelBotSubmissions.py') diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index cb1dc21..965258c 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -1,5 +1,10 @@ +from mpl_toolkits.axes_grid1 import host_subplot +import mpl_toolkits.axisartist as AA +from imgurpython import ImgurClient +import matplotlib.pyplot as plt from operator import itemgetter from database import Database +import matplotlib import datetime import login import time @@ -37,22 +42,51 @@ def update_users_flair(comment): def get_mods(): return [str(i) for i in subreddit.moderator()] + ["AutoModerator"] -def update_tables(): +def _make_graph(data): + fig = plt.figure() + + lambdaCount = [i[1] for i in data] + helpGiven = [i[2] for i in data] + uniqueUsers = [i[3] for i in data] + date = [datetime.datetime.strptime(i[4], "%Y-%m-%d") for i in data] + + fig, ax1 = plt.subplots() + ax1.plot(date, lambdaCount, label = "Total λ given", color = "r") + ax1.set_ylabel("Total λ / help given") + + ax1.plot(date, helpGiven, label = "Times help given", color = "g") + + ax2 = ax1.twinx() + ax2.plot(date, uniqueUsers, label = "Unique users") + ax2.set_ylabel("No. Unique Users") + + ax1.legend() + ax2.legend(loc = 4) + fig.autofmt_xdate() + + filepath = "graph.png" + fig.savefig(filepath) + return filepath + +def _update_tables(scores, data): content = "" date = str(datetime.date.today()) mods = get_mods() - data = db.get_scores() - bylambda = [i for i in sorted(data, key = itemgetter(1), reverse = True) if i[0] not in mods][:10] - byhelps = sorted(data, key = itemgetter(2), reverse = True)[:10] + imagepath = _make_graph(data) + imageurl = _upload_image(imagepath, date) + bylambda = [i for i in sorted(scores, key = itemgetter(1), reverse = True) if i[0] not in mods][:10] + byhelps = sorted(scores, key = itemgetter(2), reverse = True)[:10] - content += "\n\n#/r/SmallYTChannel lambda tables: %s" % date + subreddit.stylesheet.upload("wikigraph", imagepath) - content += "\n\n##By lambda:" + content += "\n\n##/r/SmallYTChannel lambda tables: %s" % date + + content += "\n\n###By lambda:" content += "\n\nUsername|Lambda|Help given\n:--|:--|:--" for line in bylambda: content += "\n/u/%s|%i|%i" % (line[0], line[1], line[2]) - content += "\n\n##By Help given:" + content += "\n\n###By Help given:" content += "\n\nUsername|Lambda|Help given\n:--|:--|:--" for line in byhelps: λ = str(line[1]) @@ -60,7 +94,36 @@ def update_tables(): λ = "∞" content += "\n/u/%s|%s|%i" % (line[0], λ, line[2]) + content += "\n\n##Statistics from %s:\n\n![](%%%%wikigraph%%%%)\n\nTotal λ given|Useful advice given|Unique users\n:--|:--|:--\n%i|%i|%i" % (date, data[-1][1], data[-1][2], data[-1][3]) + + reddit.subreddit("u_SmallYTChannelBot").submit("/r/SmallYTChannel Statistics: %s" % date, url = imageurl).reply(content).mod.distinguish(sticky = True) + subreddit.wiki["lambdatables"].edit(content, reason = "Update: %s" % date) + subreddit.wiki[date].edit(content, reason = "Update: %s" % date) + + currentdata = subreddit.wiki["index"].content_md + currentdata += "\n\n* [%s](/r/SmallYTChannel/wiki/%s)" % (date, date) + + subreddit.wiki["index"].edit(currentdata, reason = "Update: %s" % date) + +def _upload_image(path, date): + client = login.IMGUR + + config = { + 'album': None, + 'name': 'SmallYTChannelBot Statistics graph: %s' % date, + 'title': 'SmallYTChannelBot Statistics graph: %s' % date, + 'description': 'SmallYTChannelBot Statistics graph: %s' % date + } + + image = client.upload_from_path(path, config = config) + + return "https://i.imgur.com/%s.png" % image["id"] + +def every_day(): + db.update_stats() + _update_tables(db.get_scores(), db.get_stats()) + def main(): tail = "\n\n\n ^/u/SmallYTChannelBot ^*made* ^*by* ^/u/jwnskanzkwk. ^*PM* ^*for* ^*bug* ^*reports.* ^*For* ^*more* ^*information,* ^*read* ^*the* ^[FAQ.](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)" -- cgit v1.2.3 From 388d15fe0640bb50438fa2d3640b2f29bc07ada7 Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 31 Dec 2018 23:27:11 +0000 Subject: removed posts with insufficient lambda, etc. --- SmallYTChannelBotSubmissions.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'SmallYTChannelBotSubmissions.py') diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 965258c..38dd49a 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -13,8 +13,9 @@ import re reddit = login.REDDIT -subreddit = reddit.subreddit("SmallYTChannel") -#subreddit = reddit.subreddit("jwnskanzkwktest") +#subreddit = reddit.subreddit("SmallYTChannel") +subreddit = reddit.subreddit("jwnskanzkwktest") + db = Database() def get_lambda_from_flair(s): @@ -138,7 +139,7 @@ def main(): if not db.id_in_blacklist(comment.id): db.add_to_blacklist(comment.id) - if "!mylambda" in comment.body and str(comment.author) != "SmallYTChannelBot": + if "!mylambda" in comment.body.lower() and str(comment.author) != "SmallYTChannelBot": author = str(comment.author) λ, links = db.get_lambda(author) if author in get_mods(): @@ -166,18 +167,21 @@ def main(): update_users_flair(comment) - if "!givelambda" in comment.body and str(comment.author) != "SmallYTChannelBot": + if "!givelambda" in comment.body.lower() and str(comment.author) != "SmallYTChannelBot": submission = comment.submission parentauthour = str(comment.parent().author) op = str(comment.author) if op == parentauthour: text = "You cannot give yourself λ." - elif op == "SmallYTChannelBot": + elif parentauthour == "SmallYTChannelBot": text = "Please only give lambda to humans." + elif str(comment.author) in get_mods(): + text = "The moderator /u/%s has given /u/%s 1λ. /u/%s now has %iλ." % (str(comment.author), parentauthour, parentauthour, db.get_lambda(parentauthour)[0] + 1) + db.give_lambda(parentauthour, submission.permalink) elif op != str(submission.author): text = "Only the OP can give λ." - elif comment.is_root: - text = "You can only give λ to top-level comments." + elif db.user_given_lambda(parentauthour, str(submission.permalink)): + text = "You have already given /u/%s λ for this submission. Why not give λ to another user instead?" % parentauthour else: print("'/u/%s' has given '/u/%s' lambda!" % (op, parentauthour)) text = "You have given /u/%s 1λ. /u/%s now has %iλ" % (parentauthour, parentauthour, db.get_lambda(parentauthour)[0] + 1) @@ -203,18 +207,21 @@ def main(): if str(submission.author) not in get_mods(): score = db.get_lambda(str(submission.author))[0] if submission.link_flair_text in ["Discussion", "Meta", "Collab"]: - text = "Your post is a discussion, meta or collab post so it costs 0λ." + if "youtube.com" in str(submission.url): + text = "Your post has been removed because it has the wrong flair. [Discussion], [Meta] and [Collab] flairs are only for text submissions." + submission.mod.remove() + else: + text = "Your post is a discussion, meta or collab post so it costs 0λ." else: if score < 3: - text = """Thank you for submitting to /r/SmallYTChannel. Please be aware that soon you will need to have at least 3λ to submit here. - You currently have %iλ. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You will be rewarded 1λ if you - do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score, str(submission.author)) - #submission.mod.remove() + text = """Thank you for submitting to /r/SmallYTChannel. Unfortunally, you submission has been removed since you do not have enough λ. You need + 3λ to post. You currently have %iλ. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % score + submission.mod.remove() else: - #db.change_lambda(str(submission.author), -3) text = """Thank you for submitting to /r/SmallYTChannel. You have spent 3λ to submit here, making your current balance %iλ. Soon you will have to spend your λ to post here. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You - will be rewarded 1λ if you do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score, str(submission.author)) + will be rewarded 1λ if you do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score - 3, str(submission.author)) + db.change_lambda(str(submission.author), -3) update_users_flair(submission) reply = submission.reply(text + tail) -- cgit v1.2.3 From bebe783ec55d789b11343a621acc9c89df91a673 Mon Sep 17 00:00:00 2001 From: jwansek Date: Tue, 1 Jan 2019 12:27:10 +0000 Subject: added mod removal lambda --- SmallYTChannelBotSubmissions.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'SmallYTChannelBotSubmissions.py') diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 38dd49a..fa8f209 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -125,7 +125,6 @@ def every_day(): db.update_stats() _update_tables(db.get_scores(), db.get_stats()) - def main(): tail = "\n\n\n ^/u/SmallYTChannelBot ^*made* ^*by* ^/u/jwnskanzkwk. ^*PM* ^*for* ^*bug* ^*reports.* ^*For* ^*more* ^*information,* ^*read* ^*the* ^[FAQ.](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)" @@ -196,6 +195,24 @@ def main(): update_users_flair(comment.parent()) reply = comment.reply(text + tail) reply.mod.distinguish() + + if comment.body[:11] == "!takelambda" and str(comment.author) in get_mods(): + try: + splitted = comment.body.split() + user = splitted[1].replace("/u/", "") + toremove = int(splitted[2]) + reason = " ".join(splitted[3:]) + + text = "/u/%s has had %iλ taken away from them for the reason '%s'. /u/%s now has %iλ" % (user, toremove, reason, user, db.get_lambda(user)[0] - toremove) + db.change_lambda(user, -toremove) + except Exception as e: + print("[ERROR while removing λ] %s" % e) + text = r"An error was encountered. Please use the syntax `!givelambda [user] [how much to remove {integer}] [reason]`" + + update_users_flair(comment) + reply = comment.reply(text + tail) + reply.mod.distinguish() + for submission in submission_stream: if submission is None: -- cgit v1.2.3 From c8087aea0dbff1a2abf474a987465e817e5ad611 Mon Sep 17 00:00:00 2001 From: jwansek Date: Tue, 1 Jan 2019 12:34:50 +0000 Subject: fixed a bug and added archive prog --- SmallYTChannelBotSubmissions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'SmallYTChannelBotSubmissions.py') diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index fa8f209..2a58aae 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -207,7 +207,7 @@ def main(): db.change_lambda(user, -toremove) except Exception as e: print("[ERROR while removing λ] %s" % e) - text = r"An error was encountered. Please use the syntax `!givelambda [user] [how much to remove {integer}] [reason]`" + text = r"An error was encountered. Please use the syntax `!takelambda [user] [how much to remove {integer}] [reason]`" update_users_flair(comment) reply = comment.reply(text + tail) -- cgit v1.2.3 From d6e05c8118561980f5675e2a7d086d1bf60e3f8e Mon Sep 17 00:00:00 2001 From: jwansek Date: Tue, 1 Jan 2019 12:42:45 +0000 Subject: made a slight modification --- SmallYTChannelBotSubmissions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'SmallYTChannelBotSubmissions.py') diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 2a58aae..ed4a339 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -209,7 +209,7 @@ def main(): print("[ERROR while removing λ] %s" % e) text = r"An error was encountered. Please use the syntax `!takelambda [user] [how much to remove {integer}] [reason]`" - update_users_flair(comment) + update_users_flair(comment.parent()) reply = comment.reply(text + tail) reply.mod.distinguish() -- cgit v1.2.3 From b7b724c24220b9396e83787f6311082a9b6680e1 Mon Sep 17 00:00:00 2001 From: jwansek Date: Thu, 3 Jan 2019 13:59:38 +0000 Subject: fixed a tiny bug --- SmallYTChannelBotSubmissions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'SmallYTChannelBotSubmissions.py') diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index ed4a339..2a95c48 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -13,8 +13,8 @@ import re reddit = login.REDDIT -#subreddit = reddit.subreddit("SmallYTChannel") -subreddit = reddit.subreddit("jwnskanzkwktest") +subreddit = reddit.subreddit("SmallYTChannel") +#subreddit = reddit.subreddit("jwnskanzkwktest") db = Database() @@ -235,8 +235,8 @@ def main(): 3λ to post. You currently have %iλ. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % score submission.mod.remove() else: - text = """Thank you for submitting to /r/SmallYTChannel. You have spent 3λ to submit here, making your current balance %iλ. Soon - you will have to spend your λ to post here. /u/%s, please comment `!givelambda` to the most helpful advice you are given. You + text = """Thank you for submitting to /r/SmallYTChannel. You have spent 3λ to submit here, making your current balance %iλ. + /u/%s, please comment `!givelambda` to the most helpful advice you are given. You will be rewarded 1λ if you do so. For more information, read the [FAQ](https://www.reddit.com/user/SmallYTChannelBot/comments/a4u7qj/smallytchannelbot_faq/)""" % (score - 3, str(submission.author)) db.change_lambda(str(submission.author), -3) -- cgit v1.2.3 From 93c4146644ea2125fd13a971c456a9ffcf6a274d Mon Sep 17 00:00:00 2001 From: jwansek Date: Sun, 6 Jan 2019 20:43:49 +0000 Subject: added feature that restarts the program every two hours and fixed one bug --- SmallYTChannelBotSubmissions.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'SmallYTChannelBotSubmissions.py') diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 2a95c48..712f5b0 100644 --- a/SmallYTChannelBotSubmissions.py +++ b/SmallYTChannelBotSubmissions.py @@ -10,6 +10,7 @@ import login import time import praw import re +import os reddit = login.REDDIT @@ -18,6 +19,10 @@ subreddit = reddit.subreddit("SmallYTChannel") db = Database() +def get_time(): + #this is not the correct way to do this but I don't care + return str(datetime.datetime.now().time())[:8] + def get_lambda_from_flair(s): result = re.search("\[(.*)\]", s) if result is not None and "λ" in result.group(1): @@ -182,9 +187,9 @@ def main(): elif db.user_given_lambda(parentauthour, str(submission.permalink)): text = "You have already given /u/%s λ for this submission. Why not give λ to another user instead?" % parentauthour else: - print("'/u/%s' has given '/u/%s' lambda!" % (op, parentauthour)) + print("[%s] '/u/%s' has given '/u/%s' lambda!" % (get_time(), op, parentauthour)) text = "You have given /u/%s 1λ. /u/%s now has %iλ" % (parentauthour, parentauthour, db.get_lambda(parentauthour)[0] + 1) - + if not db.link_in_db(submission.permalink) or not db.link_in_db(submission.permalink.replace("https://www.reddit.com", "")): db.give_lambda(parentauthour, submission.permalink, op) print("The OP has received lambda too!") @@ -208,6 +213,9 @@ def main(): except Exception as e: print("[ERROR while removing λ] %s" % e) text = r"An error was encountered. Please use the syntax `!takelambda [user] [how much to remove {integer}] [reason]`" + reply = comment.reply(text + tail) + reply.mod.distinguish() + continue update_users_flair(comment.parent()) reply = comment.reply(text + tail) @@ -219,12 +227,12 @@ def main(): break if not db.id_in_blacklist(submission.id): db.add_to_blacklist(submission.id) - print("There has been a new submission: '%s', with flair '%s'" % (submission.title, submission.link_flair_text)) + print("[%s] There has been a new submission: '%s', with flair '%s'" % (get_time(), submission.title, submission.link_flair_text)) if str(submission.author) not in get_mods(): score = db.get_lambda(str(submission.author))[0] if submission.link_flair_text in ["Discussion", "Meta", "Collab"]: - if "youtube.com" in str(submission.url): + if "youtube.com" in str(submission.url) or "youtu.be" in str(submission.url): text = "Your post has been removed because it has the wrong flair. [Discussion], [Meta] and [Collab] flairs are only for text submissions." submission.mod.remove() else: @@ -249,5 +257,10 @@ def main(): continue if __name__ == "__main__": + #file = open("pid.txt", "w") + #file.write(str(os.getpid())) + #file.close() + + print("\n####################\n[%s] RESTARTED\n####################\n" % get_time()) main() -- cgit v1.2.3