X-Git-Url: https://plomlompom.com/repos/?p=plomlombot-irc.git;a=blobdiff_plain;f=plomlombot.py;h=6f6d33994255504e2ac4903cbe254d623db5fbdc;hp=7bf2208ab94a71774b4f1b7c6a49cf0e58661ad0;hb=93ee629ccea3331cda8ed6f0b7072381c92c626c;hpb=3c640fc4f1d19ac34cf871eb32369b90d9381a8c diff --git a/plomlombot.py b/plomlombot.py index 7bf2208..6f6d339 100755 --- a/plomlombot.py +++ b/plomlombot.py @@ -162,7 +162,7 @@ def handle_command(command, argument, notice, target, session): notice("QUOTE #" + str(i + 1) + ": " + lines[i]) def markov(): - from random import choice + from random import choice, shuffle select_length = 2 selections = [] @@ -196,9 +196,10 @@ def handle_command(command, argument, notice, target, session): lines = file.readlines() file.close() tokens = [] + sentence_end_markers = ".!?)(" for line in lines: line = line.lower().replace("\n", "") - if line[-1] not in ".!?": + if line[-1] not in sentence_end_markers: line += "." tokens += line.split() if len(tokens) <= select_length: @@ -225,6 +226,7 @@ def handle_command(command, argument, notice, target, session): # For each snippet of select_length, use markov() to find continuation # token from selections. Replace present users' names with malkovich. + # Start snippets with the beginning of a sentence, if possible. for i in range(len(tokens) - select_length): token_list = [] for j in range(select_length + 1): @@ -233,6 +235,12 @@ def handle_command(command, argument, notice, target, session): snippet = [] for i in range(select_length): snippet += [""] + shuffle(selections) + for i in range(len(selections)): + if selections[i][0][-1] in sentence_end_markers: + for i in range(select_length): + snippet[i] = selections[i][i + 1] + break msg = "" malkovich = "malkovich" while 1: @@ -314,7 +322,7 @@ def handle_url(url, notice, show_url=False): return if mobile_twitter_hack(url): return - title = bs4.BeautifulSoup(r.text, "html.parser").title + title = bs4.BeautifulSoup(r.text, "html5lib").title if title: prefix = "PAGE TITLE: " if show_url: