diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2019-01-01 12:27:43 +0000 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2019-01-01 12:27:43 +0000 |
commit | 40793ed909c97eaf03c9aa4dbf9dba75e33f10e6 (patch) | |
tree | d0d1613a5d64697ff68560c02c74f0ef256996ef | |
parent | 7d50f8192ebd000a7a0b5a2b70dc62fb305d78e0 (diff) | |
parent | bebe783ec55d789b11343a621acc9c89df91a673 (diff) | |
download | SmallYTChannelBot-40793ed909c97eaf03c9aa4dbf9dba75e33f10e6.tar.gz SmallYTChannelBot-40793ed909c97eaf03c9aa4dbf9dba75e33f10e6.zip |
Merge branch 'master' of https://github.com/jwansek/SmallYTChannelBotSubmissions
-rw-r--r-- | SmallYTChannelBotSubmissions.py | 54 | ||||
-rw-r--r-- | database.py | 6 |
2 files changed, 45 insertions, 15 deletions
diff --git a/SmallYTChannelBotSubmissions.py b/SmallYTChannelBotSubmissions.py index 965258c..fa8f209 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): @@ -124,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/)" @@ -138,7 +138,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 +166,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) @@ -192,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: @@ -203,18 +224,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) diff --git a/database.py b/database.py index 0048296..26b8e43 100644 --- a/database.py +++ b/database.py @@ -87,3 +87,9 @@ class Database: def get_stats(self): self.cursor.execute("SELECT * FROM stats;") return self.cursor.fetchall() + + def user_given_lambda(self, user, permalink): + links = self.get_lambda(user)[1] + return permalink in links or permalink.replace("https://www.reddit.com", "") in links + + |