def test_id_from_url__invalid_urls(self): urls = ['', '1', '/', 'my.it/2gmzqe', 'http://my.it/_', 'https://redd.it/_/', 'http://reddit.com/comments/_/2gmzqe', 'http://my.it/2gmzqe', 'https://redd.it/2gmzqe', 'http://reddit.com/comments/2gmzqe', 'https://www.reddit.com/r/redditdev/comments/2gmzqe/'] for url in urls: with pytest.raises(ClientException): Comment.id_from_url(url)
def test_id_from_url(self): urls = ['http://reddit.com/comments/2gmzqe/_/cklhv0f/', 'https://reddit.com/comments/2gmzqe/_/cklhv0f', 'http://www.reddit.com/r/redditdev/comments/2gmzqe/_/cklhv0f/', 'https://www.reddit.com/r/redditdev/comments/2gmzqe/_/cklhv0f'] for url in urls: assert Comment.id_from_url(url) == 'cklhv0f', url
def test_id_from_url__invalid_urls(self): urls = [ "", "1", "/", "my.it/2gmzqe", "http://my.it/_", "https://redd.it/_/", "http://reddit.com/comments/_/2gmzqe", "http://my.it/2gmzqe", "https://redd.it/2gmzqe", "http://reddit.com/comments/2gmzqe", "https://www.reddit.com/r/redditdev/comments/2gmzqe/", ] for url in urls: with pytest.raises(ClientException): Comment.id_from_url(url)
def test_id_from_url(self): urls = [ "http://reddit.com/comments/2gmzqe/_/cklhv0f/", "https://reddit.com/comments/2gmzqe/_/cklhv0f", "http://www.reddit.com/r/redditdev/comments/2gmzqe/_/cklhv0f/", "https://www.reddit.com/r/redditdev/comments/2gmzqe/_/cklhv0f", ] for url in urls: assert Comment.id_from_url(url) == "cklhv0f", url
async def on_message(message): server = message.server author = message.author name = get_disc_name(author) if message.channel.id == config.VERIFICATION_CHANNEL and message.content.startswith( "!verify"): logging.debug("Verify started by {}".format(name)) arguments = message.content.split(" ") if len(arguments) < 2: await log("No URL from %user%", author) await answer(message, "Usage: !verify <cckufi comment url>") return if name in discord_blacklist: await log( "Blacklisted discord user %user% just tried to register!", author) await answer(message, "Invalid URL!") return raw_url = arguments[1] url = url_fix(raw_url) if not url.startswith(config.POST_URL): await log("Invalid URL from %user%", author) await answer(message, "Invalid URL!") return comment_id = Comment.id_from_url(url) logging.debug("Reading comment {}".format(comment_id)) comment = get_comment(comment_id) if comment is None: await log( "User %user% linked comment {} which does not exist".format( comment_id), author) await answer(message, "that comment does not exist!") return reddit_user = comment.author reddit_name = reddit_user.name if reddit_name in reddit_blacklist: await log( "Blacklisted reddit user {} (discord %user%) just tried to register!" .format(reddit_name), author) await answer( message, "that comment does not just contain your discord ID!") return comment_body = comment.body if comment_body.startswith(name): # Check CoT submissions members, joined, betrayed = analyze_circle_flair( reddit, reddit_user, cot) if not members: await log( "Denied discord user %user% (reddit {}), they haven't posted on CoT" .format(reddit_name), author) await answer( message, "you must have posted or commented on /r/CircleofTrust to be verified." ) return if betrayed: await log( "Denied discord user %user% (reddit {}), they have betrayed!" .format(reddit_name), author) await answer( message, "you have betrayed {} times! Please ask for manual verification." .format(joined)) return await client.change_nickname(author, "/u/{}".format(reddit_name)) await client.add_roles(author, verified_role) await log("Verified %user%, member of {} circles".format(joined), author) await answer(message, "you have been successfully verified!") else: await log( "Comment does not start with their discord ID: {}, got '{}' instead." .format(url, comment_body)) await answer(message, "that comment does not start with your discord ID!") elif message.content.startswith("!flair"): logging.debug("Circle command ran by {}".format(name)) arguments = message.content.split(" ") if len(arguments) < 2: await answer(message, "Usage !circles <reddit user>") return logging.info(arguments[1]) reddit_name = arguments[1] # Check for discord mentions discord_id = re.search(r"<@!(\d{17})>", arguments[1]) if discord_id: discord_user = server.get_member(discord_id.group(1)) logging.info(discord_user) if discord_user: reddit_name = discord_user.name logging.info(reddit_name) reddit_name = re.sub(r"(@?/?u/)", "", reddit_name) reddit_user = Redditor(reddit, name=reddit_name) members, joined, betrayed = analyze_circle_flair( reddit, reddit_user, cot) if not members: await log( "Lookup by %user% for {} failed, they haven't posted on CoT". format(reddit_name), author) await answer(message, "that user has not posted on /r/CircleofTrust.") return await log("Lookup by %user% for {}.".format(reddit_name), author) await answer( message, "Users in circle: {}, member of circles: {}".format( members, joined) + (" BETRAYER!" if betrayed else "")) return