Skip to content

Commit 1384bce

Browse files
committed
Improve wyr formatting
1 parent 804fcc7 commit 1384bce

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

plugins/wyr.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@
22

33
from cloudbot import hook
44

5-
headers = {'User-Agent': 'CloudBot/dev 1.0 - CloudBot Refresh by lukeroge'}
5+
API_URL = "http://www.rrrather.com/botapi"
66

7-
@hook.command
8-
def wyr(text, message):
9-
url = "http://www.rrrather.com/botapi"
107

11-
r = requests.get(url, headers=headers)
8+
@hook.command("wyr", "wouldyourather")
9+
def wyr(bot):
10+
headers = {"User-Agent": bot.user_agent}
11+
12+
r = requests.get(url=API_URL, headers=headers)
1213
data = r.json()
13-
title = data['title'].strip().capitalize()
14-
title = title.rstrip('.?')
15-
choice1 = data['choicea'].strip().lower()
16-
choice1 = choice1.rstrip('.?')
17-
choice2 = data['choiceb'].strip().lower()
18-
choice2 = choice2.rstrip('.?')
14+
15+
# decrapify text
16+
title = data['title'].strip().capitalize().rstrip('.?,')
17+
choice1 = data['choicea'].strip().lower().rstrip('.?,!').lstrip('.')
18+
choice2 = data['choiceb'].strip().lower().rstrip('.?,!').lstrip('.')
1919
link = data['link']
2020

21-
text = "{} {}".format(choice1, choice2).split()
22-
text = [ word for word in text if word != "a" ]
21+
# get all the words in the answers
22+
text = choice1.split() + choice2.split()
23+
text = [word for word in text if word != "a"]
2324

2425
title_text = title.split()
2526

26-
#message(str(title_text))
27-
#message(str(text))
27+
print(str(title_text))
28+
print(str(text))
2829

2930
dupl_count = 0
3031

3132
for word in title_text:
3233
dupl_count += text.count(word)
3334

34-
#message(str(dupl_count / len(text)))
35+
print(str(dupl_count / len(text)))
3536

36-
if title.lower() == "would u rather":
37-
title = "Would you rather"
37+
title = title.replace(" u ", " you ")
3838

39+
# detect if the answers are also in the question
40+
# if so, replace question with a generic one
3941
if dupl_count / len(text) >= 0.6:
4042
title = "Would you rather"
41-
else:
42-
pass
4343

44-
return "{}... {} \x02OR\x02 {}? - {}".format(title, choice1, choice2, link)
44+
return "{}... {} \x02OR\x02 {}? - {}".format(title, choice1, choice2, link)

0 commit comments

Comments
 (0)