Skip to content

Commit e7beb80

Browse files
committed
@foxlet, hows this?
1 parent 70cc5ad commit e7beb80

1 file changed

Lines changed: 29 additions & 17 deletions

File tree

plugins/wyr.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,54 @@
33
from cloudbot import hook
44

55
API_URL = "http://www.rrrather.com/botapi"
6+
FILTERED_TAGS = ('rape', 'gross', 'sex')
7+
8+
9+
def get_wyr(headers):
10+
r = requests.get(url=API_URL, headers=headers)
11+
data = r.json()
12+
13+
# clean up text
14+
data['title'] = data['title'].strip().capitalize().rstrip('.?,')
15+
data['choicea'] = data['choicea'].strip().lower().rstrip('.?,!').lstrip('.')
16+
data['choiceb'] = data['choiceb'].strip().lower().rstrip('.?,!').lstrip('.')
17+
18+
if data['tags']:
19+
data['tags'] = data['tags'].lower().split(',')
20+
else:
21+
data['tags'] = []
22+
23+
return data
624

725

826
@hook.command("wyr", "wouldyourather")
927
def wyr(bot):
1028
headers = {"User-Agent": bot.user_agent}
1129

12-
r = requests.get(url=API_URL, headers=headers)
13-
data = r.json()
30+
while True:
31+
data = get_wyr(headers)
1432

15-
# clean up text
16-
title = data['title'].strip().capitalize().rstrip('.?,')
17-
choice1 = data['choicea'].strip().lower().rstrip('.?,!').lstrip('.')
18-
choice2 = data['choiceb'].strip().lower().rstrip('.?,!').lstrip('.')
19-
link = data['link']
33+
if [i for i in FILTERED_TAGS if i in data['tags']]:
34+
continue
35+
else:
36+
break
2037

2138
# get a list of all the words in the answers
22-
text = choice1.split() + choice2.split()
39+
text = data['choicea'].split() + data['choiceb'].split()
2340
text = [word for word in text if word != "a"]
2441

25-
title_text = title.split()
26-
27-
print(str(title_text))
28-
print(str(text))
42+
title_text = data['title'].split()
2943

3044
dupl_count = 0
3145

3246
for word in title_text:
3347
dupl_count += text.count(word)
3448

35-
print(str(dupl_count / len(text)))
36-
37-
title = title.replace(" u ", " you ")
49+
data['title'] = data['title'].replace(" u ", " you ")
3850

3951
# detect if the answers are also in the question
4052
# if so, replace question with a generic one
4153
if dupl_count / len(text) >= 0.6:
42-
title = "Would you rather"
54+
data['title'] = "Would you rather"
4355

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

0 commit comments

Comments
 (0)